Tomato 1.28
[tomato.git] / release / src / router / zebra / bgpd / bgp_route.c
blob954a9c985845179045826584729d1ffab800de58
1 /* Route object related function for route server.
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.
22 #include <zebra.h>
24 #include "prefix.h"
25 #include "table.h"
26 #include "linklist.h"
27 #include "memory.h"
28 #include "command.h"
29 #include "stream.h"
30 #include "filter.h"
31 #include "str.h"
32 #include "log.h"
33 #include "routemap.h"
34 #include "buffer.h"
35 #include "sockunion.h"
36 #include "plist.h"
37 #include "thread.h"
39 #include "bgpd/bgpd.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_clist.h"
45 #include "bgpd/bgp_community.h"
46 #include "bgpd/bgp_ecommunity.h"
47 #include "bgpd/bgp_packet.h"
48 #include "bgpd/bgp_regex.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"
55 /* For bgp_zebra.c */
56 void bgp_zebra_announce (struct prefix *, struct bgp_info *, struct bgp *);
57 void bgp_zebra_withdraw (struct prefix *, struct bgp_info *);
59 /* Static annoucement peer. */
60 struct peer *peer_self;
62 /* Extern from bgp_dump.c */
63 extern char *bgp_origin_str[];
64 extern char *bgp_origin_long_str[];
66 struct route_node *
67 bgp_route_node_get (struct bgp *bgp, afi_t afi, safi_t safi, struct prefix *p,
68 struct prefix_rd *prd)
70 struct route_node *rn;
71 struct route_table *table;
73 if (safi == SAFI_MPLS_VPN)
75 rn = route_node_get (bgp->rib[afi][safi], (struct prefix *) prd);
77 if (rn->info == NULL)
78 rn->info = route_table_init ();
79 else
80 route_unlock_node (rn);
81 table = rn->info;
83 else
84 table = bgp->rib[afi][safi];
86 return route_node_get (table, p);
89 /* Allocate new bgp info structure. */
90 struct bgp_info *
91 bgp_info_new ()
93 struct bgp_info *new;
95 new = XMALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
96 memset (new, 0, sizeof (struct bgp_info));
98 return new;
101 /* Free bgp route information. */
102 void
103 bgp_info_free (struct bgp_info *br)
105 if (br->bgp_damp_info)
106 br->bgp_damp_info->bgp_info = NULL;
107 if (br->attr)
108 bgp_attr_unintern (br->attr);
109 XFREE (MTYPE_BGP_ROUTE, br);
112 /* Add bgp route infomation to routing table node. */
113 void
114 bgp_info_add (struct bgp_info **rp, struct bgp_info *ri)
116 ri->next = *rp;
117 ri->prev = NULL;
118 if (*rp)
119 (*rp)->prev = ri;
120 *rp = ri;
123 /* Delete rib from rib list. */
124 void
125 bgp_info_delete (struct bgp_info **rp, struct bgp_info *ri)
127 if (ri->next)
128 ri->next->prev = ri->prev;
130 if (ri->prev)
131 ri->prev->next = ri->next;
132 else
133 *rp = ri->next;
136 /* Get MED value. If MED value is missing and "bgp bestpath
137 missing-as-worst" is specified, treat it as the worst value. */
138 u_int32_t
139 bgp_med_value (struct attr *attr, struct bgp *bgp)
141 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
142 return attr->med;
143 else
145 if (CHECK_FLAG (bgp->config, BGP_CONFIG_MED_MISSING_AS_WORST))
146 return 4294967295ul;
147 else
148 return 0;
152 /* Compare two bgp route entity. br is preferable then return 1. */
154 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
156 u_int32_t new_pref;
157 u_int32_t exist_pref;
158 u_int32_t new_med;
159 u_int32_t exist_med;
160 struct in_addr new_id;
161 struct in_addr exist_id;
162 int new_cluster;
163 int exist_cluster;
164 int internal_as_route = 0;
165 int confed_as_route = 0;
166 int ret;
168 /* 0. Null check. */
169 if (new == NULL)
170 return 0;
171 if (exist == NULL)
172 return 1;
174 /* 1. Weight check. */
175 if (new->attr->weight > exist->attr->weight)
176 return 1;
177 if (new->attr->weight < exist->attr->weight)
178 return 0;
180 /* 2. Local preference check. */
181 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
182 new_pref = new->attr->local_pref;
183 else
184 new_pref = bgp->default_local_pref;
186 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
187 exist_pref = exist->attr->local_pref;
188 else
189 exist_pref = bgp->default_local_pref;
191 if (new_pref > exist_pref)
192 return 1;
193 if (new_pref < exist_pref)
194 return 0;
196 /* 3. Local route check. */
197 if (new->type == ZEBRA_ROUTE_CONNECT)
198 return 1;
199 if (exist->type == ZEBRA_ROUTE_CONNECT)
200 return 0;
202 if (new->type == ZEBRA_ROUTE_STATIC)
203 return 1;
204 if (exist->type == ZEBRA_ROUTE_STATIC)
205 return 0;
207 if (new->sub_type == BGP_ROUTE_STATIC)
208 return 1;
209 if (exist->sub_type == BGP_ROUTE_STATIC)
210 return 0;
212 if (new->sub_type == BGP_ROUTE_AGGREGATE)
213 return 1;
214 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
215 return 0;
217 /* 4. AS path length check. */
218 if (! CHECK_FLAG (bgp->config, BGP_CONFIG_ASPATH_IGNORE))
220 if (new->attr->aspath->count < exist->attr->aspath->count)
221 return 1;
222 if (new->attr->aspath->count > exist->attr->aspath->count)
223 return 0;
226 /* 5. Origin check. */
227 if (new->attr->origin < exist->attr->origin)
228 return 1;
229 if (new->attr->origin > exist->attr->origin)
230 return 0;
232 /* 6. MED check. */
233 internal_as_route = (new->attr->aspath->length == 0
234 && exist->attr->aspath->length == 0);
235 confed_as_route = (new->attr->aspath->length > 0
236 && exist->attr->aspath->length > 0
237 && new->attr->aspath->count == 0
238 && exist->attr->aspath->count == 0);
240 if (CHECK_FLAG (bgp->config, BGP_CONFIG_ALWAYS_COMPARE_MED)
241 || (CHECK_FLAG (bgp->config, BGP_CONFIG_MED_CONFED)
242 && confed_as_route)
243 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
244 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
245 || internal_as_route)
247 new_med = bgp_med_value (new->attr, bgp);
248 exist_med = bgp_med_value (exist->attr, bgp);
250 if (new_med < exist_med)
251 return 1;
252 if (new_med > exist_med)
253 return 0;
256 /* 7. Peer type check. */
257 if (peer_sort (new->peer) == BGP_PEER_EBGP
258 && peer_sort (exist->peer) == BGP_PEER_IBGP)
259 return 1;
260 if (peer_sort (new->peer) == BGP_PEER_EBGP
261 && peer_sort (exist->peer) == BGP_PEER_CONFED)
262 return 1;
263 if (peer_sort (new->peer) == BGP_PEER_IBGP
264 && peer_sort (exist->peer) == BGP_PEER_EBGP)
265 return 0;
266 if (peer_sort (new->peer) == BGP_PEER_CONFED
267 && peer_sort (exist->peer) == BGP_PEER_EBGP)
268 return 0;
270 /* 8. IGP metric check. */
271 if (new->igpmetric < exist->igpmetric)
272 return 1;
273 if (new->igpmetric > exist->igpmetric)
274 return 0;
276 /* 9. Maximum path check. */
278 /* 10. If both paths are external, prefer the path that was received
279 first (the oldest one). This step minimizes route-flap, since a
280 newer path won't displace an older one, even if it was the
281 preferred route based on the additional decision criteria below. */
282 if (! CHECK_FLAG (bgp->config, BGP_CONFIG_COMPARE_ROUTER_ID)
283 && peer_sort (new->peer) == BGP_PEER_EBGP
284 && peer_sort (exist->peer) == BGP_PEER_EBGP)
286 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
287 return 1;
288 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
289 return 0;
292 /* 11. Rourter-ID comparision. */
293 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
294 new_id.s_addr = new->attr->originator_id.s_addr;
295 else
296 new_id.s_addr = new->peer->remote_id.s_addr;
297 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
298 exist_id.s_addr = exist->attr->originator_id.s_addr;
299 else
300 exist_id.s_addr = exist->peer->remote_id.s_addr;
302 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
303 return 1;
304 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
305 return 0;
307 /* 12. Cluster length comparision. */
308 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
309 new_cluster = new->attr->cluster->length;
310 else
311 new_cluster = 0;
312 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
313 exist_cluster = exist->attr->cluster->length;
314 else
315 exist_cluster = 0;
317 if (new_cluster < exist_cluster)
318 return 1;
319 if (new_cluster > exist_cluster)
320 return 0;
322 /* 13. Neighbor address comparision. */
323 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
325 if (ret == 1)
326 return 0;
327 if (ret == -1)
328 return 1;
330 return 1;
333 enum filter_type
334 bgp_input_filter (struct peer_conf *conf, struct prefix *p, struct attr *attr,
335 afi_t afi, safi_t safi)
337 struct bgp_filter *filter;
339 filter = &conf->filter[afi][safi];
341 if (DISTRIBUTE_IN_NAME (filter))
342 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
343 return FILTER_DENY;
345 if (PREFIX_LIST_IN_NAME (filter))
346 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
347 return FILTER_DENY;
349 if (FILTER_LIST_IN_NAME (filter))
350 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
351 return FILTER_DENY;
353 return FILTER_PERMIT;
356 enum filter_type
357 bgp_output_filter (struct peer_conf *conf, struct prefix *p, struct attr *attr,
358 afi_t afi, safi_t safi)
360 struct bgp_filter *filter;
362 filter = &conf->filter[afi][safi];
364 if (DISTRIBUTE_OUT_NAME (filter))
365 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
366 return FILTER_DENY;
368 if (PREFIX_LIST_OUT_NAME (filter))
369 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
370 return FILTER_DENY;
372 if (FILTER_LIST_OUT_NAME (filter))
373 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
374 return FILTER_DENY;
376 return FILTER_PERMIT;
379 /* If community attribute includes no_export then return 1. */
381 bgp_community_filter (struct peer *peer, struct attr *attr)
383 if (attr->community)
385 /* NO_ADVERTISE check. */
386 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
387 return 1;
389 /* NO_EXPORT check. */
390 if (peer_sort (peer) == BGP_PEER_EBGP &&
391 community_include (attr->community, COMMUNITY_NO_EXPORT))
392 return 1;
394 /* NO_EXPORT_SUBCONFED check. */
395 if (peer_sort (peer) == BGP_PEER_EBGP
396 || peer_sort (peer) == BGP_PEER_CONFED)
397 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
398 return 1;
400 return 0;
404 bgp_cluster_filter (struct peer_conf *conf, struct attr *attr)
406 struct in_addr cluster_id;
408 /* Route reflection loop check. */
409 if (attr->cluster)
411 if (conf->bgp->config & BGP_CONFIG_CLUSTER_ID)
412 cluster_id = conf->bgp->cluster;
413 else
414 cluster_id = conf->bgp->id;
416 if (cluster_loop_check (attr->cluster, cluster_id))
417 return 1;
419 return 0;
422 /* Delete all kernel routes. */
423 void
424 bgp_terminate ()
426 struct bgp *bgp;
427 struct listnode *nn;
428 struct route_node *rn;
429 struct route_table *table;
430 struct bgp_info *ri;
432 LIST_LOOP (bgp_list, bgp, nn)
434 table = bgp->rib[AFI_IP][SAFI_UNICAST];
436 for (rn = route_top (table); rn; rn = route_next (rn))
437 for (ri = rn->info; ri; ri = ri->next)
438 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
439 && ri->type == ZEBRA_ROUTE_BGP
440 && ri->sub_type == BGP_ROUTE_NORMAL)
441 bgp_zebra_withdraw (&rn->p, ri);
443 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
445 for (rn = route_top (table); rn; rn = route_next (rn))
446 for (ri = rn->info; ri; ri = ri->next)
447 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
448 && ri->type == ZEBRA_ROUTE_BGP
449 && ri->sub_type == BGP_ROUTE_NORMAL)
450 bgp_zebra_withdraw (&rn->p, ri);
454 void
455 bgp_reset ()
457 vty_reset ();
458 bgp_zclient_reset ();
459 access_list_reset ();
460 prefix_list_reset ();
463 /* Apply filters and return interned struct attr. */
465 bgp_input_modifier (struct peer *peer, struct peer_conf *conf,
466 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
468 struct bgp_filter *filter;
469 struct bgp_info info;
470 route_map_result_t ret;
472 filter = &conf->filter[afi][safi];
474 /* Apply default weight value. */
475 attr->weight = peer->weight;
477 /* Route map apply. */
478 if (ROUTE_MAP_IN_NAME (filter))
480 /* Duplicate current value to new strucutre for modification. */
481 info.peer = peer;
482 info.attr = attr;
484 /* Apply BGP route map to the attribute. */
485 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
486 if (ret == RMAP_DENYMATCH)
488 /* Free newly generated AS path and community by route-map. */
489 bgp_attr_flush (attr);
490 return RMAP_DENY;
493 return RMAP_PERMIT;
496 /* Set a route to Adj-RIBs-In or Adj-RIBs-Out. In case of attr is
497 NULL, it only store prefix information. */
499 bgp_adj_set (struct route_table *table, struct prefix *p, struct attr *attr,
500 struct prefix_rd *prd, safi_t safi)
502 struct route_node *rn;
504 if (table == NULL)
505 return 0;
507 if (safi == SAFI_MPLS_VPN)
509 rn = route_node_get (table, (struct prefix *)prd);
510 if (rn->info == NULL)
511 rn->info = route_table_init ();
512 else
513 route_unlock_node (rn);
515 table = rn->info;
518 rn = route_node_get (table, p);
519 if (rn->info)
521 if (rn->info != rn)
522 bgp_attr_unintern (rn->info);
523 route_unlock_node (rn);
526 if (attr)
527 rn->info = bgp_attr_intern (attr);
528 else
529 rn->info = rn;
531 return 0;
534 /* Unset a route from Adj-RIBs-In or Adj-RIBs-Out. If bgp_adj_set()
535 only store prefix information, this function detect it and properly
536 unset it. */
538 bgp_adj_unset (struct route_table *table, struct prefix *p,
539 struct prefix_rd *prd, safi_t safi)
541 struct route_node *rn;
543 if (table == NULL)
544 return 0;
546 if (safi == SAFI_MPLS_VPN)
548 rn = route_node_lookup (table, (struct prefix *)prd);
549 if (rn == NULL)
550 return -1;
551 table = rn->info;
554 rn = route_node_lookup (table, p);
555 if (rn == NULL)
556 return -1;
558 if (rn->info != rn)
559 bgp_attr_unintern (rn->info);
560 rn->info = NULL;
561 route_unlock_node (rn);
562 route_unlock_node (rn);
563 return 0;
566 /* Check the prefix is in Adj-RIBs-In or Adj-RIBs-Out. */
568 bgp_adj_lookup (struct route_table *table, struct prefix *p,
569 struct prefix_rd *prd, safi_t safi)
571 struct route_node *rn;
572 struct route_node *rm;
574 rn = NULL;
576 if (table == NULL)
577 return 1;
579 if (safi == SAFI_MPLS_VPN)
581 rn = route_node_lookup (table, (struct prefix *) prd);
582 if (rn == NULL)
583 return 0;
584 table = rn->info;
587 rm = route_node_lookup (table, p);
588 if (rm == NULL)
589 return 0;
591 route_unlock_node (rm);
593 if (rn)
594 route_unlock_node (rn);
596 return 1;
599 /* Clear entire table. */
600 void
601 bgp_adj_clear (struct route_table *table, safi_t safi)
603 struct route_node *rn;
605 if (table == NULL)
606 return;
608 if (safi == SAFI_MPLS_VPN)
610 struct route_table *pt;
611 struct route_node *rm;
613 for (rm = route_top(table); rm; rm = route_next (rm))
614 if ((pt = rm->info) != NULL)
616 for (rn = route_top (pt); rn; rn = route_next (rn))
617 if (rn->info)
619 if (rn->info != rn)
620 bgp_attr_unintern (rn->info);
621 rn->info = NULL;
622 route_unlock_node (rn);
625 return;
628 for (rn = route_top (table); rn; rn = route_next (rn))
629 if (rn->info)
631 if (rn->info != rn)
632 bgp_attr_unintern (rn->info);
633 rn->info = NULL;
634 route_unlock_node (rn);
639 bgp_announce_check (struct bgp_info *ri, struct peer_conf *conf,
640 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
642 int ret;
643 char buf[SU_ADDRSTRLEN];
644 struct bgp_filter *filter;
645 struct bgp_info info;
646 struct peer *peer;
647 struct peer *from;
648 struct bgp *bgp;
649 struct attr dummy_attr;
650 int transparent;
652 from = ri->peer;
653 peer = conf->peer;
654 filter = &conf->filter[afi][safi];
655 bgp = conf->bgp;
657 #ifdef DISABLE_BGP_ANNOUNCE
658 return 0;
659 #endif
661 /* Do not send back route to sender. */
662 if (from == peer)
663 return 0;
665 /* Aggregate-address suppress check. */
666 if (ri->suppress)
667 return 0;
669 /* If community is not disabled check the no-export and local. */
670 if (bgp_community_filter (peer, ri->attr))
671 return 0;
673 /* If the attribute has originator-id and it is same as remote
674 peer's id. */
675 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
677 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
679 if (BGP_DEBUG (filter, FILTER))
680 zlog (peer->log, LOG_INFO,
681 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
682 peer->host,
683 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
684 p->prefixlen);
685 return 0;
689 /* Output filter check. */
690 if (bgp_output_filter (conf, p, ri->attr, afi, safi) == FILTER_DENY)
692 if (BGP_DEBUG (filter, FILTER))
693 zlog (peer->log, LOG_INFO,
694 "%s [Update:SEND] %s/%d is filtered",
695 peer->host,
696 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
697 p->prefixlen);
698 return 0;
701 /* Default route check. */
702 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY
703 && ! (CHECK_FLAG (peer->flags, PEER_FLAG_DEFAULT_ORIGINATE)))
705 if (BGP_DEBUG (filter, FILTER))
706 zlog (peer->log, LOG_INFO,
707 "%s [Update:SEND] default route announcement is suppressed",
708 peer->host);
709 return 0;
711 #ifdef HAVE_IPV6
712 if (p->family == AF_INET6 && p->prefixlen == 0
713 && ! (CHECK_FLAG (peer->flags, PEER_FLAG_DEFAULT_ORIGINATE)))
715 if (BGP_DEBUG (filter, FILTER))
716 zlog (peer->log, LOG_INFO,
717 "%s [Update:SEND] IPv6 default route announcement is suppressed",
718 peer->host);
719 return 0;
721 #endif /* HAVE_IPV6 */
723 #ifdef BGP_SEND_ASPATH_CHECK
724 /* AS path loop check. */
725 if (aspath_loop_check (ri->attr->aspath, peer->as))
727 if (BGP_DEBUG (filter, FILTER))
728 zlog (peer->log, LOG_INFO,
729 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
730 peer->host, peer->as);
731 return 0;
733 #endif /* BGP_SEND_ASPATH_CHECK */
735 /* If we're a CONFED we need to loop check the CONFED ID too */
736 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
738 if (aspath_loop_check(ri->attr->aspath, bgp->confederation_id))
740 if (BGP_DEBUG (filter, FILTER))
741 zlog (peer->log, LOG_INFO,
742 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
743 peer->host,
744 bgp->confederation_id);
745 return 0;
749 /* IBGP reflection check. */
750 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
752 /* A route from a Client peer. */
753 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
755 /* Reflect to all the Non-Client peers and also to the
756 Client peers other than the originator. Originator check
757 is already done. So there is noting to do. */
758 /* no bgp client-to-client reflection check. */
759 if (CHECK_FLAG (bgp->config, BGP_CONFIG_NO_CLIENT_TO_CLIENT))
760 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
761 return 0;
763 else
765 /* A route from a Non-client peer. Reflect to all other
766 clients. */
767 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
768 return 0;
772 /* For modify attribute, copy it to temporary structure. */
773 *attr = *ri->attr;
775 /* If local-preference is not set. */
776 if ((peer_sort (peer) == BGP_PEER_IBGP
777 || peer_sort (peer) == BGP_PEER_CONFED)
778 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
780 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
781 attr->local_pref = bgp->default_local_pref;
784 /* Transparency check. */
785 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
786 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
787 transparent = 1;
788 else
789 transparent = 0;
791 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
792 if (transparent)
794 /* Route Server Clients are transparent MED.
795 So there is noting to do. */
797 else
799 if (peer_sort (peer) == BGP_PEER_EBGP
800 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)
801 && ri->peer != peer_self)
802 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
805 /* next-hop-set */
806 if (transparent || CHECK_FLAG (peer->flags, PEER_FLAG_TRANSPARENT_NEXTHOP))
808 /* Route Server Clients are transparent NEXT-HOP.
809 So there is noting to do. */
811 else if (! (peer_sort (from) == BGP_PEER_IBGP
812 && peer_sort (peer) == BGP_PEER_IBGP))
814 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
815 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
816 #ifdef HAVE_IPV6
817 || (p->family == AF_INET6 && ri->peer == peer_self)
818 #endif /* HAVE_IPV6 */
819 || ((peer_sort (peer) == BGP_PEER_EBGP
820 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0)))
822 /* Set IPv4 nexthop. */
823 if (safi == SAFI_MPLS_VPN)
824 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
825 else
826 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
828 #ifdef HAVE_IPV6
829 /* Set IPv6 nexthop. */
830 if (p->family == AF_INET6)
832 /* IPv6 global nexthop must be included. */
833 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
834 IPV6_MAX_BYTELEN);
835 attr->mp_nexthop_len = 16;
837 /* If the peer is on shared nextwork and we have link-local
838 nexthop set it. */
839 if (peer->shared_network
840 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
842 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
843 IPV6_MAX_BYTELEN);
844 attr->mp_nexthop_len = 32;
847 #endif /* HAVE_IPV6 */
849 else
851 #ifdef HAVE_IPV6
852 if (p->family == AF_INET6)
854 /* Link-local address should not be transit to different peer. */
855 attr->mp_nexthop_len = 16;
857 /* Set link-local address for shared network peer. */
858 if (peer->shared_network
859 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
861 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
862 IPV6_MAX_BYTELEN);
863 attr->mp_nexthop_len = 32;
866 #endif /* HAVE_IPV6 */
870 #ifdef HAVE_IPV6
871 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
872 address.*/
873 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
874 attr->mp_nexthop_len = 16;
876 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
877 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
878 attr->mp_nexthop_len = 16;
879 #endif /* HAVE_IPV6 */
881 /* Route map apply. */
882 if (ROUTE_MAP_OUT_NAME (filter))
884 info.peer = peer;
885 info.attr = attr;
887 /* The route reflector is not allowed to modify the attributes
888 of the reflected IBGP routes. */
889 if (peer_sort (from) == BGP_PEER_IBGP
890 && peer_sort (peer) == BGP_PEER_IBGP)
892 dummy_attr = *attr;
893 info.attr = &dummy_attr;
896 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
897 if (ret == RMAP_DENYMATCH)
899 bgp_attr_flush (attr);
900 return 0;
903 return 1;
906 /* Announce selected routes to the conf->peer. */
907 void
908 bgp_announce_rib (struct peer_conf *conf, afi_t afi, safi_t safi)
910 struct route_node *rn;
911 struct bgp_info *ri;
912 struct attr attr;
914 for (rn = route_top (conf->bgp->rib[afi][safi]); rn; rn = route_next(rn))
915 for (ri = rn->info; ri; ri = ri->next)
917 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
918 && ri->peer != conf->peer)
919 if (bgp_announce_check (ri, conf, &rn->p, &attr, afi, safi))
921 bgp_update_send (conf, conf->peer, &rn->p, &attr, afi, safi,
922 ri->peer, NULL, NULL);
923 bgp_adj_set (conf->peer->adj_out[afi][safi], &rn->p, &attr,
924 NULL, safi);
929 void
930 bgp_announce_rib_vpnv4 (struct peer_conf *conf, afi_t afi, safi_t safi)
932 struct route_node *rn;
933 struct route_node *rm;
934 struct route_table *table;
935 struct bgp_info *ri;
936 struct attr attr;
938 for (rn = route_top (conf->bgp->rib[afi][safi]); rn; rn = route_next(rn))
939 if ((table = (rn->info)) != NULL)
941 for (rm = route_top (table); rm; rm = route_next (rm))
942 for (ri = rm->info; ri; ri = ri->next)
944 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
945 && ri->peer != conf->peer)
946 if (bgp_announce_check ((struct bgp_info *)ri, conf,
947 &rm->p, &attr, afi, safi))
949 bgp_update_send (conf, conf->peer, &rm->p, &attr,
950 afi, safi, ri->peer,
951 (struct prefix_rd *) &rn->p, ri->tag);
952 bgp_adj_set (conf->peer->adj_out[afi][safi], &rm->p,
953 &attr, (struct prefix_rd *)&rn->p, safi);
959 /* Refresh routes conf->peer. */
960 void
961 bgp_refresh_rib (struct peer_conf *conf, afi_t afi, safi_t safi)
963 struct route_node *rn;
964 struct bgp_info *ri;
965 struct attr attr;
967 for (rn = route_top (conf->bgp->rib[afi][safi]); rn; rn = route_next(rn))
968 for (ri = rn->info; ri; ri = ri->next)
969 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != conf->peer)
971 if (bgp_announce_check (ri, conf, &rn->p, &attr, afi, safi))
973 bgp_update_send (conf, conf->peer, &rn->p, &attr, afi, safi,
974 ri->peer, NULL, NULL);
975 bgp_adj_set (conf->peer->adj_out[afi][safi], &rn->p, &attr,
976 NULL, safi);
978 else
980 /* Send withdraw to the peer */
981 if (bgp_adj_lookup (conf->peer->adj_out[afi][safi], &rn->p,
982 NULL, safi))
984 bgp_withdraw_send (conf->peer, &rn->p, afi, safi, NULL,
985 NULL);
986 bgp_adj_unset (conf->peer->adj_out[afi][safi], &rn->p, NULL,
987 safi);
993 /* Refresh routes conf->peer. */
994 void
995 bgp_refresh_rib_vpnv4 (struct peer_conf *conf, afi_t afi, safi_t safi)
997 struct route_node *rn;
998 struct route_node *rm;
999 struct route_table *table;
1000 struct bgp_info *ri;
1001 struct attr attr;
1003 for (rn = route_top (conf->bgp->rib[afi][safi]); rn; rn = route_next(rn))
1004 if ((table = rn->info) != NULL)
1006 for (rm = route_top (table); rm; rm = route_next (rm))
1007 for (ri = rm->info; ri; ri = ri->next)
1008 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
1009 && ri->peer != conf->peer)
1011 if (bgp_announce_check ((struct bgp_info *)ri, conf, &rm->p,
1012 &attr, afi, safi))
1014 bgp_update_send (conf, conf->peer, &rm->p, &attr,
1015 afi, safi, ri->peer,
1016 (struct prefix_rd *) &rn->p, ri->tag);
1017 bgp_adj_set (conf->peer->adj_out[afi][safi], &rm->p,
1018 &attr, (struct prefix_rd *) &rn->p, safi);
1020 else
1022 /* Send withdraw to the peer */
1023 if (bgp_adj_lookup (conf->peer->adj_out[afi][safi], &rm->p,
1024 (struct prefix_rd *) &rn->p, safi))
1026 bgp_withdraw_send (conf->peer, &rm->p, afi, safi,
1027 (struct prefix_rd *) &rn->p, ri->tag);
1028 bgp_adj_unset (conf->peer->adj_out[afi][safi],
1029 &rm->p, (struct prefix_rd *) &rn->p, safi);
1036 /* Announce current routing table to the peer when peer gets
1037 Established. */
1038 void
1039 bgp_announce_table (struct peer *peer)
1041 struct listnode *nn;
1042 struct peer_conf *conf;
1044 LIST_LOOP (peer->conf, conf, nn)
1046 if (conf->peer->afc_nego[AFI_IP][SAFI_UNICAST])
1047 bgp_announce_rib (conf, AFI_IP, SAFI_UNICAST);
1048 if (conf->peer->afc_nego[AFI_IP][SAFI_MULTICAST])
1049 bgp_announce_rib (conf, AFI_IP, SAFI_MULTICAST);
1050 if (conf->peer->afc_nego[AFI_IP6][SAFI_UNICAST])
1051 bgp_announce_rib (conf, AFI_IP6, SAFI_UNICAST);
1052 if (conf->peer->afc_nego[AFI_IP6][SAFI_MULTICAST])
1053 bgp_announce_rib (conf, AFI_IP6, SAFI_MULTICAST);
1055 /* MPLS-VPN */
1056 if (conf->peer->afc_nego[AFI_IP][SAFI_MPLS_VPN])
1057 bgp_announce_rib_vpnv4 (conf, AFI_IP, SAFI_MPLS_VPN);
1061 /* Announce current routing table to the peer when peer gets
1062 Established. */
1063 void
1064 bgp_refresh_table (struct peer *peer, afi_t afi, safi_t safi)
1066 struct listnode *nn;
1067 struct peer_conf *conf;
1069 LIST_LOOP (peer->conf, conf, nn)
1071 if (conf->peer->afc_nego[afi][safi])
1073 if (safi == SAFI_MPLS_VPN)
1074 bgp_refresh_rib_vpnv4 (conf, afi, safi);
1075 else
1076 bgp_refresh_rib (conf, afi, safi);
1081 /* Process changed routing entry. */
1083 bgp_process (struct bgp *bgp, struct route_node *rn, afi_t afi, safi_t safi,
1084 struct bgp_info *del, struct prefix_rd *prd, u_char *tag)
1086 struct prefix *p;
1087 struct bgp_info *ri;
1088 struct bgp_info *new_select;
1089 struct bgp_info *old_select;
1090 struct listnode *nn;
1091 struct peer_conf *conf_to;
1092 struct peer *peer_to;
1093 struct attr attr;
1094 struct bgp_info *ri1;
1095 struct bgp_info *ri2;
1097 p = &rn->p;
1099 /* bgp deterministic-med */
1100 new_select = NULL;
1101 if (CHECK_FLAG (bgp->config, BGP_CONFIG_DETERMINISTIC_MED))
1102 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1104 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1105 continue;
1106 if (BGP_INFO_HOLDDOWN (ri1))
1107 continue;
1109 new_select = ri1;
1110 if (ri1->next)
1111 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1113 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1114 continue;
1115 if (BGP_INFO_HOLDDOWN (ri2))
1116 continue;
1118 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1119 || aspath_cmp_left_confed (ri1->attr->aspath,
1120 ri2->attr->aspath))
1122 if (bgp_info_cmp (bgp, ri2, new_select))
1124 UNSET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1125 new_select = ri2;
1128 SET_FLAG (ri2->flags, BGP_INFO_DMED_CHECK);
1131 SET_FLAG (new_select->flags, BGP_INFO_DMED_CHECK);
1132 SET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1135 /* Check old selected route and new selected route. */
1136 old_select = NULL;
1137 new_select = NULL;
1138 for (ri = rn->info; ri; ri = ri->next)
1140 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1141 old_select = ri;
1143 if (BGP_INFO_HOLDDOWN (ri))
1144 continue;
1146 if (CHECK_FLAG (bgp->config, BGP_CONFIG_DETERMINISTIC_MED)
1147 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1149 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1150 continue;
1152 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1153 UNSET_FLAG (ri->flags, BGP_INFO_DMED_SELECTED);
1155 if (bgp_info_cmp (bgp, ri, new_select))
1156 new_select = ri;
1159 /* Nothing to do. */
1160 if (old_select && old_select == new_select)
1162 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1164 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1165 bgp_zebra_announce (p, old_select, bgp);
1166 return 0;
1170 if (old_select)
1171 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1172 if (new_select)
1174 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1175 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1178 /* Check each BGP peer. */
1179 LIST_LOOP (bgp->peer_conf, conf_to, nn)
1181 peer_to = conf_to->peer;
1183 /* Announce route to Established peer. */
1184 if (peer_to->status != Established)
1185 continue;
1187 /* Address family configuration check. */
1188 if (! conf_to->peer->afc_nego[afi][safi])
1189 continue;
1191 /* Announcement to peer->conf. If the route is filtered,
1192 withdraw it. */
1193 if (new_select
1194 && bgp_announce_check (new_select, conf_to, p, &attr, afi, safi))
1196 /* Send update to the peer. */
1197 bgp_update_send (conf_to, peer_to, p, &attr, afi, safi,
1198 new_select->peer, prd, tag);
1199 bgp_adj_set (peer_to->adj_out[afi][safi], p, &attr, prd, safi);
1201 else
1203 /* Send withdraw to the peer */
1204 if (bgp_adj_lookup (peer_to->adj_out[afi][safi], p, prd, safi))
1206 bgp_withdraw_send (peer_to, p, afi, safi, prd, tag);
1207 bgp_adj_unset (peer_to->adj_out[afi][safi], p, prd, safi);
1212 /* FIB update. */
1213 if (safi == SAFI_UNICAST && ! bgp->name && ! no_kernel_mode)
1215 if (new_select
1216 && new_select->type == ZEBRA_ROUTE_BGP
1217 && new_select->sub_type == BGP_ROUTE_NORMAL)
1218 bgp_zebra_announce (p, new_select, bgp);
1219 else
1221 /* In case of selected route is deleted check the pointer. */
1222 if (! old_select
1223 && del && CHECK_FLAG (del->flags, BGP_INFO_SELECTED))
1224 old_select = del;
1226 /* Withdraw the route from the kernel. */
1227 if (old_select
1228 && old_select->type == ZEBRA_ROUTE_BGP
1229 && old_select->sub_type == BGP_ROUTE_NORMAL)
1230 bgp_zebra_withdraw (p, old_select);
1233 return 0;
1236 /* maximum-prefix check. */
1238 bgp_maximum_prefix_overflow (struct peer_conf *conf, afi_t afi, safi_t safi)
1240 struct peer *peer;
1242 if (conf->pmax[afi][safi]
1243 && conf->pcount[afi][safi] >= conf->pmax[afi][safi])
1245 peer = conf->peer;
1246 zlog (peer->log, LOG_INFO,
1247 "MAXPFXEXCEED: No. of prefix received from %s (afi %d): %ld exceed limit %ld",
1248 peer->host, afi, conf->pcount[afi][safi], conf->pmax[afi][safi]);
1249 if (! conf->pmax_warning[afi][safi])
1251 BGP_EVENT_ADD (peer, BGP_Stop);
1252 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1253 return 1;
1256 return 0;
1259 void
1260 bgp_implicit_withdraw (struct peer_conf *conf, struct bgp *bgp,
1261 struct prefix *p, struct bgp_info *ri,
1262 struct route_node *rn, afi_t afi, safi_t safi)
1264 conf->pcount[afi][safi]--;
1265 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1266 bgp_info_delete ((struct bgp_info **) &rn->info, ri);
1267 bgp_info_free (ri);
1268 route_unlock_node (rn);
1271 /* Generic function for update BGP information. This function only
1272 update routing table information. To announce change we have to
1273 call bgp_process(). */
1275 bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
1276 afi_t afi, safi_t safi, int type, int sub_type,
1277 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1279 struct listnode *nn;
1280 struct route_node *rn;
1281 struct bgp *bgp;
1282 struct peer_conf *conf;
1283 struct attr new_attr;
1284 struct bgp_info *ri;
1285 struct bgp_info *new;
1286 char buf[SU_ADDRSTRLEN];
1287 int bgp_damp_update (struct bgp_info *);
1289 /* Check this route's origin is not static/aggregate/redistributed
1290 routes. */
1291 if (peer != peer_self && ! soft_reconfig)
1293 /* If peer is soft reconfiguration enabled. Record input packet for
1294 further calculation. */
1295 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
1296 bgp_adj_set (peer->adj_in[afi][safi], p, attr, prd, safi);
1299 /* Kick each configuration BGP instance. */
1300 LIST_LOOP (peer->conf, conf, nn)
1302 bgp = conf->bgp;
1304 /* Lookup node. */
1305 rn = bgp_route_node_get (bgp, afi, safi, p, prd);
1307 /* Check selected route and self inserted route. */
1308 for (ri = rn->info; ri; ri = ri->next)
1309 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1310 break;
1312 /* Aspath loop check. */
1313 if (aspath_loop_check (attr->aspath, bgp->as)
1314 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1315 && aspath_loop_check(attr->aspath, bgp->confederation_id)))
1317 /* If the update is implicit withdraw. */
1318 if (ri)
1319 bgp_implicit_withdraw (conf, bgp, p, ri, rn, afi, safi);
1321 if (BGP_DEBUG (update, UPDATE_IN))
1322 zlog (peer->log, LOG_INFO,
1323 "%s rcvd UPDATE about %s/%d -- DENIED due to: as-path contains our own AS;",
1324 peer->host,
1325 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1326 p->prefixlen);
1327 /* Process change. */
1328 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
1329 route_unlock_node (rn);
1330 continue;
1333 /* Route reflector originator ID check. */
1334 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1335 && IPV4_ADDR_SAME (&bgp->id, &attr->originator_id))
1337 /* If the update is implicit withdraw. */
1338 if (ri)
1339 bgp_implicit_withdraw (conf, bgp, p, ri, rn, afi, safi);
1341 if (BGP_DEBUG (update, UPDATE_IN))
1342 zlog (peer->log, LOG_INFO,
1343 "%s rcvd UPDATE about %s/%d -- DENIED due to: originator is us;",
1344 peer->host,
1345 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1346 p->prefixlen);
1347 /* Process change. */
1348 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
1349 route_unlock_node (rn);
1350 continue;
1353 /* Route reflector cluster ID check. */
1354 if (bgp_cluster_filter (conf, attr))
1356 /* If the update is implicit withdraw. */
1357 if (ri)
1358 bgp_implicit_withdraw (conf, bgp, p, ri, rn, afi, safi);
1360 if (BGP_DEBUG (update, UPDATE_IN))
1361 zlog (peer->log, LOG_INFO,
1362 "%s rcvd UPDATE about %s/%d -- DENIED due to: reflected from the same cluster;",
1363 peer->host,
1364 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1365 p->prefixlen);
1366 /* Process change. */
1367 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
1368 route_unlock_node (rn);
1369 continue;
1372 /* Apply input filter and route-map. Filter and route-map
1373 application logging is also don in the function. */
1374 if (bgp_input_filter (conf, p, attr, afi, safi) == FILTER_DENY)
1376 /* If the update is implicit withdraw. */
1377 if (ri)
1378 bgp_implicit_withdraw (conf, bgp, p, ri, rn, afi, safi);
1380 if (BGP_DEBUG (update, UPDATE_IN))
1382 zlog (peer->log, LOG_INFO,
1383 "%s rcvd UPDATE about %s/%d -- DENIED due to: filter;",
1384 peer->host,
1385 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1386 p->prefixlen);
1388 /* Process change. */
1389 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
1390 route_unlock_node (rn);
1391 continue;
1394 /* Apply input route-map. */
1395 new_attr = *attr;
1397 if (bgp_input_modifier (peer, conf, p, &new_attr, afi, safi) == RMAP_DENY)
1399 /* If the update is implicit withdraw. */
1400 if (ri)
1401 bgp_implicit_withdraw (conf, bgp, p, ri, rn, afi, safi);
1403 if (BGP_DEBUG (update, UPDATE_IN))
1405 zlog (peer->log, LOG_INFO,
1406 "%s rcvd UPDATE about %s/%d -- DENIED due to: route-map;",
1407 peer->host,
1408 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1409 p->prefixlen);
1411 /* Process change. */
1412 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
1413 route_unlock_node (rn);
1414 continue;
1417 /* If the peer is EBGP and nexthop is not on connected route,
1418 discard it. */
1419 if (afi == AFI_IP && safi == SAFI_UNICAST
1420 && peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1)
1422 if (! bgp_nexthop_check_ebgp (afi, &new_attr))
1424 /* Debug information. */
1425 if (BGP_DEBUG (update, UPDATE_IN))
1427 zlog (peer->log, LOG_INFO,
1428 "%s rcvd UPDATE about %s/%d -- DENIED due to: non-connected next-hop;",
1429 peer->host,
1430 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1431 p->prefixlen);
1434 /* Perform implicit withdraw. */
1435 if (ri)
1436 bgp_implicit_withdraw (conf, bgp, p, ri, rn, afi, safi);
1438 /* Process change. */
1439 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
1440 route_unlock_node (rn);
1441 continue;
1445 /* Check nexthop. */
1446 if (afi == AFI_IP && safi == SAFI_UNICAST)
1448 if (bgp_nexthop_self (afi, &new_attr)
1449 || new_attr.nexthop.s_addr == 0
1450 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1452 /* Debug information. */
1453 if (BGP_DEBUG (update, UPDATE_IN))
1455 zlog (peer->log, LOG_INFO,
1456 "%s rcvd UPDATE about %s/%d -- DENIED due to: martian next-hop;",
1457 peer->host,
1458 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1459 p->prefixlen);
1462 /* Perform implicit withdraw. */
1463 if (ri)
1464 bgp_implicit_withdraw (conf, bgp, p, ri, rn, afi, safi);
1466 /* Process change. */
1467 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
1468 route_unlock_node (rn);
1469 continue;
1473 /* If the update is implicit withdraw. */
1474 if (ri)
1476 /* Update BGP flap dampening information. */
1477 if (ri->bgp_damp_info)
1478 bgp_damp_update (ri);
1480 /* Same attribute comes in. */
1481 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
1482 && attrhash_cmp (ri->attr, &new_attr))
1484 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1486 if (BGP_DEBUG (update, UPDATE_IN))
1487 zlog (peer->log, LOG_INFO,
1488 "%s rcvd %s/%d...duplicate ignored",
1489 peer->host,
1490 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1491 p->prefixlen);
1493 ri->uptime = time (NULL);
1494 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
1495 route_unlock_node (rn);
1496 continue;
1500 /* Received Logging. */
1501 if (BGP_DEBUG (update, UPDATE_IN))
1502 zlog (peer->log, LOG_INFO, "%s rcvd %s/%d",
1503 peer->host,
1504 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1505 p->prefixlen);
1507 /* The attribute is changed. */
1508 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1510 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1512 UNSET_FLAG (ri->flags, BGP_INFO_HISTORY);
1513 conf->pcount[afi][safi]++;
1516 /* Rewrite BGP route information. */
1517 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1518 bgp_attr_unintern (ri->attr);
1519 ri->attr = bgp_attr_intern (&new_attr);
1520 ri->uptime = time (NULL);
1522 /* Update MPLS tag. */
1523 if (safi == SAFI_MPLS_VPN)
1524 memcpy (ri->tag, tag, 3);
1526 /* Nexthop reachability check. */
1527 if ((afi == AFI_IP || afi == AFI_IP6)
1528 && safi == SAFI_UNICAST
1529 && (peer_sort (peer) == BGP_PEER_IBGP ||
1530 (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)))
1532 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
1533 SET_FLAG (ri->flags, BGP_INFO_VALID);
1534 else
1535 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
1537 else
1538 SET_FLAG (ri->flags, BGP_INFO_VALID);
1540 /* Process change. */
1541 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1542 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
1543 route_unlock_node (rn);
1544 continue;
1547 /* Received Logging. */
1548 if (BGP_DEBUG (update, UPDATE_IN))
1550 zlog (peer->log, LOG_INFO, "%s rcvd %s/%d",
1551 peer->host,
1552 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1553 p->prefixlen);
1556 /* Increment prefix counter */
1557 conf->pcount[afi][safi]++;
1559 /* Make new BGP info. */
1560 new = bgp_info_new ();
1561 new->type = type;
1562 new->sub_type = sub_type;
1563 new->peer = peer;
1564 new->attr = bgp_attr_intern (&new_attr);
1565 new->uptime = time (NULL);
1567 /* Update MPLS tag. */
1568 if (safi == SAFI_MPLS_VPN)
1569 memcpy (new->tag, tag, 3);
1571 /* Nexthop reachability check. */
1572 if ((afi == AFI_IP || afi == AFI_IP6)
1573 && safi == SAFI_UNICAST
1574 && (peer_sort (peer) == BGP_PEER_IBGP
1575 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)))
1577 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
1578 SET_FLAG (new->flags, BGP_INFO_VALID);
1579 else
1580 UNSET_FLAG (new->flags, BGP_INFO_VALID);
1582 else
1583 SET_FLAG (new->flags, BGP_INFO_VALID);
1585 /* Aggregate address increment. */
1586 bgp_aggregate_increment (bgp, p, new, afi, safi);
1588 /* Register new BGP information. */
1589 bgp_info_add ((struct bgp_info **) &rn->info, new);
1591 /* If maximum prefix count is configured and current prefix
1592 count exeed it. */
1593 if (! conf->pmax_warning[afi][safi])
1594 if (bgp_maximum_prefix_overflow (conf, afi, safi))
1595 return -1;
1597 /* Process change. */
1598 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
1600 return 0;
1603 /* Generic function for withdraw BGP information */
1605 bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
1606 int afi, int safi, int type, int sub_type, struct prefix_rd *prd,
1607 u_char *tag)
1609 struct peer_conf *conf;
1610 struct listnode *nn;
1611 struct bgp *bgp;
1612 char buf[SU_ADDRSTRLEN];
1613 struct route_node *rn;
1614 struct bgp_info *ri;
1615 int bgp_damp_withdraw(struct bgp_info *);
1616 int status;
1618 if (peer != peer_self)
1620 /* If peer is soft reconfiguration enabled. Record input packet for
1621 further calculation. */
1622 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
1623 bgp_adj_unset (peer->adj_in[afi][safi], p, prd, safi);
1626 LIST_LOOP (peer->conf, conf, nn)
1628 bgp = conf->bgp;
1630 /* Logging. */
1631 if (BGP_DEBUG (update, UPDATE_IN))
1632 zlog (peer->log, LOG_INFO, "%s rcvd UPDATE about %s/%d -- withdrawn",
1633 peer->host, inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1634 p->prefixlen);
1636 /* Lookup node. */
1637 rn = bgp_route_node_get (bgp, afi, safi, p, prd);
1639 /* Check selected route and self inserted route. */
1640 for (ri = rn->info; ri; ri = ri->next)
1641 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1642 break;
1644 /* Withdraw specified route from routing table. */
1645 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1647 status = BGP_DAMP_DISABLED;
1649 if (peer_sort (peer) != BGP_PEER_IBGP
1650 && peer_sort (peer) != BGP_PEER_CONFED)
1652 status = bgp_damp_withdraw (ri);
1654 if (status == BGP_DAMP_CONTINUE
1655 || status == BGP_DAMP_DISCONTINUE)
1657 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1658 bgp_process (bgp, rn, afi, safi, ri, prd, tag);
1659 conf->pcount[afi][safi]--;
1663 if (status == BGP_DAMP_DISABLED)
1665 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1666 bgp_info_delete ((struct bgp_info **) &rn->info, ri);
1667 bgp_process (bgp, rn, afi, safi, ri, prd, tag);
1668 bgp_info_free (ri);
1669 route_unlock_node (rn);
1671 /* Prefix count updates. */
1672 conf->pcount[afi][safi]--;
1675 else
1677 if (BGP_DEBUG (update, UPDATE_IN))
1678 zlog (peer->log, LOG_INFO,
1679 "%s Can't find the route %s/%d", peer->host,
1680 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1681 p->prefixlen);
1684 /* Unlock route_node_get() lock. */
1685 route_unlock_node (rn);
1687 return 0;
1690 /* Parser of NLRI octet stream. Withdraw NLRI is recognized by NULL
1691 attr value. */
1693 nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
1695 u_char *pnt;
1696 u_char *lim;
1697 struct prefix p;
1698 int psize;
1699 int ret;
1701 /* Check peer status. */
1702 if (peer->status != Established)
1703 return 0;
1705 pnt = packet->nlri;
1706 lim = pnt + packet->length;
1708 for (; pnt < lim; pnt += psize)
1710 /* Clear prefix structure. */
1711 memset (&p, 0, sizeof (struct prefix));
1713 /* Fetch prefix length. */
1714 p.prefixlen = *pnt++;
1715 p.family = afi2family (packet->afi);
1717 /* Already checked in nlri_sanity_check(). We do double check
1718 here. */
1719 if ((packet->afi == AFI_IP && p.prefixlen > 32)
1720 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
1721 return -1;
1723 /* Packet size overflow check. */
1724 psize = PSIZE (p.prefixlen);
1726 /* When packet overflow occur return immediately. */
1727 if (pnt + psize > lim)
1728 return -1;
1730 /* Fetch prefix from NLRI packet. */
1731 memcpy (&p.u.prefix, pnt, psize);
1733 /* Check address. */
1734 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
1736 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
1738 zlog (peer->log, LOG_ERR,
1739 "IPv4 unicast NLRI is multicast address %s",
1740 inet_ntoa (p.u.prefix4));
1741 bgp_notify_send (peer,
1742 BGP_NOTIFY_UPDATE_ERR,
1743 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1744 return -1;
1748 #ifdef HAVE_IPV6
1749 /* Check address. */
1750 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
1752 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
1754 char buf[BUFSIZ];
1756 zlog (peer->log, LOG_WARNING,
1757 "IPv6 link-local NLRI received %s ignore this NLRI",
1758 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
1760 continue;
1763 #endif /* HAVE_IPV6 */
1765 /* Translate update. Convert unicast update to multicast update. */
1766 if (packet->safi == SAFI_UNICAST && peer->translate_update)
1768 if (attr)
1769 ret = bgp_update (peer, &p, attr, packet->afi, SAFI_MULTICAST,
1770 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
1771 else
1772 ret = bgp_withdraw (peer, &p, attr, packet->afi, SAFI_MULTICAST,
1773 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
1774 if (ret < 0)
1775 return -1;
1778 /* Do not process unicast update when translate update is
1779 only to multicast. */
1780 if (packet->safi == SAFI_UNICAST
1781 && peer->translate_update == SAFI_MULTICAST)
1782 continue;
1784 /* Normal process. */
1785 if (attr)
1786 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
1787 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
1788 else
1789 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
1790 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
1792 /* Address family configuration mismatch or maximum-prefix count
1793 overflow. */
1794 if (ret < 0)
1795 return -1;
1798 /* Packet length consistency check. */
1799 if (pnt != lim)
1800 return -1;
1802 return 0;
1805 /* NLRI encode syntax check routine. */
1807 nlri_sanity_check (struct peer *peer, int afi, u_char *pnt, bgp_size_t length)
1809 u_char *end;
1810 u_char prefixlen;
1811 int psize;
1813 end = pnt + length;
1815 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
1816 syntactic validity. If the field is syntactically incorrect,
1817 then the Error Subcode is set to Invalid Network Field. */
1819 while (pnt < end)
1821 prefixlen = *pnt++;
1823 /* Prefix length check. */
1824 if ((afi == AFI_IP && prefixlen > 32)
1825 || (afi == AFI_IP6 && prefixlen > 128))
1827 plog_err (peer->log,
1828 "%s [Error] Update packet error (wrong prefix length %d)",
1829 peer->host, prefixlen);
1830 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1831 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1832 return -1;
1835 /* Packet size overflow check. */
1836 psize = PSIZE (prefixlen);
1838 if (pnt + psize > end)
1840 plog_err (peer->log,
1841 "%s [Error] Update packet error"
1842 " (prefix data overflow prefix size is %d)",
1843 peer->host, psize);
1844 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1845 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1846 return -1;
1849 pnt += psize;
1852 /* Packet length consistency check. */
1853 if (pnt != end)
1855 plog_err (peer->log,
1856 "%s [Error] Update packet error"
1857 " (prefix length mismatch with total length)",
1858 peer->host);
1859 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1860 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1861 return -1;
1863 return 0;
1866 /* Soft reconfiguration for input. */
1867 void
1868 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
1870 int ret;
1871 struct route_node *rn;
1872 struct attr *attr;
1874 for (rn = route_top (peer->adj_in[afi][safi]); rn; rn = route_next (rn))
1875 if ((attr = rn->info) != NULL)
1877 ret = bgp_update (peer, &rn->p, attr, afi, safi,
1878 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
1879 NULL, NULL, 1);
1881 /* Address family configuration mismatch or maximum-prefix count
1882 overflow. */
1883 if (ret < 0)
1885 route_unlock_node (rn);
1886 return;
1891 /* Remove all routes from the peer. */
1892 void
1893 bgp_route_clear_with_afi (struct peer *peer, struct bgp *bgp, afi_t afi,
1894 safi_t safi)
1896 struct route_node *rn;
1897 struct bgp_info *ri;
1898 struct bgp_info *next;
1900 for (rn = route_top (bgp->rib[afi][safi]); rn; rn = route_next (rn))
1901 for (ri = rn->info; ri; ri = next)
1903 next = ri->next;
1905 if (ri->peer == peer)
1907 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, safi);
1908 bgp_info_delete ((struct bgp_info **) &rn->info, ri);
1909 bgp_process (bgp, rn, afi, safi, ri, NULL, NULL);
1910 bgp_info_free (ri);
1911 route_unlock_node (rn);
1916 void
1917 bgp_route_clear_with_afi_vpnv4 (struct peer *peer, struct bgp *bgp, afi_t afi,
1918 safi_t safi)
1920 struct route_node *rn;
1921 struct route_node *rm;
1922 struct route_table *table;
1923 struct bgp_info *ri;
1924 struct bgp_info *next;
1926 for (rn = route_top (bgp->rib[afi][safi]); rn; rn = route_next (rn))
1927 if ((table = (rn->info)) != NULL)
1929 for (rm = route_top (table); rm; rm = route_next (rm))
1930 for (ri = rm->info; ri; ri = next)
1932 next = ri->next;
1934 if (ri->peer == peer)
1936 bgp_aggregate_decrement (bgp, &rm->p, (struct bgp_info *)ri,
1937 afi, safi);
1938 bgp_info_delete ((struct bgp_info **) &rm->info,
1939 (struct bgp_info *)ri);
1940 bgp_process (bgp, rm, afi, safi, (struct bgp_info *)ri,
1941 (struct prefix_rd *)&rn->p, ri->tag);
1942 bgp_info_free ((struct bgp_info *)ri);
1943 route_unlock_node (rm);
1949 /* Remove all routes from the peer. */
1950 void
1951 bgp_route_clear (struct peer *peer)
1953 struct listnode *nn;
1954 struct peer_conf *conf;
1956 /* Clear BGP routes. */
1957 LIST_LOOP (peer->conf, conf, nn)
1959 bgp_route_clear_with_afi (peer, conf->bgp, AFI_IP, SAFI_UNICAST);
1960 bgp_route_clear_with_afi (peer, conf->bgp, AFI_IP, SAFI_MULTICAST);
1961 bgp_route_clear_with_afi (peer, conf->bgp, AFI_IP6, SAFI_UNICAST);
1962 bgp_route_clear_with_afi (peer, conf->bgp, AFI_IP6, SAFI_MULTICAST);
1963 bgp_route_clear_with_afi_vpnv4 (peer, conf->bgp, AFI_IP, SAFI_MPLS_VPN);
1965 /* Clear prefix counter. */
1966 conf->pcount[AFI_IP][SAFI_UNICAST] = 0;
1967 conf->pcount[AFI_IP][SAFI_MULTICAST] = 0;
1968 conf->pcount[AFI_IP][SAFI_MPLS_VPN] = 0;
1969 conf->pcount[AFI_IP6][SAFI_UNICAST] = 0;
1970 conf->pcount[AFI_IP6][SAFI_MULTICAST] = 0;
1973 /* Clear Adj-RIB-In information. */
1974 bgp_adj_clear (peer->adj_in[AFI_IP][SAFI_UNICAST], SAFI_UNICAST);
1975 bgp_adj_clear (peer->adj_in[AFI_IP][SAFI_MULTICAST], SAFI_MULTICAST);
1976 bgp_adj_clear (peer->adj_in[AFI_IP6][SAFI_UNICAST], SAFI_UNICAST);
1977 bgp_adj_clear (peer->adj_in[AFI_IP6][SAFI_MULTICAST], SAFI_MULTICAST);
1979 /* Clear Adj-RIB-Out information. */
1980 bgp_adj_clear (peer->adj_out[AFI_IP][SAFI_UNICAST], SAFI_UNICAST);
1981 bgp_adj_clear (peer->adj_out[AFI_IP][SAFI_MULTICAST], SAFI_MULTICAST);
1982 bgp_adj_clear (peer->adj_out[AFI_IP][SAFI_MPLS_VPN], SAFI_MPLS_VPN);
1983 bgp_adj_clear (peer->adj_out[AFI_IP6][SAFI_UNICAST], SAFI_UNICAST);
1984 bgp_adj_clear (peer->adj_out[AFI_IP6][SAFI_MULTICAST], SAFI_MULTICAST);
1987 struct bgp_static *
1988 bgp_static_new ()
1990 struct bgp_static *new;
1991 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
1992 memset (new, 0, sizeof (struct bgp_static));
1993 return new;
1996 void
1997 bgp_static_free (struct bgp_static *bgp_static)
1999 XFREE (MTYPE_BGP_STATIC, bgp_static);
2002 void
2003 bgp_static_update (struct bgp *bgp, struct prefix *p, u_int16_t afi,
2004 u_char safi)
2006 struct route_node *rn;
2007 struct bgp_info *new;
2008 u_int32_t igpmetric;
2010 rn = bgp_route_node_get (bgp, afi, safi, p, NULL);
2012 /* Make new BGP info. */
2013 new = bgp_info_new ();
2014 new->type = ZEBRA_ROUTE_BGP;
2015 new->sub_type = BGP_ROUTE_STATIC;
2016 new->peer = peer_self;
2017 if (afi == AFI_IP && safi == SAFI_UNICAST
2018 && CHECK_FLAG (bgp->config, BGP_CONFIG_IMPORT_CHECK))
2020 if (bgp_import_check (p, &igpmetric))
2021 SET_FLAG (new->flags, BGP_INFO_VALID);
2022 else
2023 UNSET_FLAG (new->flags, BGP_INFO_VALID);
2025 else
2026 SET_FLAG (new->flags, BGP_INFO_VALID);
2027 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
2028 new->uptime = time (NULL);
2030 /* Aggregate address increment. */
2031 bgp_aggregate_increment (bgp, p, new, afi, safi);
2033 /* Register new BGP information. */
2034 bgp_info_add ((struct bgp_info **) &rn->info, new);
2036 /* Process change. */
2037 bgp_process (bgp, rn, afi, safi, NULL, NULL, NULL);
2040 void
2041 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
2042 u_char safi, struct prefix_rd *prd, u_char *tag)
2044 struct route_node *rn;
2045 struct bgp_info *new;
2047 rn = bgp_route_node_get (bgp, afi, safi, p, prd);
2049 /* Make new BGP info. */
2050 new = bgp_info_new ();
2051 new->type = ZEBRA_ROUTE_BGP;
2052 new->sub_type = BGP_ROUTE_STATIC;
2053 new->peer = peer_self;
2054 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
2055 SET_FLAG (new->flags, BGP_INFO_VALID);
2056 new->uptime = time (NULL);
2057 memcpy (new->tag, tag, 3);
2059 /* Aggregate address increment. */
2060 bgp_aggregate_increment (bgp, p, (struct bgp_info *) new, afi, safi);
2062 /* Register new BGP information. */
2063 bgp_info_add ((struct bgp_info **) &rn->info, (struct bgp_info *) new);
2065 /* Process change. */
2066 bgp_process (bgp, rn, afi, safi, NULL, prd, tag);
2069 void
2070 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, u_int16_t afi,
2071 u_char safi)
2073 struct route_node *rn;
2074 struct bgp_info *ri;
2076 rn = bgp_route_node_get (bgp, afi, safi, p, NULL);
2078 /* Check selected route and self inserted route. */
2079 for (ri = rn->info; ri; ri = ri->next)
2080 if (ri->peer == peer_self
2081 && ri->type == ZEBRA_ROUTE_BGP
2082 && ri->sub_type == BGP_ROUTE_STATIC)
2083 break;
2085 /* Withdraw static BGP route from routing table. */
2086 if (ri)
2088 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2089 bgp_info_delete ((struct bgp_info **) &rn->info, ri);
2090 bgp_process (bgp, rn, afi, safi, ri, NULL, NULL);
2091 bgp_info_free (ri);
2092 route_unlock_node (rn);
2095 /* Unlock route_node_lookup. */
2096 route_unlock_node (rn);
2099 void
2100 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
2101 u_char safi, struct prefix_rd *prd, u_char *tag)
2103 struct route_node *rn;
2104 struct bgp_info *ri;
2106 rn = bgp_route_node_get (bgp, afi, safi, p, prd);
2108 /* Check selected route and self inserted route. */
2109 for (ri = rn->info; ri; ri = ri->next)
2110 if (ri->peer == peer_self
2111 && ri->type == ZEBRA_ROUTE_BGP
2112 && ri->sub_type == BGP_ROUTE_STATIC)
2113 break;
2115 /* Withdraw static BGP route from routing table. */
2116 if (ri)
2118 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2119 bgp_info_delete ((struct bgp_info **) &rn->info, ri);
2120 bgp_process (bgp, rn, afi, safi, ri, prd, tag);
2121 bgp_info_free (ri);
2122 route_unlock_node (rn);
2125 /* Unlock route_node_lookup. */
2126 route_unlock_node (rn);
2129 /* Configure static BGP network. */
2131 bgp_static_set (struct vty *vty, struct bgp *bgp, char *ip_str, u_int16_t afi,
2132 u_char safi, int backdoor)
2134 int ret;
2135 struct prefix p;
2136 struct bgp_static *bgp_static;
2137 struct route_node *rn;
2139 /* Convert IP prefix string to struct prefix. */
2140 ret = str2prefix (ip_str, &p);
2141 if (! ret)
2143 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2144 return CMD_WARNING;
2146 #ifdef HAVE_IPV6
2147 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2149 vty_out (vty, "%% Malformed prefix (link-local address)%s",
2150 VTY_NEWLINE);
2151 return CMD_WARNING;
2153 #endif /* HAVE_IPV6 */
2155 apply_mask (&p);
2157 /* Set BGP static route configuration. */
2158 rn = route_node_get (bgp->route[afi][safi], &p);
2160 if (rn->info)
2162 /* Configuration change. */
2163 bgp_static = rn->info;
2165 if (! backdoor)
2167 if (bgp_static->backdoor)
2168 bgp_static_update (bgp, &p, afi, safi);
2170 else
2172 if (! bgp_static->backdoor)
2173 bgp_static_withdraw (bgp, &p, afi, safi);
2175 bgp_static->backdoor = backdoor;
2176 route_unlock_node (rn);
2178 else
2180 /* New configuration. */
2181 bgp_static = bgp_static_new ();
2182 bgp_static->backdoor = backdoor;
2183 bgp_static->valid = 1;
2184 rn->info = bgp_static;
2186 if (! backdoor)
2187 bgp_static_update (bgp, &p, afi, safi);
2190 return CMD_SUCCESS;
2193 /* Configure static BGP network. */
2195 bgp_static_unset (struct vty *vty, struct bgp *bgp, char *ip_str,
2196 u_int16_t afi, u_char safi)
2198 int ret;
2199 struct prefix p;
2200 struct bgp_static *bgp_static;
2201 struct route_node *rn;
2203 /* Convert IP prefix string to struct prefix. */
2204 ret = str2prefix (ip_str, &p);
2205 if (! ret)
2207 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2208 return CMD_WARNING;
2210 #ifdef HAVE_IPV6
2211 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2213 vty_out (vty, "%% Malformed prefix (link-local address)%s",
2214 VTY_NEWLINE);
2215 return CMD_WARNING;
2217 #endif /* HAVE_IPV6 */
2219 apply_mask (&p);
2221 rn = route_node_lookup (bgp->route[afi][safi], &p);
2222 if (! rn)
2224 vty_out (vty, "%% Can't find specified static route configuration.%s",
2225 VTY_NEWLINE);
2226 return CMD_WARNING;
2229 bgp_static = rn->info;
2231 /* Update BGP RIB. */
2232 if (! bgp_static->backdoor)
2233 bgp_static_withdraw (bgp, &p, afi, safi);
2235 /* Clear configuration. */
2236 bgp_static_free (bgp_static);
2237 rn->info = NULL;
2238 route_unlock_node (rn);
2239 route_unlock_node (rn);
2241 return CMD_SUCCESS;
2244 /* Called from bgp_delete(). Delete all static routes from the BGP
2245 instance. */
2246 void
2247 bgp_static_delete (struct bgp *bgp)
2249 afi_t afi;
2250 safi_t safi;
2251 struct route_node *rn;
2252 struct route_node *rm;
2253 struct route_table *table;
2254 struct bgp_static *bgp_static;
2256 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2257 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2258 for (rn = route_top (bgp->route[afi][safi]); rn; rn = route_next (rn))
2259 if (rn->info != NULL)
2261 if (safi == SAFI_MPLS_VPN)
2263 table = rn->info;
2265 for (rm = route_top (table); rm; rm = route_next (rm))
2267 bgp_static = rn->info;
2268 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
2269 AFI_IP, SAFI_MPLS_VPN,
2270 (struct prefix_rd *)&rn->p,
2271 bgp_static->tag);
2272 bgp_static_free (bgp_static);
2273 rn->info = NULL;
2274 route_unlock_node (rn);
2277 else
2279 bgp_static = rn->info;
2280 bgp_static_withdraw (bgp, &rn->p, afi, safi);
2281 bgp_static_free (bgp_static);
2282 rn->info = NULL;
2283 route_unlock_node (rn);
2289 bgp_static_set_vpnv4 (struct vty *vty, char *ip_str, char *rd_str,
2290 char *tag_str)
2292 int ret;
2293 struct prefix p;
2294 struct prefix_rd prd;
2295 struct bgp *bgp;
2296 struct route_node *prn;
2297 struct route_node *rn;
2298 struct route_table *table;
2299 struct bgp_static *bgp_static;
2300 u_char tag[3];
2302 bgp = vty->index;
2304 ret = str2prefix (ip_str, &p);
2305 if (! ret)
2307 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2308 return CMD_WARNING;
2310 apply_mask (&p);
2312 ret = str2prefix_rd (rd_str, &prd);
2313 if (! ret)
2315 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
2316 return CMD_WARNING;
2319 ret = str2tag (tag_str, tag);
2320 if (! ret)
2322 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
2323 return CMD_WARNING;
2326 prn = route_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
2327 (struct prefix *)&prd);
2328 if (prn->info == NULL)
2329 prn->info = route_table_init ();
2330 else
2331 route_unlock_node (prn);
2332 table = prn->info;
2334 rn = route_node_get (table, &p);
2336 if (rn->info)
2338 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
2339 route_unlock_node (rn);
2341 else
2343 /* New configuration. */
2344 bgp_static = bgp_static_new ();
2345 bgp_static->valid = 1;
2346 memcpy (bgp_static->tag, tag, 3);
2347 rn->info = bgp_static;
2349 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
2352 return CMD_SUCCESS;
2355 /* Configure static BGP network. */
2357 bgp_static_unset_vpnv4 (struct vty *vty, char *ip_str, char *rd_str,
2358 char *tag_str)
2360 int ret;
2361 struct bgp *bgp;
2362 struct prefix p;
2363 struct prefix_rd prd;
2364 struct route_node *prn;
2365 struct route_node *rn;
2366 struct route_table *table;
2367 struct bgp_static *bgp_static;
2368 u_char tag[3];
2370 bgp = vty->index;
2372 /* Convert IP prefix string to struct prefix. */
2373 ret = str2prefix (ip_str, &p);
2374 if (! ret)
2376 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2377 return CMD_WARNING;
2379 apply_mask (&p);
2381 ret = str2prefix_rd (rd_str, &prd);
2382 if (! ret)
2384 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
2385 return CMD_WARNING;
2388 ret = str2tag (tag_str, tag);
2389 if (! ret)
2391 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
2392 return CMD_WARNING;
2395 prn = route_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
2396 (struct prefix *)&prd);
2397 if (prn->info == NULL)
2398 prn->info = route_table_init ();
2399 else
2400 route_unlock_node (prn);
2401 table = prn->info;
2403 rn = route_node_lookup (table, &p);
2405 if (rn)
2407 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
2409 bgp_static = rn->info;
2410 bgp_static_free (bgp_static);
2411 rn->info = NULL;
2412 route_unlock_node (rn);
2413 route_unlock_node (rn);
2415 else
2416 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
2418 return CMD_SUCCESS;
2421 afi_t
2422 bgp_node_afi (struct vty *vty)
2424 if (vty->node == BGP_IPV6_NODE)
2425 return AFI_IP6;
2426 return AFI_IP;
2429 safi_t
2430 bgp_node_safi (struct vty *vty)
2432 if (vty->node == BGP_VPNV4_NODE)
2433 return SAFI_MPLS_VPN;
2434 if (vty->node == BGP_IPV4M_NODE)
2435 return SAFI_MULTICAST;
2436 return SAFI_UNICAST;
2439 DEFUN (bgp_network,
2440 bgp_network_cmd,
2441 "network A.B.C.D/M",
2442 "Specify a network to announce via BGP\n"
2443 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2445 return bgp_static_set (vty, vty->index, argv[0],
2446 AFI_IP, bgp_node_safi (vty), 0);
2449 DEFUN (bgp_network_mask,
2450 bgp_network_mask_cmd,
2451 "network A.B.C.D mask A.B.C.D",
2452 "Specify a network to announce via BGP\n"
2453 "Network number\n"
2454 "Network mask\n"
2455 "Network mask\n")
2457 int ret;
2458 char prefix_str[BUFSIZ];
2460 if (argc == 2)
2461 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2462 else
2463 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2465 if (! ret)
2467 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2468 return CMD_WARNING;
2471 return bgp_static_set (vty, vty->index, prefix_str,
2472 AFI_IP, bgp_node_safi (vty), 0);
2475 ALIAS (bgp_network_mask,
2476 bgp_network_mask_natural_cmd,
2477 "network A.B.C.D",
2478 "Specify a network to announce via BGP\n"
2479 "Network number\n")
2481 DEFUN (bgp_network_backdoor,
2482 bgp_network_backdoor_cmd,
2483 "network A.B.C.D/M backdoor",
2484 "Specify a network to announce via BGP\n"
2485 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2486 "Specify a BGP backdoor route\n")
2488 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, 1);
2491 DEFUN (bgp_network_mask_backdoor,
2492 bgp_network_mask_backdoor_cmd,
2493 "network A.B.C.D mask A.B.C.D backdoor",
2494 "Specify a network to announce via BGP\n"
2495 "Network number\n"
2496 "Network mask\n"
2497 "Network mask\n"
2498 "Specify a BGP backdoor route\n")
2500 int ret;
2501 char prefix_str[BUFSIZ];
2503 if (argc == 2)
2504 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2505 else
2506 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2508 if (! ret)
2510 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2511 return CMD_WARNING;
2514 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, 1);
2517 ALIAS (bgp_network_mask_backdoor,
2518 bgp_network_mask_natural_backdoor_cmd,
2519 "network A.B.C.D backdoor",
2520 "Specify a network to announce via BGP\n"
2521 "Network number\n"
2522 "Specify a BGP backdoor route\n")
2524 DEFUN (no_bgp_network,
2525 no_bgp_network_cmd,
2526 "no network A.B.C.D/M",
2527 NO_STR
2528 "Specify a network to announce via BGP\n"
2529 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2531 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
2532 bgp_node_safi (vty));
2535 ALIAS (no_bgp_network,
2536 no_bgp_network_backdoor_cmd,
2537 "no network A.B.C.D/M backdoor",
2538 NO_STR
2539 "Specify a network to announce via BGP\n"
2540 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2541 "Specify a BGP backdoor route\n")
2543 DEFUN (no_bgp_network_mask,
2544 no_bgp_network_mask_cmd,
2545 "no network A.B.C.D mask A.B.C.D",
2546 NO_STR
2547 "Specify a network to announce via BGP\n"
2548 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2550 int ret;
2551 char prefix_str[BUFSIZ];
2553 if (argc == 2)
2554 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2555 else
2556 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2558 if (! ret)
2560 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2561 return CMD_WARNING;
2564 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
2565 bgp_node_safi (vty));
2568 ALIAS (no_bgp_network_mask,
2569 no_bgp_network_mask_natural_cmd,
2570 "no network A.B.C.D",
2571 "Specify a network to announce via BGP\n"
2572 "Network number\n")
2574 ALIAS (no_bgp_network_mask,
2575 no_bgp_network_mask_backdoor_cmd,
2576 "no network A.B.C.D mask A.B.C.D backdoor",
2577 NO_STR
2578 "Specify a network to announce via BGP\n"
2579 "Network number\n"
2580 "Network mask\n"
2581 "Network mask\n"
2582 "Specify a BGP backdoor route\n")
2584 ALIAS (no_bgp_network_mask,
2585 no_bgp_network_mask_natural_backdoor_cmd,
2586 "no network A.B.C.D backdoor",
2587 NO_STR
2588 "Specify a network to announce via BGP\n"
2589 "Network number\n"
2590 "Specify a BGP backdoor route\n")
2592 #ifdef HAVE_IPV6
2593 DEFUN (ipv6_bgp_network,
2594 ipv6_bgp_network_cmd,
2595 "network X:X::X:X/M",
2596 "Specify a network to announce via BGP\n"
2597 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2599 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, 0);
2602 DEFUN (no_ipv6_bgp_network,
2603 no_ipv6_bgp_network_cmd,
2604 "no network X:X::X:X/M",
2605 NO_STR
2606 "Specify a network to announce via BGP\n"
2607 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2609 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
2612 ALIAS (ipv6_bgp_network,
2613 old_ipv6_bgp_network_cmd,
2614 "ipv6 bgp network X:X::X:X/M",
2615 IPV6_STR
2616 BGP_STR
2617 "Specify a network to announce via BGP\n"
2618 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2620 ALIAS (no_ipv6_bgp_network,
2621 old_no_ipv6_bgp_network_cmd,
2622 "no ipv6 bgp network X:X::X:X/M",
2623 NO_STR
2624 IPV6_STR
2625 BGP_STR
2626 "Specify a network to announce via BGP\n"
2627 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2628 #endif /* HAVE_IPV6 */
2630 /* Aggreagete address:
2632 advertise-map Set condition to advertise attribute
2633 as-set Generate AS set path information
2634 attribute-map Set attributes of aggregate
2635 route-map Set parameters of aggregate
2636 summary-only Filter more specific routes from updates
2637 suppress-map Conditionally filter more specific routes from updates
2638 <cr>
2640 struct bgp_aggregate
2642 /* Summary-only flag. */
2643 u_char summary_only;
2645 /* AS set generation. */
2646 u_char as_set;
2648 /* Route-map for aggregated route. */
2649 struct route_map *map;
2651 /* Suppress-count. */
2652 unsigned long count;
2654 /* SAFI configuration. */
2655 safi_t safi;
2658 struct bgp_aggregate *
2659 bgp_aggregate_new ()
2661 struct bgp_aggregate *new;
2662 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
2663 memset (new, 0, sizeof (struct bgp_aggregate));
2664 return new;
2667 void
2668 bgp_aggregate_free (struct bgp_aggregate *aggregate)
2670 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
2673 void
2674 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
2675 afi_t afi, safi_t safi, struct bgp_info *del,
2676 struct bgp_aggregate *aggregate)
2678 struct route_table *table;
2679 struct route_node *top;
2680 struct route_node *rn;
2681 u_char origin;
2682 struct aspath *aspath = NULL;
2683 struct aspath *asmerge = NULL;
2684 struct community *community = NULL;
2685 struct community *commerge = NULL;
2686 struct in_addr nexthop;
2687 u_int32_t med = 0;
2688 struct bgp_info *ri;
2689 struct bgp_info *new;
2690 int first = 1;
2691 unsigned long match = 0;
2693 /* Record adding route's nexthop and med. */
2694 if (rinew)
2696 nexthop = rinew->attr->nexthop;
2697 med = rinew->attr->med;
2700 /* ORIGIN attribute: If at least one route among routes that are
2701 aggregated has ORIGIN with the value INCOMPLETE, then the
2702 aggregated route must have the ORIGIN attribute with the value
2703 INCOMPLETE. Otherwise, if at least one route among routes that
2704 are aggregated has ORIGIN with the value EGP, then the aggregated
2705 route must have the origin attribute with the value EGP. In all
2706 other case the value of the ORIGIN attribute of the aggregated
2707 route is INTERNAL. */
2708 origin = BGP_ORIGIN_IGP;
2710 table = bgp->rib[afi][safi];
2712 top = route_node_get (table, p);
2713 for (rn = route_node_get (table, p); rn; rn = route_next_until (rn, top))
2714 if (rn->p.prefixlen > p->prefixlen)
2716 match = 0;
2718 for (ri = rn->info; ri; ri = ri->next)
2720 if (BGP_INFO_HOLDDOWN (ri))
2721 continue;
2723 if (del && ri == del)
2724 continue;
2726 if (! rinew && first)
2728 nexthop = ri->attr->nexthop;
2729 med = ri->attr->med;
2730 first = 0;
2733 #ifdef AGGREGATE_NEXTHOP_CHECK
2734 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
2735 || ri->attr->med != med)
2737 if (aspath)
2738 aspath_free (aspath);
2739 if (community)
2740 community_free (community);
2741 route_unlock_node (rn);
2742 route_unlock_node (top);
2743 return;
2745 #endif /* AGGREGATE_NEXTHOP_CHECK */
2747 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
2749 if (aggregate->summary_only)
2751 ri->suppress++;
2752 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2753 match++;
2756 aggregate->count++;
2758 if (aggregate->as_set)
2760 if (origin < ri->attr->origin)
2761 origin = ri->attr->origin;
2763 if (aspath)
2765 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
2766 aspath_free (aspath);
2767 aspath = asmerge;
2769 else
2770 aspath = aspath_dup (ri->attr->aspath);
2772 if (ri->attr->community)
2774 if (community)
2776 commerge = community_merge (community,
2777 ri->attr->community);
2778 community = community_uniq_sort (commerge);
2779 community_free (commerge);
2781 else
2782 community = community_dup (ri->attr->community);
2787 if (match)
2788 bgp_process (bgp, rn, afi, safi, NULL, NULL, NULL);
2790 route_unlock_node (top);
2792 if (rinew)
2794 aggregate->count++;
2796 if (aggregate->summary_only)
2797 rinew->suppress++;
2799 if (aggregate->as_set)
2801 if (origin < rinew->attr->origin)
2802 origin = rinew->attr->origin;
2804 if (aspath)
2806 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
2807 aspath_free (aspath);
2808 aspath = asmerge;
2810 else
2811 aspath = aspath_dup (rinew->attr->aspath);
2813 if (rinew->attr->community)
2815 if (community)
2817 commerge = community_merge (community,
2818 rinew->attr->community);
2819 community = community_uniq_sort (commerge);
2820 community_free (commerge);
2822 else
2823 community = community_dup (rinew->attr->community);
2828 if (aggregate->count > 0)
2830 rn = route_node_get (table, p);
2831 new = bgp_info_new ();
2832 new->type = ZEBRA_ROUTE_BGP;
2833 new->sub_type = BGP_ROUTE_AGGREGATE;
2834 new->peer = peer_self;
2835 SET_FLAG (new->flags, BGP_INFO_VALID);
2836 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
2837 new->uptime = time (NULL);
2839 bgp_info_add ((struct bgp_info **) &rn->info, new);
2840 bgp_process (bgp, rn, afi, safi, NULL, NULL, NULL);
2842 else
2844 if (aspath)
2845 aspath_free (aspath);
2846 if (community)
2847 community_free (community);
2851 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
2852 struct bgp_aggregate *);
2854 void
2855 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
2856 struct bgp_info *ri, afi_t afi, safi_t safi)
2858 struct route_node *child;
2859 struct route_node *rn;
2860 struct bgp_aggregate *aggregate;
2862 /* MPLS-VPN aggregation is not yet supported. */
2863 if (safi == SAFI_MPLS_VPN)
2864 return;
2866 if (p->prefixlen == 0)
2867 return;
2869 if (BGP_INFO_HOLDDOWN (ri))
2870 return;
2872 child = route_node_get (bgp->aggregate[afi][safi], p);
2874 /* Aggregate address configuration check. */
2875 for (rn = child; rn; rn = rn->parent)
2876 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
2878 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
2879 bgp_aggregate_route (bgp, &rn->p, ri, safi, safi, NULL, aggregate);
2881 route_unlock_node (child);
2884 void
2885 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
2886 struct bgp_info *del, afi_t afi, safi_t safi)
2888 struct route_node *child;
2889 struct route_node *rn;
2890 struct bgp_aggregate *aggregate;
2892 /* MPLS-VPN aggregation is not yet supported. */
2893 if (safi == SAFI_MPLS_VPN)
2894 return;
2896 if (p->prefixlen == 0)
2897 return;
2899 if (BGP_INFO_HOLDDOWN (del))
2900 return;
2902 child = route_node_get (bgp->aggregate[afi][safi], p);
2904 /* Aggregate address configuration check. */
2905 for (rn = child; rn; rn = rn->parent)
2906 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
2908 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
2909 bgp_aggregate_route (bgp, &rn->p, NULL, safi, safi, del, aggregate);
2911 route_unlock_node (child);
2914 void
2915 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
2916 struct bgp_aggregate *aggregate)
2918 struct route_table *table;
2919 struct route_node *top;
2920 struct route_node *rn;
2921 struct bgp_info *new;
2922 struct bgp_info *ri;
2923 unsigned long match;
2924 u_char origin = BGP_ORIGIN_IGP;
2925 struct aspath *aspath = NULL;
2926 struct aspath *asmerge = NULL;
2927 struct community *community = NULL;
2928 struct community *commerge = NULL;
2930 table = bgp->rib[afi][safi];
2932 /* Sanity check. */
2933 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
2934 return;
2935 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
2936 return;
2938 /* If routes exists below this node, generate aggregate routes. */
2939 top = route_node_get (table, p);
2940 for (rn = route_node_get (table, p); rn; rn = route_next_until (rn, top))
2941 if (rn->p.prefixlen > p->prefixlen)
2943 match = 0;
2945 for (ri = rn->info; ri; ri = ri->next)
2947 if (BGP_INFO_HOLDDOWN (ri))
2948 continue;
2950 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
2952 /* summary-only aggregate route suppress aggregated
2953 route announcement. */
2954 if (aggregate->summary_only)
2956 ri->suppress++;
2957 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2958 match++;
2960 /* as-set aggregate route generate origin, as path,
2961 community aggregation. */
2962 if (aggregate->as_set)
2964 if (origin < ri->attr->origin)
2965 origin = ri->attr->origin;
2967 if (aspath)
2969 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
2970 aspath_free (aspath);
2971 aspath = asmerge;
2973 else
2974 aspath = aspath_dup (ri->attr->aspath);
2976 if (ri->attr->community)
2978 if (community)
2980 commerge = community_merge (community,
2981 ri->attr->community);
2982 community = community_uniq_sort (commerge);
2983 community_free (commerge);
2985 else
2986 community = community_dup (ri->attr->community);
2989 aggregate->count++;
2993 /* If this node is suppressed, process the change. */
2994 if (match)
2995 bgp_process (bgp, rn, afi, safi, NULL, NULL, NULL);
2997 route_unlock_node (top);
2999 /* Add aggregate route to BGP table. */
3000 if (aggregate->count)
3002 rn = route_node_get (table, p);
3004 new = bgp_info_new ();
3005 new->type = ZEBRA_ROUTE_BGP;
3006 new->sub_type = BGP_ROUTE_AGGREGATE;
3007 new->peer = peer_self;
3008 SET_FLAG (new->flags, BGP_INFO_VALID);
3009 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
3010 new->uptime = time (NULL);
3012 bgp_info_add ((struct bgp_info **) &rn->info, new);
3014 /* Process change. */
3015 bgp_process (bgp, rn, afi, safi, NULL, NULL, NULL);
3019 void
3020 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
3021 safi_t safi, struct bgp_aggregate *aggregate)
3023 struct route_table *table;
3024 struct route_node *top;
3025 struct route_node *rn;
3026 struct bgp_info *ri;
3027 unsigned long match;
3029 table = bgp->rib[afi][safi];
3031 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
3032 return;
3033 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
3034 return;
3036 /* If routes exists below this node, generate aggregate routes. */
3037 top = route_node_get (table, p);
3038 for (rn = route_node_get (table, p); rn; rn = route_next_until (rn, top))
3039 if (rn->p.prefixlen > p->prefixlen)
3041 match = 0;
3043 for (ri = rn->info; ri; ri = ri->next)
3045 if (BGP_INFO_HOLDDOWN (ri))
3046 continue;
3048 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
3050 if (aggregate->summary_only)
3052 ri->suppress--;
3054 if (ri->suppress == 0)
3056 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3057 match++;
3060 aggregate->count--;
3064 /* If this node is suppressed, process the change. */
3065 if (match)
3066 bgp_process (bgp, rn, afi, safi, NULL, NULL, NULL);
3068 route_unlock_node (top);
3070 /* Delete aggregate route from BGP table. */
3071 rn = route_node_get (table, p);
3073 for (ri = rn->info; ri; ri = ri->next)
3074 if (ri->peer == peer_self
3075 && ri->type == ZEBRA_ROUTE_BGP
3076 && ri->sub_type == BGP_ROUTE_AGGREGATE)
3077 break;
3079 /* Withdraw static BGP route from routing table. */
3080 if (ri)
3082 bgp_info_delete ((struct bgp_info **) &rn->info, ri);
3083 bgp_process (bgp, rn, afi, safi, ri, NULL, NULL);
3084 bgp_info_free (ri);
3085 route_unlock_node (rn);
3088 /* Unlock route_node_lookup. */
3089 route_unlock_node (rn);
3092 /* Aggregate route attribute. */
3093 #define AGGREGATE_SUMMARY_ONLY 1
3094 #define AGGREGATE_AS_SET 1
3097 bgp_aggregate_set (struct vty *vty, char *prefix_str, afi_t afi, safi_t safi,
3098 u_char summary_only, u_char as_set)
3100 int ret;
3101 struct prefix p;
3102 struct route_node *rn;
3103 struct bgp *bgp;
3104 struct bgp_aggregate *aggregate;
3106 /* Convert string to prefix structure. */
3107 ret = str2prefix (prefix_str, &p);
3108 if (!ret)
3110 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
3111 return CMD_WARNING;
3113 apply_mask (&p);
3115 /* Get BGP structure. */
3116 bgp = vty->index;
3118 /* Old configuration check. */
3119 rn = route_node_get (bgp->aggregate[afi][safi], &p);
3121 if (rn->info)
3123 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
3124 route_unlock_node (rn);
3125 return CMD_WARNING;
3128 /* Make aggregate address structure. */
3129 aggregate = bgp_aggregate_new ();
3130 aggregate->summary_only = summary_only;
3131 aggregate->as_set = as_set;
3132 aggregate->safi = safi;
3133 rn->info = aggregate;
3135 /* Aggregate address insert into BGP routing table. */
3136 if (safi & SAFI_UNICAST)
3137 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
3138 if (safi & SAFI_MULTICAST)
3139 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
3141 return CMD_SUCCESS;
3145 bgp_aggregate_unset (struct vty *vty, char *prefix_str, afi_t afi, safi_t safi)
3147 int ret;
3148 struct prefix p;
3149 struct route_node *rn;
3150 struct bgp *bgp;
3151 struct bgp_aggregate *aggregate;
3153 /* Convert string to prefix structure. */
3154 ret = str2prefix (prefix_str, &p);
3155 if (!ret)
3157 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
3158 return CMD_WARNING;
3160 apply_mask (&p);
3162 /* Get BGP structure. */
3163 bgp = vty->index;
3165 /* Old configuration check. */
3166 rn = route_node_lookup (bgp->aggregate[afi][safi], &p);
3167 if (! rn)
3169 vty_out (vty, "%% There is no aggregate-address configuration.%s",
3170 VTY_NEWLINE);
3171 return CMD_WARNING;
3174 aggregate = rn->info;
3175 if (aggregate->safi & SAFI_UNICAST)
3176 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
3177 if (aggregate->safi & SAFI_MULTICAST)
3178 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
3180 /* Unlock aggregate address configuration. */
3181 rn->info = NULL;
3182 bgp_aggregate_free (aggregate);
3183 route_unlock_node (rn);
3184 route_unlock_node (rn);
3186 return CMD_SUCCESS;
3189 DEFUN (aggregate_address,
3190 aggregate_address_cmd,
3191 "aggregate-address A.B.C.D/M",
3192 "Configure BGP aggregate entries\n"
3193 "Aggregate prefix\n")
3195 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
3198 DEFUN (aggregate_address_mask,
3199 aggregate_address_mask_cmd,
3200 "aggregate-address A.B.C.D A.B.C.D",
3201 "Configure BGP aggregate entries\n"
3202 "Aggregate address\n"
3203 "Aggregate mask\n")
3205 int ret;
3206 char prefix_str[BUFSIZ];
3208 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3210 if (! ret)
3212 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3213 return CMD_WARNING;
3216 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3217 0, 0);
3220 DEFUN (aggregate_address_summary_only,
3221 aggregate_address_summary_only_cmd,
3222 "aggregate-address A.B.C.D/M summary-only",
3223 "Configure BGP aggregate entries\n"
3224 "Aggregate prefix\n"
3225 "Filter more specific routes from updates\n")
3227 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3228 AGGREGATE_SUMMARY_ONLY, 0);
3231 DEFUN (aggregate_address_mask_summary_only,
3232 aggregate_address_mask_summary_only_cmd,
3233 "aggregate-address A.B.C.D A.B.C.D summary-only",
3234 "Configure BGP aggregate entries\n"
3235 "Aggregate address\n"
3236 "Aggregate mask\n"
3237 "Filter more specific routes from updates\n")
3239 int ret;
3240 char prefix_str[BUFSIZ];
3242 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3244 if (! ret)
3246 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3247 return CMD_WARNING;
3250 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3251 AGGREGATE_SUMMARY_ONLY, 0);
3254 DEFUN (aggregate_address_as_set,
3255 aggregate_address_as_set_cmd,
3256 "aggregate-address A.B.C.D/M as-set",
3257 "Configure BGP aggregate entries\n"
3258 "Aggregate prefix\n"
3259 "Generate AS set path information\n")
3261 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3262 0, AGGREGATE_AS_SET);
3265 DEFUN (aggregate_address_mask_as_set,
3266 aggregate_address_mask_as_set_cmd,
3267 "aggregate-address A.B.C.D A.B.C.D as-set",
3268 "Configure BGP aggregate entries\n"
3269 "Aggregate address\n"
3270 "Aggregate mask\n"
3271 "Generate AS set path information\n")
3273 int ret;
3274 char prefix_str[BUFSIZ];
3276 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3278 if (! ret)
3280 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3281 return CMD_WARNING;
3284 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3285 0, AGGREGATE_AS_SET);
3289 DEFUN (aggregate_address_as_set_summary,
3290 aggregate_address_as_set_summary_cmd,
3291 "aggregate-address A.B.C.D/M as-set summary-only",
3292 "Configure BGP aggregate entries\n"
3293 "Aggregate prefix\n"
3294 "Generate AS set path information\n"
3295 "Filter more specific routes from updates\n")
3297 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3298 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
3301 ALIAS (aggregate_address_as_set_summary,
3302 aggregate_address_summary_as_set_cmd,
3303 "aggregate-address A.B.C.D/M summary-only as-set",
3304 "Configure BGP aggregate entries\n"
3305 "Aggregate prefix\n"
3306 "Filter more specific routes from updates\n"
3307 "Generate AS set path information\n")
3309 DEFUN (aggregate_address_mask_as_set_summary,
3310 aggregate_address_mask_as_set_summary_cmd,
3311 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
3312 "Configure BGP aggregate entries\n"
3313 "Aggregate address\n"
3314 "Aggregate mask\n"
3315 "Generate AS set path information\n"
3316 "Filter more specific routes from updates\n")
3318 int ret;
3319 char prefix_str[BUFSIZ];
3321 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3323 if (! ret)
3325 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3326 return CMD_WARNING;
3329 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3330 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
3333 ALIAS (aggregate_address_mask_as_set_summary,
3334 aggregate_address_mask_summary_as_set_cmd,
3335 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
3336 "Configure BGP aggregate entries\n"
3337 "Aggregate address\n"
3338 "Aggregate mask\n"
3339 "Filter more specific routes from updates\n"
3340 "Generate AS set path information\n")
3342 DEFUN (no_aggregate_address,
3343 no_aggregate_address_cmd,
3344 "no aggregate-address A.B.C.D/M",
3345 NO_STR
3346 "Configure BGP aggregate entries\n"
3347 "Aggregate prefix\n")
3349 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
3352 ALIAS (no_aggregate_address,
3353 no_aggregate_address_summary_only_cmd,
3354 "no aggregate-address A.B.C.D/M summary-only",
3355 NO_STR
3356 "Configure BGP aggregate entries\n"
3357 "Aggregate prefix\n"
3358 "Filter more specific routes from updates\n")
3360 ALIAS (no_aggregate_address,
3361 no_aggregate_address_as_set_cmd,
3362 "no aggregate-address A.B.C.D/M as-set",
3363 NO_STR
3364 "Configure BGP aggregate entries\n"
3365 "Aggregate prefix\n"
3366 "Generate AS set path information\n")
3368 ALIAS (no_aggregate_address,
3369 no_aggregate_address_as_set_summary_cmd,
3370 "no aggregate-address A.B.C.D/M as-set summary-only",
3371 NO_STR
3372 "Configure BGP aggregate entries\n"
3373 "Aggregate prefix\n"
3374 "Generate AS set path information\n"
3375 "Filter more specific routes from updates\n")
3377 ALIAS (no_aggregate_address,
3378 no_aggregate_address_summary_as_set_cmd,
3379 "no aggregate-address A.B.C.D/M summary-only as-set",
3380 NO_STR
3381 "Configure BGP aggregate entries\n"
3382 "Aggregate prefix\n"
3383 "Filter more specific routes from updates\n"
3384 "Generate AS set path information\n")
3386 DEFUN (no_aggregate_address_mask,
3387 no_aggregate_address_mask_cmd,
3388 "no aggregate-address A.B.C.D A.B.C.D",
3389 NO_STR
3390 "Configure BGP aggregate entries\n"
3391 "Aggregate address\n"
3392 "Aggregate mask\n")
3394 int ret;
3395 char prefix_str[BUFSIZ];
3397 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3399 if (! ret)
3401 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3402 return CMD_WARNING;
3405 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
3408 ALIAS (no_aggregate_address_mask,
3409 no_aggregate_address_mask_summary_only_cmd,
3410 "no aggregate-address A.B.C.D A.B.C.D summary-only",
3411 NO_STR
3412 "Configure BGP aggregate entries\n"
3413 "Aggregate address\n"
3414 "Aggregate mask\n"
3415 "Filter more specific routes from updates\n")
3417 ALIAS (no_aggregate_address_mask,
3418 no_aggregate_address_mask_as_set_cmd,
3419 "no aggregate-address A.B.C.D A.B.C.D as-set",
3420 NO_STR
3421 "Configure BGP aggregate entries\n"
3422 "Aggregate address\n"
3423 "Aggregate mask\n"
3424 "Generate AS set path information\n")
3426 ALIAS (no_aggregate_address_mask,
3427 no_aggregate_address_mask_as_set_summary_cmd,
3428 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
3429 NO_STR
3430 "Configure BGP aggregate entries\n"
3431 "Aggregate address\n"
3432 "Aggregate mask\n"
3433 "Generate AS set path information\n"
3434 "Filter more specific routes from updates\n")
3436 ALIAS (no_aggregate_address_mask,
3437 no_aggregate_address_mask_summary_as_set_cmd,
3438 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
3439 NO_STR
3440 "Configure BGP aggregate entries\n"
3441 "Aggregate address\n"
3442 "Aggregate mask\n"
3443 "Filter more specific routes from updates\n"
3444 "Generate AS set path information\n")
3446 #ifdef HAVE_IPV6
3447 DEFUN (ipv6_aggregate_address,
3448 ipv6_aggregate_address_cmd,
3449 "aggregate-address X:X::X:X/M",
3450 "Configure BGP aggregate entries\n"
3451 "Aggregate prefix\n")
3453 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
3456 DEFUN (ipv6_aggregate_address_summary_only,
3457 ipv6_aggregate_address_summary_only_cmd,
3458 "aggregate-address X:X::X:X/M summary-only",
3459 "Configure BGP aggregate entries\n"
3460 "Aggregate prefix\n"
3461 "Filter more specific routes from updates\n")
3463 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3464 AGGREGATE_SUMMARY_ONLY, 0);
3467 DEFUN (no_ipv6_aggregate_address,
3468 no_ipv6_aggregate_address_cmd,
3469 "no aggregate-address X:X::X:X/M",
3470 NO_STR
3471 "Configure BGP aggregate entries\n"
3472 "Aggregate prefix\n")
3474 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
3477 DEFUN (no_ipv6_aggregate_address_summary_only,
3478 no_ipv6_aggregate_address_summary_only_cmd,
3479 "no aggregate-address X:X::X:X/M summary-only",
3480 NO_STR
3481 "Configure BGP aggregate entries\n"
3482 "Aggregate prefix\n"
3483 "Filter more specific routes from updates\n")
3485 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
3488 ALIAS (ipv6_aggregate_address,
3489 old_ipv6_aggregate_address_cmd,
3490 "ipv6 bgp aggregate-address X:X::X:X/M",
3491 IPV6_STR
3492 BGP_STR
3493 "Configure BGP aggregate entries\n"
3494 "Aggregate prefix\n")
3496 ALIAS (ipv6_aggregate_address_summary_only,
3497 old_ipv6_aggregate_address_summary_only_cmd,
3498 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
3499 IPV6_STR
3500 BGP_STR
3501 "Configure BGP aggregate entries\n"
3502 "Aggregate prefix\n"
3503 "Filter more specific routes from updates\n")
3505 ALIAS (no_ipv6_aggregate_address,
3506 old_no_ipv6_aggregate_address_cmd,
3507 "no ipv6 bgp aggregate-address X:X::X:X/M",
3508 NO_STR
3509 IPV6_STR
3510 BGP_STR
3511 "Configure BGP aggregate entries\n"
3512 "Aggregate prefix\n")
3514 ALIAS (no_ipv6_aggregate_address_summary_only,
3515 old_no_ipv6_aggregate_address_summary_only_cmd,
3516 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
3517 NO_STR
3518 IPV6_STR
3519 BGP_STR
3520 "Configure BGP aggregate entries\n"
3521 "Aggregate prefix\n"
3522 "Filter more specific routes from updates\n")
3523 #endif /* HAVE_IPV6 */
3525 /* Redistribute route treatment. */
3526 void
3527 bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
3528 u_int32_t metric, u_char type)
3530 struct bgp *bgp;
3531 struct listnode *nn;
3532 struct bgp_info *new;
3533 struct route_node *rn;
3534 struct attr attr;
3535 struct attr attr_new;
3536 struct bgp_info info;
3537 afi_t afi;
3538 int ret;
3540 /* Make default attribute. */
3541 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
3542 if (nexthop)
3543 attr.nexthop = *nexthop;
3545 attr.med = metric;
3546 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3548 LIST_LOOP (bgp_list, bgp, nn)
3550 afi = family2afi (p->family);
3552 if (bgp->redist[afi][type])
3554 /* Copy attribute for modification. */
3555 attr_new = attr;
3557 /* Apply route-map. */
3558 if (bgp->rmap[afi][type].map)
3560 info.peer = peer_self;
3561 info.attr = &attr_new;
3563 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
3564 &info);
3565 if (ret == RMAP_DENYMATCH)
3567 /* Free uninterned attribute. */
3568 bgp_attr_flush (&attr_new);
3570 /* Unintern original. */
3571 aspath_unintern (attr.aspath);
3572 return;
3576 new = bgp_info_new ();
3577 new->type = type;
3578 new->peer = peer_self;
3579 SET_FLAG (new->flags, BGP_INFO_VALID);
3580 new->attr = bgp_attr_intern (&attr_new);
3581 new->uptime = time (NULL);
3583 rn = bgp_route_node_get (bgp, afi, SAFI_UNICAST, p, NULL);
3584 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
3585 bgp_info_add ((struct bgp_info **) &rn->info, new);
3586 bgp_process (bgp, rn, afi, SAFI_UNICAST, NULL, NULL, NULL);
3590 /* Unintern original. */
3591 aspath_unintern (attr.aspath);
3594 void
3595 bgp_redistribute_delete (struct prefix *p, u_char type)
3597 struct bgp *bgp;
3598 struct listnode *nn;
3599 afi_t afi;
3600 struct route_node *rn;
3601 struct bgp_info *ri;
3603 LIST_LOOP (bgp_list, bgp, nn)
3605 afi = family2afi (p->family);
3607 if (bgp->redist[afi][type])
3609 rn = bgp_route_node_get (bgp, afi, SAFI_UNICAST, p, NULL);
3611 for (ri = rn->info; ri; ri = ri->next)
3612 if (ri->peer == peer_self
3613 && ri->type == type)
3614 break;
3616 if (ri)
3618 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
3619 bgp_info_delete ((struct bgp_info **) &rn->info, ri);
3620 bgp_process (bgp, rn, afi, SAFI_UNICAST, ri, NULL, NULL);
3621 bgp_info_free (ri);
3622 route_unlock_node (rn);
3624 route_unlock_node (rn);
3629 /* Withdraw specified route type's route. */
3630 void
3631 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
3633 struct route_node *rn;
3634 struct bgp_info *ri;
3635 struct route_table *table;
3637 table = bgp->rib[afi][SAFI_UNICAST];
3639 for (rn = route_top (table); rn; rn = route_next (rn))
3641 for (ri = rn->info; ri; ri = ri->next)
3642 if (ri->peer == peer_self
3643 && ri->type == type)
3644 break;
3646 if (ri)
3648 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
3649 bgp_info_delete ((struct bgp_info **) &rn->info, ri);
3650 bgp_process (bgp, rn, afi, SAFI_UNICAST, ri, NULL, NULL);
3651 bgp_info_free (ri);
3652 route_unlock_node (rn);
3657 /* Static function to display route. */
3658 void
3659 route_vty_out_route (struct prefix *p, struct vty *vty)
3661 int len;
3662 u_int32_t destination;
3663 char buf[BUFSIZ];
3665 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
3666 destination = ntohl (p->u.prefix4.s_addr);
3668 if ((IN_CLASSC (destination) && p->prefixlen == 24)
3669 || (IN_CLASSB (destination) && p->prefixlen == 16)
3670 || (IN_CLASSA (destination) && p->prefixlen == 8))
3672 /* When mask is natural, mask is not displayed. */
3674 else
3675 len += vty_out (vty, "/%d", p->prefixlen);
3677 len = 17 - len;
3678 if (len < 1)
3679 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
3680 else
3681 vty_out (vty, "%*s", len, " ");
3684 /* Calculate line number of output data. */
3686 vty_calc_line (struct vty *vty, unsigned long length)
3688 return vty->width ? (((vty->obuf->length - length) / vty->width) + 1) : 1;
3691 enum bgp_display_type
3693 normal_list,
3696 /* called from terminal list command */
3698 route_vty_out (struct vty *vty, struct prefix *p,
3699 struct bgp_info *binfo, int display, safi_t safi)
3701 struct attr *attr;
3702 unsigned long length = 0;
3704 length = vty->obuf->length;
3706 /* Route status display. */
3707 if (binfo->suppress)
3708 vty_out (vty, "s");
3709 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3710 vty_out (vty, "*");
3711 else
3712 vty_out (vty, " ");
3714 /* Selected */
3715 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3716 vty_out (vty, "h");
3717 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
3718 vty_out (vty, "d");
3719 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
3720 vty_out (vty, ">");
3721 else
3722 vty_out (vty, " ");
3724 /* Internal route. */
3725 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
3726 vty_out (vty, "i");
3727 else
3728 vty_out (vty, " ");
3730 /* print prefix and mask */
3731 if (! display)
3732 route_vty_out_route (p, vty);
3733 else
3734 vty_out (vty, "%*s", 17, " ");
3736 /* Print attribute */
3737 attr = binfo->attr;
3738 if (attr)
3740 if (p->family == AF_INET)
3742 if (safi == SAFI_MPLS_VPN)
3743 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3744 else
3745 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3747 #ifdef HAVE_IPV6
3748 else if (p->family == AF_INET6)
3750 char buf[BUFSIZ];
3751 char buf1[BUFSIZ];
3752 if (attr->mp_nexthop_len == 16)
3753 vty_out (vty, "%s",
3754 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
3755 else if (attr->mp_nexthop_len == 32)
3756 vty_out (vty, "%s(%s)",
3757 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
3758 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
3761 #endif /* HAVE_IPV6 */
3763 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
3764 vty_out (vty, "%10d", attr->med);
3765 else
3766 vty_out (vty, " ");
3768 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
3769 vty_out (vty, "%7d", attr->local_pref);
3770 else
3771 vty_out (vty, " ");
3773 vty_out (vty, "%7u ",attr->weight);
3775 /* Print aspath */
3776 if (attr->aspath)
3777 aspath_print_vty (vty, attr->aspath);
3779 /* Print origin */
3780 if (strlen (attr->aspath->str) == 0)
3781 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
3782 else
3783 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
3785 vty_out (vty, "%s", VTY_NEWLINE);
3787 return vty_calc_line (vty, length);
3790 /* called from terminal list command */
3791 void
3792 route_vty_out_tmp (struct vty *vty, struct prefix *p,
3793 struct attr *attr, safi_t safi)
3795 /* Route status display. */
3796 vty_out (vty, "*");
3797 vty_out (vty, ">");
3798 vty_out (vty, " ");
3800 /* print prefix and mask */
3801 route_vty_out_route (p, vty);
3803 /* Print attribute */
3804 if (attr)
3806 if (p->family == AF_INET)
3808 if (safi == SAFI_MPLS_VPN)
3809 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3810 else
3811 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3813 #ifdef HAVE_IPV6
3814 else if (p->family == AF_INET6)
3816 char buf[BUFSIZ];
3817 char buf1[BUFSIZ];
3818 if (attr->mp_nexthop_len == 16)
3819 vty_out (vty, "%s",
3820 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
3821 else if (attr->mp_nexthop_len == 32)
3822 vty_out (vty, "%s(%s)",
3823 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
3824 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
3827 #endif /* HAVE_IPV6 */
3829 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
3830 vty_out (vty, "%10d", attr->med);
3831 else
3832 vty_out (vty, " ");
3834 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
3835 vty_out (vty, "%7d", attr->local_pref);
3836 else
3837 vty_out (vty, " ");
3839 vty_out (vty, "%7d ",attr->weight);
3841 /* Print aspath */
3842 if (attr->aspath)
3843 aspath_print_vty (vty, attr->aspath);
3845 /* Print origin */
3846 if (strlen (attr->aspath->str) == 0)
3847 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
3848 else
3849 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
3852 vty_out (vty, "%s", VTY_NEWLINE);
3856 route_vty_out_tag (struct vty *vty, struct prefix *p,
3857 struct bgp_info *binfo, int display, safi_t safi)
3859 struct attr *attr;
3860 unsigned long length = 0;
3861 u_int32_t label = 0;
3863 length = vty->obuf->length;
3865 /* Route status display. */
3866 if (binfo->suppress)
3867 vty_out (vty, "s");
3868 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3869 vty_out (vty, "*");
3870 else
3871 vty_out (vty, " ");
3873 /* Selected */
3874 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3875 vty_out (vty, "h");
3876 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
3877 vty_out (vty, "d");
3878 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
3879 vty_out (vty, ">");
3880 else
3881 vty_out (vty, " ");
3883 /* Internal route. */
3884 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
3885 vty_out (vty, "i");
3886 else
3887 vty_out (vty, " ");
3889 /* print prefix and mask */
3890 if (! display)
3891 route_vty_out_route (p, vty);
3892 else
3893 vty_out (vty, "%*s", 17, " ");
3895 /* Print attribute */
3896 attr = binfo->attr;
3897 if (attr)
3899 if (p->family == AF_INET)
3901 if (safi == SAFI_MPLS_VPN)
3902 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3903 else
3904 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3906 #ifdef HAVE_IPV6
3907 else if (p->family == AF_INET6)
3909 char buf[BUFSIZ];
3910 char buf1[BUFSIZ];
3911 if (attr->mp_nexthop_len == 16)
3912 vty_out (vty, "%s",
3913 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
3914 else if (attr->mp_nexthop_len == 32)
3915 vty_out (vty, "%s(%s)",
3916 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
3917 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
3920 #endif /* HAVE_IPV6 */
3923 label = decode_label (binfo->tag);
3925 vty_out (vty, "notag/%d", label);
3927 vty_out (vty, "%s", VTY_NEWLINE);
3929 return vty_calc_line (vty, length);
3932 #ifdef HAVE_IPV6
3933 void
3934 route_vty_out_route_ipv6 (struct prefix *p, struct vty *vty)
3936 int len;
3937 char buf[BUFSIZ];
3939 len = vty_out (vty, "%s/%d",
3940 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
3941 p->prefixlen);
3942 len = 40 - len;
3943 if (len < 0)
3944 len = 0;
3945 vty_out (vty, "%*s", len, " ");
3948 /* called from terminal list command */
3950 route_vty_out_ipv6 (struct vty *vty, struct prefix *p, struct bgp_info *binfo)
3952 struct attr *attr;
3953 unsigned long length;
3954 int line = 0;
3956 length = vty->obuf->length;
3958 /* Route status display. */
3959 if (binfo->suppress)
3960 vty_out (vty, "s");
3961 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3962 vty_out (vty, "*");
3963 else
3964 vty_out (vty, " ");
3966 /* Selected */
3967 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
3968 vty_out (vty, ">");
3969 else
3970 vty_out (vty, " ");
3972 /* Internal route. */
3973 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
3974 vty_out (vty, "i");
3975 else
3976 vty_out (vty, " ");
3978 /* print prefix and mask */
3979 route_vty_out_route_ipv6 (p, vty);
3981 /* Print attribute */
3982 attr = binfo->attr;
3984 /* Med */
3985 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
3986 vty_out (vty, "%7d", attr->med);
3987 else
3988 vty_out (vty, " ");
3990 /* Local-pref */
3991 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
3992 vty_out (vty, "%7d", attr->local_pref);
3993 else
3994 vty_out (vty, " ");
3996 /* Weight */
3997 vty_out (vty, "%7d ",attr->weight);
3999 /* Print aspath */
4000 if (attr->aspath)
4001 aspath_print_vty (vty, attr->aspath);
4003 /* Print origin */
4004 if (strlen (attr->aspath->str) == 0)
4005 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4006 else
4007 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4009 vty_out (vty, "%s", VTY_NEWLINE);
4011 line = vty_calc_line (vty, length);
4012 length = vty->obuf->length;
4014 if (attr)
4016 char buf[BUFSIZ];
4017 char buf1[BUFSIZ];
4019 if (attr->mp_nexthop_len == 16)
4020 vty_out (vty, " %s%s",
4021 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
4022 VTY_NEWLINE);
4023 else if (attr->mp_nexthop_len == 32)
4024 vty_out (vty, " %s(%s)%s",
4025 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
4026 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ),
4027 VTY_NEWLINE);
4029 return line + vty_calc_line (vty, length);
4032 /* called from terminal list command */
4033 void
4034 route_vty_out_ipv6_tmp (struct vty *vty, struct prefix *p, struct attr *attr)
4036 /* Selected tag display. */
4037 vty_out (vty, "*> ");
4039 /* print prefix and mask */
4040 route_vty_out_route_ipv6 (p, vty);
4042 /* Med */
4043 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
4044 vty_out (vty, "%7d", attr->med);
4045 else
4046 vty_out (vty, " ");
4048 /* Local-pref */
4049 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
4050 vty_out (vty, "%7d", attr->local_pref);
4051 else
4052 vty_out (vty, " ");
4054 /* Weight */
4055 vty_out (vty, "%7d ",attr->weight);
4057 /* Print aspath */
4058 if (attr->aspath)
4059 aspath_print_vty (vty, attr->aspath);
4061 /* Print origin */
4062 if (strlen (attr->aspath->str) == 0)
4063 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4064 else
4065 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4067 vty_out (vty, "%s", VTY_NEWLINE);
4069 if (attr)
4071 char buf[BUFSIZ];
4072 char buf1[BUFSIZ];
4074 if (attr->mp_nexthop_len == 16)
4075 vty_out (vty, " %s%s",
4076 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
4077 VTY_NEWLINE);
4078 else if (attr->mp_nexthop_len == 32)
4079 vty_out (vty, " %s(%s)%s",
4080 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
4081 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ),
4082 VTY_NEWLINE);
4085 #endif /* HAVE_IPV6 */
4087 void
4088 route_vty_out_detail (struct vty *vty, struct prefix *p,
4089 struct bgp_info *binfo, afi_t afi, safi_t safi)
4091 char buf[INET6_ADDRSTRLEN];
4092 char buf1[BUFSIZ];
4093 struct attr *attr;
4094 struct bgp *bgp;
4095 int sockunion_vty_out (struct vty *, union sockunion *);
4097 attr = binfo->attr;
4098 bgp = bgp_get_default ();
4100 if (attr)
4102 /* Line1 display AS-path, Aggregator */
4103 if (attr->aspath)
4105 vty_out (vty, " ");
4106 if (attr->aspath->length == 0)
4107 vty_out (vty, "Local");
4108 else
4109 aspath_print_vty (vty, attr->aspath);
4112 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)
4113 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
4114 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
4115 || CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)
4116 || CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4118 vty_out (vty, ",");
4120 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR))
4121 vty_out (vty, " (aggregated by %d %s)", attr->aggregator_as,
4122 inet_ntoa (attr->aggregator_addr));
4123 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
4124 vty_out (vty, " (Received from a RR-client)");
4125 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
4126 vty_out (vty, " (Received from a RS-client)");
4127 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4128 vty_out (vty, " (history entry)");
4129 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4130 vty_out (vty, " (suppressed due to dampening)");
4132 vty_out (vty, "%s", VTY_NEWLINE);
4134 /* Line2 display Next-hop, Neighbor, Router-id */
4135 if (p->family == AF_INET)
4137 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
4138 inet_ntoa (attr->mp_nexthop_global_in) :
4139 inet_ntoa (attr->nexthop));
4141 #ifdef HAVE_IPV6
4142 else
4144 vty_out (vty, " %s",
4145 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
4146 buf, INET6_ADDRSTRLEN));
4148 #endif /* HAVE_IPV6 */
4150 if (binfo->peer == peer_self)
4152 vty_out (vty, " from %s ",
4153 p->family == AF_INET ? "0.0.0.0" : "::");
4154 vty_out (vty, "(%s)", inet_ntoa(bgp->id));
4156 else
4158 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
4159 vty_out (vty, " (inaccessible)");
4160 else if (binfo->igpmetric)
4161 vty_out (vty, " (metric %d)", binfo->igpmetric);
4162 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
4163 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
4164 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
4165 else
4166 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
4168 vty_out (vty, "%s", VTY_NEWLINE);
4170 #ifdef HAVE_IPV6
4171 /* display nexthop local */
4172 if (attr->mp_nexthop_len == 32)
4174 vty_out (vty, " (%s)%s",
4175 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
4176 buf, INET6_ADDRSTRLEN),
4177 VTY_NEWLINE);
4179 #endif /* HAVE_IPV6 */
4181 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
4182 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
4184 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
4185 vty_out (vty, ", metric %d", attr->med);
4187 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
4188 vty_out (vty, ", localpref %d", attr->local_pref);
4189 else
4190 vty_out (vty, ", localpref %d", bgp->default_local_pref);
4192 if (attr->weight != 0)
4193 vty_out (vty, ", weight %d", attr->weight);
4195 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4196 vty_out (vty, ", valid");
4198 if (binfo->peer != peer_self)
4200 if (binfo->peer->as == binfo->peer->local_as)
4201 vty_out (vty, ", internal");
4202 else
4203 vty_out (vty, ", %s",
4204 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
4206 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
4207 vty_out (vty, ", aggregated, local");
4208 else if (binfo->type != ZEBRA_ROUTE_BGP)
4209 vty_out (vty, ", sourced");
4210 else
4211 vty_out (vty, ", sourced, local");
4213 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4214 vty_out (vty, ", atomic-aggregate");
4216 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4217 vty_out (vty, ", best");
4219 vty_out (vty, "%s", VTY_NEWLINE);
4221 /* Line 4 display Community */
4222 if (attr->community)
4224 vty_out (vty, " Community:");
4225 community_print_vty (vty, attr->community);
4226 vty_out (vty, "%s", VTY_NEWLINE);
4229 /* Line 5 display Extended-community */
4230 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
4232 vty_out (vty, " Extended Community:");
4233 ecommunity_vty_out (vty, attr->ecommunity);
4234 vty_out (vty, "%s", VTY_NEWLINE);
4237 /* Line 6 display Originator, Cluster-id */
4238 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
4239 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
4241 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
4242 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
4244 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
4246 int i;
4247 vty_out (vty, ", Cluster list: ");
4248 for (i = 0; i < attr->cluster->length / 4; i++)
4249 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
4251 vty_out (vty, "%s", VTY_NEWLINE);
4254 if (binfo->bgp_damp_info)
4255 bgp_damp_info_print (vty, binfo);
4257 /* Line 7 display Uptime */
4258 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
4260 vty_out (vty, "%s", VTY_NEWLINE);
4263 #define BGP_SHOW_V4_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
4264 #define BGP_SHOW_V6_HEADER " Network Metric LocPrf Weight Path%s"
4266 enum bgp_show_type
4268 bgp_show_type_normal,
4269 bgp_show_type_regexp,
4270 bgp_show_type_prefix_list,
4271 bgp_show_type_filter_list,
4272 bgp_show_type_neighbor,
4273 bgp_show_type_cidr_only,
4274 bgp_show_type_prefix_longer,
4275 bgp_show_type_community_all,
4276 bgp_show_type_community,
4277 bgp_show_type_community_exact,
4278 bgp_show_type_community_list,
4279 bgp_show_type_community_list_exact
4283 bgp_show_callback (struct vty *vty, int unlock)
4285 struct route_node *rn;
4286 struct bgp_info *ri;
4287 int count;
4288 int limit;
4289 int display;
4291 rn = vty->output_rn;
4292 count = 0;
4293 limit = ((vty->lines == 0)
4294 ? 10 : (vty->lines > 0
4295 ? vty->lines : vty->height - 2));
4296 limit = limit > 0 ? limit : 2;
4298 /* Quit of display. */
4299 if (unlock && rn)
4301 route_unlock_node (rn);
4302 if (vty->output_clean)
4303 (*vty->output_clean) (vty);
4304 vty->output_rn = NULL;
4305 vty->output_func = NULL;
4306 vty->output_clean = NULL;
4307 vty->output_arg = NULL;
4308 return 0;
4311 for (; rn; rn = route_next (rn))
4312 if (rn->info != NULL)
4314 display = 0;
4316 for (ri = rn->info; ri; ri = ri->next)
4318 if (vty->output_type == bgp_show_type_regexp)
4320 regex_t *regex = vty->output_arg;
4322 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
4323 continue;
4325 if (vty->output_type == bgp_show_type_prefix_list)
4327 struct prefix_list *plist = vty->output_arg;
4329 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
4330 continue;
4332 if (vty->output_type == bgp_show_type_filter_list)
4334 struct as_list *as_list = vty->output_arg;
4336 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
4337 continue;
4339 if (vty->output_type == bgp_show_type_neighbor)
4341 union sockunion *su = vty->output_arg;
4343 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
4344 continue;
4346 if (vty->output_type == bgp_show_type_cidr_only)
4348 u_int32_t destination;
4350 destination = ntohl (rn->p.u.prefix4.s_addr);
4351 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
4352 continue;
4353 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
4354 continue;
4355 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
4356 continue;
4358 if (vty->output_type == bgp_show_type_prefix_longer)
4360 struct prefix *p = vty->output_arg;
4362 if (! prefix_match (p, &rn->p))
4363 continue;
4365 if (vty->output_type == bgp_show_type_community_all)
4367 if (! ri->attr->community)
4368 continue;
4370 if (vty->output_type == bgp_show_type_community)
4372 struct community *com = vty->output_arg;
4374 if (! ri->attr->community ||
4375 ! community_match (ri->attr->community, com))
4376 continue;
4378 if (vty->output_type == bgp_show_type_community_exact)
4380 struct community *com = vty->output_arg;
4382 if (! ri->attr->community ||
4383 ! community_cmp (ri->attr->community, com))
4384 continue;
4386 if (vty->output_type == bgp_show_type_community_list)
4388 struct community_list *list = vty->output_arg;
4390 if (! community_list_match (ri->attr->community, list))
4391 continue;
4393 if (vty->output_type == bgp_show_type_community_list_exact)
4395 struct community_list *list = vty->output_arg;
4397 if (! community_list_match_exact (ri->attr->community, list))
4398 continue;
4401 if (rn->p.family == AF_INET)
4403 count += route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4404 display++;
4406 #ifdef HAVE_IPV6
4407 else if (rn->p.family == AF_INET6)
4409 count += route_vty_out_ipv6 (vty, &rn->p, ri);
4410 display++;
4412 #endif /* HAVE_IPV6 */
4415 if (display)
4416 vty->output_count++;
4418 /* Remember current pointer then suspend output. */
4419 if (count >= limit)
4421 vty->status = VTY_CONTINUE;
4422 vty->output_rn = route_next (rn);;
4423 vty->output_func = bgp_show_callback;
4424 return 0;
4428 /* Total line display. */
4429 if (vty->output_count)
4430 vty_out (vty, "%sTotal number of prefixes %ld%s",
4431 VTY_NEWLINE, vty->output_count, VTY_NEWLINE);
4433 if (vty->output_clean)
4434 (*vty->output_clean) (vty);
4436 vty->status = VTY_CONTINUE;
4437 vty->output_rn = NULL;
4438 vty->output_func = NULL;
4439 vty->output_clean = NULL;
4440 vty->output_arg = NULL;
4442 return 0;
4446 bgp_show (struct vty *vty, char *view_name, afi_t afi, safi_t safi,
4447 enum bgp_show_type type)
4449 struct bgp *bgp;
4450 struct bgp_info *ri;
4451 struct route_node *rn;
4452 struct route_table *table;
4453 int header = 1;
4454 int count;
4455 int limit;
4456 int display;
4458 limit = ((vty->lines == 0)
4459 ? 10 : (vty->lines > 0
4460 ? vty->lines : vty->height - 2));
4461 limit = limit > 0 ? limit : 2;
4463 /* BGP structure lookup. */
4464 if (view_name)
4466 bgp = bgp_lookup_by_name (view_name);
4467 if (bgp == NULL)
4469 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
4470 return CMD_WARNING;
4473 else
4475 bgp = bgp_get_default ();
4476 if (bgp == NULL)
4478 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
4479 return CMD_WARNING;
4483 count = 0;
4485 /* This is first entry point, so reset total line. */
4486 vty->output_count = 0;
4487 vty->output_type = type;
4489 table = bgp->rib[afi][safi];
4491 /* Start processing of routes. */
4492 for (rn = route_top (table); rn; rn = route_next (rn))
4493 if (rn->info != NULL)
4495 display = 0;
4497 for (ri = rn->info; ri; ri = ri->next)
4499 if (type == bgp_show_type_regexp)
4501 regex_t *regex = vty->output_arg;
4503 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
4504 continue;
4506 if (type == bgp_show_type_prefix_list)
4508 struct prefix_list *plist = vty->output_arg;
4510 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
4511 continue;
4513 if (type == bgp_show_type_filter_list)
4515 struct as_list *as_list = vty->output_arg;
4517 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
4518 continue;
4520 if (type == bgp_show_type_neighbor)
4522 union sockunion *su = vty->output_arg;
4524 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
4525 continue;
4527 if (type == bgp_show_type_cidr_only)
4529 u_int32_t destination;
4531 destination = ntohl (rn->p.u.prefix4.s_addr);
4532 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
4533 continue;
4534 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
4535 continue;
4536 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
4537 continue;
4539 if (type == bgp_show_type_prefix_longer)
4541 struct prefix *p = vty->output_arg;
4543 if (! prefix_match (p, &rn->p))
4544 continue;
4546 if (type == bgp_show_type_community_all)
4548 if (! ri->attr->community)
4549 continue;
4551 if (type == bgp_show_type_community)
4553 struct community *com = vty->output_arg;
4555 if (! ri->attr->community ||
4556 ! community_match (ri->attr->community, com))
4557 continue;
4559 if (type == bgp_show_type_community_exact)
4561 struct community *com = vty->output_arg;
4563 if (! ri->attr->community ||
4564 ! community_cmp (ri->attr->community, com))
4565 continue;
4567 if (type == bgp_show_type_community_list)
4569 struct community_list *list = vty->output_arg;
4571 if (! community_list_match (ri->attr->community, list))
4572 continue;
4574 if (type == bgp_show_type_community_list_exact)
4576 struct community_list *list = vty->output_arg;
4578 if (! community_list_match_exact (ri->attr->community, list))
4579 continue;
4582 if (header)
4584 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->id), VTY_NEWLINE);
4585 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
4586 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
4587 if (afi == AFI_IP)
4588 vty_out (vty, BGP_SHOW_V4_HEADER, VTY_NEWLINE);
4589 else if (afi == AFI_IP6)
4590 vty_out (vty, BGP_SHOW_V6_HEADER, VTY_NEWLINE);
4591 count += 5;
4592 header = 0;
4595 if (afi == AFI_IP)
4597 count += route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4598 display++;
4600 #ifdef HAVE_IPV6
4601 else if (afi == AFI_IP6)
4603 count += route_vty_out_ipv6 (vty, &rn->p, ri);
4604 display++;
4606 #endif /* HAVE_IPV6 */
4609 if (display)
4610 vty->output_count++;
4612 /* Remember current pointer then suspend output. */
4613 if (count >= limit && vty->type != VTY_SHELL_SERV)
4615 vty->status = VTY_START;
4616 vty->output_rn = route_next (rn);
4617 vty->output_func = bgp_show_callback;
4618 vty->output_type = type;
4620 return CMD_SUCCESS;
4624 /* No route is displayed */
4625 if (vty->output_count == 0)
4627 if (type == bgp_show_type_normal)
4628 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
4630 else
4631 vty_out (vty, "%sTotal number of prefixes %ld%s",
4632 VTY_NEWLINE, vty->output_count, VTY_NEWLINE);
4634 /* Clean up allocated resources. */
4635 if (vty->output_clean)
4636 (*vty->output_clean) (vty);
4638 vty->status = VTY_START;
4639 vty->output_rn = NULL;
4640 vty->output_func = NULL;
4641 vty->output_clean = NULL;
4642 vty->output_arg = NULL;
4644 return CMD_SUCCESS;
4647 /* Display specified route of BGP table. */
4649 bgp_show_route (struct vty *vty, char *view_name, char *ip_str,
4650 afi_t afi, safi_t safi, int prefix_check)
4652 int ret;
4653 int count = 0;
4654 int best = 0;
4655 int suppress = 0;
4656 int no_export = 0;
4657 int no_advertise = 0;
4658 int local_as = 0;
4659 char buf[INET6_ADDRSTRLEN];
4660 struct bgp *bgp;
4661 struct prefix match;
4662 struct prefix *p;
4663 struct route_node *rn;
4664 struct bgp_info *ri;
4665 struct peer_conf *conf;
4666 struct listnode *nn;
4667 int first = 0;
4669 /* BGP structure lookup. */
4670 if (view_name)
4672 bgp = bgp_lookup_by_name (view_name);
4673 if (bgp == NULL)
4675 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
4676 return CMD_WARNING;
4679 else
4681 bgp = bgp_get_default ();
4682 if (bgp == NULL)
4684 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
4685 return CMD_WARNING;
4689 /* Check IP address argument. */
4690 ret = str2prefix (ip_str, &match);
4691 if (! ret)
4693 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
4694 return CMD_WARNING;
4697 match.family = afi2family (afi);
4699 /* Lookup route node. */
4700 rn = route_node_match (bgp->rib[afi][safi], &match);
4701 if (rn == NULL)
4703 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
4704 return CMD_WARNING;
4707 p = &rn->p;
4708 if (prefix_check)
4710 if (p->prefixlen != match.prefixlen)
4712 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
4713 return CMD_WARNING;
4717 /* Header of detailed BGP route information */
4718 for (ri = rn->info; ri; ri = ri->next)
4720 count++;
4721 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
4723 best = count;
4724 if (ri->suppress)
4725 suppress = 1;
4726 if (ri->attr->community != NULL)
4728 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
4729 no_advertise = 1;
4730 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
4731 no_export = 1;
4732 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
4733 local_as = 1;
4737 vty_out (vty, "BGP routing table entry for %s/%d%s",
4738 inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN),
4739 p->prefixlen, VTY_NEWLINE);
4741 vty_out (vty, "Paths: (%d available", count);
4742 if (best)
4744 vty_out (vty, ", best #%d", best);
4745 if (safi == SAFI_UNICAST)
4746 vty_out (vty, ", table Default-IP-Routing-Table");
4748 else
4749 vty_out (vty, ", no best path");
4750 if (no_advertise)
4751 vty_out (vty, ", not advertised to any peer");
4752 else if (no_export)
4753 vty_out (vty, ", not advertised to EBGP peer");
4754 else if (local_as)
4755 vty_out (vty, ", not advertised outside local AS");
4756 if (suppress)
4757 vty_out (vty, ", Advertisements suppressed by an aggregate.");
4758 vty_out (vty, ")%s", VTY_NEWLINE);
4760 /* advertised peer */
4761 LIST_LOOP (bgp->peer_conf, conf, nn)
4763 if (bgp_adj_lookup (conf->peer->adj_out[afi][safi], p, NULL, safi))
4765 if (! first)
4766 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
4767 vty_out (vty, " %s", sockunion2str (&conf->peer->su, buf, SU_ADDRSTRLEN));
4768 first = 1;
4771 if (! first)
4772 vty_out (vty, " Not advertised to any peer");
4773 vty_out (vty, "%s", VTY_NEWLINE);
4775 /* Node is locked by route_node_match(). */
4776 for (ri = rn->info; ri; ri = ri->next)
4777 route_vty_out_detail (vty, &rn->p, ri, afi, safi);
4779 /* Work is done, so unlock the node. */
4780 route_unlock_node (rn);
4782 return CMD_SUCCESS;
4785 /* BGP route print out function. */
4786 DEFUN (show_ip_bgp,
4787 show_ip_bgp_cmd,
4788 "show ip bgp",
4789 SHOW_STR
4790 IP_STR
4791 BGP_STR)
4793 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
4796 DEFUN (show_ip_bgp_ipv4,
4797 show_ip_bgp_ipv4_cmd,
4798 "show ip bgp ipv4 (unicast|multicast)",
4799 SHOW_STR
4800 IP_STR
4801 BGP_STR
4802 "Address family\n"
4803 "Address Family modifier\n"
4804 "Address Family modifier\n")
4806 if (strncmp (argv[0], "m", 1) == 0)
4807 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal);
4809 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
4812 DEFUN (show_ip_bgp_route,
4813 show_ip_bgp_route_cmd,
4814 "show ip bgp A.B.C.D",
4815 SHOW_STR
4816 IP_STR
4817 BGP_STR
4818 "Network in the BGP routing table to display\n")
4820 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, 0);
4823 DEFUN (show_ip_bgp_ipv4_route,
4824 show_ip_bgp_ipv4_route_cmd,
4825 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
4826 SHOW_STR
4827 IP_STR
4828 BGP_STR
4829 "Address family\n"
4830 "Address Family modifier\n"
4831 "Address Family modifier\n"
4832 "Network in the BGP routing table to display\n")
4834 if (strncmp (argv[0], "m", 1) == 0)
4835 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, 0);
4837 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, 0);
4840 DEFUN (show_ip_bgp_prefix,
4841 show_ip_bgp_prefix_cmd,
4842 "show ip bgp A.B.C.D/M",
4843 SHOW_STR
4844 IP_STR
4845 BGP_STR
4846 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4848 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, 1);
4851 DEFUN (show_ip_bgp_ipv4_prefix,
4852 show_ip_bgp_ipv4_prefix_cmd,
4853 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
4854 SHOW_STR
4855 IP_STR
4856 BGP_STR
4857 "Address family\n"
4858 "Address Family modifier\n"
4859 "Address Family modifier\n"
4860 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4862 if (strncmp (argv[0], "m", 1) == 0)
4863 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, 1);
4865 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, 1);
4868 DEFUN (show_ip_bgp_view,
4869 show_ip_bgp_view_cmd,
4870 "show ip bgp view WORD",
4871 SHOW_STR
4872 IP_STR
4873 BGP_STR
4874 "BGP view\n"
4875 "BGP view name\n")
4877 return bgp_show (vty, argv[0], AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
4880 DEFUN (show_ip_bgp_view_route,
4881 show_ip_bgp_view_route_cmd,
4882 "show ip bgp view WORD A.B.C.D",
4883 SHOW_STR
4884 IP_STR
4885 BGP_STR
4886 "BGP view\n"
4887 "BGP view name\n"
4888 "Network in the BGP routing table to display\n")
4890 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, 0);
4893 DEFUN (show_ip_bgp_view_prefix,
4894 show_ip_bgp_view_prefix_cmd,
4895 "show ip bgp view WORD A.B.C.D/M",
4896 SHOW_STR
4897 IP_STR
4898 BGP_STR
4899 "BGP view\n"
4900 "BGP view name\n"
4901 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4903 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, 1);
4906 #ifdef HAVE_IPV6
4907 DEFUN (show_bgp,
4908 show_bgp_cmd,
4909 "show bgp",
4910 SHOW_STR
4911 BGP_STR)
4913 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
4916 ALIAS (show_bgp,
4917 show_bgp_ipv6_cmd,
4918 "show bgp ipv6",
4919 SHOW_STR
4920 BGP_STR
4921 "Address family\n")
4923 /* old command */
4924 DEFUN (show_ipv6_bgp,
4925 show_ipv6_bgp_cmd,
4926 "show ipv6 bgp",
4927 SHOW_STR
4928 IP_STR
4929 BGP_STR)
4931 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
4934 DEFUN (show_bgp_route,
4935 show_bgp_route_cmd,
4936 "show bgp X:X::X:X",
4937 SHOW_STR
4938 BGP_STR
4939 "Network in the BGP routing table to display\n")
4941 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, 0);
4944 ALIAS (show_bgp_route,
4945 show_bgp_ipv6_route_cmd,
4946 "show bgp ipv6 X:X::X:X",
4947 SHOW_STR
4948 BGP_STR
4949 "Address family\n"
4950 "Network in the BGP routing table to display\n")
4952 /* old command */
4953 DEFUN (show_ipv6_bgp_route,
4954 show_ipv6_bgp_route_cmd,
4955 "show ipv6 bgp X:X::X:X",
4956 SHOW_STR
4957 IP_STR
4958 BGP_STR
4959 "Network in the BGP routing table to display\n")
4961 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, 0);
4964 DEFUN (show_bgp_prefix,
4965 show_bgp_prefix_cmd,
4966 "show bgp X:X::X:X/M",
4967 SHOW_STR
4968 BGP_STR
4969 "IPv6 prefix <network>/<length>\n")
4971 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, 1);
4974 ALIAS (show_bgp_prefix,
4975 show_bgp_ipv6_prefix_cmd,
4976 "show bgp ipv6 X:X::X:X/M",
4977 SHOW_STR
4978 BGP_STR
4979 "Address family\n"
4980 "IPv6 prefix <network>/<length>\n")
4982 /* old command */
4983 DEFUN (show_ipv6_bgp_prefix,
4984 show_ipv6_bgp_prefix_cmd,
4985 "show ipv6 bgp X:X::X:X/M",
4986 SHOW_STR
4987 IP_STR
4988 BGP_STR
4989 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4991 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, 1);
4994 /* old command */
4995 DEFUN (show_ipv6_mbgp,
4996 show_ipv6_mbgp_cmd,
4997 "show ipv6 mbgp",
4998 SHOW_STR
4999 IP_STR
5000 MBGP_STR)
5002 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal);
5005 /* old command */
5006 DEFUN (show_ipv6_mbgp_route,
5007 show_ipv6_mbgp_route_cmd,
5008 "show ipv6 mbgp X:X::X:X",
5009 SHOW_STR
5010 IP_STR
5011 MBGP_STR
5012 "Network in the MBGP routing table to display\n")
5014 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, 0);
5017 /* old command */
5018 DEFUN (show_ipv6_mbgp_prefix,
5019 show_ipv6_mbgp_prefix_cmd,
5020 "show ipv6 mbgp X:X::X:X/M",
5021 SHOW_STR
5022 IP_STR
5023 MBGP_STR
5024 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5026 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, 1);
5028 #endif
5030 void
5031 bgp_show_regexp_clean (struct vty *vty)
5033 bgp_regex_free (vty->output_arg);
5037 bgp_show_regexp (struct vty *vty, int argc, char **argv, u_int16_t afi,
5038 u_char safi)
5040 int i;
5041 struct buffer *b;
5042 char *regstr;
5043 int first;
5044 regex_t *regex;
5046 first = 0;
5047 b = buffer_new (1024);
5048 for (i = 0; i < argc; i++)
5050 if (first)
5051 buffer_putc (b, ' ');
5052 else
5054 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
5055 continue;
5056 first = 1;
5059 buffer_putstr (b, argv[i]);
5061 buffer_putc (b, '\0');
5063 regstr = buffer_getstr (b);
5064 buffer_free (b);
5066 regex = bgp_regcomp (regstr);
5067 if (! regex)
5069 vty_out (vty, "Can't compile regexp %s%s", argv[0],
5070 VTY_NEWLINE);
5071 return CMD_WARNING;
5074 vty->output_arg = regex;
5075 vty->output_clean = bgp_show_regexp_clean;
5077 return bgp_show (vty, NULL, afi, safi, bgp_show_type_regexp);
5080 DEFUN (show_ip_bgp_regexp,
5081 show_ip_bgp_regexp_cmd,
5082 "show ip bgp regexp .LINE",
5083 SHOW_STR
5084 IP_STR
5085 BGP_STR
5086 "Display routes matching the AS path regular expression\n"
5087 "A regular-expression to match the BGP AS paths\n")
5089 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST);
5092 DEFUN (show_ip_bgp_ipv4_regexp,
5093 show_ip_bgp_ipv4_regexp_cmd,
5094 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
5095 SHOW_STR
5096 IP_STR
5097 BGP_STR
5098 "Address family\n"
5099 "Address Family modifier\n"
5100 "Address Family modifier\n"
5101 "Display routes matching the AS path regular expression\n"
5102 "A regular-expression to match the BGP AS paths\n")
5104 if (strncmp (argv[0], "m", 1) == 0)
5105 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST);
5107 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST);
5110 #ifdef HAVE_IPV6
5111 DEFUN (show_bgp_regexp,
5112 show_bgp_regexp_cmd,
5113 "show bgp regexp .LINE",
5114 SHOW_STR
5115 BGP_STR
5116 "Display routes matching the AS path regular expression\n"
5117 "A regular-expression to match the BGP AS paths\n")
5119 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST);
5122 ALIAS (show_bgp_regexp,
5123 show_bgp_ipv6_regexp_cmd,
5124 "show bgp ipv6 regexp .LINE",
5125 SHOW_STR
5126 BGP_STR
5127 "Address family\n"
5128 "Display routes matching the AS path regular expression\n"
5129 "A regular-expression to match the BGP AS paths\n")
5131 /* old command */
5132 DEFUN (show_ipv6_bgp_regexp,
5133 show_ipv6_bgp_regexp_cmd,
5134 "show ipv6 bgp regexp .LINE",
5135 SHOW_STR
5136 IP_STR
5137 BGP_STR
5138 "Display routes matching the AS path regular expression\n"
5139 "A regular-expression to match the BGP AS paths\n")
5141 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST);
5144 /* old command */
5145 DEFUN (show_ipv6_mbgp_regexp,
5146 show_ipv6_mbgp_regexp_cmd,
5147 "show ipv6 mbgp regexp .LINE",
5148 SHOW_STR
5149 IP_STR
5150 BGP_STR
5151 "Display routes matching the AS path regular expression\n"
5152 "A regular-expression to match the MBGP AS paths\n")
5154 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST);
5156 #endif /* HAVE_IPV6 */
5159 bgp_show_prefix_list (struct vty *vty, char *prefix_list_str, u_int16_t afi,
5160 u_char safi)
5162 struct prefix_list *plist;
5164 plist = prefix_list_lookup (afi, prefix_list_str);
5165 if (plist == NULL)
5167 vty_out (vty, "%% %s is not a valid prefix-list name%s", prefix_list_str, VTY_NEWLINE);
5168 return CMD_WARNING;
5171 vty->output_arg = plist;
5173 return bgp_show (vty, NULL, afi, safi, bgp_show_type_prefix_list);
5176 DEFUN (show_ip_bgp_prefix_list,
5177 show_ip_bgp_prefix_list_cmd,
5178 "show ip bgp prefix-list WORD",
5179 SHOW_STR
5180 IP_STR
5181 BGP_STR
5182 "Display routes matching the prefix-list\n"
5183 "IP prefix-list name\n")
5185 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST);
5188 DEFUN (show_ip_bgp_ipv4_prefix_list,
5189 show_ip_bgp_ipv4_prefix_list_cmd,
5190 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
5191 SHOW_STR
5192 IP_STR
5193 BGP_STR
5194 "Address family\n"
5195 "Address Family modifier\n"
5196 "Address Family modifier\n"
5197 "Display routes matching the prefix-list\n"
5198 "IP prefix-list name\n")
5200 if (strncmp (argv[0], "m", 1) == 0)
5201 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST);
5203 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST);
5206 #ifdef HAVE_IPV6
5207 DEFUN (show_bgp_prefix_list,
5208 show_bgp_prefix_list_cmd,
5209 "show bgp prefix-list WORD",
5210 SHOW_STR
5211 BGP_STR
5212 "Display routes matching the prefix-list\n"
5213 "IPv6 prefix-list name\n")
5215 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5218 ALIAS (show_bgp_prefix_list,
5219 show_bgp_ipv6_prefix_list_cmd,
5220 "show bgp ipv6 prefix-list WORD",
5221 SHOW_STR
5222 BGP_STR
5223 "Address family\n"
5224 "Display routes matching the prefix-list\n"
5225 "IPv6 prefix-list name\n")
5227 /* old command */
5228 DEFUN (show_ipv6_bgp_prefix_list,
5229 show_ipv6_bgp_prefix_list_cmd,
5230 "show ipv6 bgp prefix-list WORD",
5231 SHOW_STR
5232 IPV6_STR
5233 BGP_STR
5234 "Display routes matching the prefix-list\n"
5235 "IPv6 prefix-list name\n")
5237 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5240 /* old command */
5241 DEFUN (show_ipv6_mbgp_prefix_list,
5242 show_ipv6_mbgp_prefix_list_cmd,
5243 "show ipv6 mbgp prefix-list WORD",
5244 SHOW_STR
5245 IPV6_STR
5246 MBGP_STR
5247 "Display routes matching the prefix-list\n"
5248 "IPv6 prefix-list name\n")
5250 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST);
5252 #endif /* HAVE_IPV6 */
5255 bgp_show_filter_list (struct vty *vty, char *filter, u_int16_t afi,
5256 u_char safi)
5258 struct as_list *as_list;
5260 as_list = as_list_lookup (filter);
5261 if (as_list == NULL)
5263 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
5264 return CMD_WARNING;
5267 vty->output_arg = as_list;
5269 return bgp_show (vty, NULL, afi, safi, bgp_show_type_filter_list);
5272 DEFUN (show_ip_bgp_filter_list,
5273 show_ip_bgp_filter_list_cmd,
5274 "show ip bgp filter-list WORD",
5275 SHOW_STR
5276 IP_STR
5277 BGP_STR
5278 "Display routes conforming to the filter-list\n"
5279 "Regular expression access list name\n")
5281 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST);
5284 DEFUN (show_ip_bgp_ipv4_filter_list,
5285 show_ip_bgp_ipv4_filter_list_cmd,
5286 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
5287 SHOW_STR
5288 IP_STR
5289 BGP_STR
5290 "Address family\n"
5291 "Address Family modifier\n"
5292 "Address Family modifier\n"
5293 "Display routes conforming to the filter-list\n"
5294 "Regular expression access list name\n")
5296 if (strncmp (argv[0], "m", 1) == 0)
5297 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST);
5299 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST);
5302 #ifdef HAVE_IPV6
5303 DEFUN (show_bgp_filter_list,
5304 show_bgp_filter_list_cmd,
5305 "show bgp filter-list WORD",
5306 SHOW_STR
5307 BGP_STR
5308 "Display routes conforming to the filter-list\n"
5309 "Regular expression access list name\n")
5311 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5314 ALIAS (show_bgp_filter_list,
5315 show_bgp_ipv6_filter_list_cmd,
5316 "show bgp ipv6 filter-list WORD",
5317 SHOW_STR
5318 BGP_STR
5319 "Address family\n"
5320 "Display routes conforming to the filter-list\n"
5321 "Regular expression access list name\n")
5323 /* old command */
5324 DEFUN (show_ipv6_bgp_filter_list,
5325 show_ipv6_bgp_filter_list_cmd,
5326 "show ipv6 bgp filter-list WORD",
5327 SHOW_STR
5328 IPV6_STR
5329 BGP_STR
5330 "Display routes conforming to the filter-list\n"
5331 "Regular expression access list name\n")
5333 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5336 /* old command */
5337 DEFUN (show_ipv6_mbgp_filter_list,
5338 show_ipv6_mbgp_filter_list_cmd,
5339 "show ipv6 mbgp filter-list WORD",
5340 SHOW_STR
5341 IPV6_STR
5342 MBGP_STR
5343 "Display routes conforming to the filter-list\n"
5344 "Regular expression access list name\n")
5346 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST);
5348 #endif /* HAVE_IPV6 */
5350 DEFUN (show_ip_bgp_cidr_only,
5351 show_ip_bgp_cidr_only_cmd,
5352 "show ip bgp cidr-only",
5353 SHOW_STR
5354 IP_STR
5355 BGP_STR
5356 "Display only routes with non-natural netmasks\n")
5358 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5359 bgp_show_type_cidr_only);
5362 DEFUN (show_ip_bgp_ipv4_cidr_only,
5363 show_ip_bgp_ipv4_cidr_only_cmd,
5364 "show ip bgp ipv4 (unicast|multicast) cidr-only",
5365 SHOW_STR
5366 IP_STR
5367 BGP_STR
5368 "Address family\n"
5369 "Address Family modifier\n"
5370 "Address Family modifier\n"
5371 "Display only routes with non-natural netmasks\n")
5373 if (strncmp (argv[0], "m", 1) == 0)
5374 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
5375 bgp_show_type_cidr_only);
5377 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5378 bgp_show_type_cidr_only);
5381 DEFUN (show_ip_bgp_community_all,
5382 show_ip_bgp_community_all_cmd,
5383 "show ip bgp community",
5384 SHOW_STR
5385 IP_STR
5386 BGP_STR
5387 "Display routes matching the communities\n")
5389 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5390 bgp_show_type_community_all);
5393 DEFUN (show_ip_bgp_ipv4_community_all,
5394 show_ip_bgp_ipv4_community_all_cmd,
5395 "show ip bgp ipv4 (unicast|multicast) community",
5396 SHOW_STR
5397 IP_STR
5398 BGP_STR
5399 "Address family\n"
5400 "Address Family modifier\n"
5401 "Address Family modifier\n"
5402 "Display routes matching the communities\n")
5404 if (strncmp (argv[0], "m", 1) == 0)
5405 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
5406 bgp_show_type_community_all);
5408 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5409 bgp_show_type_community_all);
5412 #ifdef HAVE_IPV6
5413 DEFUN (show_bgp_community_all,
5414 show_bgp_community_all_cmd,
5415 "show bgp community",
5416 SHOW_STR
5417 BGP_STR
5418 "Display routes matching the communities\n")
5420 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
5421 bgp_show_type_community_all);
5424 ALIAS (show_bgp_community_all,
5425 show_bgp_ipv6_community_all_cmd,
5426 "show bgp ipv6 community",
5427 SHOW_STR
5428 BGP_STR
5429 "Address family\n"
5430 "Display routes matching the communities\n")
5432 /* old command */
5433 DEFUN (show_ipv6_bgp_community_all,
5434 show_ipv6_bgp_community_all_cmd,
5435 "show ipv6 bgp community",
5436 SHOW_STR
5437 IPV6_STR
5438 BGP_STR
5439 "Display routes matching the communities\n")
5441 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
5442 bgp_show_type_community_all);
5445 /* old command */
5446 DEFUN (show_ipv6_mbgp_community_all,
5447 show_ipv6_mbgp_community_all_cmd,
5448 "show ipv6 mbgp community",
5449 SHOW_STR
5450 IPV6_STR
5451 MBGP_STR
5452 "Display routes matching the communities\n")
5454 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
5455 bgp_show_type_community_all);
5457 #endif /* HAVE_IPV6 */
5460 bgp_show_community (struct vty *vty, int argc, char **argv, int exact,
5461 u_int16_t afi, u_char safi)
5463 struct community *com;
5464 struct buffer *b;
5465 int i;
5466 char *str;
5467 int first = 0;
5469 b = buffer_new (1024);
5470 for (i = 0; i < argc; i++)
5472 if (first)
5473 buffer_putc (b, ' ');
5474 else
5476 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
5477 continue;
5478 first = 1;
5481 buffer_putstr (b, argv[i]);
5483 buffer_putc (b, '\0');
5485 str = buffer_getstr (b);
5486 buffer_free (b);
5488 com = community_str2com (str);
5489 free (str);
5490 if (! com)
5492 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
5493 return CMD_WARNING;
5496 vty->output_arg = com;
5498 if (exact)
5499 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_exact);
5501 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community);
5504 DEFUN (show_ip_bgp_community,
5505 show_ip_bgp_community_cmd,
5506 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
5507 SHOW_STR
5508 IP_STR
5509 BGP_STR
5510 "Display routes matching the communities\n"
5511 "community number\n"
5512 "Do not send outside local AS (well-known community)\n"
5513 "Do not advertise to any peer (well-known community)\n"
5514 "Do not export to next AS (well-known community)\n")
5516 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
5519 ALIAS (show_ip_bgp_community,
5520 show_ip_bgp_community2_cmd,
5521 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
5522 SHOW_STR
5523 IP_STR
5524 BGP_STR
5525 "Display routes matching the communities\n"
5526 "community number\n"
5527 "Do not send outside local AS (well-known community)\n"
5528 "Do not advertise to any peer (well-known community)\n"
5529 "Do not export to next AS (well-known community)\n"
5530 "community number\n"
5531 "Do not send outside local AS (well-known community)\n"
5532 "Do not advertise to any peer (well-known community)\n"
5533 "Do not export to next AS (well-known community)\n")
5535 ALIAS (show_ip_bgp_community,
5536 show_ip_bgp_community3_cmd,
5537 "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)",
5538 SHOW_STR
5539 IP_STR
5540 BGP_STR
5541 "Display routes matching the communities\n"
5542 "community number\n"
5543 "Do not send outside local AS (well-known community)\n"
5544 "Do not advertise to any peer (well-known community)\n"
5545 "Do not export to next AS (well-known community)\n"
5546 "community number\n"
5547 "Do not send outside local AS (well-known community)\n"
5548 "Do not advertise to any peer (well-known community)\n"
5549 "Do not export to next AS (well-known community)\n"
5550 "community number\n"
5551 "Do not send outside local AS (well-known community)\n"
5552 "Do not advertise to any peer (well-known community)\n"
5553 "Do not export to next AS (well-known community)\n")
5555 ALIAS (show_ip_bgp_community,
5556 show_ip_bgp_community4_cmd,
5557 "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)",
5558 SHOW_STR
5559 IP_STR
5560 BGP_STR
5561 "Display routes matching the communities\n"
5562 "community number\n"
5563 "Do not send outside local AS (well-known community)\n"
5564 "Do not advertise to any peer (well-known community)\n"
5565 "Do not export to next AS (well-known community)\n"
5566 "community number\n"
5567 "Do not send outside local AS (well-known community)\n"
5568 "Do not advertise to any peer (well-known community)\n"
5569 "Do not export to next AS (well-known community)\n"
5570 "community number\n"
5571 "Do not send outside local AS (well-known community)\n"
5572 "Do not advertise to any peer (well-known community)\n"
5573 "Do not export to next AS (well-known community)\n"
5574 "community number\n"
5575 "Do not send outside local AS (well-known community)\n"
5576 "Do not advertise to any peer (well-known community)\n"
5577 "Do not export to next AS (well-known community)\n")
5579 DEFUN (show_ip_bgp_ipv4_community,
5580 show_ip_bgp_ipv4_community_cmd,
5581 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
5582 SHOW_STR
5583 IP_STR
5584 BGP_STR
5585 "Address family\n"
5586 "Address Family modifier\n"
5587 "Address Family modifier\n"
5588 "Display routes matching the communities\n"
5589 "community number\n"
5590 "Do not send outside local AS (well-known community)\n"
5591 "Do not advertise to any peer (well-known community)\n"
5592 "Do not export to next AS (well-known community)\n")
5594 if (strncmp (argv[0], "m", 1) == 0)
5595 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
5597 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
5600 ALIAS (show_ip_bgp_ipv4_community,
5601 show_ip_bgp_ipv4_community2_cmd,
5602 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
5603 SHOW_STR
5604 IP_STR
5605 BGP_STR
5606 "Address family\n"
5607 "Address Family modifier\n"
5608 "Address Family modifier\n"
5609 "Display routes matching the communities\n"
5610 "community number\n"
5611 "Do not send outside local AS (well-known community)\n"
5612 "Do not advertise to any peer (well-known community)\n"
5613 "Do not export to next AS (well-known community)\n"
5614 "community number\n"
5615 "Do not send outside local AS (well-known community)\n"
5616 "Do not advertise to any peer (well-known community)\n"
5617 "Do not export to next AS (well-known community)\n")
5619 ALIAS (show_ip_bgp_ipv4_community,
5620 show_ip_bgp_ipv4_community3_cmd,
5621 "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)",
5622 SHOW_STR
5623 IP_STR
5624 BGP_STR
5625 "Address family\n"
5626 "Address Family modifier\n"
5627 "Address Family modifier\n"
5628 "Display routes matching the communities\n"
5629 "community number\n"
5630 "Do not send outside local AS (well-known community)\n"
5631 "Do not advertise to any peer (well-known community)\n"
5632 "Do not export to next AS (well-known community)\n"
5633 "community number\n"
5634 "Do not send outside local AS (well-known community)\n"
5635 "Do not advertise to any peer (well-known community)\n"
5636 "Do not export to next AS (well-known community)\n"
5637 "community number\n"
5638 "Do not send outside local AS (well-known community)\n"
5639 "Do not advertise to any peer (well-known community)\n"
5640 "Do not export to next AS (well-known community)\n")
5642 ALIAS (show_ip_bgp_ipv4_community,
5643 show_ip_bgp_ipv4_community4_cmd,
5644 "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)",
5645 SHOW_STR
5646 IP_STR
5647 BGP_STR
5648 "Address family\n"
5649 "Address Family modifier\n"
5650 "Address Family modifier\n"
5651 "Display routes matching the communities\n"
5652 "community number\n"
5653 "Do not send outside local AS (well-known community)\n"
5654 "Do not advertise to any peer (well-known community)\n"
5655 "Do not export to next AS (well-known community)\n"
5656 "community number\n"
5657 "Do not send outside local AS (well-known community)\n"
5658 "Do not advertise to any peer (well-known community)\n"
5659 "Do not export to next AS (well-known community)\n"
5660 "community number\n"
5661 "Do not send outside local AS (well-known community)\n"
5662 "Do not advertise to any peer (well-known community)\n"
5663 "Do not export to next AS (well-known community)\n"
5664 "community number\n"
5665 "Do not send outside local AS (well-known community)\n"
5666 "Do not advertise to any peer (well-known community)\n"
5667 "Do not export to next AS (well-known community)\n")
5669 DEFUN (show_ip_bgp_community_exact,
5670 show_ip_bgp_community_exact_cmd,
5671 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
5672 SHOW_STR
5673 IP_STR
5674 BGP_STR
5675 "Display routes matching the communities\n"
5676 "community number\n"
5677 "Do not send outside local AS (well-known community)\n"
5678 "Do not advertise to any peer (well-known community)\n"
5679 "Do not export to next AS (well-known community)\n"
5680 "Exact match of the communities")
5682 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
5685 ALIAS (show_ip_bgp_community_exact,
5686 show_ip_bgp_community2_exact_cmd,
5687 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
5688 SHOW_STR
5689 IP_STR
5690 BGP_STR
5691 "Display routes matching the communities\n"
5692 "community number\n"
5693 "Do not send outside local AS (well-known community)\n"
5694 "Do not advertise to any peer (well-known community)\n"
5695 "Do not export to next AS (well-known community)\n"
5696 "community number\n"
5697 "Do not send outside local AS (well-known community)\n"
5698 "Do not advertise to any peer (well-known community)\n"
5699 "Do not export to next AS (well-known community)\n"
5700 "Exact match of the communities")
5702 ALIAS (show_ip_bgp_community_exact,
5703 show_ip_bgp_community3_exact_cmd,
5704 "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",
5705 SHOW_STR
5706 IP_STR
5707 BGP_STR
5708 "Display routes matching the communities\n"
5709 "community number\n"
5710 "Do not send outside local AS (well-known community)\n"
5711 "Do not advertise to any peer (well-known community)\n"
5712 "Do not export to next AS (well-known community)\n"
5713 "community number\n"
5714 "Do not send outside local AS (well-known community)\n"
5715 "Do not advertise to any peer (well-known community)\n"
5716 "Do not export to next AS (well-known community)\n"
5717 "community number\n"
5718 "Do not send outside local AS (well-known community)\n"
5719 "Do not advertise to any peer (well-known community)\n"
5720 "Do not export to next AS (well-known community)\n"
5721 "Exact match of the communities")
5723 ALIAS (show_ip_bgp_community_exact,
5724 show_ip_bgp_community4_exact_cmd,
5725 "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",
5726 SHOW_STR
5727 IP_STR
5728 BGP_STR
5729 "Display routes matching the communities\n"
5730 "community number\n"
5731 "Do not send outside local AS (well-known community)\n"
5732 "Do not advertise to any peer (well-known community)\n"
5733 "Do not export to next AS (well-known community)\n"
5734 "community number\n"
5735 "Do not send outside local AS (well-known community)\n"
5736 "Do not advertise to any peer (well-known community)\n"
5737 "Do not export to next AS (well-known community)\n"
5738 "community number\n"
5739 "Do not send outside local AS (well-known community)\n"
5740 "Do not advertise to any peer (well-known community)\n"
5741 "Do not export to next AS (well-known community)\n"
5742 "community number\n"
5743 "Do not send outside local AS (well-known community)\n"
5744 "Do not advertise to any peer (well-known community)\n"
5745 "Do not export to next AS (well-known community)\n"
5746 "Exact match of the communities")
5748 DEFUN (show_ip_bgp_ipv4_community_exact,
5749 show_ip_bgp_ipv4_community_exact_cmd,
5750 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
5751 SHOW_STR
5752 IP_STR
5753 BGP_STR
5754 "Address family\n"
5755 "Address Family modifier\n"
5756 "Address Family modifier\n"
5757 "Display routes matching the communities\n"
5758 "community number\n"
5759 "Do not send outside local AS (well-known community)\n"
5760 "Do not advertise to any peer (well-known community)\n"
5761 "Do not export to next AS (well-known community)\n"
5762 "Exact match of the communities")
5764 if (strncmp (argv[0], "m", 1) == 0)
5765 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
5767 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
5770 ALIAS (show_ip_bgp_ipv4_community_exact,
5771 show_ip_bgp_ipv4_community2_exact_cmd,
5772 "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",
5773 SHOW_STR
5774 IP_STR
5775 BGP_STR
5776 "Address family\n"
5777 "Address Family modifier\n"
5778 "Address Family modifier\n"
5779 "Display routes matching the communities\n"
5780 "community number\n"
5781 "Do not send outside local AS (well-known community)\n"
5782 "Do not advertise to any peer (well-known community)\n"
5783 "Do not export to next AS (well-known community)\n"
5784 "community number\n"
5785 "Do not send outside local AS (well-known community)\n"
5786 "Do not advertise to any peer (well-known community)\n"
5787 "Do not export to next AS (well-known community)\n"
5788 "Exact match of the communities")
5790 ALIAS (show_ip_bgp_ipv4_community_exact,
5791 show_ip_bgp_ipv4_community3_exact_cmd,
5792 "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",
5793 SHOW_STR
5794 IP_STR
5795 BGP_STR
5796 "Address family\n"
5797 "Address Family modifier\n"
5798 "Address Family modifier\n"
5799 "Display routes matching the communities\n"
5800 "community number\n"
5801 "Do not send outside local AS (well-known community)\n"
5802 "Do not advertise to any peer (well-known community)\n"
5803 "Do not export to next AS (well-known community)\n"
5804 "community number\n"
5805 "Do not send outside local AS (well-known community)\n"
5806 "Do not advertise to any peer (well-known community)\n"
5807 "Do not export to next AS (well-known community)\n"
5808 "community number\n"
5809 "Do not send outside local AS (well-known community)\n"
5810 "Do not advertise to any peer (well-known community)\n"
5811 "Do not export to next AS (well-known community)\n"
5812 "Exact match of the communities")
5814 ALIAS (show_ip_bgp_ipv4_community_exact,
5815 show_ip_bgp_ipv4_community4_exact_cmd,
5816 "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",
5817 SHOW_STR
5818 IP_STR
5819 BGP_STR
5820 "Address family\n"
5821 "Address Family modifier\n"
5822 "Address Family modifier\n"
5823 "Display routes matching the communities\n"
5824 "community number\n"
5825 "Do not send outside local AS (well-known community)\n"
5826 "Do not advertise to any peer (well-known community)\n"
5827 "Do not export to next AS (well-known community)\n"
5828 "community number\n"
5829 "Do not send outside local AS (well-known community)\n"
5830 "Do not advertise to any peer (well-known community)\n"
5831 "Do not export to next AS (well-known community)\n"
5832 "community number\n"
5833 "Do not send outside local AS (well-known community)\n"
5834 "Do not advertise to any peer (well-known community)\n"
5835 "Do not export to next AS (well-known community)\n"
5836 "community number\n"
5837 "Do not send outside local AS (well-known community)\n"
5838 "Do not advertise to any peer (well-known community)\n"
5839 "Do not export to next AS (well-known community)\n"
5840 "Exact match of the communities")
5842 #ifdef HAVE_IPV6
5843 DEFUN (show_bgp_community,
5844 show_bgp_community_cmd,
5845 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
5846 SHOW_STR
5847 BGP_STR
5848 "Display routes matching the communities\n"
5849 "community number\n"
5850 "Do not send outside local AS (well-known community)\n"
5851 "Do not advertise to any peer (well-known community)\n"
5852 "Do not export to next AS (well-known community)\n")
5854 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
5857 ALIAS (show_bgp_community,
5858 show_bgp_ipv6_community_cmd,
5859 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
5860 SHOW_STR
5861 BGP_STR
5862 "Address family\n"
5863 "Display routes matching the communities\n"
5864 "community number\n"
5865 "Do not send outside local AS (well-known community)\n"
5866 "Do not advertise to any peer (well-known community)\n"
5867 "Do not export to next AS (well-known community)\n")
5869 ALIAS (show_bgp_community,
5870 show_bgp_community2_cmd,
5871 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
5872 SHOW_STR
5873 BGP_STR
5874 "Display routes matching the communities\n"
5875 "community number\n"
5876 "Do not send outside local AS (well-known community)\n"
5877 "Do not advertise to any peer (well-known community)\n"
5878 "Do not export to next AS (well-known community)\n"
5879 "community number\n"
5880 "Do not send outside local AS (well-known community)\n"
5881 "Do not advertise to any peer (well-known community)\n"
5882 "Do not export to next AS (well-known community)\n")
5884 ALIAS (show_bgp_community,
5885 show_bgp_ipv6_community2_cmd,
5886 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
5887 SHOW_STR
5888 BGP_STR
5889 "Address family\n"
5890 "Display routes matching the communities\n"
5891 "community number\n"
5892 "Do not send outside local AS (well-known community)\n"
5893 "Do not advertise to any peer (well-known community)\n"
5894 "Do not export to next AS (well-known community)\n"
5895 "community number\n"
5896 "Do not send outside local AS (well-known community)\n"
5897 "Do not advertise to any peer (well-known community)\n"
5898 "Do not export to next AS (well-known community)\n")
5900 ALIAS (show_bgp_community,
5901 show_bgp_community3_cmd,
5902 "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)",
5903 SHOW_STR
5904 BGP_STR
5905 "Display routes matching the communities\n"
5906 "community number\n"
5907 "Do not send outside local AS (well-known community)\n"
5908 "Do not advertise to any peer (well-known community)\n"
5909 "Do not export to next AS (well-known community)\n"
5910 "community number\n"
5911 "Do not send outside local AS (well-known community)\n"
5912 "Do not advertise to any peer (well-known community)\n"
5913 "Do not export to next AS (well-known community)\n"
5914 "community number\n"
5915 "Do not send outside local AS (well-known community)\n"
5916 "Do not advertise to any peer (well-known community)\n"
5917 "Do not export to next AS (well-known community)\n")
5919 ALIAS (show_bgp_community,
5920 show_bgp_ipv6_community3_cmd,
5921 "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)",
5922 SHOW_STR
5923 BGP_STR
5924 "Address family\n"
5925 "Display routes matching the communities\n"
5926 "community number\n"
5927 "Do not send outside local AS (well-known community)\n"
5928 "Do not advertise to any peer (well-known community)\n"
5929 "Do not export to next AS (well-known community)\n"
5930 "community number\n"
5931 "Do not send outside local AS (well-known community)\n"
5932 "Do not advertise to any peer (well-known community)\n"
5933 "Do not export to next AS (well-known community)\n"
5934 "community number\n"
5935 "Do not send outside local AS (well-known community)\n"
5936 "Do not advertise to any peer (well-known community)\n"
5937 "Do not export to next AS (well-known community)\n")
5939 ALIAS (show_bgp_community,
5940 show_bgp_community4_cmd,
5941 "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)",
5942 SHOW_STR
5943 BGP_STR
5944 "Display routes matching the communities\n"
5945 "community number\n"
5946 "Do not send outside local AS (well-known community)\n"
5947 "Do not advertise to any peer (well-known community)\n"
5948 "Do not export to next AS (well-known community)\n"
5949 "community number\n"
5950 "Do not send outside local AS (well-known community)\n"
5951 "Do not advertise to any peer (well-known community)\n"
5952 "Do not export to next AS (well-known community)\n"
5953 "community number\n"
5954 "Do not send outside local AS (well-known community)\n"
5955 "Do not advertise to any peer (well-known community)\n"
5956 "Do not export to next AS (well-known community)\n"
5957 "community number\n"
5958 "Do not send outside local AS (well-known community)\n"
5959 "Do not advertise to any peer (well-known community)\n"
5960 "Do not export to next AS (well-known community)\n")
5962 ALIAS (show_bgp_community,
5963 show_bgp_ipv6_community4_cmd,
5964 "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)",
5965 SHOW_STR
5966 BGP_STR
5967 "Address family\n"
5968 "Display routes matching the communities\n"
5969 "community number\n"
5970 "Do not send outside local AS (well-known community)\n"
5971 "Do not advertise to any peer (well-known community)\n"
5972 "Do not export to next AS (well-known community)\n"
5973 "community number\n"
5974 "Do not send outside local AS (well-known community)\n"
5975 "Do not advertise to any peer (well-known community)\n"
5976 "Do not export to next AS (well-known community)\n"
5977 "community number\n"
5978 "Do not send outside local AS (well-known community)\n"
5979 "Do not advertise to any peer (well-known community)\n"
5980 "Do not export to next AS (well-known community)\n"
5981 "community number\n"
5982 "Do not send outside local AS (well-known community)\n"
5983 "Do not advertise to any peer (well-known community)\n"
5984 "Do not export to next AS (well-known community)\n")
5986 /* old command */
5987 DEFUN (show_ipv6_bgp_community,
5988 show_ipv6_bgp_community_cmd,
5989 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
5990 SHOW_STR
5991 IPV6_STR
5992 BGP_STR
5993 "Display routes matching the communities\n"
5994 "community number\n"
5995 "Do not send outside local AS (well-known community)\n"
5996 "Do not advertise to any peer (well-known community)\n"
5997 "Do not export to next AS (well-known community)\n")
5999 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
6002 /* old command */
6003 ALIAS (show_ipv6_bgp_community,
6004 show_ipv6_bgp_community2_cmd,
6005 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6006 SHOW_STR
6007 IPV6_STR
6008 BGP_STR
6009 "Display routes matching the communities\n"
6010 "community number\n"
6011 "Do not send outside local AS (well-known community)\n"
6012 "Do not advertise to any peer (well-known community)\n"
6013 "Do not export to next AS (well-known community)\n"
6014 "community number\n"
6015 "Do not send outside local AS (well-known community)\n"
6016 "Do not advertise to any peer (well-known community)\n"
6017 "Do not export to next AS (well-known community)\n")
6019 /* old command */
6020 ALIAS (show_ipv6_bgp_community,
6021 show_ipv6_bgp_community3_cmd,
6022 "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)",
6023 SHOW_STR
6024 IPV6_STR
6025 BGP_STR
6026 "Display routes matching the communities\n"
6027 "community number\n"
6028 "Do not send outside local AS (well-known community)\n"
6029 "Do not advertise to any peer (well-known community)\n"
6030 "Do not export to next AS (well-known community)\n"
6031 "community number\n"
6032 "Do not send outside local AS (well-known community)\n"
6033 "Do not advertise to any peer (well-known community)\n"
6034 "Do not export to next AS (well-known community)\n"
6035 "community number\n"
6036 "Do not send outside local AS (well-known community)\n"
6037 "Do not advertise to any peer (well-known community)\n"
6038 "Do not export to next AS (well-known community)\n")
6040 /* old command */
6041 ALIAS (show_ipv6_bgp_community,
6042 show_ipv6_bgp_community4_cmd,
6043 "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)",
6044 SHOW_STR
6045 IPV6_STR
6046 BGP_STR
6047 "Display routes matching the communities\n"
6048 "community number\n"
6049 "Do not send outside local AS (well-known community)\n"
6050 "Do not advertise to any peer (well-known community)\n"
6051 "Do not export to next AS (well-known community)\n"
6052 "community number\n"
6053 "Do not send outside local AS (well-known community)\n"
6054 "Do not advertise to any peer (well-known community)\n"
6055 "Do not export to next AS (well-known community)\n"
6056 "community number\n"
6057 "Do not send outside local AS (well-known community)\n"
6058 "Do not advertise to any peer (well-known community)\n"
6059 "Do not export to next AS (well-known community)\n"
6060 "community number\n"
6061 "Do not send outside local AS (well-known community)\n"
6062 "Do not advertise to any peer (well-known community)\n"
6063 "Do not export to next AS (well-known community)\n")
6065 DEFUN (show_bgp_community_exact,
6066 show_bgp_community_exact_cmd,
6067 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6068 SHOW_STR
6069 BGP_STR
6070 "Display routes matching the communities\n"
6071 "community number\n"
6072 "Do not send outside local AS (well-known community)\n"
6073 "Do not advertise to any peer (well-known community)\n"
6074 "Do not export to next AS (well-known community)\n"
6075 "Exact match of the communities")
6077 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
6080 ALIAS (show_bgp_community_exact,
6081 show_bgp_ipv6_community_exact_cmd,
6082 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6083 SHOW_STR
6084 BGP_STR
6085 "Address family\n"
6086 "Display routes matching the communities\n"
6087 "community number\n"
6088 "Do not send outside local AS (well-known community)\n"
6089 "Do not advertise to any peer (well-known community)\n"
6090 "Do not export to next AS (well-known community)\n"
6091 "Exact match of the communities")
6093 ALIAS (show_bgp_community_exact,
6094 show_bgp_community2_exact_cmd,
6095 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6096 SHOW_STR
6097 BGP_STR
6098 "Display routes matching the communities\n"
6099 "community number\n"
6100 "Do not send outside local AS (well-known community)\n"
6101 "Do not advertise to any peer (well-known community)\n"
6102 "Do not export to next AS (well-known community)\n"
6103 "community number\n"
6104 "Do not send outside local AS (well-known community)\n"
6105 "Do not advertise to any peer (well-known community)\n"
6106 "Do not export to next AS (well-known community)\n"
6107 "Exact match of the communities")
6109 ALIAS (show_bgp_community_exact,
6110 show_bgp_ipv6_community2_exact_cmd,
6111 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6112 SHOW_STR
6113 BGP_STR
6114 "Address family\n"
6115 "Display routes matching the communities\n"
6116 "community number\n"
6117 "Do not send outside local AS (well-known community)\n"
6118 "Do not advertise to any peer (well-known community)\n"
6119 "Do not export to next AS (well-known community)\n"
6120 "community number\n"
6121 "Do not send outside local AS (well-known community)\n"
6122 "Do not advertise to any peer (well-known community)\n"
6123 "Do not export to next AS (well-known community)\n"
6124 "Exact match of the communities")
6126 ALIAS (show_bgp_community_exact,
6127 show_bgp_community3_exact_cmd,
6128 "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",
6129 SHOW_STR
6130 BGP_STR
6131 "Display routes matching the communities\n"
6132 "community number\n"
6133 "Do not send outside local AS (well-known community)\n"
6134 "Do not advertise to any peer (well-known community)\n"
6135 "Do not export to next AS (well-known community)\n"
6136 "community number\n"
6137 "Do not send outside local AS (well-known community)\n"
6138 "Do not advertise to any peer (well-known community)\n"
6139 "Do not export to next AS (well-known community)\n"
6140 "community number\n"
6141 "Do not send outside local AS (well-known community)\n"
6142 "Do not advertise to any peer (well-known community)\n"
6143 "Do not export to next AS (well-known community)\n"
6144 "Exact match of the communities")
6146 ALIAS (show_bgp_community_exact,
6147 show_bgp_ipv6_community3_exact_cmd,
6148 "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",
6149 SHOW_STR
6150 BGP_STR
6151 "Address family\n"
6152 "Display routes matching the communities\n"
6153 "community number\n"
6154 "Do not send outside local AS (well-known community)\n"
6155 "Do not advertise to any peer (well-known community)\n"
6156 "Do not export to next AS (well-known community)\n"
6157 "community number\n"
6158 "Do not send outside local AS (well-known community)\n"
6159 "Do not advertise to any peer (well-known community)\n"
6160 "Do not export to next AS (well-known community)\n"
6161 "community number\n"
6162 "Do not send outside local AS (well-known community)\n"
6163 "Do not advertise to any peer (well-known community)\n"
6164 "Do not export to next AS (well-known community)\n"
6165 "Exact match of the communities")
6167 ALIAS (show_bgp_community_exact,
6168 show_bgp_community4_exact_cmd,
6169 "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",
6170 SHOW_STR
6171 BGP_STR
6172 "Display routes matching the communities\n"
6173 "community number\n"
6174 "Do not send outside local AS (well-known community)\n"
6175 "Do not advertise to any peer (well-known community)\n"
6176 "Do not export to next AS (well-known community)\n"
6177 "community number\n"
6178 "Do not send outside local AS (well-known community)\n"
6179 "Do not advertise to any peer (well-known community)\n"
6180 "Do not export to next AS (well-known community)\n"
6181 "community number\n"
6182 "Do not send outside local AS (well-known community)\n"
6183 "Do not advertise to any peer (well-known community)\n"
6184 "Do not export to next AS (well-known community)\n"
6185 "community number\n"
6186 "Do not send outside local AS (well-known community)\n"
6187 "Do not advertise to any peer (well-known community)\n"
6188 "Do not export to next AS (well-known community)\n"
6189 "Exact match of the communities")
6191 ALIAS (show_bgp_community_exact,
6192 show_bgp_ipv6_community4_exact_cmd,
6193 "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",
6194 SHOW_STR
6195 BGP_STR
6196 "Address family\n"
6197 "Display routes matching the communities\n"
6198 "community number\n"
6199 "Do not send outside local AS (well-known community)\n"
6200 "Do not advertise to any peer (well-known community)\n"
6201 "Do not export to next AS (well-known community)\n"
6202 "community number\n"
6203 "Do not send outside local AS (well-known community)\n"
6204 "Do not advertise to any peer (well-known community)\n"
6205 "Do not export to next AS (well-known community)\n"
6206 "community number\n"
6207 "Do not send outside local AS (well-known community)\n"
6208 "Do not advertise to any peer (well-known community)\n"
6209 "Do not export to next AS (well-known community)\n"
6210 "community number\n"
6211 "Do not send outside local AS (well-known community)\n"
6212 "Do not advertise to any peer (well-known community)\n"
6213 "Do not export to next AS (well-known community)\n"
6214 "Exact match of the communities")
6216 /* old command */
6217 DEFUN (show_ipv6_bgp_community_exact,
6218 show_ipv6_bgp_community_exact_cmd,
6219 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6220 SHOW_STR
6221 IPV6_STR
6222 BGP_STR
6223 "Display routes matching the communities\n"
6224 "community number\n"
6225 "Do not send outside local AS (well-known community)\n"
6226 "Do not advertise to any peer (well-known community)\n"
6227 "Do not export to next AS (well-known community)\n"
6228 "Exact match of the communities")
6230 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
6233 /* old command */
6234 ALIAS (show_ipv6_bgp_community_exact,
6235 show_ipv6_bgp_community2_exact_cmd,
6236 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6237 SHOW_STR
6238 IPV6_STR
6239 BGP_STR
6240 "Display routes matching the communities\n"
6241 "community number\n"
6242 "Do not send outside local AS (well-known community)\n"
6243 "Do not advertise to any peer (well-known community)\n"
6244 "Do not export to next AS (well-known community)\n"
6245 "community number\n"
6246 "Do not send outside local AS (well-known community)\n"
6247 "Do not advertise to any peer (well-known community)\n"
6248 "Do not export to next AS (well-known community)\n"
6249 "Exact match of the communities")
6251 /* old command */
6252 ALIAS (show_ipv6_bgp_community_exact,
6253 show_ipv6_bgp_community3_exact_cmd,
6254 "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",
6255 SHOW_STR
6256 IPV6_STR
6257 BGP_STR
6258 "Display routes matching the communities\n"
6259 "community number\n"
6260 "Do not send outside local AS (well-known community)\n"
6261 "Do not advertise to any peer (well-known community)\n"
6262 "Do not export to next AS (well-known community)\n"
6263 "community number\n"
6264 "Do not send outside local AS (well-known community)\n"
6265 "Do not advertise to any peer (well-known community)\n"
6266 "Do not export to next AS (well-known community)\n"
6267 "community number\n"
6268 "Do not send outside local AS (well-known community)\n"
6269 "Do not advertise to any peer (well-known community)\n"
6270 "Do not export to next AS (well-known community)\n"
6271 "Exact match of the communities")
6273 /* old command */
6274 ALIAS (show_ipv6_bgp_community_exact,
6275 show_ipv6_bgp_community4_exact_cmd,
6276 "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",
6277 SHOW_STR
6278 IPV6_STR
6279 BGP_STR
6280 "Display routes matching the communities\n"
6281 "community number\n"
6282 "Do not send outside local AS (well-known community)\n"
6283 "Do not advertise to any peer (well-known community)\n"
6284 "Do not export to next AS (well-known community)\n"
6285 "community number\n"
6286 "Do not send outside local AS (well-known community)\n"
6287 "Do not advertise to any peer (well-known community)\n"
6288 "Do not export to next AS (well-known community)\n"
6289 "community number\n"
6290 "Do not send outside local AS (well-known community)\n"
6291 "Do not advertise to any peer (well-known community)\n"
6292 "Do not export to next AS (well-known community)\n"
6293 "community number\n"
6294 "Do not send outside local AS (well-known community)\n"
6295 "Do not advertise to any peer (well-known community)\n"
6296 "Do not export to next AS (well-known community)\n"
6297 "Exact match of the communities")
6299 /* old command */
6300 DEFUN (show_ipv6_mbgp_community,
6301 show_ipv6_mbgp_community_cmd,
6302 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
6303 SHOW_STR
6304 IPV6_STR
6305 MBGP_STR
6306 "Display routes matching the communities\n"
6307 "community number\n"
6308 "Do not send outside local AS (well-known community)\n"
6309 "Do not advertise to any peer (well-known community)\n"
6310 "Do not export to next AS (well-known community)\n")
6312 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
6315 /* old command */
6316 ALIAS (show_ipv6_mbgp_community,
6317 show_ipv6_mbgp_community2_cmd,
6318 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6319 SHOW_STR
6320 IPV6_STR
6321 MBGP_STR
6322 "Display routes matching the communities\n"
6323 "community number\n"
6324 "Do not send outside local AS (well-known community)\n"
6325 "Do not advertise to any peer (well-known community)\n"
6326 "Do not export to next AS (well-known community)\n"
6327 "community number\n"
6328 "Do not send outside local AS (well-known community)\n"
6329 "Do not advertise to any peer (well-known community)\n"
6330 "Do not export to next AS (well-known community)\n")
6332 /* old command */
6333 ALIAS (show_ipv6_mbgp_community,
6334 show_ipv6_mbgp_community3_cmd,
6335 "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)",
6336 SHOW_STR
6337 IPV6_STR
6338 MBGP_STR
6339 "Display routes matching the communities\n"
6340 "community number\n"
6341 "Do not send outside local AS (well-known community)\n"
6342 "Do not advertise to any peer (well-known community)\n"
6343 "Do not export to next AS (well-known community)\n"
6344 "community number\n"
6345 "Do not send outside local AS (well-known community)\n"
6346 "Do not advertise to any peer (well-known community)\n"
6347 "Do not export to next AS (well-known community)\n"
6348 "community number\n"
6349 "Do not send outside local AS (well-known community)\n"
6350 "Do not advertise to any peer (well-known community)\n"
6351 "Do not export to next AS (well-known community)\n")
6353 /* old command */
6354 ALIAS (show_ipv6_mbgp_community,
6355 show_ipv6_mbgp_community4_cmd,
6356 "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)",
6357 SHOW_STR
6358 IPV6_STR
6359 MBGP_STR
6360 "Display routes matching the communities\n"
6361 "community number\n"
6362 "Do not send outside local AS (well-known community)\n"
6363 "Do not advertise to any peer (well-known community)\n"
6364 "Do not export to next AS (well-known community)\n"
6365 "community number\n"
6366 "Do not send outside local AS (well-known community)\n"
6367 "Do not advertise to any peer (well-known community)\n"
6368 "Do not export to next AS (well-known community)\n"
6369 "community number\n"
6370 "Do not send outside local AS (well-known community)\n"
6371 "Do not advertise to any peer (well-known community)\n"
6372 "Do not export to next AS (well-known community)\n"
6373 "community number\n"
6374 "Do not send outside local AS (well-known community)\n"
6375 "Do not advertise to any peer (well-known community)\n"
6376 "Do not export to next AS (well-known community)\n")
6378 /* old command */
6379 DEFUN (show_ipv6_mbgp_community_exact,
6380 show_ipv6_mbgp_community_exact_cmd,
6381 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6382 SHOW_STR
6383 IPV6_STR
6384 MBGP_STR
6385 "Display routes matching the communities\n"
6386 "community number\n"
6387 "Do not send outside local AS (well-known community)\n"
6388 "Do not advertise to any peer (well-known community)\n"
6389 "Do not export to next AS (well-known community)\n"
6390 "Exact match of the communities")
6392 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
6395 /* old command */
6396 ALIAS (show_ipv6_mbgp_community_exact,
6397 show_ipv6_mbgp_community2_exact_cmd,
6398 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6399 SHOW_STR
6400 IPV6_STR
6401 MBGP_STR
6402 "Display routes matching the communities\n"
6403 "community number\n"
6404 "Do not send outside local AS (well-known community)\n"
6405 "Do not advertise to any peer (well-known community)\n"
6406 "Do not export to next AS (well-known community)\n"
6407 "community number\n"
6408 "Do not send outside local AS (well-known community)\n"
6409 "Do not advertise to any peer (well-known community)\n"
6410 "Do not export to next AS (well-known community)\n"
6411 "Exact match of the communities")
6413 /* old command */
6414 ALIAS (show_ipv6_mbgp_community_exact,
6415 show_ipv6_mbgp_community3_exact_cmd,
6416 "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",
6417 SHOW_STR
6418 IPV6_STR
6419 MBGP_STR
6420 "Display routes matching the communities\n"
6421 "community number\n"
6422 "Do not send outside local AS (well-known community)\n"
6423 "Do not advertise to any peer (well-known community)\n"
6424 "Do not export to next AS (well-known community)\n"
6425 "community number\n"
6426 "Do not send outside local AS (well-known community)\n"
6427 "Do not advertise to any peer (well-known community)\n"
6428 "Do not export to next AS (well-known community)\n"
6429 "community number\n"
6430 "Do not send outside local AS (well-known community)\n"
6431 "Do not advertise to any peer (well-known community)\n"
6432 "Do not export to next AS (well-known community)\n"
6433 "Exact match of the communities")
6435 /* old command */
6436 ALIAS (show_ipv6_mbgp_community_exact,
6437 show_ipv6_mbgp_community4_exact_cmd,
6438 "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",
6439 SHOW_STR
6440 IPV6_STR
6441 MBGP_STR
6442 "Display routes matching the communities\n"
6443 "community number\n"
6444 "Do not send outside local AS (well-known community)\n"
6445 "Do not advertise to any peer (well-known community)\n"
6446 "Do not export to next AS (well-known community)\n"
6447 "community number\n"
6448 "Do not send outside local AS (well-known community)\n"
6449 "Do not advertise to any peer (well-known community)\n"
6450 "Do not export to next AS (well-known community)\n"
6451 "community number\n"
6452 "Do not send outside local AS (well-known community)\n"
6453 "Do not advertise to any peer (well-known community)\n"
6454 "Do not export to next AS (well-known community)\n"
6455 "community number\n"
6456 "Do not send outside local AS (well-known community)\n"
6457 "Do not advertise to any peer (well-known community)\n"
6458 "Do not export to next AS (well-known community)\n"
6459 "Exact match of the communities")
6460 #endif /* HAVE_IPV6 */
6463 bgp_show_community_list (struct vty *vty, char *com, int exact,
6464 u_int16_t afi, u_char safi)
6466 struct community_list *list;
6468 list = community_list_lookup (com);
6469 if (list == NULL)
6471 vty_out (vty, "%% %s is not a valid community-list name%s", com, VTY_NEWLINE);
6472 return CMD_WARNING;
6475 vty->output_arg = list;
6477 if (exact)
6478 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_list_exact);
6480 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_list);
6483 DEFUN (show_ip_bgp_community_list,
6484 show_ip_bgp_community_list_cmd,
6485 "show ip bgp community-list WORD",
6486 SHOW_STR
6487 IP_STR
6488 BGP_STR
6489 "Display routes matching the community-list\n"
6490 "community-list name\n")
6492 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
6495 DEFUN (show_ip_bgp_ipv4_community_list,
6496 show_ip_bgp_ipv4_community_list_cmd,
6497 "show ip bgp ipv4 (unicast|multicast) community-list WORD",
6498 SHOW_STR
6499 IP_STR
6500 BGP_STR
6501 "Address family\n"
6502 "Address Family modifier\n"
6503 "Address Family modifier\n"
6504 "Display routes matching the community-list\n"
6505 "community-list name\n")
6507 if (strncmp (argv[0], "m", 1) == 0)
6508 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
6510 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
6513 DEFUN (show_ip_bgp_community_list_exact,
6514 show_ip_bgp_community_list_exact_cmd,
6515 "show ip bgp community-list WORD exact-match",
6516 SHOW_STR
6517 IP_STR
6518 BGP_STR
6519 "Display routes matching the community-list\n"
6520 "community-list name\n"
6521 "Exact match of the communities\n")
6523 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
6526 DEFUN (show_ip_bgp_ipv4_community_list_exact,
6527 show_ip_bgp_ipv4_community_list_exact_cmd,
6528 "show ip bgp ipv4 (unicast|multicast) community-list WORD exact-match",
6529 SHOW_STR
6530 IP_STR
6531 BGP_STR
6532 "Address family\n"
6533 "Address Family modifier\n"
6534 "Address Family modifier\n"
6535 "Display routes matching the community-list\n"
6536 "community-list name\n"
6537 "Exact match of the communities\n")
6539 if (strncmp (argv[0], "m", 1) == 0)
6540 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
6542 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
6545 #ifdef HAVE_IPV6
6546 DEFUN (show_bgp_community_list,
6547 show_bgp_community_list_cmd,
6548 "show bgp community-list WORD",
6549 SHOW_STR
6550 BGP_STR
6551 "Display routes matching the community-list\n"
6552 "community-list name\n")
6554 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
6557 ALIAS (show_bgp_community_list,
6558 show_bgp_ipv6_community_list_cmd,
6559 "show bgp ipv6 community-list WORD",
6560 SHOW_STR
6561 BGP_STR
6562 "Address family\n"
6563 "Display routes matching the community-list\n"
6564 "community-list name\n")
6566 /* old command */
6567 DEFUN (show_ipv6_bgp_community_list,
6568 show_ipv6_bgp_community_list_cmd,
6569 "show ipv6 bgp community-list WORD",
6570 SHOW_STR
6571 IPV6_STR
6572 BGP_STR
6573 "Display routes matching the community-list\n"
6574 "community-list name\n")
6576 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
6579 /* old command */
6580 DEFUN (show_ipv6_mbgp_community_list,
6581 show_ipv6_mbgp_community_list_cmd,
6582 "show ipv6 mbgp community-list WORD",
6583 SHOW_STR
6584 IPV6_STR
6585 MBGP_STR
6586 "Display routes matching the community-list\n"
6587 "community-list name\n")
6589 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
6592 DEFUN (show_bgp_community_list_exact,
6593 show_bgp_community_list_exact_cmd,
6594 "show bgp community-list WORD exact-match",
6595 SHOW_STR
6596 BGP_STR
6597 "Display routes matching the community-list\n"
6598 "community-list name\n"
6599 "Exact match of the communities\n")
6601 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
6604 ALIAS (show_bgp_community_list_exact,
6605 show_bgp_ipv6_community_list_exact_cmd,
6606 "show bgp ipv6 community-list WORD exact-match",
6607 SHOW_STR
6608 BGP_STR
6609 "Address family\n"
6610 "Display routes matching the community-list\n"
6611 "community-list name\n"
6612 "Exact match of the communities\n")
6614 /* old command */
6615 DEFUN (show_ipv6_bgp_community_list_exact,
6616 show_ipv6_bgp_community_list_exact_cmd,
6617 "show ipv6 bgp community-list WORD exact-match",
6618 SHOW_STR
6619 IPV6_STR
6620 BGP_STR
6621 "Display routes matching the community-list\n"
6622 "community-list name\n"
6623 "Exact match of the communities\n")
6625 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
6628 /* old command */
6629 DEFUN (show_ipv6_mbgp_community_list_exact,
6630 show_ipv6_mbgp_community_list_exact_cmd,
6631 "show ipv6 mbgp community-list WORD exact-match",
6632 SHOW_STR
6633 IPV6_STR
6634 MBGP_STR
6635 "Display routes matching the community-list\n"
6636 "community-list name\n"
6637 "Exact match of the communities\n")
6639 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
6641 #endif /* HAVE_IPV6 */
6643 void
6644 bgp_show_prefix_longer_clean (struct vty *vty)
6646 struct prefix *p;
6648 p = vty->output_arg;
6649 prefix_free (p);
6653 bgp_show_prefix_longer (struct vty *vty, char *prefix,
6654 u_int16_t afi, u_char safi)
6656 int ret;
6657 struct prefix *p;
6659 p = prefix_new();
6661 ret = str2prefix (prefix, p);
6662 if (! ret)
6664 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
6665 return CMD_WARNING;
6668 vty->output_arg = p;
6669 vty->output_clean = bgp_show_prefix_longer_clean;
6671 return bgp_show (vty, NULL, afi, safi, bgp_show_type_prefix_longer);
6674 DEFUN (show_ip_bgp_prefix_longer,
6675 show_ip_bgp_prefix_longer_cmd,
6676 "show ip bgp A.B.C.D/M longer-prefixes",
6677 SHOW_STR
6678 IP_STR
6679 BGP_STR
6680 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6681 "Display route and more specific routes\n")
6683 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST);
6686 DEFUN (show_ip_bgp_ipv4_prefix_longer,
6687 show_ip_bgp_ipv4_prefix_longer_cmd,
6688 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
6689 SHOW_STR
6690 IP_STR
6691 BGP_STR
6692 "Address family\n"
6693 "Address Family modifier\n"
6694 "Address Family modifier\n"
6695 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6696 "Display route and more specific routes\n")
6698 if (strncmp (argv[0], "m", 1) == 0)
6699 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST);
6701 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST);
6704 #ifdef HAVE_IPV6
6705 DEFUN (show_bgp_prefix_longer,
6706 show_bgp_prefix_longer_cmd,
6707 "show bgp X:X::X:X/M longer-prefixes",
6708 SHOW_STR
6709 BGP_STR
6710 "IPv6 prefix <network>/<length>\n"
6711 "Display route and more specific routes\n")
6713 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6716 ALIAS (show_bgp_prefix_longer,
6717 show_bgp_ipv6_prefix_longer_cmd,
6718 "show bgp ipv6 X:X::X:X/M longer-prefixes",
6719 SHOW_STR
6720 BGP_STR
6721 "Address family\n"
6722 "IPv6 prefix <network>/<length>\n"
6723 "Display route and more specific routes\n")
6725 /* old command */
6726 DEFUN (show_ipv6_bgp_prefix_longer,
6727 show_ipv6_bgp_prefix_longer_cmd,
6728 "show ipv6 bgp X:X::X:X/M longer-prefixes",
6729 SHOW_STR
6730 IPV6_STR
6731 BGP_STR
6732 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
6733 "Display route and more specific routes\n")
6735 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST);
6738 /* old command */
6739 DEFUN (show_ipv6_mbgp_prefix_longer,
6740 show_ipv6_mbgp_prefix_longer_cmd,
6741 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
6742 SHOW_STR
6743 IPV6_STR
6744 MBGP_STR
6745 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
6746 "Display route and more specific routes\n")
6748 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST);
6750 #endif /* HAVE_IPV6 */
6752 void
6753 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
6754 int in)
6756 struct route_table *table;
6757 struct route_node *rn;
6758 struct prefix *p;
6759 struct attr *attr;
6760 struct bgp *bgp;
6761 unsigned long output_count;
6762 int header = 1;
6764 if (in)
6765 table = peer->adj_in[afi][safi];
6766 else
6767 table = peer->adj_out[afi][safi];
6769 bgp = bgp_get_default ();
6770 output_count = 0;
6772 for (rn = route_top (table); rn; rn = route_next (rn))
6773 if ((attr = rn->info) != NULL)
6775 p = &rn->p;
6777 if (header)
6779 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->id), VTY_NEWLINE);
6780 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
6781 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
6783 if (afi == AFI_IP)
6784 vty_out (vty, BGP_SHOW_V4_HEADER, VTY_NEWLINE);
6785 else if (afi == AFI_IP6)
6786 vty_out (vty, BGP_SHOW_V6_HEADER, VTY_NEWLINE);
6787 header = 0;
6790 if (p->family == AF_INET)
6792 route_vty_out_tmp (vty, p, attr, safi);
6793 output_count++;
6795 #ifdef HAVE_IPV6
6796 else if (p->family == AF_INET6)
6798 route_vty_out_ipv6_tmp (vty, p, attr);
6799 output_count++;
6801 #endif /* HAVE_IPV6 */
6803 if (output_count != 0)
6804 vty_out (vty, "%sTotal number of prefixes %ld%s",
6805 VTY_NEWLINE, output_count, VTY_NEWLINE);
6809 peer_adj_routes (struct vty *vty, char *ip_str, afi_t afi, safi_t safi, int in)
6811 int ret;
6812 struct peer *peer;
6813 union sockunion su;
6815 ret = str2sockunion (ip_str, &su);
6816 if (ret < 0)
6818 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
6819 return CMD_WARNING;
6821 peer = peer_lookup_by_su (&su);
6822 if (! peer || ! peer->afc[afi][safi])
6824 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
6825 return CMD_WARNING;
6828 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
6830 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
6831 VTY_NEWLINE);
6832 return CMD_WARNING;
6834 show_adj_route (vty, peer, afi, safi, in);
6836 return CMD_SUCCESS;
6839 DEFUN (show_ip_bgp_neighbor_advertised_route,
6840 show_ip_bgp_neighbor_advertised_route_cmd,
6841 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
6842 SHOW_STR
6843 IP_STR
6844 BGP_STR
6845 "Detailed information on TCP and BGP neighbor connections\n"
6846 "Neighbor to display information about\n"
6847 "Neighbor to display information about\n"
6848 "Display the routes advertised to a BGP neighbor\n")
6850 return peer_adj_routes (vty, argv[0], AFI_IP, SAFI_UNICAST, 0);
6853 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
6854 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
6855 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
6856 SHOW_STR
6857 IP_STR
6858 BGP_STR
6859 "Address family\n"
6860 "Address Family modifier\n"
6861 "Address Family modifier\n"
6862 "Detailed information on TCP and BGP neighbor connections\n"
6863 "Neighbor to display information about\n"
6864 "Neighbor to display information about\n"
6865 "Display the routes advertised to a BGP neighbor\n")
6867 if (strncmp (argv[0], "m", 1) == 0)
6868 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_MULTICAST, 0);
6870 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_UNICAST, 0);
6873 #ifdef HAVE_IPV6
6874 DEFUN (show_bgp_neighbor_advertised_route,
6875 show_bgp_neighbor_advertised_route_cmd,
6876 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
6877 SHOW_STR
6878 BGP_STR
6879 "Detailed information on TCP and BGP neighbor connections\n"
6880 "Neighbor to display information about\n"
6881 "Neighbor to display information about\n"
6882 "Display the routes advertised to a BGP neighbor\n")
6884 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0);
6887 ALIAS (show_bgp_neighbor_advertised_route,
6888 show_bgp_ipv6_neighbor_advertised_route_cmd,
6889 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
6890 SHOW_STR
6891 BGP_STR
6892 "Address family\n"
6893 "Detailed information on TCP and BGP neighbor connections\n"
6894 "Neighbor to display information about\n"
6895 "Neighbor to display information about\n"
6896 "Display the routes advertised to a BGP neighbor\n")
6898 /* old command */
6899 DEFUN (ipv6_bgp_neighbor_advertised_route,
6900 ipv6_bgp_neighbor_advertised_route_cmd,
6901 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
6902 SHOW_STR
6903 IPV6_STR
6904 BGP_STR
6905 "Detailed information on TCP and BGP neighbor connections\n"
6906 "Neighbor to display information about\n"
6907 "Neighbor to display information about\n"
6908 "Display the routes advertised to a BGP neighbor\n")
6910 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0);
6913 /* old command */
6914 DEFUN (ipv6_mbgp_neighbor_advertised_route,
6915 ipv6_mbgp_neighbor_advertised_route_cmd,
6916 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
6917 SHOW_STR
6918 IPV6_STR
6919 MBGP_STR
6920 "Detailed information on TCP and BGP neighbor connections\n"
6921 "Neighbor to display information about\n"
6922 "Neighbor to display information about\n"
6923 "Display the routes advertised to a BGP neighbor\n")
6925 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_MULTICAST, 0);
6927 #endif /* HAVE_IPV6 */
6929 DEFUN (show_ip_bgp_neighbor_received_routes,
6930 show_ip_bgp_neighbor_received_routes_cmd,
6931 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
6932 SHOW_STR
6933 IP_STR
6934 BGP_STR
6935 "Detailed information on TCP and BGP neighbor connections\n"
6936 "Neighbor to display information about\n"
6937 "Neighbor to display information about\n"
6938 "Display the received routes from neighbor\n")
6940 return peer_adj_routes (vty, argv[0], AFI_IP, SAFI_UNICAST, 1);
6943 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
6944 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
6945 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
6946 SHOW_STR
6947 IP_STR
6948 BGP_STR
6949 "Address family\n"
6950 "Address Family modifier\n"
6951 "Address Family modifier\n"
6952 "Detailed information on TCP and BGP neighbor connections\n"
6953 "Neighbor to display information about\n"
6954 "Neighbor to display information about\n"
6955 "Display the received routes from neighbor\n")
6957 if (strncmp (argv[0], "m", 1) == 0)
6958 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_MULTICAST, 1);
6960 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_UNICAST, 1);
6963 #ifdef HAVE_IPV6
6964 DEFUN (show_bgp_neighbor_received_routes,
6965 show_bgp_neighbor_received_routes_cmd,
6966 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
6967 SHOW_STR
6968 BGP_STR
6969 "Detailed information on TCP and BGP neighbor connections\n"
6970 "Neighbor to display information about\n"
6971 "Neighbor to display information about\n"
6972 "Display the received routes from neighbor\n")
6974 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 1);
6977 ALIAS (show_bgp_neighbor_received_routes,
6978 show_bgp_ipv6_neighbor_received_routes_cmd,
6979 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
6980 SHOW_STR
6981 BGP_STR
6982 "Address family\n"
6983 "Detailed information on TCP and BGP neighbor connections\n"
6984 "Neighbor to display information about\n"
6985 "Neighbor to display information about\n"
6986 "Display the received routes from neighbor\n")
6988 /* old command */
6989 DEFUN (ipv6_bgp_neighbor_received_routes,
6990 ipv6_bgp_neighbor_received_routes_cmd,
6991 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
6992 SHOW_STR
6993 IPV6_STR
6994 BGP_STR
6995 "Detailed information on TCP and BGP neighbor connections\n"
6996 "Neighbor to display information about\n"
6997 "Neighbor to display information about\n"
6998 "Display the received routes from neighbor\n")
7000 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 1);
7003 /* old command */
7004 DEFUN (ipv6_mbgp_neighbor_received_routes,
7005 ipv6_mbgp_neighbor_received_routes_cmd,
7006 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7007 SHOW_STR
7008 IPV6_STR
7009 MBGP_STR
7010 "Detailed information on TCP and BGP neighbor connections\n"
7011 "Neighbor to display information about\n"
7012 "Neighbor to display information about\n"
7013 "Display the received routes from neighbor\n")
7015 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_MULTICAST, 1);
7017 #endif /* HAVE_IPV6 */
7019 void
7020 bgp_show_neighbor_route_clean (struct vty *vty)
7022 union sockunion *su;
7024 su = vty->output_arg;
7025 XFREE (MTYPE_SOCKUNION, su);
7029 bgp_show_neighbor_route (struct vty *vty, char *ip_str, u_int16_t afi,
7030 u_char safi)
7032 union sockunion *su;
7033 struct peer *peer;
7035 su = sockunion_str2su (ip_str);
7036 if (su == NULL)
7038 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
7039 return CMD_WARNING;
7042 peer = peer_lookup_by_su (su);
7043 if (! peer || ! peer->afc[afi][safi])
7045 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
7046 XFREE (MTYPE_SOCKUNION, su);
7047 return CMD_WARNING;
7050 vty->output_arg = su;
7051 vty->output_clean = bgp_show_neighbor_route_clean;
7053 return bgp_show (vty, NULL, afi, safi, bgp_show_type_neighbor);
7056 DEFUN (show_ip_bgp_neighbor_routes,
7057 show_ip_bgp_neighbor_routes_cmd,
7058 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
7059 SHOW_STR
7060 IP_STR
7061 BGP_STR
7062 "Detailed information on TCP and BGP neighbor connections\n"
7063 "Neighbor to display information about\n"
7064 "Neighbor to display information about\n"
7065 "Display routes learned from neighbor\n")
7067 return bgp_show_neighbor_route (vty, argv[0], AFI_IP, SAFI_UNICAST);
7070 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
7071 show_ip_bgp_ipv4_neighbor_routes_cmd,
7072 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
7073 SHOW_STR
7074 IP_STR
7075 BGP_STR
7076 "Address family\n"
7077 "Address Family modifier\n"
7078 "Address Family modifier\n"
7079 "Detailed information on TCP and BGP neighbor connections\n"
7080 "Neighbor to display information about\n"
7081 "Neighbor to display information about\n"
7082 "Display routes learned from neighbor\n")
7084 if (strncmp (argv[0], "m", 1) == 0)
7085 return bgp_show_neighbor_route (vty, argv[1], AFI_IP, SAFI_MULTICAST);
7087 return bgp_show_neighbor_route (vty, argv[1], AFI_IP, SAFI_UNICAST);
7089 #ifdef HAVE_IPV6
7090 DEFUN (show_bgp_neighbor_routes,
7091 show_bgp_neighbor_routes_cmd,
7092 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
7093 SHOW_STR
7094 BGP_STR
7095 "Detailed information on TCP and BGP neighbor connections\n"
7096 "Neighbor to display information about\n"
7097 "Neighbor to display information about\n"
7098 "Display routes learned from neighbor\n")
7100 return bgp_show_neighbor_route (vty, argv[0], AFI_IP6, SAFI_UNICAST);
7103 ALIAS (show_bgp_neighbor_routes,
7104 show_bgp_ipv6_neighbor_routes_cmd,
7105 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
7106 SHOW_STR
7107 BGP_STR
7108 "Address family\n"
7109 "Detailed information on TCP and BGP neighbor connections\n"
7110 "Neighbor to display information about\n"
7111 "Neighbor to display information about\n"
7112 "Display routes learned from neighbor\n")
7114 /* old command */
7115 DEFUN (ipv6_bgp_neighbor_routes,
7116 ipv6_bgp_neighbor_routes_cmd,
7117 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
7118 SHOW_STR
7119 IPV6_STR
7120 BGP_STR
7121 "Detailed information on TCP and BGP neighbor connections\n"
7122 "Neighbor to display information about\n"
7123 "Neighbor to display information about\n"
7124 "Display routes learned from neighbor\n")
7126 return bgp_show_neighbor_route (vty, argv[0], AFI_IP6, SAFI_UNICAST);
7129 /* old command */
7130 DEFUN (ipv6_mbgp_neighbor_routes,
7131 ipv6_mbgp_neighbor_routes_cmd,
7132 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
7133 SHOW_STR
7134 IPV6_STR
7135 MBGP_STR
7136 "Detailed information on TCP and BGP neighbor connections\n"
7137 "Neighbor to display information about\n"
7138 "Neighbor to display information about\n"
7139 "Display routes learned from neighbor\n")
7141 return bgp_show_neighbor_route (vty, argv[0], AFI_IP6, SAFI_MULTICAST);
7143 #endif /* HAVE_IPV6 */
7145 struct route_table *bgp_distance_table;
7147 struct bgp_distance
7149 /* Distance value for the IP source prefix. */
7150 u_char distance;
7152 /* Name of the access-list to be matched. */
7153 char *access_list;
7156 struct bgp_distance *
7157 bgp_distance_new ()
7159 struct bgp_distance *new;
7160 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
7161 memset (new, 0, sizeof (struct bgp_distance));
7162 return new;
7165 void
7166 bgp_distance_free (struct bgp_distance *bdistance)
7168 XFREE (MTYPE_BGP_DISTANCE, bdistance);
7172 bgp_distance_set (struct vty *vty, char *distance_str, char *ip_str,
7173 char *access_list_str)
7175 int ret;
7176 struct prefix_ipv4 p;
7177 u_char distance;
7178 struct route_node *rn;
7179 struct bgp_distance *bdistance;
7181 ret = str2prefix_ipv4 (ip_str, &p);
7182 if (ret == 0)
7184 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
7185 return CMD_WARNING;
7188 distance = atoi (distance_str);
7190 /* Get BGP distance node. */
7191 rn = route_node_get (bgp_distance_table, (struct prefix *) &p);
7192 if (rn->info)
7194 bdistance = rn->info;
7195 route_unlock_node (rn);
7197 else
7199 bdistance = bgp_distance_new ();
7200 rn->info = bdistance;
7203 /* Set distance value. */
7204 bdistance->distance = distance;
7206 /* Reset access-list configuration. */
7207 if (bdistance->access_list)
7209 free (bdistance->access_list);
7210 bdistance->access_list = NULL;
7212 if (access_list_str)
7213 bdistance->access_list = strdup (access_list_str);
7215 return CMD_SUCCESS;
7219 bgp_distance_unset (struct vty *vty, char *distance_str, char *ip_str,
7220 char *access_list_str)
7222 int ret;
7223 struct prefix_ipv4 p;
7224 u_char distance;
7225 struct route_node *rn;
7226 struct bgp_distance *bdistance;
7228 ret = str2prefix_ipv4 (ip_str, &p);
7229 if (ret == 0)
7231 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
7232 return CMD_WARNING;
7235 distance = atoi (distance_str);
7237 rn = route_node_lookup (bgp_distance_table, (struct prefix *)&p);
7238 if (! rn)
7240 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
7241 return CMD_WARNING;
7244 bdistance = rn->info;
7246 if (bdistance->access_list)
7247 free (bdistance->access_list);
7248 bgp_distance_free (bdistance);
7250 rn->info = NULL;
7251 route_unlock_node (rn);
7252 route_unlock_node (rn);
7254 return CMD_SUCCESS;
7257 void
7258 bgp_distance_reset ()
7260 struct route_node *rn;
7261 struct bgp_distance *bdistance;
7263 for (rn = route_top (bgp_distance_table); rn; rn = route_next (rn))
7264 if ((bdistance = rn->info) != NULL)
7266 if (bdistance->access_list)
7267 free (bdistance->access_list);
7268 bgp_distance_free (bdistance);
7269 rn->info = NULL;
7270 route_unlock_node (rn);
7274 /* Apply BGP information to distance method. */
7275 u_char
7276 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
7278 struct route_node *rn;
7279 struct prefix_ipv4 q;
7280 struct peer *peer;
7281 struct bgp_distance *bdistance;
7282 struct access_list *alist;
7283 struct bgp_static *bgp_static;
7285 if (! bgp)
7286 return 0;
7288 if (p->family != AF_INET)
7289 return 0;
7291 peer = rinfo->peer;
7293 if (peer->su.sa.sa_family != AF_INET)
7294 return 0;
7296 memset (&q, 0, sizeof (struct prefix_ipv4));
7297 q.family = AF_INET;
7298 q.prefix = peer->su.sin.sin_addr;
7299 q.prefixlen = IPV4_MAX_BITLEN;
7301 /* Check source address. */
7302 rn = route_node_match (bgp_distance_table, (struct prefix *) &q);
7303 if (rn)
7305 bdistance = rn->info;
7306 route_unlock_node (rn);
7308 if (bdistance->access_list)
7310 alist = access_list_lookup (AFI_IP, bdistance->access_list);
7311 if (alist == NULL)
7312 return 0;
7313 if (access_list_apply (alist, p) == FILTER_DENY)
7314 return 0;
7316 return bdistance->distance;
7318 else
7319 return bdistance->distance;
7322 if (peer_sort (peer) == BGP_PEER_EBGP)
7324 /* Backdoor check. */
7325 rn = route_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
7326 if (rn)
7328 bgp_static = rn->info;
7329 route_unlock_node (rn);
7331 if (bgp_static->backdoor)
7333 if (bgp->distance_local)
7334 return bgp->distance_local;
7335 else
7336 return ZEBRA_IBGP_DISTANCE_DEFAULT;
7340 if (bgp->distance_ebgp)
7341 return bgp->distance_ebgp;
7343 else
7345 if (bgp->distance_ibgp)
7346 return bgp->distance_ibgp;
7349 return 0;
7352 DEFUN (bgp_distance,
7353 bgp_distance_cmd,
7354 "distance bgp <1-255> <1-255> <1-255>",
7355 "Define an administrative distance\n"
7356 "BGP distance\n"
7357 "Distance for routes external to the AS\n"
7358 "Distance for routes internal to the AS\n"
7359 "Distance for local routes\n")
7361 struct bgp *bgp;
7363 bgp = vty->index;
7365 bgp->distance_ebgp = atoi (argv[0]);
7366 bgp->distance_ibgp = atoi (argv[1]);
7367 bgp->distance_local = atoi (argv[2]);
7368 return CMD_SUCCESS;
7371 DEFUN (no_bgp_distance,
7372 no_bgp_distance_cmd,
7373 "no distance bgp <1-255> <1-255> <1-255>",
7374 NO_STR
7375 "Define an administrative distance\n"
7376 "BGP distance\n"
7377 "Distance for routes external to the AS\n"
7378 "Distance for routes internal to the AS\n"
7379 "Distance for local routes\n")
7381 struct bgp *bgp;
7383 bgp = vty->index;
7385 bgp->distance_ebgp= 0;
7386 bgp->distance_ibgp = 0;
7387 bgp->distance_local = 0;
7388 return CMD_SUCCESS;
7391 ALIAS (no_bgp_distance,
7392 no_bgp_distance2_cmd,
7393 "no distance bgp",
7394 NO_STR
7395 "Define an administrative distance\n"
7396 "BGP distance\n")
7398 DEFUN (bgp_distance_source,
7399 bgp_distance_source_cmd,
7400 "distance <1-255> A.B.C.D/M",
7401 "Define an administrative distance\n"
7402 "Administrative distance\n"
7403 "IP source prefix\n")
7405 bgp_distance_set (vty, argv[0], argv[1], NULL);
7406 return CMD_SUCCESS;
7409 DEFUN (no_bgp_distance_source,
7410 no_bgp_distance_source_cmd,
7411 "no distance <1-255> A.B.C.D/M",
7412 NO_STR
7413 "Define an administrative distance\n"
7414 "Administrative distance\n"
7415 "IP source prefix\n")
7417 bgp_distance_unset (vty, argv[0], argv[1], NULL);
7418 return CMD_SUCCESS;
7421 DEFUN (bgp_distance_source_access_list,
7422 bgp_distance_source_access_list_cmd,
7423 "distance <1-255> A.B.C.D/M WORD",
7424 "Define an administrative distance\n"
7425 "Administrative distance\n"
7426 "IP source prefix\n"
7427 "Access list name\n")
7429 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
7430 return CMD_SUCCESS;
7433 DEFUN (no_bgp_distance_source_access_list,
7434 no_bgp_distance_source_access_list_cmd,
7435 "no distance <1-255> A.B.C.D/M WORD",
7436 NO_STR
7437 "Define an administrative distance\n"
7438 "Administrative distance\n"
7439 "IP source prefix\n"
7440 "Access list name\n")
7442 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
7443 return CMD_SUCCESS;
7446 DEFUN (bgp_damp_set,
7447 bgp_damp_set_cmd,
7448 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
7449 "BGP Specific commands\n"
7450 "Enable route-flap dampening\n"
7451 "Half-life time for the penalty\n"
7452 "Value to start reusing a route\n"
7453 "Value to start suppressing a route\n"
7454 "Maximum duration to suppress a stable route\n")
7456 struct bgp *bgp;
7458 bgp = vty->index;
7459 if (bgp_damp_enable (vty, argc, argv) == CMD_SUCCESS)
7461 SET_FLAG (bgp->config, BGP_CONFIG_DAMPENING);
7462 return CMD_SUCCESS;
7465 return CMD_WARNING;
7468 ALIAS (bgp_damp_set,
7469 bgp_damp_set2_cmd,
7470 "bgp dampening <1-45>",
7471 "BGP Specific commands\n"
7472 "Enable route-flap dampening\n"
7473 "Half-life time for the penalty\n")
7475 ALIAS (bgp_damp_set,
7476 bgp_damp_set3_cmd,
7477 "bgp dampening",
7478 "BGP Specific commands\n"
7479 "Enable route-flap dampening\n")
7481 DEFUN (bgp_damp_unset,
7482 bgp_damp_unset_cmd,
7483 "no bgp dampening",
7484 NO_STR
7485 "BGP Specific commands\n"
7486 "Enable route-flap dampening\n")
7488 struct bgp *bgp;
7490 bgp = vty->index;
7491 if (bgp_damp_disable (vty) == CMD_SUCCESS)
7493 UNSET_FLAG (bgp->config, BGP_CONFIG_DAMPENING);
7494 return CMD_SUCCESS;
7497 return CMD_WARNING;
7500 ALIAS (bgp_damp_unset,
7501 bgp_damp_unset2_cmd,
7502 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
7503 NO_STR
7504 "BGP Specific commands\n"
7505 "Enable route-flap dampening\n"
7506 "Half-life time for the penalty\n"
7507 "Value to start reusing a route\n"
7508 "Value to start suppressing a route\n"
7509 "Maximum duration to suppress a stable route\n")
7512 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
7513 afi_t afi, safi_t safi, int *write)
7515 struct route_node *prn;
7516 struct route_node *rn;
7517 struct route_table *table;
7518 struct prefix *p;
7519 struct prefix_rd *prd;
7520 struct bgp_static *bgp_static;
7521 u_int32_t label;
7522 char buf[SU_ADDRSTRLEN];
7523 char rdbuf[RD_ADDRSTRLEN];
7525 /* Network configuration. */
7526 for (prn = route_top (bgp->route[afi][safi]); prn; prn = route_next (prn))
7527 if ((table = prn->info) != NULL)
7528 for (rn = route_top (table); rn; rn = route_next (rn))
7529 if ((bgp_static = rn->info) != NULL)
7531 p = &rn->p;
7532 prd = (struct prefix_rd *) &prn->p;
7534 /* "address-family" display. */
7535 bgp_config_write_family_header (vty, afi, safi, write);
7537 /* "network" configuration display. */
7538 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
7539 label = decode_label (bgp_static->tag);
7541 vty_out (vty, " network %s/%d rd %s tag %d",
7542 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
7543 p->prefixlen,
7544 rdbuf, label);
7545 vty_out (vty, "%s", VTY_NEWLINE);
7547 return 0;
7550 /* Configuration of static route announcement and aggregate
7551 information. */
7553 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
7554 afi_t afi, safi_t safi, int *write)
7556 struct route_node *rn;
7557 struct prefix *p;
7558 struct bgp_static *bgp_static;
7559 struct bgp_aggregate *bgp_aggregate;
7560 char buf[SU_ADDRSTRLEN];
7562 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7563 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
7565 /* Network configuration. */
7566 for (rn = route_top (bgp->route[afi][safi]); rn; rn = route_next (rn))
7567 if ((bgp_static = rn->info) != NULL)
7569 p = &rn->p;
7571 /* "address-family" display. */
7572 bgp_config_write_family_header (vty, afi, safi, write);
7574 /* "network" configuration display. */
7575 vty_out (vty, " network %s/%d",
7576 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
7577 p->prefixlen);
7579 if (bgp_static->backdoor)
7580 vty_out (vty, " backdoor");
7582 vty_out (vty, "%s", VTY_NEWLINE);
7585 /* Aggregate-address configuration. */
7586 for (rn = route_top (bgp->aggregate[afi][safi]); rn; rn = route_next (rn))
7587 if ((bgp_aggregate = rn->info) != NULL)
7589 p = &rn->p;
7591 /* "address-family" display. */
7592 bgp_config_write_family_header (vty, afi, safi, write);
7594 vty_out (vty, " aggregate-address %s/%d",
7595 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
7596 p->prefixlen);
7598 if (bgp_aggregate->as_set)
7599 vty_out (vty, " as-set");
7601 if (bgp_aggregate->summary_only)
7602 vty_out (vty, " summary-only");
7604 vty_out (vty, "%s", VTY_NEWLINE);
7607 return 0;
7611 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
7613 struct route_node *rn;
7614 struct bgp_distance *bdistance;
7616 /* Distance configuration. */
7617 if (bgp->distance_ebgp
7618 && bgp->distance_ibgp
7619 && bgp->distance_local
7620 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
7621 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
7622 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
7623 vty_out (vty, " distance bgp %d %d %d%s",
7624 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
7625 VTY_NEWLINE);
7627 for (rn = route_top (bgp_distance_table); rn; rn = route_next (rn))
7628 if ((bdistance = rn->info) != NULL)
7630 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
7631 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
7632 bdistance->access_list ? bdistance->access_list : "",
7633 VTY_NEWLINE);
7636 return 0;
7639 /* Allocate routing table structure and install commands. */
7640 void
7641 bgp_route_init ()
7643 /* Make static announcement peer. */
7644 peer_self = peer_new ();
7645 peer_self->host = "Static announcement";
7647 /* Init BGP distance table. */
7648 bgp_distance_table = route_table_init ();
7650 /* IPv4 BGP commands. */
7651 install_element (BGP_NODE, &bgp_network_cmd);
7652 install_element (BGP_NODE, &bgp_network_mask_cmd);
7653 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
7654 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
7655 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
7656 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
7657 install_element (BGP_NODE, &no_bgp_network_cmd);
7658 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
7659 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
7660 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
7661 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
7662 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
7664 install_element (BGP_NODE, &aggregate_address_cmd);
7665 install_element (BGP_NODE, &aggregate_address_mask_cmd);
7666 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
7667 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
7668 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
7669 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
7670 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
7671 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
7672 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
7673 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
7674 install_element (BGP_NODE, &no_aggregate_address_cmd);
7675 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
7676 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
7677 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
7678 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
7679 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
7680 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
7681 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
7682 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
7683 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
7685 /* IPv4 multicast configuration. */
7686 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
7687 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
7688 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
7689 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
7690 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
7691 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
7692 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
7693 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
7694 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
7695 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
7696 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
7697 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
7698 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
7699 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
7700 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
7701 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
7702 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
7703 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
7704 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
7705 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
7706 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
7707 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
7708 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
7709 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
7710 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
7711 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
7713 install_element (VIEW_NODE, &show_ip_bgp_cmd);
7714 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
7715 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
7716 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
7717 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
7718 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
7719 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
7720 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
7721 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
7722 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
7723 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
7724 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
7725 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
7726 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
7727 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
7728 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
7729 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
7730 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
7731 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
7732 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
7733 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
7734 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
7735 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
7736 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
7737 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
7738 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
7739 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
7740 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
7741 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
7742 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
7743 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
7744 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
7745 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
7746 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
7747 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
7748 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
7749 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
7750 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
7751 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
7752 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
7753 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
7754 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
7755 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
7756 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
7757 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
7758 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
7759 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
7761 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
7762 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
7763 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
7764 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
7765 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
7766 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
7767 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
7768 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
7769 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
7770 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
7771 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
7772 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
7773 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
7774 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
7775 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
7776 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
7777 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
7778 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
7779 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
7780 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
7781 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
7782 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
7783 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
7784 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
7785 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
7786 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
7787 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
7788 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
7789 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
7790 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
7791 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
7792 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
7793 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
7794 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
7795 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
7796 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
7797 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
7798 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
7799 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
7800 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
7801 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
7802 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
7803 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
7804 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
7805 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
7806 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
7807 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
7809 #ifdef HAVE_IPV6
7810 /* New config IPv6 BGP commands. */
7811 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
7812 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
7814 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
7815 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
7816 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
7817 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
7819 /* Old config IPv6 BGP commands. */
7820 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
7821 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
7823 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
7824 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
7825 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
7826 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
7828 install_element (VIEW_NODE, &show_bgp_cmd);
7829 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
7830 install_element (VIEW_NODE, &show_bgp_route_cmd);
7831 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
7832 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
7833 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
7834 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
7835 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
7836 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
7837 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
7838 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
7839 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
7840 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
7841 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
7842 install_element (VIEW_NODE, &show_bgp_community_cmd);
7843 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
7844 install_element (VIEW_NODE, &show_bgp_community2_cmd);
7845 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
7846 install_element (VIEW_NODE, &show_bgp_community3_cmd);
7847 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
7848 install_element (VIEW_NODE, &show_bgp_community4_cmd);
7849 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
7850 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
7851 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
7852 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
7853 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
7854 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
7855 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
7856 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
7857 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
7858 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
7859 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
7860 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
7861 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
7862 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
7863 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
7864 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
7865 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
7866 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
7867 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
7868 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
7869 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
7871 install_element (ENABLE_NODE, &show_bgp_cmd);
7872 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
7873 install_element (ENABLE_NODE, &show_bgp_route_cmd);
7874 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
7875 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
7876 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
7877 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
7878 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
7879 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
7880 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
7881 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
7882 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
7883 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
7884 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
7885 install_element (ENABLE_NODE, &show_bgp_community_cmd);
7886 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
7887 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
7888 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
7889 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
7890 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
7891 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
7892 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
7893 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
7894 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
7895 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
7896 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
7897 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
7898 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
7899 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
7900 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
7901 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
7902 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
7903 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
7904 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
7905 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
7906 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
7907 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
7908 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
7909 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
7910 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
7911 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
7912 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
7914 /* old command */
7915 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
7916 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
7917 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
7918 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
7919 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
7920 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
7921 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
7922 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
7923 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
7924 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
7925 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
7926 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
7927 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
7928 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
7929 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
7930 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
7931 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
7932 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
7933 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
7934 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
7935 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
7936 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
7937 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
7938 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
7939 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
7940 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
7941 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
7942 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
7943 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
7944 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
7945 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
7946 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
7947 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
7948 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
7949 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
7950 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
7952 /* old command */
7953 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
7954 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
7955 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
7956 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
7957 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
7958 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
7959 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
7960 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
7961 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
7962 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
7963 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
7964 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
7965 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
7966 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
7967 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
7968 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
7969 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
7970 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
7971 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
7972 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
7973 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
7974 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
7975 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
7976 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
7977 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
7978 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
7979 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
7980 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
7981 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
7982 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
7983 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
7984 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
7985 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
7986 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
7987 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
7988 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
7990 /* old command */
7991 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
7992 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
7993 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
7994 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
7996 /* old command */
7997 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
7998 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
7999 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
8000 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
8002 /* old command */
8003 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
8004 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
8005 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
8006 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
8007 #endif /* HAVE_IPV6 */
8009 install_element (BGP_NODE, &bgp_distance_cmd);
8010 install_element (BGP_NODE, &no_bgp_distance_cmd);
8011 install_element (BGP_NODE, &no_bgp_distance2_cmd);
8012 install_element (BGP_NODE, &bgp_distance_source_cmd);
8013 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
8014 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
8015 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
8017 install_element (BGP_NODE, &bgp_damp_set_cmd);
8018 install_element (BGP_NODE, &bgp_damp_set2_cmd);
8019 install_element (BGP_NODE, &bgp_damp_set3_cmd);
8020 install_element (BGP_NODE, &bgp_damp_unset_cmd);
8021 install_element (BGP_NODE, &bgp_damp_unset2_cmd);