blob: 87d305cb7ca010924a1ef900b0dd8ae3473303e5 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
36
37#include "bgpd/bgpd.h"
38#include "bgpd/bgp_table.h"
39#include "bgpd/bgp_route.h"
40#include "bgpd/bgp_attr.h"
41#include "bgpd/bgp_debug.h"
42#include "bgpd/bgp_aspath.h"
43#include "bgpd/bgp_regex.h"
44#include "bgpd/bgp_community.h"
45#include "bgpd/bgp_ecommunity.h"
46#include "bgpd/bgp_clist.h"
47#include "bgpd/bgp_packet.h"
48#include "bgpd/bgp_filter.h"
49#include "bgpd/bgp_fsm.h"
50#include "bgpd/bgp_mplsvpn.h"
51#include "bgpd/bgp_nexthop.h"
52#include "bgpd/bgp_damp.h"
53#include "bgpd/bgp_advertise.h"
54#include "bgpd/bgp_zebra.h"
55
56/* Extern from bgp_dump.c */
57extern char *bgp_origin_str[];
58extern char *bgp_origin_long_str[];
59
60struct bgp_node *
61bgp_afi_node_get (struct bgp *bgp, afi_t afi, safi_t safi, struct prefix *p,
62 struct prefix_rd *prd)
63{
64 struct bgp_node *rn;
65 struct bgp_node *prn = NULL;
66 struct bgp_table *table;
67
68 if (safi == SAFI_MPLS_VPN)
69 {
70 prn = bgp_node_get (bgp->rib[afi][safi], (struct prefix *) prd);
71
72 if (prn->info == NULL)
73 prn->info = bgp_table_init ();
74 else
75 bgp_unlock_node (prn);
76 table = prn->info;
77 }
78 else
79 table = bgp->rib[afi][safi];
80
81 rn = bgp_node_get (table, p);
82
83 if (safi == SAFI_MPLS_VPN)
84 rn->prn = prn;
85
86 return rn;
87}
88
89/* Allocate new bgp info structure. */
90struct bgp_info *
91bgp_info_new ()
92{
93 struct bgp_info *new;
94
95 new = XMALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
96 memset (new, 0, sizeof (struct bgp_info));
97
98 return new;
99}
100
101/* Free bgp route information. */
102void
103bgp_info_free (struct bgp_info *binfo)
104{
105 if (binfo->attr)
106 bgp_attr_unintern (binfo->attr);
107
108 if (binfo->damp_info)
109 bgp_damp_info_free (binfo->damp_info, 0);
110
111 XFREE (MTYPE_BGP_ROUTE, binfo);
112}
113
114void
115bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
116{
117 struct bgp_info *top;
118
119 top = rn->info;
120
121 ri->next = rn->info;
122 ri->prev = NULL;
123 if (top)
124 top->prev = ri;
125 rn->info = ri;
126}
127
128void
129bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
130{
131 if (ri->next)
132 ri->next->prev = ri->prev;
133 if (ri->prev)
134 ri->prev->next = ri->next;
135 else
136 rn->info = ri->next;
137}
138
139/* Get MED value. If MED value is missing and "bgp bestpath
140 missing-as-worst" is specified, treat it as the worst value. */
141u_int32_t
142bgp_med_value (struct attr *attr, struct bgp *bgp)
143{
144 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
145 return attr->med;
146 else
147 {
148 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
149 return 4294967295ul;
150 else
151 return 0;
152 }
153}
154
155/* Compare two bgp route entity. br is preferable then return 1. */
156int
157bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
158{
159 u_int32_t new_pref;
160 u_int32_t exist_pref;
161 u_int32_t new_med;
162 u_int32_t exist_med;
163 struct in_addr new_id;
164 struct in_addr exist_id;
165 int new_cluster;
166 int exist_cluster;
167 int internal_as_route = 0;
168 int confed_as_route = 0;
169 int ret;
170
171 /* 0. Null check. */
172 if (new == NULL)
173 return 0;
174 if (exist == NULL)
175 return 1;
176
177 /* 1. Weight check. */
178 if (new->attr->weight > exist->attr->weight)
179 return 1;
180 if (new->attr->weight < exist->attr->weight)
181 return 0;
182
183 /* 2. Local preference check. */
184 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
185 new_pref = new->attr->local_pref;
186 else
187 new_pref = bgp->default_local_pref;
188
189 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
190 exist_pref = exist->attr->local_pref;
191 else
192 exist_pref = bgp->default_local_pref;
193
194 if (new_pref > exist_pref)
195 return 1;
196 if (new_pref < exist_pref)
197 return 0;
198
199 /* 3. Local route check. */
200 if (new->sub_type == BGP_ROUTE_STATIC)
201 return 1;
202 if (exist->sub_type == BGP_ROUTE_STATIC)
203 return 0;
204
205 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
206 return 1;
207 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
208 return 0;
209
210 if (new->sub_type == BGP_ROUTE_AGGREGATE)
211 return 1;
212 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
213 return 0;
214
215 /* 4. AS path length check. */
216 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
217 {
218 if (new->attr->aspath->count < exist->attr->aspath->count)
219 return 1;
220 if (new->attr->aspath->count > exist->attr->aspath->count)
221 return 0;
222 }
223
224 /* 5. Origin check. */
225 if (new->attr->origin < exist->attr->origin)
226 return 1;
227 if (new->attr->origin > exist->attr->origin)
228 return 0;
229
230 /* 6. MED check. */
231 internal_as_route = (new->attr->aspath->length == 0
232 && exist->attr->aspath->length == 0);
233 confed_as_route = (new->attr->aspath->length > 0
234 && exist->attr->aspath->length > 0
235 && new->attr->aspath->count == 0
236 && exist->attr->aspath->count == 0);
237
238 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
239 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
240 && confed_as_route)
241 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
242 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
243 || internal_as_route)
244 {
245 new_med = bgp_med_value (new->attr, bgp);
246 exist_med = bgp_med_value (exist->attr, bgp);
247
248 if (new_med < exist_med)
249 return 1;
250 if (new_med > exist_med)
251 return 0;
252 }
253
254 /* 7. Peer type check. */
255 if (peer_sort (new->peer) == BGP_PEER_EBGP
256 && peer_sort (exist->peer) == BGP_PEER_IBGP)
257 return 1;
258 if (peer_sort (new->peer) == BGP_PEER_EBGP
259 && peer_sort (exist->peer) == BGP_PEER_CONFED)
260 return 1;
261 if (peer_sort (new->peer) == BGP_PEER_IBGP
262 && peer_sort (exist->peer) == BGP_PEER_EBGP)
263 return 0;
264 if (peer_sort (new->peer) == BGP_PEER_CONFED
265 && peer_sort (exist->peer) == BGP_PEER_EBGP)
266 return 0;
267
268 /* 8. IGP metric check. */
269 if (new->igpmetric < exist->igpmetric)
270 return 1;
271 if (new->igpmetric > exist->igpmetric)
272 return 0;
273
274 /* 9. Maximum path check. */
275
276 /* 10. If both paths are external, prefer the path that was received
277 first (the oldest one). This step minimizes route-flap, since a
278 newer path won't displace an older one, even if it was the
279 preferred route based on the additional decision criteria below. */
280 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
281 && peer_sort (new->peer) == BGP_PEER_EBGP
282 && peer_sort (exist->peer) == BGP_PEER_EBGP)
283 {
284 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
285 return 1;
286 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
287 return 0;
288 }
289
290 /* 11. Rourter-ID comparision. */
291 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
292 new_id.s_addr = new->attr->originator_id.s_addr;
293 else
294 new_id.s_addr = new->peer->remote_id.s_addr;
295 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
296 exist_id.s_addr = exist->attr->originator_id.s_addr;
297 else
298 exist_id.s_addr = exist->peer->remote_id.s_addr;
299
300 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
301 return 1;
302 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
303 return 0;
304
305 /* 12. Cluster length comparision. */
306 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
307 new_cluster = new->attr->cluster->length;
308 else
309 new_cluster = 0;
310 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
311 exist_cluster = exist->attr->cluster->length;
312 else
313 exist_cluster = 0;
314
315 if (new_cluster < exist_cluster)
316 return 1;
317 if (new_cluster > exist_cluster)
318 return 0;
319
320 /* 13. Neighbor address comparision. */
321 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
322
323 if (ret == 1)
324 return 0;
325 if (ret == -1)
326 return 1;
327
328 return 1;
329}
330
331enum filter_type
332bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
333 afi_t afi, safi_t safi)
334{
335 struct bgp_filter *filter;
336
337 filter = &peer->filter[afi][safi];
338
339 if (DISTRIBUTE_IN_NAME (filter))
340 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
341 return FILTER_DENY;
342
343 if (PREFIX_LIST_IN_NAME (filter))
344 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
345 return FILTER_DENY;
346
347 if (FILTER_LIST_IN_NAME (filter))
348 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
349 return FILTER_DENY;
350
351 return FILTER_PERMIT;
352}
353
354enum filter_type
355bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
356 afi_t afi, safi_t safi)
357{
358 struct bgp_filter *filter;
359
360 filter = &peer->filter[afi][safi];
361
362 if (DISTRIBUTE_OUT_NAME (filter))
363 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
364 return FILTER_DENY;
365
366 if (PREFIX_LIST_OUT_NAME (filter))
367 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
368 return FILTER_DENY;
369
370 if (FILTER_LIST_OUT_NAME (filter))
371 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
372 return FILTER_DENY;
373
374 return FILTER_PERMIT;
375}
376
377/* If community attribute includes no_export then return 1. */
378int
379bgp_community_filter (struct peer *peer, struct attr *attr)
380{
381 if (attr->community)
382 {
383 /* NO_ADVERTISE check. */
384 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
385 return 1;
386
387 /* NO_EXPORT check. */
388 if (peer_sort (peer) == BGP_PEER_EBGP &&
389 community_include (attr->community, COMMUNITY_NO_EXPORT))
390 return 1;
391
392 /* NO_EXPORT_SUBCONFED check. */
393 if (peer_sort (peer) == BGP_PEER_EBGP
394 || peer_sort (peer) == BGP_PEER_CONFED)
395 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
396 return 1;
397 }
398 return 0;
399}
400
401/* Route reflection loop check. */
402static int
403bgp_cluster_filter (struct peer *peer, struct attr *attr)
404{
405 struct in_addr cluster_id;
406
407 if (attr->cluster)
408 {
409 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
410 cluster_id = peer->bgp->cluster_id;
411 else
412 cluster_id = peer->bgp->router_id;
413
414 if (cluster_loop_check (attr->cluster, cluster_id))
415 return 1;
416 }
417 return 0;
418}
419
420int
421bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
422 afi_t afi, safi_t safi)
423{
424 struct bgp_filter *filter;
425 struct bgp_info info;
426 route_map_result_t ret;
427
428 filter = &peer->filter[afi][safi];
429
430 /* Apply default weight value. */
431 attr->weight = peer->weight;
432
433 /* Route map apply. */
434 if (ROUTE_MAP_IN_NAME (filter))
435 {
436 /* Duplicate current value to new strucutre for modification. */
437 info.peer = peer;
438 info.attr = attr;
439
440 /* Apply BGP route map to the attribute. */
441 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
442 if (ret == RMAP_DENYMATCH)
443 {
444 /* Free newly generated AS path and community by route-map. */
445 bgp_attr_flush (attr);
446 return RMAP_DENY;
447 }
448 }
449 return RMAP_PERMIT;
450}
451
452int
453bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
454 struct attr *attr, afi_t afi, safi_t safi)
455{
456 int ret;
457 char buf[SU_ADDRSTRLEN];
458 struct bgp_filter *filter;
459 struct bgp_info info;
460 struct peer *from;
461 struct bgp *bgp;
462 struct attr dummy_attr;
463 int transparent;
464 int reflect;
465
466 from = ri->peer;
467 filter = &peer->filter[afi][safi];
468 bgp = peer->bgp;
469
470#ifdef DISABLE_BGP_ANNOUNCE
471 return 0;
472#endif
473
474 /* Do not send back route to sender. */
475 if (from == peer)
476 return 0;
477
478 /* Aggregate-address suppress check. */
479 if (ri->suppress)
480 if (! UNSUPPRESS_MAP_NAME (filter))
481 return 0;
482
483 /* Default route check. */
484 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
485 {
486 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
487 return 0;
488#ifdef HAVE_IPV6
489 else if (p->family == AF_INET6 && p->prefixlen == 0)
490 return 0;
491#endif /* HAVE_IPV6 */
492 }
493
494 /* If community is not disabled check the no-export and local. */
495 if (bgp_community_filter (peer, ri->attr))
496 return 0;
497
498 /* If the attribute has originator-id and it is same as remote
499 peer's id. */
500 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
501 {
502 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
503 {
504 if (BGP_DEBUG (filter, FILTER))
505 zlog (peer->log, LOG_INFO,
506 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
507 peer->host,
508 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
509 p->prefixlen);
510 return 0;
511 }
512 }
513
514 /* ORF prefix-list filter check */
515 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
516 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
517 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
518 if (peer->orf_plist[afi][safi])
519 {
520 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
521 return 0;
522 }
523
524 /* Output filter check. */
525 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
526 {
527 if (BGP_DEBUG (filter, FILTER))
528 zlog (peer->log, LOG_INFO,
529 "%s [Update:SEND] %s/%d is filtered",
530 peer->host,
531 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
532 p->prefixlen);
533 return 0;
534 }
535
536#ifdef BGP_SEND_ASPATH_CHECK
537 /* AS path loop check. */
538 if (aspath_loop_check (ri->attr->aspath, peer->as))
539 {
540 if (BGP_DEBUG (filter, FILTER))
541 zlog (peer->log, LOG_INFO,
542 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
543 peer->host, peer->as);
544 return 0;
545 }
546#endif /* BGP_SEND_ASPATH_CHECK */
547
548 /* If we're a CONFED we need to loop check the CONFED ID too */
549 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
550 {
551 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
552 {
553 if (BGP_DEBUG (filter, FILTER))
554 zlog (peer->log, LOG_INFO,
555 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
556 peer->host,
557 bgp->confed_id);
558 return 0;
559 }
560 }
561
562 /* Route-Reflect check. */
563 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
564 reflect = 1;
565 else
566 reflect = 0;
567
568 /* IBGP reflection check. */
569 if (reflect)
570 {
571 /* A route from a Client peer. */
572 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
573 {
574 /* Reflect to all the Non-Client peers and also to the
575 Client peers other than the originator. Originator check
576 is already done. So there is noting to do. */
577 /* no bgp client-to-client reflection check. */
578 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
579 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
580 return 0;
581 }
582 else
583 {
584 /* A route from a Non-client peer. Reflect to all other
585 clients. */
586 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
587 return 0;
588 }
589 }
590
591 /* For modify attribute, copy it to temporary structure. */
592 *attr = *ri->attr;
593
594 /* If local-preference is not set. */
595 if ((peer_sort (peer) == BGP_PEER_IBGP
596 || peer_sort (peer) == BGP_PEER_CONFED)
597 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
598 {
599 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
600 attr->local_pref = bgp->default_local_pref;
601 }
602
603 /* Transparency check. */
604 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
605 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
606 transparent = 1;
607 else
608 transparent = 0;
609
610 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
611 if (peer_sort (peer) == BGP_PEER_EBGP
612 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
613 {
614 if (ri->peer != bgp->peer_self && ! transparent
615 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
616 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
617 }
618
619 /* next-hop-set */
620 if (transparent || reflect
621 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
622 && ((p->family == AF_INET && attr->nexthop.s_addr)
623 || (p->family == AF_INET6 && ri->peer != bgp->peer_self))))
624 {
625 /* NEXT-HOP Unchanged. */
626 }
627 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
628 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
629#ifdef HAVE_IPV6
630 || (p->family == AF_INET6 && ri->peer == bgp->peer_self)
631#endif /* HAVE_IPV6 */
632 || (peer_sort (peer) == BGP_PEER_EBGP
633 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
634 {
635 /* Set IPv4 nexthop. */
636 if (p->family == AF_INET)
637 {
638 if (safi == SAFI_MPLS_VPN)
639 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
640 else
641 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
642 }
643#ifdef HAVE_IPV6
644 /* Set IPv6 nexthop. */
645 if (p->family == AF_INET6)
646 {
647 /* IPv6 global nexthop must be included. */
648 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
649 IPV6_MAX_BYTELEN);
650 attr->mp_nexthop_len = 16;
651 }
652#endif /* HAVE_IPV6 */
653 }
654
655#ifdef HAVE_IPV6
656 if (p->family == AF_INET6)
657 {
658 /* Link-local address should not be transit to different peer. */
659 attr->mp_nexthop_len = 16;
660
661 /* Set link-local address for shared network peer. */
662 if (peer->shared_network
663 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
664 {
665 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
666 IPV6_MAX_BYTELEN);
667 attr->mp_nexthop_len = 32;
668 }
669
670 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
671 address.*/
672 if (reflect)
673 attr->mp_nexthop_len = 16;
674
675 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
676 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
677 attr->mp_nexthop_len = 16;
678 }
679#endif /* HAVE_IPV6 */
680
681 /* If this is EBGP peer and remove-private-AS is set. */
682 if (peer_sort (peer) == BGP_PEER_EBGP
683 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
684 && aspath_private_as_check (attr->aspath))
685 attr->aspath = aspath_empty_get ();
686
687 /* Route map & unsuppress-map apply. */
688 if (ROUTE_MAP_OUT_NAME (filter)
689 || ri->suppress)
690 {
691 info.peer = peer;
692 info.attr = attr;
693
694 /* The route reflector is not allowed to modify the attributes
695 of the reflected IBGP routes. */
696 if (peer_sort (from) == BGP_PEER_IBGP
697 && peer_sort (peer) == BGP_PEER_IBGP)
698 {
699 dummy_attr = *attr;
700 info.attr = &dummy_attr;
701 }
702
703 if (ri->suppress)
704 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
705 else
706 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
707
708 if (ret == RMAP_DENYMATCH)
709 {
710 bgp_attr_flush (attr);
711 return 0;
712 }
713 }
714 return 1;
715}
716
717int
718bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
719{
720 struct prefix *p;
721 struct bgp_info *ri;
722 struct bgp_info *new_select;
723 struct bgp_info *old_select;
724 struct listnode *nn;
725 struct peer *peer;
726 struct attr attr;
727 struct bgp_info *ri1;
728 struct bgp_info *ri2;
729
730 p = &rn->p;
731
732 /* bgp deterministic-med */
733 new_select = NULL;
734 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
735 for (ri1 = rn->info; ri1; ri1 = ri1->next)
736 {
737 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
738 continue;
739 if (BGP_INFO_HOLDDOWN (ri1))
740 continue;
741
742 new_select = ri1;
743 if (ri1->next)
744 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
745 {
746 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
747 continue;
748 if (BGP_INFO_HOLDDOWN (ri2))
749 continue;
750
751 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
752 || aspath_cmp_left_confed (ri1->attr->aspath,
753 ri2->attr->aspath))
754 {
755 if (bgp_info_cmp (bgp, ri2, new_select))
756 {
757 UNSET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
758 new_select = ri2;
759 }
760
761 SET_FLAG (ri2->flags, BGP_INFO_DMED_CHECK);
762 }
763 }
764 SET_FLAG (new_select->flags, BGP_INFO_DMED_CHECK);
765 SET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
766 }
767
768 /* Check old selected route and new selected route. */
769 old_select = NULL;
770 new_select = NULL;
771 for (ri = rn->info; ri; ri = ri->next)
772 {
773 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
774 old_select = ri;
775
776 if (BGP_INFO_HOLDDOWN (ri))
777 continue;
778
779 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
780 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
781 {
782 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
783 continue;
784 }
785 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
786 UNSET_FLAG (ri->flags, BGP_INFO_DMED_SELECTED);
787
788 if (bgp_info_cmp (bgp, ri, new_select))
789 new_select = ri;
790 }
791
792 /* Nothing to do. */
793 if (old_select && old_select == new_select)
794 {
795 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
796 {
797 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
798 bgp_zebra_announce (p, old_select, bgp);
799 return 0;
800 }
801 }
802
803 if (old_select)
804 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
805 if (new_select)
806 {
807 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
808 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
809 }
810
811 /* Check each BGP peer. */
812 LIST_LOOP (bgp->peer, peer, nn)
813 {
814 /* Announce route to Established peer. */
815 if (peer->status != Established)
816 continue;
817
818 /* Address family configuration check. */
819 if (! peer->afc_nego[afi][safi])
820 continue;
821
822 /* First update is deferred until ORF or ROUTE-REFRESH is received */
823 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
824 continue;
825
826 /* Announcement to peer->conf. If the route is filtered,
827 withdraw it. */
828 if (new_select
829 && bgp_announce_check (new_select, peer, p, &attr, afi, safi))
830 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, new_select);
831 else
832 bgp_adj_out_unset (rn, peer, p, afi, safi);
833 }
834
835 /* FIB update. */
836 if (safi == SAFI_UNICAST && ! bgp->name &&
837 ! bgp_option_check (BGP_OPT_NO_FIB))
838 {
839 if (new_select
840 && new_select->type == ZEBRA_ROUTE_BGP
841 && new_select->sub_type == BGP_ROUTE_NORMAL)
842 bgp_zebra_announce (p, new_select, bgp);
843 else
844 {
845 /* Withdraw the route from the kernel. */
846 if (old_select
847 && old_select->type == ZEBRA_ROUTE_BGP
848 && old_select->sub_type == BGP_ROUTE_NORMAL)
849 bgp_zebra_withdraw (p, old_select);
850 }
851 }
852 return 0;
853}
854
855int
856bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi, safi_t safi)
857{
858 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)
859 && peer->pcount[afi][safi] >= peer->pmax[afi][safi])
860 {
861 zlog (peer->log, LOG_INFO,
862 "MAXPFXEXCEED: No. of prefix received from %s (afi %d): %ld exceed limit %ld",
863 peer->host, afi, peer->pcount[afi][safi], peer->pmax[afi][safi]);
864 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
865 {
866 char ndata[7];
867
868 ndata[0] = (u_char)(afi >> 8);
869 ndata[1] = (u_char) afi;
870 ndata[3] = (u_char)(peer->pmax[afi][safi] >> 24);
871 ndata[4] = (u_char)(peer->pmax[afi][safi] >> 16);
872 ndata[5] = (u_char)(peer->pmax[afi][safi] >> 8);
873 ndata[6] = (u_char)(peer->pmax[afi][safi]);
874
875 if (safi == SAFI_MPLS_VPN)
876 safi = BGP_SAFI_VPNV4;
877 ndata[2] = (u_char) safi;
878
879 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
880 BGP_NOTIFY_CEASE_MAX_PREFIX,
881 ndata, 7);
882 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
883 return 1;
884 }
885 }
886 return 0;
887}
888
889void
890bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
891 afi_t afi, safi_t safi)
892{
893 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
894 {
895 peer->pcount[afi][safi]--;
896 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
897 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
898 bgp_process (peer->bgp, rn, afi, safi);
899 }
900 bgp_info_delete (rn, ri);
901 bgp_info_free (ri);
902 bgp_unlock_node (rn);
903}
904
905void
906bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
907 afi_t afi, safi_t safi, int force)
908{
909 int valid;
910 int status = BGP_DAMP_NONE;
911
912 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
913 {
914 peer->pcount[afi][safi]--;
915 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
916 }
917
918 if (! force)
919 {
920 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
921 && peer_sort (peer) == BGP_PEER_EBGP)
922 status = bgp_damp_withdraw (ri, rn, afi, safi, 0);
923
924 if (status == BGP_DAMP_SUPPRESSED)
925 return;
926 }
927
928 valid = CHECK_FLAG (ri->flags, BGP_INFO_VALID);
929 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
930 bgp_process (peer->bgp, rn, afi, safi);
931
932 if (valid)
933 SET_FLAG (ri->flags, BGP_INFO_VALID);
934
935 if (status != BGP_DAMP_USED)
936 {
937 bgp_info_delete (rn, ri);
938 bgp_info_free (ri);
939 bgp_unlock_node (rn);
940 }
941}
942
943int
944bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
945 afi_t afi, safi_t safi, int type, int sub_type,
946 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
947{
948 int ret;
949 int aspath_loop_count = 0;
950 struct bgp_node *rn;
951 struct bgp *bgp;
952 struct attr new_attr;
953 struct attr *attr_new;
954 struct bgp_info *ri;
955 struct bgp_info *new;
956 char *reason;
957 char buf[SU_ADDRSTRLEN];
958
959 bgp = peer->bgp;
960 rn = bgp_afi_node_get (bgp, afi, safi, p, prd);
961
962 /* When peer's soft reconfiguration enabled. Record input packet in
963 Adj-RIBs-In. */
964 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
965 && peer != bgp->peer_self && ! soft_reconfig)
966 bgp_adj_in_set (rn, peer, attr);
967
968 /* Check previously received route. */
969 for (ri = rn->info; ri; ri = ri->next)
970 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
971 break;
972
973 /* AS path local-as loop check. */
974 if (peer->change_local_as)
975 {
976 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
977 aspath_loop_count = 1;
978
979 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
980 {
981 reason = "as-path contains our own AS;";
982 goto filtered;
983 }
984 }
985
986 /* AS path loop check. */
987 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
988 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
989 && aspath_loop_check(attr->aspath, bgp->confed_id)
990 > peer->allowas_in[afi][safi]))
991 {
992 reason = "as-path contains our own AS;";
993 goto filtered;
994 }
995
996 /* Route reflector originator ID check. */
997 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
998 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
999 {
1000 reason = "originator is us;";
1001 goto filtered;
1002 }
1003
1004 /* Route reflector cluster ID check. */
1005 if (bgp_cluster_filter (peer, attr))
1006 {
1007 reason = "reflected from the same cluster;";
1008 goto filtered;
1009 }
1010
1011 /* Apply incoming filter. */
1012 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1013 {
1014 reason = "filter;";
1015 goto filtered;
1016 }
1017
1018 /* Apply incoming route-map. */
1019 new_attr = *attr;
1020
1021 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1022 {
1023 reason = "route-map;";
1024 goto filtered;
1025 }
1026
1027 /* IPv4 unicast next hop check. */
1028 if (afi == AFI_IP && safi == SAFI_UNICAST)
1029 {
1030 /* If the peer is EBGP and nexthop is not on connected route,
1031 discard it. */
1032 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1033 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
1034 && ! CHECK_FLAG (peer->flags, PEER_FLAG_ENFORCE_MULTIHOP))
1035 {
1036 reason = "non-connected next-hop;";
1037 goto filtered;
1038 }
1039
1040 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1041 must not be my own address. */
1042 if (bgp_nexthop_self (afi, &new_attr)
1043 || new_attr.nexthop.s_addr == 0
1044 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1045 {
1046 reason = "martian next-hop;";
1047 goto filtered;
1048 }
1049 }
1050
1051 attr_new = bgp_attr_intern (&new_attr);
1052
1053 /* If the update is implicit withdraw. */
1054 if (ri)
1055 {
1056 ri->uptime = time (NULL);
1057
1058 /* Same attribute comes in. */
1059 if (attrhash_cmp (ri->attr, attr_new))
1060 {
1061 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1062
1063 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1064 && peer_sort (peer) == BGP_PEER_EBGP
1065 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1066 {
1067 if (BGP_DEBUG (update, UPDATE_IN))
1068 zlog (peer->log, LOG_INFO, "%s rcvd %s/%d",
1069 peer->host,
1070 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1071 p->prefixlen);
1072
1073 peer->pcount[afi][safi]++;
1074 ret = bgp_damp_update (ri, rn, afi, safi);
1075 if (ret != BGP_DAMP_SUPPRESSED)
1076 {
1077 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1078 bgp_process (bgp, rn, afi, safi);
1079 }
1080 }
1081 else
1082 {
1083 if (BGP_DEBUG (update, UPDATE_IN))
1084 zlog (peer->log, LOG_INFO,
1085 "%s rcvd %s/%d...duplicate ignored",
1086 peer->host,
1087 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1088 p->prefixlen);
1089 }
1090
1091 bgp_unlock_node (rn);
1092 bgp_attr_unintern (attr_new);
1093 return 0;
1094 }
1095
1096 /* Received Logging. */
1097 if (BGP_DEBUG (update, UPDATE_IN))
1098 zlog (peer->log, LOG_INFO, "%s rcvd %s/%d",
1099 peer->host,
1100 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1101 p->prefixlen);
1102
1103 /* The attribute is changed. */
1104 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1105
1106 /* Update bgp route dampening information. */
1107 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1108 && peer_sort (peer) == BGP_PEER_EBGP)
1109 {
1110 /* This is implicit withdraw so we should update dampening
1111 information. */
1112 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1113 bgp_damp_withdraw (ri, rn, afi, safi, 1);
1114 else
1115 peer->pcount[afi][safi]++;
1116 }
1117
1118 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1119
1120 /* Update to new attribute. */
1121 bgp_attr_unintern (ri->attr);
1122 ri->attr = attr_new;
1123
1124 /* Update MPLS tag. */
1125 if (safi == SAFI_MPLS_VPN)
1126 memcpy (ri->tag, tag, 3);
1127
1128 /* Update bgp route dampening information. */
1129 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1130 && peer_sort (peer) == BGP_PEER_EBGP)
1131 {
1132 /* Now we do normal update dampening. */
1133 ret = bgp_damp_update (ri, rn, afi, safi);
1134 if (ret == BGP_DAMP_SUPPRESSED)
1135 {
1136 bgp_unlock_node (rn);
1137 return 0;
1138 }
1139 }
1140
1141 /* Nexthop reachability check. */
1142 if ((afi == AFI_IP || afi == AFI_IP6)
1143 && safi == SAFI_UNICAST
1144 && (peer_sort (peer) == BGP_PEER_IBGP
1145 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
1146 || CHECK_FLAG (peer->flags, PEER_FLAG_ENFORCE_MULTIHOP)))
1147 {
1148 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
1149 SET_FLAG (ri->flags, BGP_INFO_VALID);
1150 else
1151 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
1152 }
1153 else
1154 SET_FLAG (ri->flags, BGP_INFO_VALID);
1155
1156 /* Process change. */
1157 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1158
1159 bgp_process (bgp, rn, afi, safi);
1160 bgp_unlock_node (rn);
1161 return 0;
1162 }
1163
1164 /* Received Logging. */
1165 if (BGP_DEBUG (update, UPDATE_IN))
1166 {
1167 zlog (peer->log, LOG_INFO, "%s rcvd %s/%d",
1168 peer->host,
1169 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1170 p->prefixlen);
1171 }
1172
1173 /* Increment prefix counter */
1174 peer->pcount[afi][safi]++;
1175
1176 /* Make new BGP info. */
1177 new = bgp_info_new ();
1178 new->type = type;
1179 new->sub_type = sub_type;
1180 new->peer = peer;
1181 new->attr = attr_new;
1182 new->uptime = time (NULL);
1183
1184 /* Update MPLS tag. */
1185 if (safi == SAFI_MPLS_VPN)
1186 memcpy (new->tag, tag, 3);
1187
1188 /* Nexthop reachability check. */
1189 if ((afi == AFI_IP || afi == AFI_IP6)
1190 && safi == SAFI_UNICAST
1191 && (peer_sort (peer) == BGP_PEER_IBGP
1192 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
1193 || CHECK_FLAG (peer->flags, PEER_FLAG_ENFORCE_MULTIHOP)))
1194 {
1195 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
1196 SET_FLAG (new->flags, BGP_INFO_VALID);
1197 else
1198 UNSET_FLAG (new->flags, BGP_INFO_VALID);
1199 }
1200 else
1201 SET_FLAG (new->flags, BGP_INFO_VALID);
1202
1203 /* Aggregate address increment. */
1204 bgp_aggregate_increment (bgp, p, new, afi, safi);
1205
1206 /* Register new BGP information. */
1207 bgp_info_add (rn, new);
1208
1209 /* If maximum prefix count is configured and current prefix
1210 count exeed it. */
1211 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1212 if (bgp_maximum_prefix_overflow (peer, afi, safi))
1213 return -1;
1214
1215 /* Process change. */
1216 bgp_process (bgp, rn, afi, safi);
1217
1218 return 0;
1219
1220 /* This BGP update is filtered. Log the reason then update BGP
1221 entry. */
1222 filtered:
1223 if (BGP_DEBUG (update, UPDATE_IN))
1224 zlog (peer->log, LOG_INFO,
1225 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
1226 peer->host,
1227 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1228 p->prefixlen, reason);
1229
1230 if (ri)
1231 bgp_rib_withdraw (rn, ri, peer, afi, safi, 1);
1232
1233 bgp_unlock_node (rn);
1234
1235 return 0;
1236}
1237
1238int
1239bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
1240 int afi, int safi, int type, int sub_type, struct prefix_rd *prd,
1241 u_char *tag)
1242{
1243 struct bgp *bgp;
1244 char buf[SU_ADDRSTRLEN];
1245 struct bgp_node *rn;
1246 struct bgp_info *ri;
1247
1248 bgp = peer->bgp;
1249
1250 /* Logging. */
1251 if (BGP_DEBUG (update, UPDATE_IN))
1252 zlog (peer->log, LOG_INFO, "%s rcvd UPDATE about %s/%d -- withdrawn",
1253 peer->host,
1254 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1255 p->prefixlen);
1256
1257 /* Lookup node. */
1258 rn = bgp_afi_node_get (bgp, afi, safi, p, prd);
1259
1260 /* If peer is soft reconfiguration enabled. Record input packet for
1261 further calculation. */
1262 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1263 && peer != bgp->peer_self)
1264 bgp_adj_in_unset (rn, peer);
1265
1266 /* Lookup withdrawn route. */
1267 for (ri = rn->info; ri; ri = ri->next)
1268 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1269 break;
1270
1271 /* Withdraw specified route from routing table. */
1272 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1273 bgp_rib_withdraw (rn, ri, peer, afi, safi, 0);
1274 else if (BGP_DEBUG (update, UPDATE_IN))
1275 zlog (peer->log, LOG_INFO,
1276 "%s Can't find the route %s/%d", peer->host,
1277 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1278 p->prefixlen);
1279
1280 /* Unlock bgp_node_get() lock. */
1281 bgp_unlock_node (rn);
1282
1283 return 0;
1284}
1285
1286void
1287bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
1288{
1289 struct bgp *bgp;
1290 struct attr attr;
1291 struct aspath *aspath;
1292 struct prefix p;
1293 struct bgp_info binfo;
1294 struct peer *from;
1295 int ret = RMAP_DENYMATCH;
1296
1297 bgp = peer->bgp;
1298 from = bgp->peer_self;
1299
1300 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
1301 aspath = attr.aspath;
1302 attr.local_pref = bgp->default_local_pref;
1303 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1304
1305 if (afi == AFI_IP)
1306 str2prefix ("0.0.0.0/0", &p);
1307#ifdef HAVE_IPV6
1308 else if (afi == AFI_IP6)
1309 {
1310 str2prefix ("::/0", &p);
1311
1312 /* IPv6 global nexthop must be included. */
1313 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
1314 IPV6_MAX_BYTELEN);
1315 attr.mp_nexthop_len = 16;
1316
1317 /* If the peer is on shared nextwork and we have link-local
1318 nexthop set it. */
1319 if (peer->shared_network
1320 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1321 {
1322 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
1323 IPV6_MAX_BYTELEN);
1324 attr.mp_nexthop_len = 32;
1325 }
1326 }
1327#endif /* HAVE_IPV6 */
1328 else
1329 return;
1330
1331 if (peer->default_rmap[afi][safi].name)
1332 {
1333 binfo.peer = bgp->peer_self;
1334 binfo.attr = &attr;
1335
1336 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
1337 RMAP_BGP, &binfo);
1338
1339 if (ret == RMAP_DENYMATCH)
1340 {
1341 bgp_attr_flush (&attr);
1342 withdraw = 1;
1343 }
1344 }
1345
1346 if (withdraw)
1347 {
1348 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
1349 bgp_default_withdraw_send (peer, afi, safi);
1350 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
1351 }
1352 else
1353 {
1354 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
1355 bgp_default_update_send (peer, &attr, afi, safi, from);
1356 }
1357
1358 aspath_unintern (aspath);
1359}
1360
1361static void
1362bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
1363 struct bgp_table *table)
1364{
1365 struct bgp_node *rn;
1366 struct bgp_info *ri;
1367 struct attr attr;
1368
1369 if (! table)
1370 table = peer->bgp->rib[afi][safi];
1371
1372 if (safi != SAFI_MPLS_VPN
1373 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1374 bgp_default_originate (peer, afi, safi, 0);
1375
1376 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
1377 for (ri = rn->info; ri; ri = ri->next)
1378 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
1379 {
1380 if (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi))
1381 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
1382 else
1383 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
1384 }
1385}
1386
1387void
1388bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
1389{
1390 struct bgp_node *rn;
1391 struct bgp_table *table;
1392
1393 if (peer->status != Established)
1394 return;
1395
1396 if (! peer->afc_nego[afi][safi])
1397 return;
1398
1399 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1400 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
1401 return;
1402
1403 if (safi != SAFI_MPLS_VPN)
1404 bgp_announce_table (peer, afi, safi, NULL);
1405 else
1406 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
1407 rn = bgp_route_next(rn))
1408 if ((table = (rn->info)) != NULL)
1409 bgp_announce_table (peer, afi, safi, table);
1410}
1411
1412void
1413bgp_announce_route_all (struct peer *peer)
1414{
1415 afi_t afi;
1416 safi_t safi;
1417
1418 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1419 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1420 bgp_announce_route (peer, afi, safi);
1421}
1422
1423static void
1424bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
1425 struct bgp_table *table)
1426{
1427 int ret;
1428 struct bgp_node *rn;
1429 struct bgp_adj_in *ain;
1430
1431 if (! table)
1432 table = peer->bgp->rib[afi][safi];
1433
1434 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1435 for (ain = rn->adj_in; ain; ain = ain->next)
1436 {
1437 if (ain->peer == peer)
1438 {
1439 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
1440 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
1441 NULL, NULL, 1);
1442 if (ret < 0)
1443 {
1444 bgp_unlock_node (rn);
1445 return;
1446 }
1447 continue;
1448 }
1449 }
1450}
1451
1452void
1453bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
1454{
1455 struct bgp_node *rn;
1456 struct bgp_table *table;
1457
1458 if (peer->status != Established)
1459 return;
1460
1461 if (safi != SAFI_MPLS_VPN)
1462 bgp_soft_reconfig_table (peer, afi, safi, NULL);
1463 else
1464 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
1465 rn = bgp_route_next (rn))
1466 if ((table = rn->info) != NULL)
1467 bgp_soft_reconfig_table (peer, afi, safi, table);
1468}
1469
1470static void
1471bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
1472 struct bgp_table *table)
1473{
1474 struct bgp_node *rn;
1475 struct bgp_adj_in *ain;
1476 struct bgp_adj_out *aout;
1477 struct bgp_info *ri;
1478
1479 if (! table)
1480 table = peer->bgp->rib[afi][safi];
1481
1482 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1483 {
1484 for (ri = rn->info; ri; ri = ri->next)
1485 if (ri->peer == peer)
1486 {
1487 bgp_rib_remove (rn, ri, peer, afi, safi);
1488 break;
1489 }
1490 for (ain = rn->adj_in; ain; ain = ain->next)
1491 if (ain->peer == peer)
1492 {
1493 bgp_adj_in_remove (rn, ain);
1494 bgp_unlock_node (rn);
1495 break;
1496 }
1497 for (aout = rn->adj_out; aout; aout = aout->next)
1498 if (aout->peer == peer)
1499 {
1500 bgp_adj_out_remove (rn, aout, peer, afi, safi);
1501 bgp_unlock_node (rn);
1502 break;
1503 }
1504 }
1505}
1506
1507void
1508bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
1509{
1510 struct bgp_node *rn;
1511 struct bgp_table *table;
1512
1513 if (! peer->afc[afi][safi])
1514 return;
1515
1516 if (safi != SAFI_MPLS_VPN)
1517 bgp_clear_route_table (peer, afi, safi, NULL);
1518 else
1519 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
1520 rn = bgp_route_next (rn))
1521 if ((table = rn->info) != NULL)
1522 bgp_clear_route_table (peer, afi, safi, table);
1523}
1524
1525void
1526bgp_clear_route_all (struct peer *peer)
1527{
1528 afi_t afi;
1529 safi_t safi;
1530
1531 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1532 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1533 bgp_clear_route (peer, afi, safi);
1534}
1535
1536void
1537bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
1538{
1539 struct bgp_table *table;
1540 struct bgp_node *rn;
1541 struct bgp_adj_in *ain;
1542
1543 table = peer->bgp->rib[afi][safi];
1544
1545 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1546 for (ain = rn->adj_in; ain ; ain = ain->next)
1547 if (ain->peer == peer)
1548 {
1549 bgp_adj_in_remove (rn, ain);
1550 bgp_unlock_node (rn);
1551 break;
1552 }
1553}
1554
1555/* Delete all kernel routes. */
1556void
1557bgp_terminate ()
1558{
1559 struct bgp *bgp;
1560 struct listnode *nn;
1561 struct bgp_node *rn;
1562 struct bgp_table *table;
1563 struct bgp_info *ri;
1564
1565 LIST_LOOP (bm->bgp, bgp, nn)
1566 {
1567 table = bgp->rib[AFI_IP][SAFI_UNICAST];
1568
1569 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1570 for (ri = rn->info; ri; ri = ri->next)
1571 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
1572 && ri->type == ZEBRA_ROUTE_BGP
1573 && ri->sub_type == BGP_ROUTE_NORMAL)
1574 bgp_zebra_withdraw (&rn->p, ri);
1575
1576 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
1577
1578 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1579 for (ri = rn->info; ri; ri = ri->next)
1580 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
1581 && ri->type == ZEBRA_ROUTE_BGP
1582 && ri->sub_type == BGP_ROUTE_NORMAL)
1583 bgp_zebra_withdraw (&rn->p, ri);
1584 }
1585}
1586
1587void
1588bgp_reset ()
1589{
1590 vty_reset ();
1591 bgp_zclient_reset ();
1592 access_list_reset ();
1593 prefix_list_reset ();
1594}
1595
1596/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
1597 value. */
1598int
1599bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
1600{
1601 u_char *pnt;
1602 u_char *lim;
1603 struct prefix p;
1604 int psize;
1605 int ret;
1606
1607 /* Check peer status. */
1608 if (peer->status != Established)
1609 return 0;
1610
1611 pnt = packet->nlri;
1612 lim = pnt + packet->length;
1613
1614 for (; pnt < lim; pnt += psize)
1615 {
1616 /* Clear prefix structure. */
1617 memset (&p, 0, sizeof (struct prefix));
1618
1619 /* Fetch prefix length. */
1620 p.prefixlen = *pnt++;
1621 p.family = afi2family (packet->afi);
1622
1623 /* Already checked in nlri_sanity_check(). We do double check
1624 here. */
1625 if ((packet->afi == AFI_IP && p.prefixlen > 32)
1626 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
1627 return -1;
1628
1629 /* Packet size overflow check. */
1630 psize = PSIZE (p.prefixlen);
1631
1632 /* When packet overflow occur return immediately. */
1633 if (pnt + psize > lim)
1634 return -1;
1635
1636 /* Fetch prefix from NLRI packet. */
1637 memcpy (&p.u.prefix, pnt, psize);
1638
1639 /* Check address. */
1640 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
1641 {
1642 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
1643 {
1644 zlog (peer->log, LOG_ERR,
1645 "IPv4 unicast NLRI is multicast address %s",
1646 inet_ntoa (p.u.prefix4));
1647 bgp_notify_send (peer,
1648 BGP_NOTIFY_UPDATE_ERR,
1649 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1650 return -1;
1651 }
1652 }
1653
1654#ifdef HAVE_IPV6
1655 /* Check address. */
1656 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
1657 {
1658 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
1659 {
1660 char buf[BUFSIZ];
1661
1662 zlog (peer->log, LOG_WARNING,
1663 "IPv6 link-local NLRI received %s ignore this NLRI",
1664 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
1665
1666 continue;
1667 }
1668 }
1669#endif /* HAVE_IPV6 */
1670
1671 /* Normal process. */
1672 if (attr)
1673 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
1674 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
1675 else
1676 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
1677 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
1678
1679 /* Address family configuration mismatch or maximum-prefix count
1680 overflow. */
1681 if (ret < 0)
1682 return -1;
1683 }
1684
1685 /* Packet length consistency check. */
1686 if (pnt != lim)
1687 return -1;
1688
1689 return 0;
1690}
1691
1692/* NLRI encode syntax check routine. */
1693int
1694bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
1695 bgp_size_t length)
1696{
1697 u_char *end;
1698 u_char prefixlen;
1699 int psize;
1700
1701 end = pnt + length;
1702
1703 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
1704 syntactic validity. If the field is syntactically incorrect,
1705 then the Error Subcode is set to Invalid Network Field. */
1706
1707 while (pnt < end)
1708 {
1709 prefixlen = *pnt++;
1710
1711 /* Prefix length check. */
1712 if ((afi == AFI_IP && prefixlen > 32)
1713 || (afi == AFI_IP6 && prefixlen > 128))
1714 {
1715 plog_err (peer->log,
1716 "%s [Error] Update packet error (wrong prefix length %d)",
1717 peer->host, prefixlen);
1718 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1719 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1720 return -1;
1721 }
1722
1723 /* Packet size overflow check. */
1724 psize = PSIZE (prefixlen);
1725
1726 if (pnt + psize > end)
1727 {
1728 plog_err (peer->log,
1729 "%s [Error] Update packet error"
1730 " (prefix data overflow prefix size is %d)",
1731 peer->host, psize);
1732 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1733 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1734 return -1;
1735 }
1736
1737 pnt += psize;
1738 }
1739
1740 /* Packet length consistency check. */
1741 if (pnt != end)
1742 {
1743 plog_err (peer->log,
1744 "%s [Error] Update packet error"
1745 " (prefix length mismatch with total length)",
1746 peer->host);
1747 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1748 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1749 return -1;
1750 }
1751 return 0;
1752}
1753
1754struct bgp_static *
1755bgp_static_new ()
1756{
1757 struct bgp_static *new;
1758 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
1759 memset (new, 0, sizeof (struct bgp_static));
1760 return new;
1761}
1762
1763void
1764bgp_static_free (struct bgp_static *bgp_static)
1765{
1766 if (bgp_static->rmap.name)
1767 free (bgp_static->rmap.name);
1768 XFREE (MTYPE_BGP_STATIC, bgp_static);
1769}
1770
1771void
1772bgp_static_update (struct bgp *bgp, struct prefix *p,
1773 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
1774{
1775 struct bgp_node *rn;
1776 struct bgp_info *ri;
1777 struct bgp_info *new;
1778 struct bgp_info info;
1779 struct attr attr;
1780 struct attr *attr_new;
1781 int ret;
1782
1783 rn = bgp_afi_node_get (bgp, afi, safi, p, NULL);
1784
1785 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
1786 if (bgp_static)
1787 {
1788 attr.nexthop = bgp_static->igpnexthop;
1789 attr.med = bgp_static->igpmetric;
1790 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
1791 }
1792
1793 /* Apply route-map. */
1794 if (bgp_static->rmap.name)
1795 {
1796 info.peer = bgp->peer_self;
1797 info.attr = &attr;
1798
1799 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
1800 if (ret == RMAP_DENYMATCH)
1801 {
1802 /* Free uninterned attribute. */
1803 bgp_attr_flush (&attr);
1804
1805 /* Unintern original. */
1806 aspath_unintern (attr.aspath);
1807 bgp_static_withdraw (bgp, p, afi, safi);
1808 return;
1809 }
1810 }
1811
1812 attr_new = bgp_attr_intern (&attr);
1813
1814 for (ri = rn->info; ri; ri = ri->next)
1815 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
1816 && ri->sub_type == BGP_ROUTE_STATIC)
1817 break;
1818
1819 if (ri)
1820 {
1821 if (attrhash_cmp (ri->attr, attr_new))
1822 {
1823 bgp_unlock_node (rn);
1824 bgp_attr_unintern (attr_new);
1825 aspath_unintern (attr.aspath);
1826 return;
1827 }
1828 else
1829 {
1830 /* The attribute is changed. */
1831 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1832
1833 /* Rewrite BGP route information. */
1834 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1835 bgp_attr_unintern (ri->attr);
1836 ri->attr = attr_new;
1837 ri->uptime = time (NULL);
1838
1839 /* Process change. */
1840 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1841 bgp_process (bgp, rn, afi, safi);
1842 bgp_unlock_node (rn);
1843 aspath_unintern (attr.aspath);
1844 return;
1845 }
1846 }
1847
1848 /* Make new BGP info. */
1849 new = bgp_info_new ();
1850 new->type = ZEBRA_ROUTE_BGP;
1851 new->sub_type = BGP_ROUTE_STATIC;
1852 new->peer = bgp->peer_self;
1853 SET_FLAG (new->flags, BGP_INFO_VALID);
1854 new->attr = attr_new;
1855 new->uptime = time (NULL);
1856
1857 /* Aggregate address increment. */
1858 bgp_aggregate_increment (bgp, p, new, afi, safi);
1859
1860 /* Register new BGP information. */
1861 bgp_info_add (rn, new);
1862
1863 /* Process change. */
1864 bgp_process (bgp, rn, afi, safi);
1865
1866 /* Unintern original. */
1867 aspath_unintern (attr.aspath);
1868}
1869
1870void
1871bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
1872 u_char safi, struct prefix_rd *prd, u_char *tag)
1873{
1874 struct bgp_node *rn;
1875 struct bgp_info *new;
1876
1877 rn = bgp_afi_node_get (bgp, afi, safi, p, prd);
1878
1879 /* Make new BGP info. */
1880 new = bgp_info_new ();
1881 new->type = ZEBRA_ROUTE_BGP;
1882 new->sub_type = BGP_ROUTE_STATIC;
1883 new->peer = bgp->peer_self;
1884 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
1885 SET_FLAG (new->flags, BGP_INFO_VALID);
1886 new->uptime = time (NULL);
1887 memcpy (new->tag, tag, 3);
1888
1889 /* Aggregate address increment. */
1890 bgp_aggregate_increment (bgp, p, (struct bgp_info *) new, afi, safi);
1891
1892 /* Register new BGP information. */
1893 bgp_info_add (rn, (struct bgp_info *) new);
1894
1895 /* Process change. */
1896 bgp_process (bgp, rn, afi, safi);
1897}
1898
1899void
1900bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
1901 safi_t safi)
1902{
1903 struct bgp_node *rn;
1904 struct bgp_info *ri;
1905
1906 rn = bgp_afi_node_get (bgp, afi, safi, p, NULL);
1907
1908 /* Check selected route and self inserted route. */
1909 for (ri = rn->info; ri; ri = ri->next)
1910 if (ri->peer == bgp->peer_self
1911 && ri->type == ZEBRA_ROUTE_BGP
1912 && ri->sub_type == BGP_ROUTE_STATIC)
1913 break;
1914
1915 /* Withdraw static BGP route from routing table. */
1916 if (ri)
1917 {
1918 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1919 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
1920 bgp_process (bgp, rn, afi, safi);
1921 bgp_info_delete (rn, ri);
1922 bgp_info_free (ri);
1923 bgp_unlock_node (rn);
1924 }
1925
1926 /* Unlock bgp_node_lookup. */
1927 bgp_unlock_node (rn);
1928}
1929
1930void
1931bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
1932 u_char safi, struct prefix_rd *prd, u_char *tag)
1933{
1934 struct bgp_node *rn;
1935 struct bgp_info *ri;
1936
1937 rn = bgp_afi_node_get (bgp, afi, safi, p, prd);
1938
1939 /* Check selected route and self inserted route. */
1940 for (ri = rn->info; ri; ri = ri->next)
1941 if (ri->peer == bgp->peer_self
1942 && ri->type == ZEBRA_ROUTE_BGP
1943 && ri->sub_type == BGP_ROUTE_STATIC)
1944 break;
1945
1946 /* Withdraw static BGP route from routing table. */
1947 if (ri)
1948 {
1949 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1950 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
1951 bgp_process (bgp, rn, afi, safi);
1952 bgp_info_delete (rn, ri);
1953 bgp_info_free (ri);
1954 bgp_unlock_node (rn);
1955 }
1956
1957 /* Unlock bgp_node_lookup. */
1958 bgp_unlock_node (rn);
1959}
1960
1961/* Configure static BGP network. When user don't run zebra, static
1962 route should be installed as valid. */
1963int
1964bgp_static_set (struct vty *vty, struct bgp *bgp, char *ip_str, u_int16_t afi,
1965 u_char safi, char *rmap, int backdoor)
1966{
1967 int ret;
1968 struct prefix p;
1969 struct bgp_static *bgp_static;
1970 struct bgp_node *rn;
1971 int need_update = 0;
1972
1973 /* Convert IP prefix string to struct prefix. */
1974 ret = str2prefix (ip_str, &p);
1975 if (! ret)
1976 {
1977 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
1978 return CMD_WARNING;
1979 }
1980#ifdef HAVE_IPV6
1981 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
1982 {
1983 vty_out (vty, "%% Malformed prefix (link-local address)%s",
1984 VTY_NEWLINE);
1985 return CMD_WARNING;
1986 }
1987#endif /* HAVE_IPV6 */
1988
1989 apply_mask (&p);
1990
1991 /* Set BGP static route configuration. */
1992 rn = bgp_node_get (bgp->route[afi][safi], &p);
1993
1994 if (rn->info)
1995 {
1996 /* Configuration change. */
1997 bgp_static = rn->info;
1998
1999 /* Check previous routes are installed into BGP. */
2000 if (! bgp_static->backdoor && bgp_static->valid)
2001 need_update = 1;
2002
2003 bgp_static->backdoor = backdoor;
2004 if (rmap)
2005 {
2006 if (bgp_static->rmap.name)
2007 free (bgp_static->rmap.name);
2008 bgp_static->rmap.name = strdup (rmap);
2009 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
2010 }
2011 else
2012 {
2013 if (bgp_static->rmap.name)
2014 free (bgp_static->rmap.name);
2015 bgp_static->rmap.name = NULL;
2016 bgp_static->rmap.map = NULL;
2017 bgp_static->valid = 0;
2018 }
2019 bgp_unlock_node (rn);
2020 }
2021 else
2022 {
2023 /* New configuration. */
2024 bgp_static = bgp_static_new ();
2025 bgp_static->backdoor = backdoor;
2026 bgp_static->valid = 0;
2027 bgp_static->igpmetric = 0;
2028 bgp_static->igpnexthop.s_addr = 0;
2029 if (rmap)
2030 {
2031 if (bgp_static->rmap.name)
2032 free (bgp_static->rmap.name);
2033 bgp_static->rmap.name = strdup (rmap);
2034 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
2035 }
2036 rn->info = bgp_static;
2037 }
2038
2039 /* If BGP scan is not enabled, we should install this route here. */
2040 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
2041 {
2042 bgp_static->valid = 1;
2043
2044 if (need_update)
2045 bgp_static_withdraw (bgp, &p, afi, safi);
2046
2047 if (! bgp_static->backdoor)
2048 bgp_static_update (bgp, &p, bgp_static, afi, safi);
2049 }
2050
2051 return CMD_SUCCESS;
2052}
2053
2054/* Configure static BGP network. */
2055int
2056bgp_static_unset (struct vty *vty, struct bgp *bgp, char *ip_str,
2057 u_int16_t afi, u_char safi)
2058{
2059 int ret;
2060 struct prefix p;
2061 struct bgp_static *bgp_static;
2062 struct bgp_node *rn;
2063
2064 /* Convert IP prefix string to struct prefix. */
2065 ret = str2prefix (ip_str, &p);
2066 if (! ret)
2067 {
2068 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2069 return CMD_WARNING;
2070 }
2071#ifdef HAVE_IPV6
2072 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2073 {
2074 vty_out (vty, "%% Malformed prefix (link-local address)%s",
2075 VTY_NEWLINE);
2076 return CMD_WARNING;
2077 }
2078#endif /* HAVE_IPV6 */
2079
2080 apply_mask (&p);
2081
2082 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
2083 if (! rn)
2084 {
2085 vty_out (vty, "%% Can't find specified static route configuration.%s",
2086 VTY_NEWLINE);
2087 return CMD_WARNING;
2088 }
2089
2090 bgp_static = rn->info;
2091
2092 /* Update BGP RIB. */
2093 if (! bgp_static->backdoor)
2094 bgp_static_withdraw (bgp, &p, afi, safi);
2095
2096 /* Clear configuration. */
2097 bgp_static_free (bgp_static);
2098 rn->info = NULL;
2099 bgp_unlock_node (rn);
2100 bgp_unlock_node (rn);
2101
2102 return CMD_SUCCESS;
2103}
2104
2105/* Called from bgp_delete(). Delete all static routes from the BGP
2106 instance. */
2107void
2108bgp_static_delete (struct bgp *bgp)
2109{
2110 afi_t afi;
2111 safi_t safi;
2112 struct bgp_node *rn;
2113 struct bgp_node *rm;
2114 struct bgp_table *table;
2115 struct bgp_static *bgp_static;
2116
2117 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2118 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2119 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
2120 if (rn->info != NULL)
2121 {
2122 if (safi == SAFI_MPLS_VPN)
2123 {
2124 table = rn->info;
2125
2126 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
2127 {
2128 bgp_static = rn->info;
2129 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
2130 AFI_IP, SAFI_MPLS_VPN,
2131 (struct prefix_rd *)&rn->p,
2132 bgp_static->tag);
2133 bgp_static_free (bgp_static);
2134 rn->info = NULL;
2135 bgp_unlock_node (rn);
2136 }
2137 }
2138 else
2139 {
2140 bgp_static = rn->info;
2141 bgp_static_withdraw (bgp, &rn->p, afi, safi);
2142 bgp_static_free (bgp_static);
2143 rn->info = NULL;
2144 bgp_unlock_node (rn);
2145 }
2146 }
2147}
2148
2149int
2150bgp_static_set_vpnv4 (struct vty *vty, char *ip_str, char *rd_str,
2151 char *tag_str)
2152{
2153 int ret;
2154 struct prefix p;
2155 struct prefix_rd prd;
2156 struct bgp *bgp;
2157 struct bgp_node *prn;
2158 struct bgp_node *rn;
2159 struct bgp_table *table;
2160 struct bgp_static *bgp_static;
2161 u_char tag[3];
2162
2163 bgp = vty->index;
2164
2165 ret = str2prefix (ip_str, &p);
2166 if (! ret)
2167 {
2168 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2169 return CMD_WARNING;
2170 }
2171 apply_mask (&p);
2172
2173 ret = str2prefix_rd (rd_str, &prd);
2174 if (! ret)
2175 {
2176 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
2177 return CMD_WARNING;
2178 }
2179
2180 ret = str2tag (tag_str, tag);
2181 if (! ret)
2182 {
2183 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
2184 return CMD_WARNING;
2185 }
2186
2187 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
2188 (struct prefix *)&prd);
2189 if (prn->info == NULL)
2190 prn->info = bgp_table_init ();
2191 else
2192 bgp_unlock_node (prn);
2193 table = prn->info;
2194
2195 rn = bgp_node_get (table, &p);
2196
2197 if (rn->info)
2198 {
2199 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
2200 bgp_unlock_node (rn);
2201 }
2202 else
2203 {
2204 /* New configuration. */
2205 bgp_static = bgp_static_new ();
2206 bgp_static->valid = 1;
2207 memcpy (bgp_static->tag, tag, 3);
2208 rn->info = bgp_static;
2209
2210 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
2211 }
2212
2213 return CMD_SUCCESS;
2214}
2215
2216/* Configure static BGP network. */
2217int
2218bgp_static_unset_vpnv4 (struct vty *vty, char *ip_str, char *rd_str,
2219 char *tag_str)
2220{
2221 int ret;
2222 struct bgp *bgp;
2223 struct prefix p;
2224 struct prefix_rd prd;
2225 struct bgp_node *prn;
2226 struct bgp_node *rn;
2227 struct bgp_table *table;
2228 struct bgp_static *bgp_static;
2229 u_char tag[3];
2230
2231 bgp = vty->index;
2232
2233 /* Convert IP prefix string to struct prefix. */
2234 ret = str2prefix (ip_str, &p);
2235 if (! ret)
2236 {
2237 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2238 return CMD_WARNING;
2239 }
2240 apply_mask (&p);
2241
2242 ret = str2prefix_rd (rd_str, &prd);
2243 if (! ret)
2244 {
2245 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
2246 return CMD_WARNING;
2247 }
2248
2249 ret = str2tag (tag_str, tag);
2250 if (! ret)
2251 {
2252 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
2253 return CMD_WARNING;
2254 }
2255
2256 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
2257 (struct prefix *)&prd);
2258 if (prn->info == NULL)
2259 prn->info = bgp_table_init ();
2260 else
2261 bgp_unlock_node (prn);
2262 table = prn->info;
2263
2264 rn = bgp_node_lookup (table, &p);
2265
2266 if (rn)
2267 {
2268 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
2269
2270 bgp_static = rn->info;
2271 bgp_static_free (bgp_static);
2272 rn->info = NULL;
2273 bgp_unlock_node (rn);
2274 bgp_unlock_node (rn);
2275 }
2276 else
2277 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
2278
2279 return CMD_SUCCESS;
2280}
2281
2282DEFUN (bgp_network,
2283 bgp_network_cmd,
2284 "network A.B.C.D/M",
2285 "Specify a network to announce via BGP\n"
2286 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2287{
2288 return bgp_static_set (vty, vty->index, argv[0],
2289 AFI_IP, bgp_node_safi (vty), NULL, 0);
2290}
2291
2292DEFUN (bgp_network_route_map,
2293 bgp_network_route_map_cmd,
2294 "network A.B.C.D/M route-map WORD",
2295 "Specify a network to announce via BGP\n"
2296 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2297 "Route-map to modify the attributes\n"
2298 "Name of the route map\n")
2299{
2300 return bgp_static_set (vty, vty->index, argv[0],
2301 AFI_IP, bgp_node_safi (vty), argv[1], 0);
2302}
2303
2304DEFUN (bgp_network_backdoor,
2305 bgp_network_backdoor_cmd,
2306 "network A.B.C.D/M backdoor",
2307 "Specify a network to announce via BGP\n"
2308 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2309 "Specify a BGP backdoor route\n")
2310{
2311 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
2312}
2313
2314DEFUN (bgp_network_mask,
2315 bgp_network_mask_cmd,
2316 "network A.B.C.D mask A.B.C.D",
2317 "Specify a network to announce via BGP\n"
2318 "Network number\n"
2319 "Network mask\n"
2320 "Network mask\n")
2321{
2322 int ret;
2323 char prefix_str[BUFSIZ];
2324
2325 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2326 if (! ret)
2327 {
2328 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2329 return CMD_WARNING;
2330 }
2331
2332 return bgp_static_set (vty, vty->index, prefix_str,
2333 AFI_IP, bgp_node_safi (vty), NULL, 0);
2334}
2335
2336DEFUN (bgp_network_mask_route_map,
2337 bgp_network_mask_route_map_cmd,
2338 "network A.B.C.D mask A.B.C.D route-map WORD",
2339 "Specify a network to announce via BGP\n"
2340 "Network number\n"
2341 "Network mask\n"
2342 "Network mask\n"
2343 "Route-map to modify the attributes\n"
2344 "Name of the route map\n")
2345{
2346 int ret;
2347 char prefix_str[BUFSIZ];
2348
2349 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2350 if (! ret)
2351 {
2352 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2353 return CMD_WARNING;
2354 }
2355
2356 return bgp_static_set (vty, vty->index, prefix_str,
2357 AFI_IP, bgp_node_safi (vty), argv[2], 0);
2358}
2359
2360DEFUN (bgp_network_mask_backdoor,
2361 bgp_network_mask_backdoor_cmd,
2362 "network A.B.C.D mask A.B.C.D backdoor",
2363 "Specify a network to announce via BGP\n"
2364 "Network number\n"
2365 "Network mask\n"
2366 "Network mask\n"
2367 "Specify a BGP backdoor route\n")
2368{
2369 int ret;
2370 char prefix_str[BUFSIZ];
2371
2372 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2373 if (! ret)
2374 {
2375 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2376 return CMD_WARNING;
2377 }
2378
2379 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
2380}
2381
2382DEFUN (bgp_network_mask_natural,
2383 bgp_network_mask_natural_cmd,
2384 "network A.B.C.D",
2385 "Specify a network to announce via BGP\n"
2386 "Network number\n")
2387{
2388 int ret;
2389 char prefix_str[BUFSIZ];
2390
2391 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2392 if (! ret)
2393 {
2394 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2395 return CMD_WARNING;
2396 }
2397
2398 return bgp_static_set (vty, vty->index, prefix_str,
2399 AFI_IP, bgp_node_safi (vty), NULL, 0);
2400}
2401
2402DEFUN (bgp_network_mask_natural_route_map,
2403 bgp_network_mask_natural_route_map_cmd,
2404 "network A.B.C.D route-map WORD",
2405 "Specify a network to announce via BGP\n"
2406 "Network number\n"
2407 "Route-map to modify the attributes\n"
2408 "Name of the route map\n")
2409{
2410 int ret;
2411 char prefix_str[BUFSIZ];
2412
2413 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2414 if (! ret)
2415 {
2416 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2417 return CMD_WARNING;
2418 }
2419
2420 return bgp_static_set (vty, vty->index, prefix_str,
2421 AFI_IP, bgp_node_safi (vty), argv[1], 0);
2422}
2423
2424DEFUN (bgp_network_mask_natural_backdoor,
2425 bgp_network_mask_natural_backdoor_cmd,
2426 "network A.B.C.D backdoor",
2427 "Specify a network to announce via BGP\n"
2428 "Network number\n"
2429 "Specify a BGP backdoor route\n")
2430{
2431 int ret;
2432 char prefix_str[BUFSIZ];
2433
2434 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2435 if (! ret)
2436 {
2437 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2438 return CMD_WARNING;
2439 }
2440
2441 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
2442}
2443
2444DEFUN (no_bgp_network,
2445 no_bgp_network_cmd,
2446 "no network A.B.C.D/M",
2447 NO_STR
2448 "Specify a network to announce via BGP\n"
2449 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2450{
2451 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
2452 bgp_node_safi (vty));
2453}
2454
2455ALIAS (no_bgp_network,
2456 no_bgp_network_route_map_cmd,
2457 "no network A.B.C.D/M route-map WORD",
2458 NO_STR
2459 "Specify a network to announce via BGP\n"
2460 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2461 "Route-map to modify the attributes\n"
2462 "Name of the route map\n")
2463
2464ALIAS (no_bgp_network,
2465 no_bgp_network_backdoor_cmd,
2466 "no network A.B.C.D/M backdoor",
2467 NO_STR
2468 "Specify a network to announce via BGP\n"
2469 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2470 "Specify a BGP backdoor route\n")
2471
2472DEFUN (no_bgp_network_mask,
2473 no_bgp_network_mask_cmd,
2474 "no network A.B.C.D mask A.B.C.D",
2475 NO_STR
2476 "Specify a network to announce via BGP\n"
2477 "Network number\n"
2478 "Network mask\n"
2479 "Network mask\n")
2480{
2481 int ret;
2482 char prefix_str[BUFSIZ];
2483
2484 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2485 if (! ret)
2486 {
2487 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2488 return CMD_WARNING;
2489 }
2490
2491 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
2492 bgp_node_safi (vty));
2493}
2494
2495ALIAS (no_bgp_network_mask,
2496 no_bgp_network_mask_route_map_cmd,
2497 "no network A.B.C.D mask A.B.C.D route-map WORD",
2498 NO_STR
2499 "Specify a network to announce via BGP\n"
2500 "Network number\n"
2501 "Network mask\n"
2502 "Network mask\n"
2503 "Route-map to modify the attributes\n"
2504 "Name of the route map\n")
2505
2506ALIAS (no_bgp_network_mask,
2507 no_bgp_network_mask_backdoor_cmd,
2508 "no network A.B.C.D mask A.B.C.D backdoor",
2509 NO_STR
2510 "Specify a network to announce via BGP\n"
2511 "Network number\n"
2512 "Network mask\n"
2513 "Network mask\n"
2514 "Specify a BGP backdoor route\n")
2515
2516DEFUN (no_bgp_network_mask_natural,
2517 no_bgp_network_mask_natural_cmd,
2518 "no network A.B.C.D",
2519 NO_STR
2520 "Specify a network to announce via BGP\n"
2521 "Network number\n")
2522{
2523 int ret;
2524 char prefix_str[BUFSIZ];
2525
2526 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2527 if (! ret)
2528 {
2529 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2530 return CMD_WARNING;
2531 }
2532
2533 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
2534 bgp_node_safi (vty));
2535}
2536
2537ALIAS (no_bgp_network_mask_natural,
2538 no_bgp_network_mask_natural_route_map_cmd,
2539 "no network A.B.C.D route-map WORD",
2540 NO_STR
2541 "Specify a network to announce via BGP\n"
2542 "Network number\n"
2543 "Route-map to modify the attributes\n"
2544 "Name of the route map\n")
2545
2546ALIAS (no_bgp_network_mask_natural,
2547 no_bgp_network_mask_natural_backdoor_cmd,
2548 "no network A.B.C.D backdoor",
2549 NO_STR
2550 "Specify a network to announce via BGP\n"
2551 "Network number\n"
2552 "Specify a BGP backdoor route\n")
2553
2554#ifdef HAVE_IPV6
2555DEFUN (ipv6_bgp_network,
2556 ipv6_bgp_network_cmd,
2557 "network X:X::X:X/M",
2558 "Specify a network to announce via BGP\n"
2559 "IPv6 prefix <network>/<length>\n")
2560{
2561 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
2562}
2563
2564DEFUN (ipv6_bgp_network_route_map,
2565 ipv6_bgp_network_route_map_cmd,
2566 "network X:X::X:X/M route-map WORD",
2567 "Specify a network to announce via BGP\n"
2568 "IPv6 prefix <network>/<length>\n"
2569 "Route-map to modify the attributes\n"
2570 "Name of the route map\n")
2571{
2572 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
2573 bgp_node_safi (vty), argv[1], 0);
2574}
2575
2576DEFUN (no_ipv6_bgp_network,
2577 no_ipv6_bgp_network_cmd,
2578 "no network X:X::X:X/M",
2579 NO_STR
2580 "Specify a network to announce via BGP\n"
2581 "IPv6 prefix <network>/<length>\n")
2582{
2583 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
2584}
2585
2586ALIAS (no_ipv6_bgp_network,
2587 no_ipv6_bgp_network_route_map_cmd,
2588 "no network X:X::X:X/M route-map WORD",
2589 NO_STR
2590 "Specify a network to announce via BGP\n"
2591 "IPv6 prefix <network>/<length>\n"
2592 "Route-map to modify the attributes\n"
2593 "Name of the route map\n")
2594
2595ALIAS (ipv6_bgp_network,
2596 old_ipv6_bgp_network_cmd,
2597 "ipv6 bgp network X:X::X:X/M",
2598 IPV6_STR
2599 BGP_STR
2600 "Specify a network to announce via BGP\n"
2601 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2602
2603ALIAS (no_ipv6_bgp_network,
2604 old_no_ipv6_bgp_network_cmd,
2605 "no ipv6 bgp network X:X::X:X/M",
2606 NO_STR
2607 IPV6_STR
2608 BGP_STR
2609 "Specify a network to announce via BGP\n"
2610 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2611#endif /* HAVE_IPV6 */
2612
2613/* Aggreagete address:
2614
2615 advertise-map Set condition to advertise attribute
2616 as-set Generate AS set path information
2617 attribute-map Set attributes of aggregate
2618 route-map Set parameters of aggregate
2619 summary-only Filter more specific routes from updates
2620 suppress-map Conditionally filter more specific routes from updates
2621 <cr>
2622 */
2623struct bgp_aggregate
2624{
2625 /* Summary-only flag. */
2626 u_char summary_only;
2627
2628 /* AS set generation. */
2629 u_char as_set;
2630
2631 /* Route-map for aggregated route. */
2632 struct route_map *map;
2633
2634 /* Suppress-count. */
2635 unsigned long count;
2636
2637 /* SAFI configuration. */
2638 safi_t safi;
2639};
2640
2641struct bgp_aggregate *
2642bgp_aggregate_new ()
2643{
2644 struct bgp_aggregate *new;
2645 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
2646 memset (new, 0, sizeof (struct bgp_aggregate));
2647 return new;
2648}
2649
2650void
2651bgp_aggregate_free (struct bgp_aggregate *aggregate)
2652{
2653 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
2654}
2655
2656void
2657bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
2658 afi_t afi, safi_t safi, struct bgp_info *del,
2659 struct bgp_aggregate *aggregate)
2660{
2661 struct bgp_table *table;
2662 struct bgp_node *top;
2663 struct bgp_node *rn;
2664 u_char origin;
2665 struct aspath *aspath = NULL;
2666 struct aspath *asmerge = NULL;
2667 struct community *community = NULL;
2668 struct community *commerge = NULL;
2669 struct in_addr nexthop;
2670 u_int32_t med = 0;
2671 struct bgp_info *ri;
2672 struct bgp_info *new;
2673 int first = 1;
2674 unsigned long match = 0;
2675
2676 /* Record adding route's nexthop and med. */
2677 if (rinew)
2678 {
2679 nexthop = rinew->attr->nexthop;
2680 med = rinew->attr->med;
2681 }
2682
2683 /* ORIGIN attribute: If at least one route among routes that are
2684 aggregated has ORIGIN with the value INCOMPLETE, then the
2685 aggregated route must have the ORIGIN attribute with the value
2686 INCOMPLETE. Otherwise, if at least one route among routes that
2687 are aggregated has ORIGIN with the value EGP, then the aggregated
2688 route must have the origin attribute with the value EGP. In all
2689 other case the value of the ORIGIN attribute of the aggregated
2690 route is INTERNAL. */
2691 origin = BGP_ORIGIN_IGP;
2692
2693 table = bgp->rib[afi][safi];
2694
2695 top = bgp_node_get (table, p);
2696 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
2697 if (rn->p.prefixlen > p->prefixlen)
2698 {
2699 match = 0;
2700
2701 for (ri = rn->info; ri; ri = ri->next)
2702 {
2703 if (BGP_INFO_HOLDDOWN (ri))
2704 continue;
2705
2706 if (del && ri == del)
2707 continue;
2708
2709 if (! rinew && first)
2710 {
2711 nexthop = ri->attr->nexthop;
2712 med = ri->attr->med;
2713 first = 0;
2714 }
2715
2716#ifdef AGGREGATE_NEXTHOP_CHECK
2717 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
2718 || ri->attr->med != med)
2719 {
2720 if (aspath)
2721 aspath_free (aspath);
2722 if (community)
2723 community_free (community);
2724 bgp_unlock_node (rn);
2725 bgp_unlock_node (top);
2726 return;
2727 }
2728#endif /* AGGREGATE_NEXTHOP_CHECK */
2729
2730 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
2731 {
2732 if (aggregate->summary_only)
2733 {
2734 ri->suppress++;
2735 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2736 match++;
2737 }
2738
2739 aggregate->count++;
2740
2741 if (aggregate->as_set)
2742 {
2743 if (origin < ri->attr->origin)
2744 origin = ri->attr->origin;
2745
2746 if (aspath)
2747 {
2748 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
2749 aspath_free (aspath);
2750 aspath = asmerge;
2751 }
2752 else
2753 aspath = aspath_dup (ri->attr->aspath);
2754
2755 if (ri->attr->community)
2756 {
2757 if (community)
2758 {
2759 commerge = community_merge (community,
2760 ri->attr->community);
2761 community = community_uniq_sort (commerge);
2762 community_free (commerge);
2763 }
2764 else
2765 community = community_dup (ri->attr->community);
2766 }
2767 }
2768 }
2769 }
2770 if (match)
2771 bgp_process (bgp, rn, afi, safi);
2772 }
2773 bgp_unlock_node (top);
2774
2775 if (rinew)
2776 {
2777 aggregate->count++;
2778
2779 if (aggregate->summary_only)
2780 rinew->suppress++;
2781
2782 if (aggregate->as_set)
2783 {
2784 if (origin < rinew->attr->origin)
2785 origin = rinew->attr->origin;
2786
2787 if (aspath)
2788 {
2789 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
2790 aspath_free (aspath);
2791 aspath = asmerge;
2792 }
2793 else
2794 aspath = aspath_dup (rinew->attr->aspath);
2795
2796 if (rinew->attr->community)
2797 {
2798 if (community)
2799 {
2800 commerge = community_merge (community,
2801 rinew->attr->community);
2802 community = community_uniq_sort (commerge);
2803 community_free (commerge);
2804 }
2805 else
2806 community = community_dup (rinew->attr->community);
2807 }
2808 }
2809 }
2810
2811 if (aggregate->count > 0)
2812 {
2813 rn = bgp_node_get (table, p);
2814 new = bgp_info_new ();
2815 new->type = ZEBRA_ROUTE_BGP;
2816 new->sub_type = BGP_ROUTE_AGGREGATE;
2817 new->peer = bgp->peer_self;
2818 SET_FLAG (new->flags, BGP_INFO_VALID);
2819 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
2820 new->uptime = time (NULL);
2821
2822 bgp_info_add (rn, new);
2823 bgp_process (bgp, rn, afi, safi);
2824 }
2825 else
2826 {
2827 if (aspath)
2828 aspath_free (aspath);
2829 if (community)
2830 community_free (community);
2831 }
2832}
2833
2834void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
2835 struct bgp_aggregate *);
2836
2837void
2838bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
2839 struct bgp_info *ri, afi_t afi, safi_t safi)
2840{
2841 struct bgp_node *child;
2842 struct bgp_node *rn;
2843 struct bgp_aggregate *aggregate;
2844
2845 /* MPLS-VPN aggregation is not yet supported. */
2846 if (safi == SAFI_MPLS_VPN)
2847 return;
2848
2849 if (p->prefixlen == 0)
2850 return;
2851
2852 if (BGP_INFO_HOLDDOWN (ri))
2853 return;
2854
2855 child = bgp_node_get (bgp->aggregate[afi][safi], p);
2856
2857 /* Aggregate address configuration check. */
2858 for (rn = child; rn; rn = rn->parent)
2859 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
2860 {
2861 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
2862 bgp_aggregate_route (bgp, &rn->p, ri, safi, safi, NULL, aggregate);
2863 }
2864 bgp_unlock_node (child);
2865}
2866
2867void
2868bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
2869 struct bgp_info *del, afi_t afi, safi_t safi)
2870{
2871 struct bgp_node *child;
2872 struct bgp_node *rn;
2873 struct bgp_aggregate *aggregate;
2874
2875 /* MPLS-VPN aggregation is not yet supported. */
2876 if (safi == SAFI_MPLS_VPN)
2877 return;
2878
2879 if (p->prefixlen == 0)
2880 return;
2881
2882 child = bgp_node_get (bgp->aggregate[afi][safi], p);
2883
2884 /* Aggregate address configuration check. */
2885 for (rn = child; rn; rn = rn->parent)
2886 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
2887 {
2888 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
2889 bgp_aggregate_route (bgp, &rn->p, NULL, safi, safi, del, aggregate);
2890 }
2891 bgp_unlock_node (child);
2892}
2893
2894void
2895bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
2896 struct bgp_aggregate *aggregate)
2897{
2898 struct bgp_table *table;
2899 struct bgp_node *top;
2900 struct bgp_node *rn;
2901 struct bgp_info *new;
2902 struct bgp_info *ri;
2903 unsigned long match;
2904 u_char origin = BGP_ORIGIN_IGP;
2905 struct aspath *aspath = NULL;
2906 struct aspath *asmerge = NULL;
2907 struct community *community = NULL;
2908 struct community *commerge = NULL;
2909
2910 table = bgp->rib[afi][safi];
2911
2912 /* Sanity check. */
2913 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
2914 return;
2915 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
2916 return;
2917
2918 /* If routes exists below this node, generate aggregate routes. */
2919 top = bgp_node_get (table, p);
2920 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
2921 if (rn->p.prefixlen > p->prefixlen)
2922 {
2923 match = 0;
2924
2925 for (ri = rn->info; ri; ri = ri->next)
2926 {
2927 if (BGP_INFO_HOLDDOWN (ri))
2928 continue;
2929
2930 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
2931 {
2932 /* summary-only aggregate route suppress aggregated
2933 route announcement. */
2934 if (aggregate->summary_only)
2935 {
2936 ri->suppress++;
2937 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2938 match++;
2939 }
2940 /* as-set aggregate route generate origin, as path,
2941 community aggregation. */
2942 if (aggregate->as_set)
2943 {
2944 if (origin < ri->attr->origin)
2945 origin = ri->attr->origin;
2946
2947 if (aspath)
2948 {
2949 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
2950 aspath_free (aspath);
2951 aspath = asmerge;
2952 }
2953 else
2954 aspath = aspath_dup (ri->attr->aspath);
2955
2956 if (ri->attr->community)
2957 {
2958 if (community)
2959 {
2960 commerge = community_merge (community,
2961 ri->attr->community);
2962 community = community_uniq_sort (commerge);
2963 community_free (commerge);
2964 }
2965 else
2966 community = community_dup (ri->attr->community);
2967 }
2968 }
2969 aggregate->count++;
2970 }
2971 }
2972
2973 /* If this node is suppressed, process the change. */
2974 if (match)
2975 bgp_process (bgp, rn, afi, safi);
2976 }
2977 bgp_unlock_node (top);
2978
2979 /* Add aggregate route to BGP table. */
2980 if (aggregate->count)
2981 {
2982 rn = bgp_node_get (table, p);
2983
2984 new = bgp_info_new ();
2985 new->type = ZEBRA_ROUTE_BGP;
2986 new->sub_type = BGP_ROUTE_AGGREGATE;
2987 new->peer = bgp->peer_self;
2988 SET_FLAG (new->flags, BGP_INFO_VALID);
2989 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
2990 new->uptime = time (NULL);
2991
2992 bgp_info_add (rn, new);
2993
2994 /* Process change. */
2995 bgp_process (bgp, rn, afi, safi);
2996 }
2997}
2998
2999void
3000bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
3001 safi_t safi, struct bgp_aggregate *aggregate)
3002{
3003 struct bgp_table *table;
3004 struct bgp_node *top;
3005 struct bgp_node *rn;
3006 struct bgp_info *ri;
3007 unsigned long match;
3008
3009 table = bgp->rib[afi][safi];
3010
3011 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
3012 return;
3013 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
3014 return;
3015
3016 /* If routes exists below this node, generate aggregate routes. */
3017 top = bgp_node_get (table, p);
3018 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
3019 if (rn->p.prefixlen > p->prefixlen)
3020 {
3021 match = 0;
3022
3023 for (ri = rn->info; ri; ri = ri->next)
3024 {
3025 if (BGP_INFO_HOLDDOWN (ri))
3026 continue;
3027
3028 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
3029 {
3030 if (aggregate->summary_only)
3031 {
3032 ri->suppress--;
3033
3034 if (ri->suppress == 0)
3035 {
3036 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3037 match++;
3038 }
3039 }
3040 aggregate->count--;
3041 }
3042 }
3043
3044 /* If this node is suppressed, process the change. */
3045 if (match)
3046 bgp_process (bgp, rn, afi, safi);
3047 }
3048 bgp_unlock_node (top);
3049
3050 /* Delete aggregate route from BGP table. */
3051 rn = bgp_node_get (table, p);
3052
3053 for (ri = rn->info; ri; ri = ri->next)
3054 if (ri->peer == bgp->peer_self
3055 && ri->type == ZEBRA_ROUTE_BGP
3056 && ri->sub_type == BGP_ROUTE_AGGREGATE)
3057 break;
3058
3059 /* Withdraw static BGP route from routing table. */
3060 if (ri)
3061 {
3062 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3063 bgp_process (bgp, rn, afi, safi);
3064 bgp_info_delete (rn, ri);
3065 bgp_info_free (ri);
3066 bgp_unlock_node (rn);
3067 }
3068
3069 /* Unlock bgp_node_lookup. */
3070 bgp_unlock_node (rn);
3071}
3072
3073/* Aggregate route attribute. */
3074#define AGGREGATE_SUMMARY_ONLY 1
3075#define AGGREGATE_AS_SET 1
3076
3077int
3078bgp_aggregate_set (struct vty *vty, char *prefix_str, afi_t afi, safi_t safi,
3079 u_char summary_only, u_char as_set)
3080{
3081 int ret;
3082 struct prefix p;
3083 struct bgp_node *rn;
3084 struct bgp *bgp;
3085 struct bgp_aggregate *aggregate;
3086
3087 /* Convert string to prefix structure. */
3088 ret = str2prefix (prefix_str, &p);
3089 if (!ret)
3090 {
3091 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
3092 return CMD_WARNING;
3093 }
3094 apply_mask (&p);
3095
3096 /* Get BGP structure. */
3097 bgp = vty->index;
3098
3099 /* Old configuration check. */
3100 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
3101
3102 if (rn->info)
3103 {
3104 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
3105 bgp_unlock_node (rn);
3106 return CMD_WARNING;
3107 }
3108
3109 /* Make aggregate address structure. */
3110 aggregate = bgp_aggregate_new ();
3111 aggregate->summary_only = summary_only;
3112 aggregate->as_set = as_set;
3113 aggregate->safi = safi;
3114 rn->info = aggregate;
3115
3116 /* Aggregate address insert into BGP routing table. */
3117 if (safi & SAFI_UNICAST)
3118 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
3119 if (safi & SAFI_MULTICAST)
3120 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
3121
3122 return CMD_SUCCESS;
3123}
3124
3125int
3126bgp_aggregate_unset (struct vty *vty, char *prefix_str, afi_t afi, safi_t safi)
3127{
3128 int ret;
3129 struct prefix p;
3130 struct bgp_node *rn;
3131 struct bgp *bgp;
3132 struct bgp_aggregate *aggregate;
3133
3134 /* Convert string to prefix structure. */
3135 ret = str2prefix (prefix_str, &p);
3136 if (!ret)
3137 {
3138 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
3139 return CMD_WARNING;
3140 }
3141 apply_mask (&p);
3142
3143 /* Get BGP structure. */
3144 bgp = vty->index;
3145
3146 /* Old configuration check. */
3147 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
3148 if (! rn)
3149 {
3150 vty_out (vty, "%% There is no aggregate-address configuration.%s",
3151 VTY_NEWLINE);
3152 return CMD_WARNING;
3153 }
3154
3155 aggregate = rn->info;
3156 if (aggregate->safi & SAFI_UNICAST)
3157 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
3158 if (aggregate->safi & SAFI_MULTICAST)
3159 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
3160
3161 /* Unlock aggregate address configuration. */
3162 rn->info = NULL;
3163 bgp_aggregate_free (aggregate);
3164 bgp_unlock_node (rn);
3165 bgp_unlock_node (rn);
3166
3167 return CMD_SUCCESS;
3168}
3169
3170DEFUN (aggregate_address,
3171 aggregate_address_cmd,
3172 "aggregate-address A.B.C.D/M",
3173 "Configure BGP aggregate entries\n"
3174 "Aggregate prefix\n")
3175{
3176 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
3177}
3178
3179DEFUN (aggregate_address_mask,
3180 aggregate_address_mask_cmd,
3181 "aggregate-address A.B.C.D A.B.C.D",
3182 "Configure BGP aggregate entries\n"
3183 "Aggregate address\n"
3184 "Aggregate mask\n")
3185{
3186 int ret;
3187 char prefix_str[BUFSIZ];
3188
3189 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3190
3191 if (! ret)
3192 {
3193 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3194 return CMD_WARNING;
3195 }
3196
3197 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3198 0, 0);
3199}
3200
3201DEFUN (aggregate_address_summary_only,
3202 aggregate_address_summary_only_cmd,
3203 "aggregate-address A.B.C.D/M summary-only",
3204 "Configure BGP aggregate entries\n"
3205 "Aggregate prefix\n"
3206 "Filter more specific routes from updates\n")
3207{
3208 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3209 AGGREGATE_SUMMARY_ONLY, 0);
3210}
3211
3212DEFUN (aggregate_address_mask_summary_only,
3213 aggregate_address_mask_summary_only_cmd,
3214 "aggregate-address A.B.C.D A.B.C.D summary-only",
3215 "Configure BGP aggregate entries\n"
3216 "Aggregate address\n"
3217 "Aggregate mask\n"
3218 "Filter more specific routes from updates\n")
3219{
3220 int ret;
3221 char prefix_str[BUFSIZ];
3222
3223 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3224
3225 if (! ret)
3226 {
3227 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3228 return CMD_WARNING;
3229 }
3230
3231 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3232 AGGREGATE_SUMMARY_ONLY, 0);
3233}
3234
3235DEFUN (aggregate_address_as_set,
3236 aggregate_address_as_set_cmd,
3237 "aggregate-address A.B.C.D/M as-set",
3238 "Configure BGP aggregate entries\n"
3239 "Aggregate prefix\n"
3240 "Generate AS set path information\n")
3241{
3242 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3243 0, AGGREGATE_AS_SET);
3244}
3245
3246DEFUN (aggregate_address_mask_as_set,
3247 aggregate_address_mask_as_set_cmd,
3248 "aggregate-address A.B.C.D A.B.C.D as-set",
3249 "Configure BGP aggregate entries\n"
3250 "Aggregate address\n"
3251 "Aggregate mask\n"
3252 "Generate AS set path information\n")
3253{
3254 int ret;
3255 char prefix_str[BUFSIZ];
3256
3257 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3258
3259 if (! ret)
3260 {
3261 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3262 return CMD_WARNING;
3263 }
3264
3265 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3266 0, AGGREGATE_AS_SET);
3267}
3268
3269
3270DEFUN (aggregate_address_as_set_summary,
3271 aggregate_address_as_set_summary_cmd,
3272 "aggregate-address A.B.C.D/M as-set summary-only",
3273 "Configure BGP aggregate entries\n"
3274 "Aggregate prefix\n"
3275 "Generate AS set path information\n"
3276 "Filter more specific routes from updates\n")
3277{
3278 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3279 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
3280}
3281
3282ALIAS (aggregate_address_as_set_summary,
3283 aggregate_address_summary_as_set_cmd,
3284 "aggregate-address A.B.C.D/M summary-only as-set",
3285 "Configure BGP aggregate entries\n"
3286 "Aggregate prefix\n"
3287 "Filter more specific routes from updates\n"
3288 "Generate AS set path information\n")
3289
3290DEFUN (aggregate_address_mask_as_set_summary,
3291 aggregate_address_mask_as_set_summary_cmd,
3292 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
3293 "Configure BGP aggregate entries\n"
3294 "Aggregate address\n"
3295 "Aggregate mask\n"
3296 "Generate AS set path information\n"
3297 "Filter more specific routes from updates\n")
3298{
3299 int ret;
3300 char prefix_str[BUFSIZ];
3301
3302 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3303
3304 if (! ret)
3305 {
3306 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3307 return CMD_WARNING;
3308 }
3309
3310 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3311 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
3312}
3313
3314ALIAS (aggregate_address_mask_as_set_summary,
3315 aggregate_address_mask_summary_as_set_cmd,
3316 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
3317 "Configure BGP aggregate entries\n"
3318 "Aggregate address\n"
3319 "Aggregate mask\n"
3320 "Filter more specific routes from updates\n"
3321 "Generate AS set path information\n")
3322
3323DEFUN (no_aggregate_address,
3324 no_aggregate_address_cmd,
3325 "no aggregate-address A.B.C.D/M",
3326 NO_STR
3327 "Configure BGP aggregate entries\n"
3328 "Aggregate prefix\n")
3329{
3330 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
3331}
3332
3333ALIAS (no_aggregate_address,
3334 no_aggregate_address_summary_only_cmd,
3335 "no aggregate-address A.B.C.D/M summary-only",
3336 NO_STR
3337 "Configure BGP aggregate entries\n"
3338 "Aggregate prefix\n"
3339 "Filter more specific routes from updates\n")
3340
3341ALIAS (no_aggregate_address,
3342 no_aggregate_address_as_set_cmd,
3343 "no aggregate-address A.B.C.D/M as-set",
3344 NO_STR
3345 "Configure BGP aggregate entries\n"
3346 "Aggregate prefix\n"
3347 "Generate AS set path information\n")
3348
3349ALIAS (no_aggregate_address,
3350 no_aggregate_address_as_set_summary_cmd,
3351 "no aggregate-address A.B.C.D/M as-set summary-only",
3352 NO_STR
3353 "Configure BGP aggregate entries\n"
3354 "Aggregate prefix\n"
3355 "Generate AS set path information\n"
3356 "Filter more specific routes from updates\n")
3357
3358ALIAS (no_aggregate_address,
3359 no_aggregate_address_summary_as_set_cmd,
3360 "no aggregate-address A.B.C.D/M summary-only as-set",
3361 NO_STR
3362 "Configure BGP aggregate entries\n"
3363 "Aggregate prefix\n"
3364 "Filter more specific routes from updates\n"
3365 "Generate AS set path information\n")
3366
3367DEFUN (no_aggregate_address_mask,
3368 no_aggregate_address_mask_cmd,
3369 "no aggregate-address A.B.C.D A.B.C.D",
3370 NO_STR
3371 "Configure BGP aggregate entries\n"
3372 "Aggregate address\n"
3373 "Aggregate mask\n")
3374{
3375 int ret;
3376 char prefix_str[BUFSIZ];
3377
3378 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3379
3380 if (! ret)
3381 {
3382 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3383 return CMD_WARNING;
3384 }
3385
3386 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
3387}
3388
3389ALIAS (no_aggregate_address_mask,
3390 no_aggregate_address_mask_summary_only_cmd,
3391 "no aggregate-address A.B.C.D A.B.C.D summary-only",
3392 NO_STR
3393 "Configure BGP aggregate entries\n"
3394 "Aggregate address\n"
3395 "Aggregate mask\n"
3396 "Filter more specific routes from updates\n")
3397
3398ALIAS (no_aggregate_address_mask,
3399 no_aggregate_address_mask_as_set_cmd,
3400 "no aggregate-address A.B.C.D A.B.C.D as-set",
3401 NO_STR
3402 "Configure BGP aggregate entries\n"
3403 "Aggregate address\n"
3404 "Aggregate mask\n"
3405 "Generate AS set path information\n")
3406
3407ALIAS (no_aggregate_address_mask,
3408 no_aggregate_address_mask_as_set_summary_cmd,
3409 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
3410 NO_STR
3411 "Configure BGP aggregate entries\n"
3412 "Aggregate address\n"
3413 "Aggregate mask\n"
3414 "Generate AS set path information\n"
3415 "Filter more specific routes from updates\n")
3416
3417ALIAS (no_aggregate_address_mask,
3418 no_aggregate_address_mask_summary_as_set_cmd,
3419 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
3420 NO_STR
3421 "Configure BGP aggregate entries\n"
3422 "Aggregate address\n"
3423 "Aggregate mask\n"
3424 "Filter more specific routes from updates\n"
3425 "Generate AS set path information\n")
3426
3427#ifdef HAVE_IPV6
3428DEFUN (ipv6_aggregate_address,
3429 ipv6_aggregate_address_cmd,
3430 "aggregate-address X:X::X:X/M",
3431 "Configure BGP aggregate entries\n"
3432 "Aggregate prefix\n")
3433{
3434 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
3435}
3436
3437DEFUN (ipv6_aggregate_address_summary_only,
3438 ipv6_aggregate_address_summary_only_cmd,
3439 "aggregate-address X:X::X:X/M summary-only",
3440 "Configure BGP aggregate entries\n"
3441 "Aggregate prefix\n"
3442 "Filter more specific routes from updates\n")
3443{
3444 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3445 AGGREGATE_SUMMARY_ONLY, 0);
3446}
3447
3448DEFUN (no_ipv6_aggregate_address,
3449 no_ipv6_aggregate_address_cmd,
3450 "no aggregate-address X:X::X:X/M",
3451 NO_STR
3452 "Configure BGP aggregate entries\n"
3453 "Aggregate prefix\n")
3454{
3455 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
3456}
3457
3458DEFUN (no_ipv6_aggregate_address_summary_only,
3459 no_ipv6_aggregate_address_summary_only_cmd,
3460 "no aggregate-address X:X::X:X/M summary-only",
3461 NO_STR
3462 "Configure BGP aggregate entries\n"
3463 "Aggregate prefix\n"
3464 "Filter more specific routes from updates\n")
3465{
3466 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
3467}
3468
3469ALIAS (ipv6_aggregate_address,
3470 old_ipv6_aggregate_address_cmd,
3471 "ipv6 bgp aggregate-address X:X::X:X/M",
3472 IPV6_STR
3473 BGP_STR
3474 "Configure BGP aggregate entries\n"
3475 "Aggregate prefix\n")
3476
3477ALIAS (ipv6_aggregate_address_summary_only,
3478 old_ipv6_aggregate_address_summary_only_cmd,
3479 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
3480 IPV6_STR
3481 BGP_STR
3482 "Configure BGP aggregate entries\n"
3483 "Aggregate prefix\n"
3484 "Filter more specific routes from updates\n")
3485
3486ALIAS (no_ipv6_aggregate_address,
3487 old_no_ipv6_aggregate_address_cmd,
3488 "no ipv6 bgp aggregate-address X:X::X:X/M",
3489 NO_STR
3490 IPV6_STR
3491 BGP_STR
3492 "Configure BGP aggregate entries\n"
3493 "Aggregate prefix\n")
3494
3495ALIAS (no_ipv6_aggregate_address_summary_only,
3496 old_no_ipv6_aggregate_address_summary_only_cmd,
3497 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
3498 NO_STR
3499 IPV6_STR
3500 BGP_STR
3501 "Configure BGP aggregate entries\n"
3502 "Aggregate prefix\n"
3503 "Filter more specific routes from updates\n")
3504#endif /* HAVE_IPV6 */
3505
3506/* Redistribute route treatment. */
3507void
3508bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
3509 u_int32_t metric, u_char type)
3510{
3511 struct bgp *bgp;
3512 struct listnode *nn;
3513 struct bgp_info *new;
3514 struct bgp_info *bi;
3515 struct bgp_info info;
3516 struct bgp_node *bn;
3517 struct attr attr;
3518 struct attr attr_new;
3519 struct attr *new_attr;
3520 afi_t afi;
3521 int ret;
3522
3523 /* Make default attribute. */
3524 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
3525 if (nexthop)
3526 attr.nexthop = *nexthop;
3527
3528 attr.med = metric;
3529 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3530
3531 LIST_LOOP (bm->bgp, bgp, nn)
3532 {
3533 afi = family2afi (p->family);
3534
3535 if (bgp->redist[afi][type])
3536 {
3537 /* Copy attribute for modification. */
3538 attr_new = attr;
3539
3540 if (bgp->redist_metric_flag[afi][type])
3541 attr_new.med = bgp->redist_metric[afi][type];
3542
3543 /* Apply route-map. */
3544 if (bgp->rmap[afi][type].map)
3545 {
3546 info.peer = bgp->peer_self;
3547 info.attr = &attr_new;
3548
3549 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
3550 &info);
3551 if (ret == RMAP_DENYMATCH)
3552 {
3553 /* Free uninterned attribute. */
3554 bgp_attr_flush (&attr_new);
3555
3556 /* Unintern original. */
3557 aspath_unintern (attr.aspath);
3558 bgp_redistribute_delete (p, type);
3559 return;
3560 }
3561 }
3562
3563 bn = bgp_afi_node_get (bgp, afi, SAFI_UNICAST, p, NULL);
3564 new_attr = bgp_attr_intern (&attr_new);
3565
3566 for (bi = bn->info; bi; bi = bi->next)
3567 if (bi->peer == bgp->peer_self
3568 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
3569 break;
3570
3571 if (bi)
3572 {
3573 if (attrhash_cmp (bi->attr, new_attr))
3574 {
3575 bgp_attr_unintern (new_attr);
3576 aspath_unintern (attr.aspath);
3577 bgp_unlock_node (bn);
3578 return;
3579 }
3580 else
3581 {
3582 /* The attribute is changed. */
3583 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
3584
3585 /* Rewrite BGP route information. */
3586 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
3587 bgp_attr_unintern (bi->attr);
3588 bi->attr = new_attr;
3589 bi->uptime = time (NULL);
3590
3591 /* Process change. */
3592 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
3593 bgp_process (bgp, bn, afi, SAFI_UNICAST);
3594 bgp_unlock_node (bn);
3595 aspath_unintern (attr.aspath);
3596 return;
3597 }
3598 }
3599
3600 new = bgp_info_new ();
3601 new->type = type;
3602 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
3603 new->peer = bgp->peer_self;
3604 SET_FLAG (new->flags, BGP_INFO_VALID);
3605 new->attr = new_attr;
3606 new->uptime = time (NULL);
3607
3608 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
3609 bgp_info_add (bn, new);
3610 bgp_process (bgp, bn, afi, SAFI_UNICAST);
3611 }
3612 }
3613
3614 /* Unintern original. */
3615 aspath_unintern (attr.aspath);
3616}
3617
3618void
3619bgp_redistribute_delete (struct prefix *p, u_char type)
3620{
3621 struct bgp *bgp;
3622 struct listnode *nn;
3623 afi_t afi;
3624 struct bgp_node *rn;
3625 struct bgp_info *ri;
3626
3627 LIST_LOOP (bm->bgp, bgp, nn)
3628 {
3629 afi = family2afi (p->family);
3630
3631 if (bgp->redist[afi][type])
3632 {
3633 rn = bgp_afi_node_get (bgp, afi, SAFI_UNICAST, p, NULL);
3634
3635 for (ri = rn->info; ri; ri = ri->next)
3636 if (ri->peer == bgp->peer_self
3637 && ri->type == type)
3638 break;
3639
3640 if (ri)
3641 {
3642 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
3643 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3644 bgp_process (bgp, rn, afi, SAFI_UNICAST);
3645 bgp_info_delete (rn, ri);
3646 bgp_info_free (ri);
3647 bgp_unlock_node (rn);
3648 }
3649 bgp_unlock_node (rn);
3650 }
3651 }
3652}
3653
3654/* Withdraw specified route type's route. */
3655void
3656bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
3657{
3658 struct bgp_node *rn;
3659 struct bgp_info *ri;
3660 struct bgp_table *table;
3661
3662 table = bgp->rib[afi][SAFI_UNICAST];
3663
3664 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3665 {
3666 for (ri = rn->info; ri; ri = ri->next)
3667 if (ri->peer == bgp->peer_self
3668 && ri->type == type)
3669 break;
3670
3671 if (ri)
3672 {
3673 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
3674 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3675 bgp_process (bgp, rn, afi, SAFI_UNICAST);
3676 bgp_info_delete (rn, ri);
3677 bgp_info_free (ri);
3678 bgp_unlock_node (rn);
3679 }
3680 }
3681}
3682
3683/* Static function to display route. */
3684void
3685route_vty_out_route (struct prefix *p, struct vty *vty)
3686{
3687 int len;
3688 u_int32_t destination;
3689 char buf[BUFSIZ];
3690
3691 if (p->family == AF_INET)
3692 {
3693 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
3694 destination = ntohl (p->u.prefix4.s_addr);
3695
3696 if ((IN_CLASSC (destination) && p->prefixlen == 24)
3697 || (IN_CLASSB (destination) && p->prefixlen == 16)
3698 || (IN_CLASSA (destination) && p->prefixlen == 8)
3699 || p->u.prefix4.s_addr == 0)
3700 {
3701 /* When mask is natural, mask is not displayed. */
3702 }
3703 else
3704 len += vty_out (vty, "/%d", p->prefixlen);
3705 }
3706 else
3707 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
3708 p->prefixlen);
3709
3710 len = 17 - len;
3711 if (len < 1)
3712 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
3713 else
3714 vty_out (vty, "%*s", len, " ");
3715}
3716
3717/* Calculate line number of output data. */
3718int
3719vty_calc_line (struct vty *vty, unsigned long length)
3720{
3721 return vty->width ? (((vty->obuf->length - length) / vty->width) + 1) : 1;
3722}
3723
3724enum bgp_display_type
3725{
3726 normal_list,
3727};
3728
3729/* called from terminal list command */
3730int
3731route_vty_out (struct vty *vty, struct prefix *p,
3732 struct bgp_info *binfo, int display, safi_t safi)
3733{
3734 struct attr *attr;
3735 unsigned long length = 0;
3736
3737 length = vty->obuf->length;
3738
3739 /* Route status display. */
3740 if (binfo->suppress)
3741 vty_out (vty, "s");
3742 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3743 vty_out (vty, "*");
3744 else
3745 vty_out (vty, " ");
3746
3747 /* Selected */
3748 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3749 vty_out (vty, "h");
3750 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
3751 vty_out (vty, "d");
3752 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
3753 vty_out (vty, ">");
3754 else
3755 vty_out (vty, " ");
3756
3757 /* Internal route. */
3758 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
3759 vty_out (vty, "i");
3760 else
3761 vty_out (vty, " ");
3762
3763 /* print prefix and mask */
3764 if (! display)
3765 route_vty_out_route (p, vty);
3766 else
3767 vty_out (vty, "%*s", 17, " ");
3768
3769 /* Print attribute */
3770 attr = binfo->attr;
3771 if (attr)
3772 {
3773 if (p->family == AF_INET)
3774 {
3775 if (safi == SAFI_MPLS_VPN)
3776 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3777 else
3778 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3779 }
3780#ifdef HAVE_IPV6
3781 else if (p->family == AF_INET6)
3782 {
3783 int len;
3784 char buf[BUFSIZ];
3785
3786 len = vty_out (vty, "%s",
3787 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
3788 len = 16 - len;
3789 if (len < 1)
3790 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
3791 else
3792 vty_out (vty, "%*s", len, " ");
3793 }
3794#endif /* HAVE_IPV6 */
3795
3796 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
3797 vty_out (vty, "%10d", attr->med);
3798 else
3799 vty_out (vty, " ");
3800
3801 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
3802 vty_out (vty, "%7d", attr->local_pref);
3803 else
3804 vty_out (vty, " ");
3805
3806 vty_out (vty, "%7u ",attr->weight);
3807
3808 /* Print aspath */
3809 if (attr->aspath)
3810 aspath_print_vty (vty, attr->aspath);
3811
3812 /* Print origin */
3813 if (strlen (attr->aspath->str) == 0)
3814 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
3815 else
3816 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
3817 }
3818 vty_out (vty, "%s", VTY_NEWLINE);
3819
3820 return vty_calc_line (vty, length);
3821}
3822
3823/* called from terminal list command */
3824void
3825route_vty_out_tmp (struct vty *vty, struct prefix *p,
3826 struct attr *attr, safi_t safi)
3827{
3828 /* Route status display. */
3829 vty_out (vty, "*");
3830 vty_out (vty, ">");
3831 vty_out (vty, " ");
3832
3833 /* print prefix and mask */
3834 route_vty_out_route (p, vty);
3835
3836 /* Print attribute */
3837 if (attr)
3838 {
3839 if (p->family == AF_INET)
3840 {
3841 if (safi == SAFI_MPLS_VPN)
3842 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3843 else
3844 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3845 }
3846#ifdef HAVE_IPV6
3847 else if (p->family == AF_INET6)
3848 {
3849 int len;
3850 char buf[BUFSIZ];
3851
3852 len = vty_out (vty, "%s",
3853 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
3854 len = 16 - len;
3855 if (len < 1)
3856 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
3857 else
3858 vty_out (vty, "%*s", len, " ");
3859 }
3860#endif /* HAVE_IPV6 */
3861
3862 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
3863 vty_out (vty, "%10d", attr->med);
3864 else
3865 vty_out (vty, " ");
3866
3867 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
3868 vty_out (vty, "%7d", attr->local_pref);
3869 else
3870 vty_out (vty, " ");
3871
3872 vty_out (vty, "%7d ",attr->weight);
3873
3874 /* Print aspath */
3875 if (attr->aspath)
3876 aspath_print_vty (vty, attr->aspath);
3877
3878 /* Print origin */
3879 if (strlen (attr->aspath->str) == 0)
3880 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
3881 else
3882 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
3883 }
3884
3885 vty_out (vty, "%s", VTY_NEWLINE);
3886}
3887
3888int
3889route_vty_out_tag (struct vty *vty, struct prefix *p,
3890 struct bgp_info *binfo, int display, safi_t safi)
3891{
3892 struct attr *attr;
3893 unsigned long length = 0;
3894 u_int32_t label = 0;
3895
3896 length = vty->obuf->length;
3897
3898 /* Route status display. */
3899 if (binfo->suppress)
3900 vty_out (vty, "s");
3901 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3902 vty_out (vty, "*");
3903 else
3904 vty_out (vty, " ");
3905
3906 /* Selected */
3907 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3908 vty_out (vty, "h");
3909 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
3910 vty_out (vty, "d");
3911 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
3912 vty_out (vty, ">");
3913 else
3914 vty_out (vty, " ");
3915
3916 /* Internal route. */
3917 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
3918 vty_out (vty, "i");
3919 else
3920 vty_out (vty, " ");
3921
3922 /* print prefix and mask */
3923 if (! display)
3924 route_vty_out_route (p, vty);
3925 else
3926 vty_out (vty, "%*s", 17, " ");
3927
3928 /* Print attribute */
3929 attr = binfo->attr;
3930 if (attr)
3931 {
3932 if (p->family == AF_INET)
3933 {
3934 if (safi == SAFI_MPLS_VPN)
3935 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3936 else
3937 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3938 }
3939#ifdef HAVE_IPV6
3940 else if (p->family == AF_INET6)
3941 {
3942 char buf[BUFSIZ];
3943 char buf1[BUFSIZ];
3944 if (attr->mp_nexthop_len == 16)
3945 vty_out (vty, "%s",
3946 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
3947 else if (attr->mp_nexthop_len == 32)
3948 vty_out (vty, "%s(%s)",
3949 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
3950 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
3951
3952 }
3953#endif /* HAVE_IPV6 */
3954 }
3955
3956 label = decode_label (binfo->tag);
3957
3958 vty_out (vty, "notag/%d", label);
3959
3960 vty_out (vty, "%s", VTY_NEWLINE);
3961
3962 return vty_calc_line (vty, length);
3963}
3964
3965/* dampening route */
3966int
3967damp_route_vty_out (struct vty *vty, struct prefix *p,
3968 struct bgp_info *binfo, int display, safi_t safi)
3969{
3970 struct attr *attr;
3971 unsigned long length = 0;
3972 int len;
3973
3974 length = vty->obuf->length;
3975
3976 /* Route status display. */
3977 if (binfo->suppress)
3978 vty_out (vty, "s");
3979 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3980 vty_out (vty, "*");
3981 else
3982 vty_out (vty, " ");
3983
3984 /* Selected */
3985 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3986 vty_out (vty, "h");
3987 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
3988 vty_out (vty, "d");
3989 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
3990 vty_out (vty, ">");
3991 else
3992 vty_out (vty, " ");
3993
3994 vty_out (vty, " ");
3995
3996 /* print prefix and mask */
3997 if (! display)
3998 route_vty_out_route (p, vty);
3999 else
4000 vty_out (vty, "%*s", 17, " ");
4001
4002 len = vty_out (vty, "%s", binfo->peer->host);
4003 len = 17 - len;
4004 if (len < 1)
4005 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
4006 else
4007 vty_out (vty, "%*s", len, " ");
4008
4009 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
4010
4011 /* Print attribute */
4012 attr = binfo->attr;
4013 if (attr)
4014 {
4015 /* Print aspath */
4016 if (attr->aspath)
4017 aspath_print_vty (vty, attr->aspath);
4018
4019 /* Print origin */
4020 if (strlen (attr->aspath->str) == 0)
4021 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4022 else
4023 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4024 }
4025 vty_out (vty, "%s", VTY_NEWLINE);
4026
4027 return vty_calc_line (vty, length);
4028}
4029
4030#define BGP_UPTIME_LEN 25
4031
4032/* flap route */
4033int
4034flap_route_vty_out (struct vty *vty, struct prefix *p,
4035 struct bgp_info *binfo, int display, safi_t safi)
4036{
4037 struct attr *attr;
4038 struct bgp_damp_info *bdi;
4039 unsigned long length = 0;
4040 char timebuf[BGP_UPTIME_LEN];
4041 int len;
4042
4043 length = vty->obuf->length;
4044 bdi = binfo->damp_info;
4045
4046 /* Route status display. */
4047 if (binfo->suppress)
4048 vty_out (vty, "s");
4049 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4050 vty_out (vty, "*");
4051 else
4052 vty_out (vty, " ");
4053
4054 /* Selected */
4055 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4056 vty_out (vty, "h");
4057 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4058 vty_out (vty, "d");
4059 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4060 vty_out (vty, ">");
4061 else
4062 vty_out (vty, " ");
4063
4064 vty_out (vty, " ");
4065
4066 /* print prefix and mask */
4067 if (! display)
4068 route_vty_out_route (p, vty);
4069 else
4070 vty_out (vty, "%*s", 17, " ");
4071
4072 len = vty_out (vty, "%s", binfo->peer->host);
4073 len = 16 - len;
4074 if (len < 1)
4075 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
4076 else
4077 vty_out (vty, "%*s", len, " ");
4078
4079 len = vty_out (vty, "%d", bdi->flap);
4080 len = 5 - len;
4081 if (len < 1)
4082 vty_out (vty, " ");
4083 else
4084 vty_out (vty, "%*s ", len, " ");
4085
4086 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
4087 timebuf, BGP_UPTIME_LEN));
4088
4089 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
4090 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4091 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
4092 else
4093 vty_out (vty, "%*s ", 8, " ");
4094
4095 /* Print attribute */
4096 attr = binfo->attr;
4097 if (attr)
4098 {
4099 /* Print aspath */
4100 if (attr->aspath)
4101 aspath_print_vty (vty, attr->aspath);
4102
4103 /* Print origin */
4104 if (strlen (attr->aspath->str) == 0)
4105 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4106 else
4107 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4108 }
4109 vty_out (vty, "%s", VTY_NEWLINE);
4110
4111 return vty_calc_line (vty, length);
4112}
4113
4114void
4115route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
4116 struct bgp_info *binfo, afi_t afi, safi_t safi)
4117{
4118 char buf[INET6_ADDRSTRLEN];
4119 char buf1[BUFSIZ];
4120 struct attr *attr;
4121 int sockunion_vty_out (struct vty *, union sockunion *);
4122
4123 attr = binfo->attr;
4124
4125 if (attr)
4126 {
4127 /* Line1 display AS-path, Aggregator */
4128 if (attr->aspath)
4129 {
4130 vty_out (vty, " ");
4131 if (attr->aspath->length == 0)
4132 vty_out (vty, "Local");
4133 else
4134 aspath_print_vty (vty, attr->aspath);
4135 }
4136
4137 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)
4138 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
4139 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
4140 || CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)
4141 || CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4142 {
4143 vty_out (vty, ",");
4144
4145 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR))
4146 vty_out (vty, " (aggregated by %d %s)", attr->aggregator_as,
4147 inet_ntoa (attr->aggregator_addr));
4148 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
4149 vty_out (vty, " (Received from a RR-client)");
4150 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
4151 vty_out (vty, " (Received from a RS-client)");
4152 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4153 vty_out (vty, " (history entry)");
4154 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4155 vty_out (vty, " (suppressed due to dampening)");
4156 }
4157 vty_out (vty, "%s", VTY_NEWLINE);
4158
4159 /* Line2 display Next-hop, Neighbor, Router-id */
4160 if (p->family == AF_INET)
4161 {
4162 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
4163 inet_ntoa (attr->mp_nexthop_global_in) :
4164 inet_ntoa (attr->nexthop));
4165 }
4166#ifdef HAVE_IPV6
4167 else
4168 {
4169 vty_out (vty, " %s",
4170 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
4171 buf, INET6_ADDRSTRLEN));
4172 }
4173#endif /* HAVE_IPV6 */
4174
4175 if (binfo->peer == bgp->peer_self)
4176 {
4177 vty_out (vty, " from %s ",
4178 p->family == AF_INET ? "0.0.0.0" : "::");
4179 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
4180 }
4181 else
4182 {
4183 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
4184 vty_out (vty, " (inaccessible)");
4185 else if (binfo->igpmetric)
4186 vty_out (vty, " (metric %d)", binfo->igpmetric);
4187 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
4188 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
4189 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
4190 else
4191 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
4192 }
4193 vty_out (vty, "%s", VTY_NEWLINE);
4194
4195#ifdef HAVE_IPV6
4196 /* display nexthop local */
4197 if (attr->mp_nexthop_len == 32)
4198 {
4199 vty_out (vty, " (%s)%s",
4200 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
4201 buf, INET6_ADDRSTRLEN),
4202 VTY_NEWLINE);
4203 }
4204#endif /* HAVE_IPV6 */
4205
4206 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
4207 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
4208
4209 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
4210 vty_out (vty, ", metric %d", attr->med);
4211
4212 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
4213 vty_out (vty, ", localpref %d", attr->local_pref);
4214 else
4215 vty_out (vty, ", localpref %d", bgp->default_local_pref);
4216
4217 if (attr->weight != 0)
4218 vty_out (vty, ", weight %d", attr->weight);
4219
4220 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4221 vty_out (vty, ", valid");
4222
4223 if (binfo->peer != bgp->peer_self)
4224 {
4225 if (binfo->peer->as == binfo->peer->local_as)
4226 vty_out (vty, ", internal");
4227 else
4228 vty_out (vty, ", %s",
4229 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
4230 }
4231 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
4232 vty_out (vty, ", aggregated, local");
4233 else if (binfo->type != ZEBRA_ROUTE_BGP)
4234 vty_out (vty, ", sourced");
4235 else
4236 vty_out (vty, ", sourced, local");
4237
4238 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4239 vty_out (vty, ", atomic-aggregate");
4240
4241 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4242 vty_out (vty, ", best");
4243
4244 vty_out (vty, "%s", VTY_NEWLINE);
4245
4246 /* Line 4 display Community */
4247 if (attr->community)
4248 vty_out (vty, " Community: %s%s", attr->community->str,
4249 VTY_NEWLINE);
4250
4251 /* Line 5 display Extended-community */
4252 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
4253 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
4254 VTY_NEWLINE);
4255
4256 /* Line 6 display Originator, Cluster-id */
4257 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
4258 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
4259 {
4260 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
4261 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
4262
4263 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
4264 {
4265 int i;
4266 vty_out (vty, ", Cluster list: ");
4267 for (i = 0; i < attr->cluster->length / 4; i++)
4268 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
4269 }
4270 vty_out (vty, "%s", VTY_NEWLINE);
4271 }
4272
4273 if (binfo->damp_info)
4274 bgp_damp_info_vty (vty, binfo);
4275
4276 /* Line 7 display Uptime */
4277 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
4278 }
4279 vty_out (vty, "%s", VTY_NEWLINE);
4280}
4281
4282#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
4283#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
4284#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
4285
4286enum bgp_show_type
4287{
4288 bgp_show_type_normal,
4289 bgp_show_type_regexp,
4290 bgp_show_type_prefix_list,
4291 bgp_show_type_filter_list,
4292 bgp_show_type_route_map,
4293 bgp_show_type_neighbor,
4294 bgp_show_type_cidr_only,
4295 bgp_show_type_prefix_longer,
4296 bgp_show_type_community_all,
4297 bgp_show_type_community,
4298 bgp_show_type_community_exact,
4299 bgp_show_type_community_list,
4300 bgp_show_type_community_list_exact,
4301 bgp_show_type_flap_statistics,
4302 bgp_show_type_flap_address,
4303 bgp_show_type_flap_prefix,
4304 bgp_show_type_flap_cidr_only,
4305 bgp_show_type_flap_regexp,
4306 bgp_show_type_flap_filter_list,
4307 bgp_show_type_flap_prefix_list,
4308 bgp_show_type_flap_prefix_longer,
4309 bgp_show_type_flap_route_map,
4310 bgp_show_type_flap_neighbor,
4311 bgp_show_type_dampend_paths,
4312 bgp_show_type_damp_neighbor
4313};
4314
4315int
4316bgp_show_callback (struct vty *vty, int unlock)
4317{
4318 struct bgp_node *rn;
4319 struct bgp_info *ri;
4320 int count;
4321 int limit;
4322 int display;
4323
4324 rn = vty->output_rn;
4325 count = 0;
4326 limit = ((vty->lines == 0)
4327 ? 10 : (vty->lines > 0
4328 ? vty->lines : vty->height - 2));
4329 limit = limit > 0 ? limit : 2;
4330
4331 /* Quit of display. */
4332 if (unlock && rn)
4333 {
4334 bgp_unlock_node (rn);
4335 if (vty->output_clean)
4336 (*vty->output_clean) (vty);
4337 vty->output_rn = NULL;
4338 vty->output_func = NULL;
4339 vty->output_clean = NULL;
4340 vty->output_arg = NULL;
4341 return 0;
4342 }
4343
4344 for (; rn; rn = bgp_route_next (rn))
4345 if (rn->info != NULL)
4346 {
4347 display = 0;
4348
4349 for (ri = rn->info; ri; ri = ri->next)
4350 {
4351 if (vty->output_type == bgp_show_type_flap_statistics
4352 || vty->output_type == bgp_show_type_flap_address
4353 || vty->output_type == bgp_show_type_flap_prefix
4354 || vty->output_type == bgp_show_type_flap_cidr_only
4355 || vty->output_type == bgp_show_type_flap_regexp
4356 || vty->output_type == bgp_show_type_flap_filter_list
4357 || vty->output_type == bgp_show_type_flap_prefix_list
4358 || vty->output_type == bgp_show_type_flap_prefix_longer
4359 || vty->output_type == bgp_show_type_flap_route_map
4360 || vty->output_type == bgp_show_type_flap_neighbor
4361 || vty->output_type == bgp_show_type_dampend_paths
4362 || vty->output_type == bgp_show_type_damp_neighbor)
4363 {
4364 if (! ri->damp_info)
4365 continue;
4366 }
4367 if (vty->output_type == bgp_show_type_regexp
4368 || vty->output_type == bgp_show_type_flap_regexp)
4369 {
4370 regex_t *regex = vty->output_arg;
4371
4372 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
4373 continue;
4374 }
4375 if (vty->output_type == bgp_show_type_prefix_list
4376 || vty->output_type == bgp_show_type_flap_prefix_list)
4377 {
4378 struct prefix_list *plist = vty->output_arg;
4379
4380 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
4381 continue;
4382 }
4383 if (vty->output_type == bgp_show_type_filter_list
4384 || vty->output_type == bgp_show_type_flap_filter_list)
4385 {
4386 struct as_list *as_list = vty->output_arg;
4387
4388 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
4389 continue;
4390 }
4391 if (vty->output_type == bgp_show_type_route_map
4392 || vty->output_type == bgp_show_type_flap_route_map)
4393 {
4394 struct route_map *rmap = vty->output_arg;
4395 struct bgp_info binfo;
4396 struct attr dummy_attr;
4397 int ret;
4398
4399 dummy_attr = *ri->attr;
4400 binfo.peer = ri->peer;
4401 binfo.attr = &dummy_attr;
4402
4403 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
4404
4405 if (ret == RMAP_DENYMATCH)
4406 continue;
4407 }
4408 if (vty->output_type == bgp_show_type_neighbor
4409 || vty->output_type == bgp_show_type_flap_neighbor
4410 || vty->output_type == bgp_show_type_damp_neighbor)
4411 {
4412 union sockunion *su = vty->output_arg;
4413
4414 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
4415 continue;
4416 }
4417 if (vty->output_type == bgp_show_type_cidr_only
4418 || vty->output_type == bgp_show_type_flap_cidr_only)
4419 {
4420 u_int32_t destination;
4421
4422 destination = ntohl (rn->p.u.prefix4.s_addr);
4423 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
4424 continue;
4425 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
4426 continue;
4427 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
4428 continue;
4429 }
4430 if (vty->output_type == bgp_show_type_prefix_longer
4431 || vty->output_type == bgp_show_type_flap_prefix_longer)
4432 {
4433 struct prefix *p = vty->output_arg;
4434
4435 if (! prefix_match (p, &rn->p))
4436 continue;
4437 }
4438 if (vty->output_type == bgp_show_type_community_all)
4439 {
4440 if (! ri->attr->community)
4441 continue;
4442 }
4443 if (vty->output_type == bgp_show_type_community)
4444 {
4445 struct community *com = vty->output_arg;
4446
4447 if (! ri->attr->community ||
4448 ! community_match (ri->attr->community, com))
4449 continue;
4450 }
4451 if (vty->output_type == bgp_show_type_community_exact)
4452 {
4453 struct community *com = vty->output_arg;
4454
4455 if (! ri->attr->community ||
4456 ! community_cmp (ri->attr->community, com))
4457 continue;
4458 }
4459 if (vty->output_type == bgp_show_type_community_list)
4460 {
4461 struct community_list *list = vty->output_arg;
4462
4463 if (! community_list_match (ri->attr->community, list))
4464 continue;
4465 }
4466 if (vty->output_type == bgp_show_type_community_list_exact)
4467 {
4468 struct community_list *list = vty->output_arg;
4469
4470 if (! community_list_exact_match (ri->attr->community, list))
4471 continue;
4472 }
4473 if (vty->output_type == bgp_show_type_flap_address
4474 || vty->output_type == bgp_show_type_flap_prefix)
4475 {
4476 struct prefix *p = vty->output_arg;
4477
4478 if (! prefix_match (&rn->p, p))
4479 continue;
4480
4481 if (vty->output_type == bgp_show_type_flap_prefix)
4482 if (p->prefixlen != rn->p.prefixlen)
4483 continue;
4484 }
4485 if (vty->output_type == bgp_show_type_dampend_paths
4486 || vty->output_type == bgp_show_type_damp_neighbor)
4487 {
4488 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
4489 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
4490 continue;
4491 }
4492
4493 if (vty->output_type == bgp_show_type_dampend_paths
4494 || vty->output_type == bgp_show_type_damp_neighbor)
4495 count += damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4496 else if (vty->output_type == bgp_show_type_flap_statistics
4497 || vty->output_type == bgp_show_type_flap_address
4498 || vty->output_type == bgp_show_type_flap_prefix
4499 || vty->output_type == bgp_show_type_flap_cidr_only
4500 || vty->output_type == bgp_show_type_flap_regexp
4501 || vty->output_type == bgp_show_type_flap_filter_list
4502 || vty->output_type == bgp_show_type_flap_prefix_list
4503 || vty->output_type == bgp_show_type_flap_prefix_longer
4504 || vty->output_type == bgp_show_type_flap_route_map
4505 || vty->output_type == bgp_show_type_flap_neighbor)
4506 count += flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4507 else
4508 count += route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4509 display++;
4510 }
4511
4512 if (display)
4513 vty->output_count++;
4514
4515 /* Remember current pointer then suspend output. */
4516 if (count >= limit)
4517 {
4518 vty->status = VTY_CONTINUE;
4519 vty->output_rn = bgp_route_next (rn);;
4520 vty->output_func = bgp_show_callback;
4521 return 0;
4522 }
4523 }
4524
4525 /* Total line display. */
4526 if (vty->output_count)
4527 vty_out (vty, "%sTotal number of prefixes %ld%s",
4528 VTY_NEWLINE, vty->output_count, VTY_NEWLINE);
4529
4530 if (vty->output_clean)
4531 (*vty->output_clean) (vty);
4532
4533 vty->status = VTY_CONTINUE;
4534 vty->output_rn = NULL;
4535 vty->output_func = NULL;
4536 vty->output_clean = NULL;
4537 vty->output_arg = NULL;
4538
4539 return 0;
4540}
4541
4542int
4543bgp_show (struct vty *vty, char *view_name, afi_t afi, safi_t safi,
4544 enum bgp_show_type type)
4545{
4546 struct bgp *bgp;
4547 struct bgp_info *ri;
4548 struct bgp_node *rn;
4549 struct bgp_table *table;
4550 int header = 1;
4551 int count;
4552 int limit;
4553 int display;
4554
4555 limit = ((vty->lines == 0)
4556 ? 10 : (vty->lines > 0
4557 ? vty->lines : vty->height - 2));
4558 limit = limit > 0 ? limit : 2;
4559
4560 /* BGP structure lookup. */
4561 if (view_name)
4562 {
4563 bgp = bgp_lookup_by_name (view_name);
4564 if (bgp == NULL)
4565 {
4566 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
4567 return CMD_WARNING;
4568 }
4569 }
4570 else
4571 {
4572 bgp = bgp_get_default ();
4573 if (bgp == NULL)
4574 {
4575 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
4576 return CMD_WARNING;
4577 }
4578 }
4579
4580 count = 0;
4581
4582 /* This is first entry point, so reset total line. */
4583 vty->output_count = 0;
4584 vty->output_type = type;
4585
4586 table = bgp->rib[afi][safi];
4587
4588 /* Start processing of routes. */
4589 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4590 if (rn->info != NULL)
4591 {
4592 display = 0;
4593
4594 for (ri = rn->info; ri; ri = ri->next)
4595 {
4596 if (vty->output_type == bgp_show_type_flap_statistics
4597 || type == bgp_show_type_flap_address
4598 || type == bgp_show_type_flap_prefix
4599 || type == bgp_show_type_flap_cidr_only
4600 || type == bgp_show_type_flap_regexp
4601 || type == bgp_show_type_flap_filter_list
4602 || type == bgp_show_type_flap_prefix_list
4603 || type == bgp_show_type_flap_prefix_longer
4604 || type == bgp_show_type_flap_route_map
4605 || type == bgp_show_type_flap_neighbor
4606 || type == bgp_show_type_dampend_paths
4607 || type == bgp_show_type_damp_neighbor)
4608 {
4609 if (! ri->damp_info)
4610 continue;
4611 }
4612 if (type == bgp_show_type_regexp
4613 || type == bgp_show_type_flap_regexp)
4614 {
4615 regex_t *regex = vty->output_arg;
4616
4617 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
4618 continue;
4619 }
4620 if (type == bgp_show_type_prefix_list
4621 || type == bgp_show_type_flap_prefix_list)
4622 {
4623 struct prefix_list *plist = vty->output_arg;
4624
4625 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
4626 continue;
4627 }
4628 if (type == bgp_show_type_filter_list
4629 || type == bgp_show_type_flap_filter_list)
4630 {
4631 struct as_list *as_list = vty->output_arg;
4632
4633 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
4634 continue;
4635 }
4636 if (type == bgp_show_type_route_map
4637 || type == bgp_show_type_flap_route_map)
4638 {
4639 struct route_map *rmap = vty->output_arg;
4640 struct bgp_info binfo;
4641 struct attr dummy_attr;
4642 int ret;
4643
4644 dummy_attr = *ri->attr;
4645 binfo.peer = ri->peer;
4646 binfo.attr = &dummy_attr;
4647
4648 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
4649
4650 if (ret == RMAP_DENYMATCH)
4651 continue;
4652 }
4653 if (type == bgp_show_type_neighbor
4654 || type == bgp_show_type_flap_neighbor
4655 || type == bgp_show_type_damp_neighbor)
4656 {
4657 union sockunion *su = vty->output_arg;
4658
4659 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
4660 continue;
4661 }
4662 if (type == bgp_show_type_cidr_only
4663 || type == bgp_show_type_flap_cidr_only)
4664 {
4665 u_int32_t destination;
4666
4667 destination = ntohl (rn->p.u.prefix4.s_addr);
4668 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
4669 continue;
4670 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
4671 continue;
4672 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
4673 continue;
4674 }
4675 if (type == bgp_show_type_prefix_longer
4676 || type == bgp_show_type_flap_prefix_longer)
4677 {
4678 struct prefix *p = vty->output_arg;
4679
4680 if (! prefix_match (p, &rn->p))
4681 continue;
4682 }
4683 if (type == bgp_show_type_community_all)
4684 {
4685 if (! ri->attr->community)
4686 continue;
4687 }
4688 if (type == bgp_show_type_community)
4689 {
4690 struct community *com = vty->output_arg;
4691
4692 if (! ri->attr->community ||
4693 ! community_match (ri->attr->community, com))
4694 continue;
4695 }
4696 if (type == bgp_show_type_community_exact)
4697 {
4698 struct community *com = vty->output_arg;
4699
4700 if (! ri->attr->community ||
4701 ! community_cmp (ri->attr->community, com))
4702 continue;
4703 }
4704 if (type == bgp_show_type_community_list)
4705 {
4706 struct community_list *list = vty->output_arg;
4707
4708 if (! community_list_match (ri->attr->community, list))
4709 continue;
4710 }
4711 if (type == bgp_show_type_community_list_exact)
4712 {
4713 struct community_list *list = vty->output_arg;
4714
4715 if (! community_list_exact_match (ri->attr->community, list))
4716 continue;
4717 }
4718 if (type == bgp_show_type_flap_address
4719 || type == bgp_show_type_flap_prefix)
4720 {
4721 struct prefix *p = vty->output_arg;
4722
4723 if (! prefix_match (&rn->p, p))
4724 continue;
4725
4726 if (type == bgp_show_type_flap_prefix)
4727 if (p->prefixlen != rn->p.prefixlen)
4728 continue;
4729 }
4730 if (type == bgp_show_type_dampend_paths
4731 || type == bgp_show_type_damp_neighbor)
4732 {
4733 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
4734 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
4735 continue;
4736 }
4737
4738 if (header)
4739 {
4740 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
4741 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
4742 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
4743 if (type == bgp_show_type_dampend_paths
4744 || type == bgp_show_type_damp_neighbor)
4745 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
4746 else if (type == bgp_show_type_flap_statistics
4747 || type == bgp_show_type_flap_address
4748 || type == bgp_show_type_flap_prefix
4749 || type == bgp_show_type_flap_cidr_only
4750 || type == bgp_show_type_flap_regexp
4751 || type == bgp_show_type_flap_filter_list
4752 || type == bgp_show_type_flap_prefix_list
4753 || type == bgp_show_type_flap_prefix_longer
4754 || type == bgp_show_type_flap_route_map
4755 || type == bgp_show_type_flap_neighbor)
4756 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
4757 else
4758 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
4759 count += 5;
4760 header = 0;
4761 }
4762
4763 if (type == bgp_show_type_dampend_paths
4764 || type == bgp_show_type_damp_neighbor)
4765 count += damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4766 else if (type == bgp_show_type_flap_statistics
4767 || type == bgp_show_type_flap_address
4768 || type == bgp_show_type_flap_prefix
4769 || type == bgp_show_type_flap_cidr_only
4770 || type == bgp_show_type_flap_regexp
4771 || type == bgp_show_type_flap_filter_list
4772 || type == bgp_show_type_flap_prefix_list
4773 || type == bgp_show_type_flap_prefix_longer
4774 || type == bgp_show_type_flap_route_map
4775 || type == bgp_show_type_flap_neighbor)
4776 count += flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4777 else
4778 count += route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4779 display++;
4780 }
4781 if (display)
4782 vty->output_count++;
4783
4784 /* Remember current pointer then suspend output. */
4785 if (count >= limit && vty->type != VTY_SHELL_SERV)
4786 {
4787 vty->status = VTY_START;
4788 vty->output_rn = bgp_route_next (rn);
4789 vty->output_func = bgp_show_callback;
4790 vty->output_type = type;
4791
4792 return CMD_SUCCESS;
4793 }
4794 }
4795
4796 /* No route is displayed */
4797 if (vty->output_count == 0)
4798 {
4799 if (type == bgp_show_type_normal)
4800 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
4801 }
4802 else
4803 vty_out (vty, "%sTotal number of prefixes %ld%s",
4804 VTY_NEWLINE, vty->output_count, VTY_NEWLINE);
4805
4806 /* Clean up allocated resources. */
4807 if (vty->output_clean)
4808 (*vty->output_clean) (vty);
4809
4810 vty->status = VTY_START;
4811 vty->output_rn = NULL;
4812 vty->output_func = NULL;
4813 vty->output_clean = NULL;
4814 vty->output_arg = NULL;
4815
4816 return CMD_SUCCESS;
4817}
4818
4819/* Header of detailed BGP route information */
4820void
4821route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
4822 struct bgp_node *rn,
4823 struct prefix_rd *prd, afi_t afi, safi_t safi)
4824{
4825 struct bgp_info *ri;
4826 struct prefix *p;
4827 struct peer *peer;
4828 struct listnode *nn;
4829 char buf1[INET6_ADDRSTRLEN];
4830 char buf2[INET6_ADDRSTRLEN];
4831 int count = 0;
4832 int best = 0;
4833 int suppress = 0;
4834 int no_export = 0;
4835 int no_advertise = 0;
4836 int local_as = 0;
4837 int first = 0;
4838
4839 p = &rn->p;
4840 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
4841 (safi == SAFI_MPLS_VPN ?
4842 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
4843 safi == SAFI_MPLS_VPN ? ":" : "",
4844 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
4845 p->prefixlen, VTY_NEWLINE);
4846
4847 for (ri = rn->info; ri; ri = ri->next)
4848 {
4849 count++;
4850 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
4851 {
4852 best = count;
4853 if (ri->suppress)
4854 suppress = 1;
4855 if (ri->attr->community != NULL)
4856 {
4857 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
4858 no_advertise = 1;
4859 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
4860 no_export = 1;
4861 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
4862 local_as = 1;
4863 }
4864 }
4865 }
4866
4867 vty_out (vty, "Paths: (%d available", count);
4868 if (best)
4869 {
4870 vty_out (vty, ", best #%d", best);
4871 if (safi == SAFI_UNICAST)
4872 vty_out (vty, ", table Default-IP-Routing-Table");
4873 }
4874 else
4875 vty_out (vty, ", no best path");
4876 if (no_advertise)
4877 vty_out (vty, ", not advertised to any peer");
4878 else if (no_export)
4879 vty_out (vty, ", not advertised to EBGP peer");
4880 else if (local_as)
4881 vty_out (vty, ", not advertised outside local AS");
4882 if (suppress)
4883 vty_out (vty, ", Advertisements suppressed by an aggregate.");
4884 vty_out (vty, ")%s", VTY_NEWLINE);
4885
4886 /* advertised peer */
4887 LIST_LOOP (bgp->peer, peer, nn)
4888 {
4889 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
4890 {
4891 if (! first)
4892 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
4893 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
4894 first = 1;
4895 }
4896 }
4897 if (! first)
4898 vty_out (vty, " Not advertised to any peer");
4899 vty_out (vty, "%s", VTY_NEWLINE);
4900}
4901
4902/* Display specified route of BGP table. */
4903int
4904bgp_show_route (struct vty *vty, char *view_name, char *ip_str,
4905 afi_t afi, safi_t safi, struct prefix_rd *prd,
4906 int prefix_check)
4907{
4908 int ret;
4909 int header;
4910 int display = 0;
4911 struct prefix match;
4912 struct bgp_node *rn;
4913 struct bgp_node *rm;
4914 struct bgp_info *ri;
4915 struct bgp *bgp;
4916 struct bgp_table *table;
4917
4918 /* BGP structure lookup. */
4919 if (view_name)
4920 {
4921 bgp = bgp_lookup_by_name (view_name);
4922 if (bgp == NULL)
4923 {
4924 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
4925 return CMD_WARNING;
4926 }
4927 }
4928 else
4929 {
4930 bgp = bgp_get_default ();
4931 if (bgp == NULL)
4932 {
4933 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
4934 return CMD_WARNING;
4935 }
4936 }
4937
4938 /* Check IP address argument. */
4939 ret = str2prefix (ip_str, &match);
4940 if (! ret)
4941 {
4942 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
4943 return CMD_WARNING;
4944 }
4945
4946 match.family = afi2family (afi);
4947
4948 if (safi == SAFI_MPLS_VPN)
4949 {
4950 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
4951 {
4952 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
4953 continue;
4954
4955 if ((table = rn->info) != NULL)
4956 {
4957 header = 1;
4958
4959 if ((rm = bgp_node_match (table, &match)) != NULL)
4960 {
4961 if (prefix_check && rm->p.prefixlen != match.prefixlen)
4962 continue;
4963
4964 for (ri = rm->info; ri; ri = ri->next)
4965 {
4966 if (header)
4967 {
4968 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
4969 AFI_IP, SAFI_MPLS_VPN);
4970
4971 header = 0;
4972 }
4973 display++;
4974 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
4975 }
4976 }
4977 }
4978 }
4979 }
4980 else
4981 {
4982 header = 1;
4983
4984 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
4985 {
4986 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
4987 {
4988 for (ri = rn->info; ri; ri = ri->next)
4989 {
4990 if (header)
4991 {
4992 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
4993 header = 0;
4994 }
4995 display++;
4996 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
4997 }
4998 }
4999 }
5000 }
5001
5002 if (! display)
5003 {
5004 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5005 return CMD_WARNING;
5006 }
5007
5008 return CMD_SUCCESS;
5009}
5010
5011/* BGP route print out function. */
5012DEFUN (show_ip_bgp,
5013 show_ip_bgp_cmd,
5014 "show ip bgp",
5015 SHOW_STR
5016 IP_STR
5017 BGP_STR)
5018{
5019 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
5020}
5021
5022DEFUN (show_ip_bgp_ipv4,
5023 show_ip_bgp_ipv4_cmd,
5024 "show ip bgp ipv4 (unicast|multicast)",
5025 SHOW_STR
5026 IP_STR
5027 BGP_STR
5028 "Address family\n"
5029 "Address Family modifier\n"
5030 "Address Family modifier\n")
5031{
5032 if (strncmp (argv[0], "m", 1) == 0)
5033 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal);
5034
5035 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
5036}
5037
5038DEFUN (show_ip_bgp_route,
5039 show_ip_bgp_route_cmd,
5040 "show ip bgp A.B.C.D",
5041 SHOW_STR
5042 IP_STR
5043 BGP_STR
5044 "Network in the BGP routing table to display\n")
5045{
5046 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
5047}
5048
5049DEFUN (show_ip_bgp_ipv4_route,
5050 show_ip_bgp_ipv4_route_cmd,
5051 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
5052 SHOW_STR
5053 IP_STR
5054 BGP_STR
5055 "Address family\n"
5056 "Address Family modifier\n"
5057 "Address Family modifier\n"
5058 "Network in the BGP routing table to display\n")
5059{
5060 if (strncmp (argv[0], "m", 1) == 0)
5061 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
5062
5063 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
5064}
5065
5066DEFUN (show_ip_bgp_vpnv4_all_route,
5067 show_ip_bgp_vpnv4_all_route_cmd,
5068 "show ip bgp vpnv4 all A.B.C.D",
5069 SHOW_STR
5070 IP_STR
5071 BGP_STR
5072 "Display VPNv4 NLRI specific information\n"
5073 "Display information about all VPNv4 NLRIs\n"
5074 "Network in the BGP routing table to display\n")
5075{
5076 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
5077}
5078
5079DEFUN (show_ip_bgp_vpnv4_rd_route,
5080 show_ip_bgp_vpnv4_rd_route_cmd,
5081 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
5082 SHOW_STR
5083 IP_STR
5084 BGP_STR
5085 "Display VPNv4 NLRI specific information\n"
5086 "Display information for a route distinguisher\n"
5087 "VPN Route Distinguisher\n"
5088 "Network in the BGP routing table to display\n")
5089{
5090 int ret;
5091 struct prefix_rd prd;
5092
5093 ret = str2prefix_rd (argv[0], &prd);
5094 if (! ret)
5095 {
5096 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
5097 return CMD_WARNING;
5098 }
5099 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
5100}
5101
5102DEFUN (show_ip_bgp_prefix,
5103 show_ip_bgp_prefix_cmd,
5104 "show ip bgp A.B.C.D/M",
5105 SHOW_STR
5106 IP_STR
5107 BGP_STR
5108 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5109{
5110 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
5111}
5112
5113DEFUN (show_ip_bgp_ipv4_prefix,
5114 show_ip_bgp_ipv4_prefix_cmd,
5115 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
5116 SHOW_STR
5117 IP_STR
5118 BGP_STR
5119 "Address family\n"
5120 "Address Family modifier\n"
5121 "Address Family modifier\n"
5122 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5123{
5124 if (strncmp (argv[0], "m", 1) == 0)
5125 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
5126
5127 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
5128}
5129
5130DEFUN (show_ip_bgp_vpnv4_all_prefix,
5131 show_ip_bgp_vpnv4_all_prefix_cmd,
5132 "show ip bgp vpnv4 all A.B.C.D/M",
5133 SHOW_STR
5134 IP_STR
5135 BGP_STR
5136 "Display VPNv4 NLRI specific information\n"
5137 "Display information about all VPNv4 NLRIs\n"
5138 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5139{
5140 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
5141}
5142
5143DEFUN (show_ip_bgp_vpnv4_rd_prefix,
5144 show_ip_bgp_vpnv4_rd_prefix_cmd,
5145 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
5146 SHOW_STR
5147 IP_STR
5148 BGP_STR
5149 "Display VPNv4 NLRI specific information\n"
5150 "Display information for a route distinguisher\n"
5151 "VPN Route Distinguisher\n"
5152 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5153{
5154 int ret;
5155 struct prefix_rd prd;
5156
5157 ret = str2prefix_rd (argv[0], &prd);
5158 if (! ret)
5159 {
5160 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
5161 return CMD_WARNING;
5162 }
5163 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
5164}
5165
5166DEFUN (show_ip_bgp_view,
5167 show_ip_bgp_view_cmd,
5168 "show ip bgp view WORD",
5169 SHOW_STR
5170 IP_STR
5171 BGP_STR
5172 "BGP view\n"
5173 "BGP view name\n")
5174{
5175 return bgp_show (vty, argv[0], AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
5176}
5177
5178DEFUN (show_ip_bgp_view_route,
5179 show_ip_bgp_view_route_cmd,
5180 "show ip bgp view WORD A.B.C.D",
5181 SHOW_STR
5182 IP_STR
5183 BGP_STR
5184 "BGP view\n"
5185 "BGP view name\n"
5186 "Network in the BGP routing table to display\n")
5187{
5188 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
5189}
5190
5191DEFUN (show_ip_bgp_view_prefix,
5192 show_ip_bgp_view_prefix_cmd,
5193 "show ip bgp view WORD A.B.C.D/M",
5194 SHOW_STR
5195 IP_STR
5196 BGP_STR
5197 "BGP view\n"
5198 "BGP view name\n"
5199 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5200{
5201 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
5202}
5203
5204#ifdef HAVE_IPV6
5205DEFUN (show_bgp,
5206 show_bgp_cmd,
5207 "show bgp",
5208 SHOW_STR
5209 BGP_STR)
5210{
5211 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
5212}
5213
5214ALIAS (show_bgp,
5215 show_bgp_ipv6_cmd,
5216 "show bgp ipv6",
5217 SHOW_STR
5218 BGP_STR
5219 "Address family\n")
5220
5221/* old command */
5222DEFUN (show_ipv6_bgp,
5223 show_ipv6_bgp_cmd,
5224 "show ipv6 bgp",
5225 SHOW_STR
5226 IP_STR
5227 BGP_STR)
5228{
5229 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
5230}
5231
5232DEFUN (show_bgp_route,
5233 show_bgp_route_cmd,
5234 "show bgp X:X::X:X",
5235 SHOW_STR
5236 BGP_STR
5237 "Network in the BGP routing table to display\n")
5238{
5239 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
5240}
5241
5242ALIAS (show_bgp_route,
5243 show_bgp_ipv6_route_cmd,
5244 "show bgp ipv6 X:X::X:X",
5245 SHOW_STR
5246 BGP_STR
5247 "Address family\n"
5248 "Network in the BGP routing table to display\n")
5249
5250/* old command */
5251DEFUN (show_ipv6_bgp_route,
5252 show_ipv6_bgp_route_cmd,
5253 "show ipv6 bgp X:X::X:X",
5254 SHOW_STR
5255 IP_STR
5256 BGP_STR
5257 "Network in the BGP routing table to display\n")
5258{
5259 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
5260}
5261
5262DEFUN (show_bgp_prefix,
5263 show_bgp_prefix_cmd,
5264 "show bgp X:X::X:X/M",
5265 SHOW_STR
5266 BGP_STR
5267 "IPv6 prefix <network>/<length>\n")
5268{
5269 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
5270}
5271
5272ALIAS (show_bgp_prefix,
5273 show_bgp_ipv6_prefix_cmd,
5274 "show bgp ipv6 X:X::X:X/M",
5275 SHOW_STR
5276 BGP_STR
5277 "Address family\n"
5278 "IPv6 prefix <network>/<length>\n")
5279
5280/* old command */
5281DEFUN (show_ipv6_bgp_prefix,
5282 show_ipv6_bgp_prefix_cmd,
5283 "show ipv6 bgp X:X::X:X/M",
5284 SHOW_STR
5285 IP_STR
5286 BGP_STR
5287 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5288{
5289 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
5290}
5291
5292/* old command */
5293DEFUN (show_ipv6_mbgp,
5294 show_ipv6_mbgp_cmd,
5295 "show ipv6 mbgp",
5296 SHOW_STR
5297 IP_STR
5298 MBGP_STR)
5299{
5300 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal);
5301}
5302
5303/* old command */
5304DEFUN (show_ipv6_mbgp_route,
5305 show_ipv6_mbgp_route_cmd,
5306 "show ipv6 mbgp X:X::X:X",
5307 SHOW_STR
5308 IP_STR
5309 MBGP_STR
5310 "Network in the MBGP routing table to display\n")
5311{
5312 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
5313}
5314
5315/* old command */
5316DEFUN (show_ipv6_mbgp_prefix,
5317 show_ipv6_mbgp_prefix_cmd,
5318 "show ipv6 mbgp X:X::X:X/M",
5319 SHOW_STR
5320 IP_STR
5321 MBGP_STR
5322 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5323{
5324 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
5325}
5326#endif
5327
5328void
5329bgp_show_regexp_clean (struct vty *vty)
5330{
5331 bgp_regex_free (vty->output_arg);
5332}
5333
5334int
5335bgp_show_regexp (struct vty *vty, int argc, char **argv, afi_t afi,
5336 safi_t safi, enum bgp_show_type type)
5337{
5338 int i;
5339 struct buffer *b;
5340 char *regstr;
5341 int first;
5342 regex_t *regex;
5343
5344 first = 0;
5345 b = buffer_new (1024);
5346 for (i = 0; i < argc; i++)
5347 {
5348 if (first)
5349 buffer_putc (b, ' ');
5350 else
5351 {
5352 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
5353 continue;
5354 first = 1;
5355 }
5356
5357 buffer_putstr (b, argv[i]);
5358 }
5359 buffer_putc (b, '\0');
5360
5361 regstr = buffer_getstr (b);
5362 buffer_free (b);
5363
5364 regex = bgp_regcomp (regstr);
5365 if (! regex)
5366 {
5367 vty_out (vty, "Can't compile regexp %s%s", argv[0],
5368 VTY_NEWLINE);
5369 return CMD_WARNING;
5370 }
5371
5372 vty->output_arg = regex;
5373 vty->output_clean = bgp_show_regexp_clean;
5374
5375 return bgp_show (vty, NULL, afi, safi, type);
5376}
5377
5378DEFUN (show_ip_bgp_regexp,
5379 show_ip_bgp_regexp_cmd,
5380 "show ip bgp regexp .LINE",
5381 SHOW_STR
5382 IP_STR
5383 BGP_STR
5384 "Display routes matching the AS path regular expression\n"
5385 "A regular-expression to match the BGP AS paths\n")
5386{
5387 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
5388 bgp_show_type_regexp);
5389}
5390
5391DEFUN (show_ip_bgp_flap_regexp,
5392 show_ip_bgp_flap_regexp_cmd,
5393 "show ip bgp flap-statistics regexp .LINE",
5394 SHOW_STR
5395 IP_STR
5396 BGP_STR
5397 "Display flap statistics of routes\n"
5398 "Display routes matching the AS path regular expression\n"
5399 "A regular-expression to match the BGP AS paths\n")
5400{
5401 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
5402 bgp_show_type_flap_regexp);
5403}
5404
5405DEFUN (show_ip_bgp_ipv4_regexp,
5406 show_ip_bgp_ipv4_regexp_cmd,
5407 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
5408 SHOW_STR
5409 IP_STR
5410 BGP_STR
5411 "Address family\n"
5412 "Address Family modifier\n"
5413 "Address Family modifier\n"
5414 "Display routes matching the AS path regular expression\n"
5415 "A regular-expression to match the BGP AS paths\n")
5416{
5417 if (strncmp (argv[0], "m", 1) == 0)
5418 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
5419 bgp_show_type_regexp);
5420
5421 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
5422 bgp_show_type_regexp);
5423}
5424
5425#ifdef HAVE_IPV6
5426DEFUN (show_bgp_regexp,
5427 show_bgp_regexp_cmd,
5428 "show bgp regexp .LINE",
5429 SHOW_STR
5430 BGP_STR
5431 "Display routes matching the AS path regular expression\n"
5432 "A regular-expression to match the BGP AS paths\n")
5433{
5434 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
5435 bgp_show_type_regexp);
5436}
5437
5438ALIAS (show_bgp_regexp,
5439 show_bgp_ipv6_regexp_cmd,
5440 "show bgp ipv6 regexp .LINE",
5441 SHOW_STR
5442 BGP_STR
5443 "Address family\n"
5444 "Display routes matching the AS path regular expression\n"
5445 "A regular-expression to match the BGP AS paths\n")
5446
5447/* old command */
5448DEFUN (show_ipv6_bgp_regexp,
5449 show_ipv6_bgp_regexp_cmd,
5450 "show ipv6 bgp regexp .LINE",
5451 SHOW_STR
5452 IP_STR
5453 BGP_STR
5454 "Display routes matching the AS path regular expression\n"
5455 "A regular-expression to match the BGP AS paths\n")
5456{
5457 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
5458 bgp_show_type_regexp);
5459}
5460
5461/* old command */
5462DEFUN (show_ipv6_mbgp_regexp,
5463 show_ipv6_mbgp_regexp_cmd,
5464 "show ipv6 mbgp regexp .LINE",
5465 SHOW_STR
5466 IP_STR
5467 BGP_STR
5468 "Display routes matching the AS path regular expression\n"
5469 "A regular-expression to match the MBGP AS paths\n")
5470{
5471 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
5472 bgp_show_type_regexp);
5473}
5474#endif /* HAVE_IPV6 */
5475
5476int
5477bgp_show_prefix_list (struct vty *vty, char *prefix_list_str, afi_t afi,
5478 safi_t safi, enum bgp_show_type type)
5479{
5480 struct prefix_list *plist;
5481
5482 plist = prefix_list_lookup (afi, prefix_list_str);
5483 if (plist == NULL)
5484 {
5485 vty_out (vty, "%% %s is not a valid prefix-list name%s",
5486 prefix_list_str, VTY_NEWLINE);
5487 return CMD_WARNING;
5488 }
5489
5490 vty->output_arg = plist;
5491
5492 return bgp_show (vty, NULL, afi, safi, type);
5493}
5494
5495DEFUN (show_ip_bgp_prefix_list,
5496 show_ip_bgp_prefix_list_cmd,
5497 "show ip bgp prefix-list WORD",
5498 SHOW_STR
5499 IP_STR
5500 BGP_STR
5501 "Display routes conforming to the prefix-list\n"
5502 "IP prefix-list name\n")
5503{
5504 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5505 bgp_show_type_prefix_list);
5506}
5507
5508DEFUN (show_ip_bgp_flap_prefix_list,
5509 show_ip_bgp_flap_prefix_list_cmd,
5510 "show ip bgp flap-statistics prefix-list WORD",
5511 SHOW_STR
5512 IP_STR
5513 BGP_STR
5514 "Display flap statistics of routes\n"
5515 "Display routes conforming to the prefix-list\n"
5516 "IP prefix-list name\n")
5517{
5518 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5519 bgp_show_type_flap_prefix_list);
5520}
5521
5522DEFUN (show_ip_bgp_ipv4_prefix_list,
5523 show_ip_bgp_ipv4_prefix_list_cmd,
5524 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
5525 SHOW_STR
5526 IP_STR
5527 BGP_STR
5528 "Address family\n"
5529 "Address Family modifier\n"
5530 "Address Family modifier\n"
5531 "Display routes conforming to the prefix-list\n"
5532 "IP prefix-list name\n")
5533{
5534 if (strncmp (argv[0], "m", 1) == 0)
5535 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
5536 bgp_show_type_prefix_list);
5537
5538 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
5539 bgp_show_type_prefix_list);
5540}
5541
5542#ifdef HAVE_IPV6
5543DEFUN (show_bgp_prefix_list,
5544 show_bgp_prefix_list_cmd,
5545 "show bgp prefix-list WORD",
5546 SHOW_STR
5547 BGP_STR
5548 "Display routes conforming to the prefix-list\n"
5549 "IPv6 prefix-list name\n")
5550{
5551 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5552 bgp_show_type_prefix_list);
5553}
5554
5555ALIAS (show_bgp_prefix_list,
5556 show_bgp_ipv6_prefix_list_cmd,
5557 "show bgp ipv6 prefix-list WORD",
5558 SHOW_STR
5559 BGP_STR
5560 "Address family\n"
5561 "Display routes conforming to the prefix-list\n"
5562 "IPv6 prefix-list name\n")
5563
5564/* old command */
5565DEFUN (show_ipv6_bgp_prefix_list,
5566 show_ipv6_bgp_prefix_list_cmd,
5567 "show ipv6 bgp prefix-list WORD",
5568 SHOW_STR
5569 IPV6_STR
5570 BGP_STR
5571 "Display routes matching the prefix-list\n"
5572 "IPv6 prefix-list name\n")
5573{
5574 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5575 bgp_show_type_prefix_list);
5576}
5577
5578/* old command */
5579DEFUN (show_ipv6_mbgp_prefix_list,
5580 show_ipv6_mbgp_prefix_list_cmd,
5581 "show ipv6 mbgp prefix-list WORD",
5582 SHOW_STR
5583 IPV6_STR
5584 MBGP_STR
5585 "Display routes matching the prefix-list\n"
5586 "IPv6 prefix-list name\n")
5587{
5588 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
5589 bgp_show_type_prefix_list);
5590}
5591#endif /* HAVE_IPV6 */
5592
5593int
5594bgp_show_filter_list (struct vty *vty, char *filter, afi_t afi,
5595 safi_t safi, enum bgp_show_type type)
5596{
5597 struct as_list *as_list;
5598
5599 as_list = as_list_lookup (filter);
5600 if (as_list == NULL)
5601 {
5602 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
5603 return CMD_WARNING;
5604 }
5605
5606 vty->output_arg = as_list;
5607
5608 return bgp_show (vty, NULL, afi, safi, type);
5609}
5610
5611DEFUN (show_ip_bgp_filter_list,
5612 show_ip_bgp_filter_list_cmd,
5613 "show ip bgp filter-list WORD",
5614 SHOW_STR
5615 IP_STR
5616 BGP_STR
5617 "Display routes conforming to the filter-list\n"
5618 "Regular expression access list name\n")
5619{
5620 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5621 bgp_show_type_filter_list);
5622}
5623
5624DEFUN (show_ip_bgp_flap_filter_list,
5625 show_ip_bgp_flap_filter_list_cmd,
5626 "show ip bgp flap-statistics filter-list WORD",
5627 SHOW_STR
5628 IP_STR
5629 BGP_STR
5630 "Display flap statistics of routes\n"
5631 "Display routes conforming to the filter-list\n"
5632 "Regular expression access list name\n")
5633{
5634 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5635 bgp_show_type_flap_filter_list);
5636}
5637
5638DEFUN (show_ip_bgp_ipv4_filter_list,
5639 show_ip_bgp_ipv4_filter_list_cmd,
5640 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
5641 SHOW_STR
5642 IP_STR
5643 BGP_STR
5644 "Address family\n"
5645 "Address Family modifier\n"
5646 "Address Family modifier\n"
5647 "Display routes conforming to the filter-list\n"
5648 "Regular expression access list name\n")
5649{
5650 if (strncmp (argv[0], "m", 1) == 0)
5651 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
5652 bgp_show_type_filter_list);
5653
5654 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
5655 bgp_show_type_filter_list);
5656}
5657
5658#ifdef HAVE_IPV6
5659DEFUN (show_bgp_filter_list,
5660 show_bgp_filter_list_cmd,
5661 "show bgp filter-list WORD",
5662 SHOW_STR
5663 BGP_STR
5664 "Display routes conforming to the filter-list\n"
5665 "Regular expression access list name\n")
5666{
5667 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5668 bgp_show_type_filter_list);
5669}
5670
5671ALIAS (show_bgp_filter_list,
5672 show_bgp_ipv6_filter_list_cmd,
5673 "show bgp ipv6 filter-list WORD",
5674 SHOW_STR
5675 BGP_STR
5676 "Address family\n"
5677 "Display routes conforming to the filter-list\n"
5678 "Regular expression access list name\n")
5679
5680/* old command */
5681DEFUN (show_ipv6_bgp_filter_list,
5682 show_ipv6_bgp_filter_list_cmd,
5683 "show ipv6 bgp filter-list WORD",
5684 SHOW_STR
5685 IPV6_STR
5686 BGP_STR
5687 "Display routes conforming to the filter-list\n"
5688 "Regular expression access list name\n")
5689{
5690 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5691 bgp_show_type_filter_list);
5692}
5693
5694/* old command */
5695DEFUN (show_ipv6_mbgp_filter_list,
5696 show_ipv6_mbgp_filter_list_cmd,
5697 "show ipv6 mbgp filter-list WORD",
5698 SHOW_STR
5699 IPV6_STR
5700 MBGP_STR
5701 "Display routes conforming to the filter-list\n"
5702 "Regular expression access list name\n")
5703{
5704 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
5705 bgp_show_type_filter_list);
5706}
5707#endif /* HAVE_IPV6 */
5708
5709int
5710bgp_show_route_map (struct vty *vty, char *rmap_str, afi_t afi,
5711 safi_t safi, enum bgp_show_type type)
5712{
5713 struct route_map *rmap;
5714
5715 rmap = route_map_lookup_by_name (rmap_str);
5716 if (! rmap)
5717 {
5718 vty_out (vty, "%% %s is not a valid route-map name%s",
5719 rmap_str, VTY_NEWLINE);
5720 return CMD_WARNING;
5721 }
5722
5723 vty->output_arg = rmap;
5724
5725 return bgp_show (vty, NULL, afi, safi, type);
5726}
5727
5728DEFUN (show_ip_bgp_route_map,
5729 show_ip_bgp_route_map_cmd,
5730 "show ip bgp route-map WORD",
5731 SHOW_STR
5732 IP_STR
5733 BGP_STR
5734 "Display routes matching the route-map\n"
5735 "A route-map to match on\n")
5736{
5737 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
5738 bgp_show_type_route_map);
5739}
5740
5741DEFUN (show_ip_bgp_flap_route_map,
5742 show_ip_bgp_flap_route_map_cmd,
5743 "show ip bgp flap-statistics route-map WORD",
5744 SHOW_STR
5745 IP_STR
5746 BGP_STR
5747 "Display flap statistics of routes\n"
5748 "Display routes matching the route-map\n"
5749 "A route-map to match on\n")
5750{
5751 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
5752 bgp_show_type_flap_route_map);
5753}
5754
5755DEFUN (show_ip_bgp_ipv4_route_map,
5756 show_ip_bgp_ipv4_route_map_cmd,
5757 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
5758 SHOW_STR
5759 IP_STR
5760 BGP_STR
5761 "Address family\n"
5762 "Address Family modifier\n"
5763 "Address Family modifier\n"
5764 "Display routes matching the route-map\n"
5765 "A route-map to match on\n")
5766{
5767 if (strncmp (argv[0], "m", 1) == 0)
5768 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
5769 bgp_show_type_route_map);
5770
5771 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
5772 bgp_show_type_route_map);
5773}
5774
5775DEFUN (show_bgp_route_map,
5776 show_bgp_route_map_cmd,
5777 "show bgp route-map WORD",
5778 SHOW_STR
5779 BGP_STR
5780 "Display routes matching the route-map\n"
5781 "A route-map to match on\n")
5782{
5783 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5784 bgp_show_type_route_map);
5785}
5786
5787ALIAS (show_bgp_route_map,
5788 show_bgp_ipv6_route_map_cmd,
5789 "show bgp ipv6 route-map WORD",
5790 SHOW_STR
5791 BGP_STR
5792 "Address family\n"
5793 "Display routes matching the route-map\n"
5794 "A route-map to match on\n")
5795
5796DEFUN (show_ip_bgp_cidr_only,
5797 show_ip_bgp_cidr_only_cmd,
5798 "show ip bgp cidr-only",
5799 SHOW_STR
5800 IP_STR
5801 BGP_STR
5802 "Display only routes with non-natural netmasks\n")
5803{
5804 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5805 bgp_show_type_cidr_only);
5806}
5807
5808DEFUN (show_ip_bgp_flap_cidr_only,
5809 show_ip_bgp_flap_cidr_only_cmd,
5810 "show ip bgp flap-statistics cidr-only",
5811 SHOW_STR
5812 IP_STR
5813 BGP_STR
5814 "Display flap statistics of routes\n"
5815 "Display only routes with non-natural netmasks\n")
5816{
5817 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5818 bgp_show_type_flap_cidr_only);
5819}
5820
5821DEFUN (show_ip_bgp_ipv4_cidr_only,
5822 show_ip_bgp_ipv4_cidr_only_cmd,
5823 "show ip bgp ipv4 (unicast|multicast) cidr-only",
5824 SHOW_STR
5825 IP_STR
5826 BGP_STR
5827 "Address family\n"
5828 "Address Family modifier\n"
5829 "Address Family modifier\n"
5830 "Display only routes with non-natural netmasks\n")
5831{
5832 if (strncmp (argv[0], "m", 1) == 0)
5833 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
5834 bgp_show_type_cidr_only);
5835
5836 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5837 bgp_show_type_cidr_only);
5838}
5839
5840DEFUN (show_ip_bgp_community_all,
5841 show_ip_bgp_community_all_cmd,
5842 "show ip bgp community",
5843 SHOW_STR
5844 IP_STR
5845 BGP_STR
5846 "Display routes matching the communities\n")
5847{
5848 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5849 bgp_show_type_community_all);
5850}
5851
5852DEFUN (show_ip_bgp_ipv4_community_all,
5853 show_ip_bgp_ipv4_community_all_cmd,
5854 "show ip bgp ipv4 (unicast|multicast) community",
5855 SHOW_STR
5856 IP_STR
5857 BGP_STR
5858 "Address family\n"
5859 "Address Family modifier\n"
5860 "Address Family modifier\n"
5861 "Display routes matching the communities\n")
5862{
5863 if (strncmp (argv[0], "m", 1) == 0)
5864 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
5865 bgp_show_type_community_all);
5866
5867 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5868 bgp_show_type_community_all);
5869}
5870
5871#ifdef HAVE_IPV6
5872DEFUN (show_bgp_community_all,
5873 show_bgp_community_all_cmd,
5874 "show bgp community",
5875 SHOW_STR
5876 BGP_STR
5877 "Display routes matching the communities\n")
5878{
5879 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
5880 bgp_show_type_community_all);
5881}
5882
5883ALIAS (show_bgp_community_all,
5884 show_bgp_ipv6_community_all_cmd,
5885 "show bgp ipv6 community",
5886 SHOW_STR
5887 BGP_STR
5888 "Address family\n"
5889 "Display routes matching the communities\n")
5890
5891/* old command */
5892DEFUN (show_ipv6_bgp_community_all,
5893 show_ipv6_bgp_community_all_cmd,
5894 "show ipv6 bgp community",
5895 SHOW_STR
5896 IPV6_STR
5897 BGP_STR
5898 "Display routes matching the communities\n")
5899{
5900 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
5901 bgp_show_type_community_all);
5902}
5903
5904/* old command */
5905DEFUN (show_ipv6_mbgp_community_all,
5906 show_ipv6_mbgp_community_all_cmd,
5907 "show ipv6 mbgp community",
5908 SHOW_STR
5909 IPV6_STR
5910 MBGP_STR
5911 "Display routes matching the communities\n")
5912{
5913 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
5914 bgp_show_type_community_all);
5915}
5916#endif /* HAVE_IPV6 */
5917
5918int
5919bgp_show_community (struct vty *vty, int argc, char **argv, int exact,
5920 u_int16_t afi, u_char safi)
5921{
5922 struct community *com;
5923 struct buffer *b;
5924 int i;
5925 char *str;
5926 int first = 0;
5927
5928 b = buffer_new (1024);
5929 for (i = 0; i < argc; i++)
5930 {
5931 if (first)
5932 buffer_putc (b, ' ');
5933 else
5934 {
5935 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
5936 continue;
5937 first = 1;
5938 }
5939
5940 buffer_putstr (b, argv[i]);
5941 }
5942 buffer_putc (b, '\0');
5943
5944 str = buffer_getstr (b);
5945 buffer_free (b);
5946
5947 com = community_str2com (str);
5948 free (str);
5949 if (! com)
5950 {
5951 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
5952 return CMD_WARNING;
5953 }
5954
5955 vty->output_arg = com;
5956
5957 if (exact)
5958 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_exact);
5959
5960 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community);
5961}
5962
5963DEFUN (show_ip_bgp_community,
5964 show_ip_bgp_community_cmd,
5965 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
5966 SHOW_STR
5967 IP_STR
5968 BGP_STR
5969 "Display routes matching the communities\n"
5970 "community number\n"
5971 "Do not send outside local AS (well-known community)\n"
5972 "Do not advertise to any peer (well-known community)\n"
5973 "Do not export to next AS (well-known community)\n")
5974{
5975 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
5976}
5977
5978ALIAS (show_ip_bgp_community,
5979 show_ip_bgp_community2_cmd,
5980 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
5981 SHOW_STR
5982 IP_STR
5983 BGP_STR
5984 "Display routes matching the communities\n"
5985 "community number\n"
5986 "Do not send outside local AS (well-known community)\n"
5987 "Do not advertise to any peer (well-known community)\n"
5988 "Do not export to next AS (well-known community)\n"
5989 "community number\n"
5990 "Do not send outside local AS (well-known community)\n"
5991 "Do not advertise to any peer (well-known community)\n"
5992 "Do not export to next AS (well-known community)\n")
5993
5994ALIAS (show_ip_bgp_community,
5995 show_ip_bgp_community3_cmd,
5996 "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)",
5997 SHOW_STR
5998 IP_STR
5999 BGP_STR
6000 "Display routes matching the communities\n"
6001 "community number\n"
6002 "Do not send outside local AS (well-known community)\n"
6003 "Do not advertise to any peer (well-known community)\n"
6004 "Do not export to next AS (well-known community)\n"
6005 "community number\n"
6006 "Do not send outside local AS (well-known community)\n"
6007 "Do not advertise to any peer (well-known community)\n"
6008 "Do not export to next AS (well-known community)\n"
6009 "community number\n"
6010 "Do not send outside local AS (well-known community)\n"
6011 "Do not advertise to any peer (well-known community)\n"
6012 "Do not export to next AS (well-known community)\n")
6013
6014ALIAS (show_ip_bgp_community,
6015 show_ip_bgp_community4_cmd,
6016 "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)",
6017 SHOW_STR
6018 IP_STR
6019 BGP_STR
6020 "Display routes matching the communities\n"
6021 "community number\n"
6022 "Do not send outside local AS (well-known community)\n"
6023 "Do not advertise to any peer (well-known community)\n"
6024 "Do not export to next AS (well-known community)\n"
6025 "community number\n"
6026 "Do not send outside local AS (well-known community)\n"
6027 "Do not advertise to any peer (well-known community)\n"
6028 "Do not export to next AS (well-known community)\n"
6029 "community number\n"
6030 "Do not send outside local AS (well-known community)\n"
6031 "Do not advertise to any peer (well-known community)\n"
6032 "Do not export to next AS (well-known community)\n"
6033 "community number\n"
6034 "Do not send outside local AS (well-known community)\n"
6035 "Do not advertise to any peer (well-known community)\n"
6036 "Do not export to next AS (well-known community)\n")
6037
6038DEFUN (show_ip_bgp_ipv4_community,
6039 show_ip_bgp_ipv4_community_cmd,
6040 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
6041 SHOW_STR
6042 IP_STR
6043 BGP_STR
6044 "Address family\n"
6045 "Address Family modifier\n"
6046 "Address Family modifier\n"
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{
6053 if (strncmp (argv[0], "m", 1) == 0)
6054 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
6055
6056 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
6057}
6058
6059ALIAS (show_ip_bgp_ipv4_community,
6060 show_ip_bgp_ipv4_community2_cmd,
6061 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6062 SHOW_STR
6063 IP_STR
6064 BGP_STR
6065 "Address family\n"
6066 "Address Family modifier\n"
6067 "Address Family modifier\n"
6068 "Display routes matching the communities\n"
6069 "community number\n"
6070 "Do not send outside local AS (well-known community)\n"
6071 "Do not advertise to any peer (well-known community)\n"
6072 "Do not export to next AS (well-known community)\n"
6073 "community number\n"
6074 "Do not send outside local AS (well-known community)\n"
6075 "Do not advertise to any peer (well-known community)\n"
6076 "Do not export to next AS (well-known community)\n")
6077
6078ALIAS (show_ip_bgp_ipv4_community,
6079 show_ip_bgp_ipv4_community3_cmd,
6080 "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)",
6081 SHOW_STR
6082 IP_STR
6083 BGP_STR
6084 "Address family\n"
6085 "Address Family modifier\n"
6086 "Address Family modifier\n"
6087 "Display routes matching the communities\n"
6088 "community number\n"
6089 "Do not send outside local AS (well-known community)\n"
6090 "Do not advertise to any peer (well-known community)\n"
6091 "Do not export to next AS (well-known community)\n"
6092 "community number\n"
6093 "Do not send outside local AS (well-known community)\n"
6094 "Do not advertise to any peer (well-known community)\n"
6095 "Do not export to next AS (well-known community)\n"
6096 "community number\n"
6097 "Do not send outside local AS (well-known community)\n"
6098 "Do not advertise to any peer (well-known community)\n"
6099 "Do not export to next AS (well-known community)\n")
6100
6101ALIAS (show_ip_bgp_ipv4_community,
6102 show_ip_bgp_ipv4_community4_cmd,
6103 "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)",
6104 SHOW_STR
6105 IP_STR
6106 BGP_STR
6107 "Address family\n"
6108 "Address Family modifier\n"
6109 "Address Family modifier\n"
6110 "Display routes matching the communities\n"
6111 "community number\n"
6112 "Do not send outside local AS (well-known community)\n"
6113 "Do not advertise to any peer (well-known community)\n"
6114 "Do not export to next AS (well-known community)\n"
6115 "community number\n"
6116 "Do not send outside local AS (well-known community)\n"
6117 "Do not advertise to any peer (well-known community)\n"
6118 "Do not export to next AS (well-known community)\n"
6119 "community number\n"
6120 "Do not send outside local AS (well-known community)\n"
6121 "Do not advertise to any peer (well-known community)\n"
6122 "Do not export to next AS (well-known community)\n"
6123 "community number\n"
6124 "Do not send outside local AS (well-known community)\n"
6125 "Do not advertise to any peer (well-known community)\n"
6126 "Do not export to next AS (well-known community)\n")
6127
6128DEFUN (show_ip_bgp_community_exact,
6129 show_ip_bgp_community_exact_cmd,
6130 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6131 SHOW_STR
6132 IP_STR
6133 BGP_STR
6134 "Display routes matching the communities\n"
6135 "community number\n"
6136 "Do not send outside local AS (well-known community)\n"
6137 "Do not advertise to any peer (well-known community)\n"
6138 "Do not export to next AS (well-known community)\n"
6139 "Exact match of the communities")
6140{
6141 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
6142}
6143
6144ALIAS (show_ip_bgp_community_exact,
6145 show_ip_bgp_community2_exact_cmd,
6146 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6147 SHOW_STR
6148 IP_STR
6149 BGP_STR
6150 "Display routes matching the communities\n"
6151 "community number\n"
6152 "Do not send outside local AS (well-known community)\n"
6153 "Do not advertise to any peer (well-known community)\n"
6154 "Do not export to next AS (well-known community)\n"
6155 "community number\n"
6156 "Do not send outside local AS (well-known community)\n"
6157 "Do not advertise to any peer (well-known community)\n"
6158 "Do not export to next AS (well-known community)\n"
6159 "Exact match of the communities")
6160
6161ALIAS (show_ip_bgp_community_exact,
6162 show_ip_bgp_community3_exact_cmd,
6163 "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",
6164 SHOW_STR
6165 IP_STR
6166 BGP_STR
6167 "Display routes matching the communities\n"
6168 "community number\n"
6169 "Do not send outside local AS (well-known community)\n"
6170 "Do not advertise to any peer (well-known community)\n"
6171 "Do not export to next AS (well-known community)\n"
6172 "community number\n"
6173 "Do not send outside local AS (well-known community)\n"
6174 "Do not advertise to any peer (well-known community)\n"
6175 "Do not export to next AS (well-known community)\n"
6176 "community number\n"
6177 "Do not send outside local AS (well-known community)\n"
6178 "Do not advertise to any peer (well-known community)\n"
6179 "Do not export to next AS (well-known community)\n"
6180 "Exact match of the communities")
6181
6182ALIAS (show_ip_bgp_community_exact,
6183 show_ip_bgp_community4_exact_cmd,
6184 "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",
6185 SHOW_STR
6186 IP_STR
6187 BGP_STR
6188 "Display routes matching the communities\n"
6189 "community number\n"
6190 "Do not send outside local AS (well-known community)\n"
6191 "Do not advertise to any peer (well-known community)\n"
6192 "Do not export to next AS (well-known community)\n"
6193 "community number\n"
6194 "Do not send outside local AS (well-known community)\n"
6195 "Do not advertise to any peer (well-known community)\n"
6196 "Do not export to next AS (well-known community)\n"
6197 "community number\n"
6198 "Do not send outside local AS (well-known community)\n"
6199 "Do not advertise to any peer (well-known community)\n"
6200 "Do not export to next AS (well-known community)\n"
6201 "community number\n"
6202 "Do not send outside local AS (well-known community)\n"
6203 "Do not advertise to any peer (well-known community)\n"
6204 "Do not export to next AS (well-known community)\n"
6205 "Exact match of the communities")
6206
6207DEFUN (show_ip_bgp_ipv4_community_exact,
6208 show_ip_bgp_ipv4_community_exact_cmd,
6209 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6210 SHOW_STR
6211 IP_STR
6212 BGP_STR
6213 "Address family\n"
6214 "Address Family modifier\n"
6215 "Address Family modifier\n"
6216 "Display routes matching the communities\n"
6217 "community number\n"
6218 "Do not send outside local AS (well-known community)\n"
6219 "Do not advertise to any peer (well-known community)\n"
6220 "Do not export to next AS (well-known community)\n"
6221 "Exact match of the communities")
6222{
6223 if (strncmp (argv[0], "m", 1) == 0)
6224 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
6225
6226 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
6227}
6228
6229ALIAS (show_ip_bgp_ipv4_community_exact,
6230 show_ip_bgp_ipv4_community2_exact_cmd,
6231 "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",
6232 SHOW_STR
6233 IP_STR
6234 BGP_STR
6235 "Address family\n"
6236 "Address Family modifier\n"
6237 "Address Family modifier\n"
6238 "Display routes matching the communities\n"
6239 "community number\n"
6240 "Do not send outside local AS (well-known community)\n"
6241 "Do not advertise to any peer (well-known community)\n"
6242 "Do not export to next AS (well-known community)\n"
6243 "community number\n"
6244 "Do not send outside local AS (well-known community)\n"
6245 "Do not advertise to any peer (well-known community)\n"
6246 "Do not export to next AS (well-known community)\n"
6247 "Exact match of the communities")
6248
6249ALIAS (show_ip_bgp_ipv4_community_exact,
6250 show_ip_bgp_ipv4_community3_exact_cmd,
6251 "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",
6252 SHOW_STR
6253 IP_STR
6254 BGP_STR
6255 "Address family\n"
6256 "Address Family modifier\n"
6257 "Address Family modifier\n"
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")
6272
6273ALIAS (show_ip_bgp_ipv4_community_exact,
6274 show_ip_bgp_ipv4_community4_exact_cmd,
6275 "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",
6276 SHOW_STR
6277 IP_STR
6278 BGP_STR
6279 "Address family\n"
6280 "Address Family modifier\n"
6281 "Address Family modifier\n"
6282 "Display routes matching the communities\n"
6283 "community number\n"
6284 "Do not send outside local AS (well-known community)\n"
6285 "Do not advertise to any peer (well-known community)\n"
6286 "Do not export to next AS (well-known community)\n"
6287 "community number\n"
6288 "Do not send outside local AS (well-known community)\n"
6289 "Do not advertise to any peer (well-known community)\n"
6290 "Do not export to next AS (well-known community)\n"
6291 "community number\n"
6292 "Do not send outside local AS (well-known community)\n"
6293 "Do not advertise to any peer (well-known community)\n"
6294 "Do not export to next AS (well-known community)\n"
6295 "community number\n"
6296 "Do not send outside local AS (well-known community)\n"
6297 "Do not advertise to any peer (well-known community)\n"
6298 "Do not export to next AS (well-known community)\n"
6299 "Exact match of the communities")
6300
6301#ifdef HAVE_IPV6
6302DEFUN (show_bgp_community,
6303 show_bgp_community_cmd,
6304 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
6305 SHOW_STR
6306 BGP_STR
6307 "Display routes matching the communities\n"
6308 "community number\n"
6309 "Do not send outside local AS (well-known community)\n"
6310 "Do not advertise to any peer (well-known community)\n"
6311 "Do not export to next AS (well-known community)\n")
6312{
6313 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
6314}
6315
6316ALIAS (show_bgp_community,
6317 show_bgp_ipv6_community_cmd,
6318 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
6319 SHOW_STR
6320 BGP_STR
6321 "Address family\n"
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
6328ALIAS (show_bgp_community,
6329 show_bgp_community2_cmd,
6330 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6331 SHOW_STR
6332 BGP_STR
6333 "Display routes matching the communities\n"
6334 "community number\n"
6335 "Do not send outside local AS (well-known community)\n"
6336 "Do not advertise to any peer (well-known community)\n"
6337 "Do not export to next AS (well-known community)\n"
6338 "community number\n"
6339 "Do not send outside local AS (well-known community)\n"
6340 "Do not advertise to any peer (well-known community)\n"
6341 "Do not export to next AS (well-known community)\n")
6342
6343ALIAS (show_bgp_community,
6344 show_bgp_ipv6_community2_cmd,
6345 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6346 SHOW_STR
6347 BGP_STR
6348 "Address family\n"
6349 "Display routes matching the communities\n"
6350 "community number\n"
6351 "Do not send outside local AS (well-known community)\n"
6352 "Do not advertise to any peer (well-known community)\n"
6353 "Do not export to next AS (well-known community)\n"
6354 "community number\n"
6355 "Do not send outside local AS (well-known community)\n"
6356 "Do not advertise to any peer (well-known community)\n"
6357 "Do not export to next AS (well-known community)\n")
6358
6359ALIAS (show_bgp_community,
6360 show_bgp_community3_cmd,
6361 "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)",
6362 SHOW_STR
6363 BGP_STR
6364 "Display routes matching the communities\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")
6377
6378ALIAS (show_bgp_community,
6379 show_bgp_ipv6_community3_cmd,
6380 "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)",
6381 SHOW_STR
6382 BGP_STR
6383 "Address family\n"
6384 "Display routes matching the communities\n"
6385 "community number\n"
6386 "Do not send outside local AS (well-known community)\n"
6387 "Do not advertise to any peer (well-known community)\n"
6388 "Do not export to next AS (well-known community)\n"
6389 "community number\n"
6390 "Do not send outside local AS (well-known community)\n"
6391 "Do not advertise to any peer (well-known community)\n"
6392 "Do not export to next AS (well-known community)\n"
6393 "community number\n"
6394 "Do not send outside local AS (well-known community)\n"
6395 "Do not advertise to any peer (well-known community)\n"
6396 "Do not export to next AS (well-known community)\n")
6397
6398ALIAS (show_bgp_community,
6399 show_bgp_community4_cmd,
6400 "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)",
6401 SHOW_STR
6402 BGP_STR
6403 "Display routes matching the communities\n"
6404 "community number\n"
6405 "Do not send outside local AS (well-known community)\n"
6406 "Do not advertise to any peer (well-known community)\n"
6407 "Do not export to next AS (well-known community)\n"
6408 "community number\n"
6409 "Do not send outside local AS (well-known community)\n"
6410 "Do not advertise to any peer (well-known community)\n"
6411 "Do not export to next AS (well-known community)\n"
6412 "community number\n"
6413 "Do not send outside local AS (well-known community)\n"
6414 "Do not advertise to any peer (well-known community)\n"
6415 "Do not export to next AS (well-known community)\n"
6416 "community number\n"
6417 "Do not send outside local AS (well-known community)\n"
6418 "Do not advertise to any peer (well-known community)\n"
6419 "Do not export to next AS (well-known community)\n")
6420
6421ALIAS (show_bgp_community,
6422 show_bgp_ipv6_community4_cmd,
6423 "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)",
6424 SHOW_STR
6425 BGP_STR
6426 "Address family\n"
6427 "Display routes matching the communities\n"
6428 "community number\n"
6429 "Do not send outside local AS (well-known community)\n"
6430 "Do not advertise to any peer (well-known community)\n"
6431 "Do not export to next AS (well-known community)\n"
6432 "community number\n"
6433 "Do not send outside local AS (well-known community)\n"
6434 "Do not advertise to any peer (well-known community)\n"
6435 "Do not export to next AS (well-known community)\n"
6436 "community number\n"
6437 "Do not send outside local AS (well-known community)\n"
6438 "Do not advertise to any peer (well-known community)\n"
6439 "Do not export to next AS (well-known community)\n"
6440 "community number\n"
6441 "Do not send outside local AS (well-known community)\n"
6442 "Do not advertise to any peer (well-known community)\n"
6443 "Do not export to next AS (well-known community)\n")
6444
6445/* old command */
6446DEFUN (show_ipv6_bgp_community,
6447 show_ipv6_bgp_community_cmd,
6448 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
6449 SHOW_STR
6450 IPV6_STR
6451 BGP_STR
6452 "Display routes matching the communities\n"
6453 "community number\n"
6454 "Do not send outside local AS (well-known community)\n"
6455 "Do not advertise to any peer (well-known community)\n"
6456 "Do not export to next AS (well-known community)\n")
6457{
6458 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
6459}
6460
6461/* old command */
6462ALIAS (show_ipv6_bgp_community,
6463 show_ipv6_bgp_community2_cmd,
6464 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6465 SHOW_STR
6466 IPV6_STR
6467 BGP_STR
6468 "Display routes matching the communities\n"
6469 "community number\n"
6470 "Do not send outside local AS (well-known community)\n"
6471 "Do not advertise to any peer (well-known community)\n"
6472 "Do not export to next AS (well-known community)\n"
6473 "community number\n"
6474 "Do not send outside local AS (well-known community)\n"
6475 "Do not advertise to any peer (well-known community)\n"
6476 "Do not export to next AS (well-known community)\n")
6477
6478/* old command */
6479ALIAS (show_ipv6_bgp_community,
6480 show_ipv6_bgp_community3_cmd,
6481 "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)",
6482 SHOW_STR
6483 IPV6_STR
6484 BGP_STR
6485 "Display routes matching the communities\n"
6486 "community number\n"
6487 "Do not send outside local AS (well-known community)\n"
6488 "Do not advertise to any peer (well-known community)\n"
6489 "Do not export to next AS (well-known community)\n"
6490 "community number\n"
6491 "Do not send outside local AS (well-known community)\n"
6492 "Do not advertise to any peer (well-known community)\n"
6493 "Do not export to next AS (well-known community)\n"
6494 "community number\n"
6495 "Do not send outside local AS (well-known community)\n"
6496 "Do not advertise to any peer (well-known community)\n"
6497 "Do not export to next AS (well-known community)\n")
6498
6499/* old command */
6500ALIAS (show_ipv6_bgp_community,
6501 show_ipv6_bgp_community4_cmd,
6502 "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)",
6503 SHOW_STR
6504 IPV6_STR
6505 BGP_STR
6506 "Display routes matching the communities\n"
6507 "community number\n"
6508 "Do not send outside local AS (well-known community)\n"
6509 "Do not advertise to any peer (well-known community)\n"
6510 "Do not export to next AS (well-known community)\n"
6511 "community number\n"
6512 "Do not send outside local AS (well-known community)\n"
6513 "Do not advertise to any peer (well-known community)\n"
6514 "Do not export to next AS (well-known community)\n"
6515 "community number\n"
6516 "Do not send outside local AS (well-known community)\n"
6517 "Do not advertise to any peer (well-known community)\n"
6518 "Do not export to next AS (well-known community)\n"
6519 "community number\n"
6520 "Do not send outside local AS (well-known community)\n"
6521 "Do not advertise to any peer (well-known community)\n"
6522 "Do not export to next AS (well-known community)\n")
6523
6524DEFUN (show_bgp_community_exact,
6525 show_bgp_community_exact_cmd,
6526 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6527 SHOW_STR
6528 BGP_STR
6529 "Display routes matching the communities\n"
6530 "community number\n"
6531 "Do not send outside local AS (well-known community)\n"
6532 "Do not advertise to any peer (well-known community)\n"
6533 "Do not export to next AS (well-known community)\n"
6534 "Exact match of the communities")
6535{
6536 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
6537}
6538
6539ALIAS (show_bgp_community_exact,
6540 show_bgp_ipv6_community_exact_cmd,
6541 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6542 SHOW_STR
6543 BGP_STR
6544 "Address family\n"
6545 "Display routes matching the communities\n"
6546 "community number\n"
6547 "Do not send outside local AS (well-known community)\n"
6548 "Do not advertise to any peer (well-known community)\n"
6549 "Do not export to next AS (well-known community)\n"
6550 "Exact match of the communities")
6551
6552ALIAS (show_bgp_community_exact,
6553 show_bgp_community2_exact_cmd,
6554 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6555 SHOW_STR
6556 BGP_STR
6557 "Display routes matching the communities\n"
6558 "community number\n"
6559 "Do not send outside local AS (well-known community)\n"
6560 "Do not advertise to any peer (well-known community)\n"
6561 "Do not export to next AS (well-known community)\n"
6562 "community number\n"
6563 "Do not send outside local AS (well-known community)\n"
6564 "Do not advertise to any peer (well-known community)\n"
6565 "Do not export to next AS (well-known community)\n"
6566 "Exact match of the communities")
6567
6568ALIAS (show_bgp_community_exact,
6569 show_bgp_ipv6_community2_exact_cmd,
6570 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6571 SHOW_STR
6572 BGP_STR
6573 "Address family\n"
6574 "Display routes matching the communities\n"
6575 "community number\n"
6576 "Do not send outside local AS (well-known community)\n"
6577 "Do not advertise to any peer (well-known community)\n"
6578 "Do not export to next AS (well-known community)\n"
6579 "community number\n"
6580 "Do not send outside local AS (well-known community)\n"
6581 "Do not advertise to any peer (well-known community)\n"
6582 "Do not export to next AS (well-known community)\n"
6583 "Exact match of the communities")
6584
6585ALIAS (show_bgp_community_exact,
6586 show_bgp_community3_exact_cmd,
6587 "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",
6588 SHOW_STR
6589 BGP_STR
6590 "Display routes matching the communities\n"
6591 "community number\n"
6592 "Do not send outside local AS (well-known community)\n"
6593 "Do not advertise to any peer (well-known community)\n"
6594 "Do not export to next AS (well-known community)\n"
6595 "community number\n"
6596 "Do not send outside local AS (well-known community)\n"
6597 "Do not advertise to any peer (well-known community)\n"
6598 "Do not export to next AS (well-known community)\n"
6599 "community number\n"
6600 "Do not send outside local AS (well-known community)\n"
6601 "Do not advertise to any peer (well-known community)\n"
6602 "Do not export to next AS (well-known community)\n"
6603 "Exact match of the communities")
6604
6605ALIAS (show_bgp_community_exact,
6606 show_bgp_ipv6_community3_exact_cmd,
6607 "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",
6608 SHOW_STR
6609 BGP_STR
6610 "Address family\n"
6611 "Display routes matching the communities\n"
6612 "community number\n"
6613 "Do not send outside local AS (well-known community)\n"
6614 "Do not advertise to any peer (well-known community)\n"
6615 "Do not export to next AS (well-known community)\n"
6616 "community number\n"
6617 "Do not send outside local AS (well-known community)\n"
6618 "Do not advertise to any peer (well-known community)\n"
6619 "Do not export to next AS (well-known community)\n"
6620 "community number\n"
6621 "Do not send outside local AS (well-known community)\n"
6622 "Do not advertise to any peer (well-known community)\n"
6623 "Do not export to next AS (well-known community)\n"
6624 "Exact match of the communities")
6625
6626ALIAS (show_bgp_community_exact,
6627 show_bgp_community4_exact_cmd,
6628 "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",
6629 SHOW_STR
6630 BGP_STR
6631 "Display routes matching the communities\n"
6632 "community number\n"
6633 "Do not send outside local AS (well-known community)\n"
6634 "Do not advertise to any peer (well-known community)\n"
6635 "Do not export to next AS (well-known community)\n"
6636 "community number\n"
6637 "Do not send outside local AS (well-known community)\n"
6638 "Do not advertise to any peer (well-known community)\n"
6639 "Do not export to next AS (well-known community)\n"
6640 "community number\n"
6641 "Do not send outside local AS (well-known community)\n"
6642 "Do not advertise to any peer (well-known community)\n"
6643 "Do not export to next AS (well-known community)\n"
6644 "community number\n"
6645 "Do not send outside local AS (well-known community)\n"
6646 "Do not advertise to any peer (well-known community)\n"
6647 "Do not export to next AS (well-known community)\n"
6648 "Exact match of the communities")
6649
6650ALIAS (show_bgp_community_exact,
6651 show_bgp_ipv6_community4_exact_cmd,
6652 "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",
6653 SHOW_STR
6654 BGP_STR
6655 "Address family\n"
6656 "Display routes matching the communities\n"
6657 "community number\n"
6658 "Do not send outside local AS (well-known community)\n"
6659 "Do not advertise to any peer (well-known community)\n"
6660 "Do not export to next AS (well-known community)\n"
6661 "community number\n"
6662 "Do not send outside local AS (well-known community)\n"
6663 "Do not advertise to any peer (well-known community)\n"
6664 "Do not export to next AS (well-known community)\n"
6665 "community number\n"
6666 "Do not send outside local AS (well-known community)\n"
6667 "Do not advertise to any peer (well-known community)\n"
6668 "Do not export to next AS (well-known community)\n"
6669 "community number\n"
6670 "Do not send outside local AS (well-known community)\n"
6671 "Do not advertise to any peer (well-known community)\n"
6672 "Do not export to next AS (well-known community)\n"
6673 "Exact match of the communities")
6674
6675/* old command */
6676DEFUN (show_ipv6_bgp_community_exact,
6677 show_ipv6_bgp_community_exact_cmd,
6678 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6679 SHOW_STR
6680 IPV6_STR
6681 BGP_STR
6682 "Display routes matching the communities\n"
6683 "community number\n"
6684 "Do not send outside local AS (well-known community)\n"
6685 "Do not advertise to any peer (well-known community)\n"
6686 "Do not export to next AS (well-known community)\n"
6687 "Exact match of the communities")
6688{
6689 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
6690}
6691
6692/* old command */
6693ALIAS (show_ipv6_bgp_community_exact,
6694 show_ipv6_bgp_community2_exact_cmd,
6695 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6696 SHOW_STR
6697 IPV6_STR
6698 BGP_STR
6699 "Display routes matching the communities\n"
6700 "community number\n"
6701 "Do not send outside local AS (well-known community)\n"
6702 "Do not advertise to any peer (well-known community)\n"
6703 "Do not export to next AS (well-known community)\n"
6704 "community number\n"
6705 "Do not send outside local AS (well-known community)\n"
6706 "Do not advertise to any peer (well-known community)\n"
6707 "Do not export to next AS (well-known community)\n"
6708 "Exact match of the communities")
6709
6710/* old command */
6711ALIAS (show_ipv6_bgp_community_exact,
6712 show_ipv6_bgp_community3_exact_cmd,
6713 "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",
6714 SHOW_STR
6715 IPV6_STR
6716 BGP_STR
6717 "Display routes matching the communities\n"
6718 "community number\n"
6719 "Do not send outside local AS (well-known community)\n"
6720 "Do not advertise to any peer (well-known community)\n"
6721 "Do not export to next AS (well-known community)\n"
6722 "community number\n"
6723 "Do not send outside local AS (well-known community)\n"
6724 "Do not advertise to any peer (well-known community)\n"
6725 "Do not export to next AS (well-known community)\n"
6726 "community number\n"
6727 "Do not send outside local AS (well-known community)\n"
6728 "Do not advertise to any peer (well-known community)\n"
6729 "Do not export to next AS (well-known community)\n"
6730 "Exact match of the communities")
6731
6732/* old command */
6733ALIAS (show_ipv6_bgp_community_exact,
6734 show_ipv6_bgp_community4_exact_cmd,
6735 "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",
6736 SHOW_STR
6737 IPV6_STR
6738 BGP_STR
6739 "Display routes matching the communities\n"
6740 "community number\n"
6741 "Do not send outside local AS (well-known community)\n"
6742 "Do not advertise to any peer (well-known community)\n"
6743 "Do not export to next AS (well-known community)\n"
6744 "community number\n"
6745 "Do not send outside local AS (well-known community)\n"
6746 "Do not advertise to any peer (well-known community)\n"
6747 "Do not export to next AS (well-known community)\n"
6748 "community number\n"
6749 "Do not send outside local AS (well-known community)\n"
6750 "Do not advertise to any peer (well-known community)\n"
6751 "Do not export to next AS (well-known community)\n"
6752 "community number\n"
6753 "Do not send outside local AS (well-known community)\n"
6754 "Do not advertise to any peer (well-known community)\n"
6755 "Do not export to next AS (well-known community)\n"
6756 "Exact match of the communities")
6757
6758/* old command */
6759DEFUN (show_ipv6_mbgp_community,
6760 show_ipv6_mbgp_community_cmd,
6761 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
6762 SHOW_STR
6763 IPV6_STR
6764 MBGP_STR
6765 "Display routes matching the communities\n"
6766 "community number\n"
6767 "Do not send outside local AS (well-known community)\n"
6768 "Do not advertise to any peer (well-known community)\n"
6769 "Do not export to next AS (well-known community)\n")
6770{
6771 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
6772}
6773
6774/* old command */
6775ALIAS (show_ipv6_mbgp_community,
6776 show_ipv6_mbgp_community2_cmd,
6777 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6778 SHOW_STR
6779 IPV6_STR
6780 MBGP_STR
6781 "Display routes matching the communities\n"
6782 "community number\n"
6783 "Do not send outside local AS (well-known community)\n"
6784 "Do not advertise to any peer (well-known community)\n"
6785 "Do not export to next AS (well-known community)\n"
6786 "community number\n"
6787 "Do not send outside local AS (well-known community)\n"
6788 "Do not advertise to any peer (well-known community)\n"
6789 "Do not export to next AS (well-known community)\n")
6790
6791/* old command */
6792ALIAS (show_ipv6_mbgp_community,
6793 show_ipv6_mbgp_community3_cmd,
6794 "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)",
6795 SHOW_STR
6796 IPV6_STR
6797 MBGP_STR
6798 "Display routes matching the communities\n"
6799 "community number\n"
6800 "Do not send outside local AS (well-known community)\n"
6801 "Do not advertise to any peer (well-known community)\n"
6802 "Do not export to next AS (well-known community)\n"
6803 "community number\n"
6804 "Do not send outside local AS (well-known community)\n"
6805 "Do not advertise to any peer (well-known community)\n"
6806 "Do not export to next AS (well-known community)\n"
6807 "community number\n"
6808 "Do not send outside local AS (well-known community)\n"
6809 "Do not advertise to any peer (well-known community)\n"
6810 "Do not export to next AS (well-known community)\n")
6811
6812/* old command */
6813ALIAS (show_ipv6_mbgp_community,
6814 show_ipv6_mbgp_community4_cmd,
6815 "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)",
6816 SHOW_STR
6817 IPV6_STR
6818 MBGP_STR
6819 "Display routes matching the communities\n"
6820 "community number\n"
6821 "Do not send outside local AS (well-known community)\n"
6822 "Do not advertise to any peer (well-known community)\n"
6823 "Do not export to next AS (well-known community)\n"
6824 "community number\n"
6825 "Do not send outside local AS (well-known community)\n"
6826 "Do not advertise to any peer (well-known community)\n"
6827 "Do not export to next AS (well-known community)\n"
6828 "community number\n"
6829 "Do not send outside local AS (well-known community)\n"
6830 "Do not advertise to any peer (well-known community)\n"
6831 "Do not export to next AS (well-known community)\n"
6832 "community number\n"
6833 "Do not send outside local AS (well-known community)\n"
6834 "Do not advertise to any peer (well-known community)\n"
6835 "Do not export to next AS (well-known community)\n")
6836
6837/* old command */
6838DEFUN (show_ipv6_mbgp_community_exact,
6839 show_ipv6_mbgp_community_exact_cmd,
6840 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6841 SHOW_STR
6842 IPV6_STR
6843 MBGP_STR
6844 "Display routes matching the communities\n"
6845 "community number\n"
6846 "Do not send outside local AS (well-known community)\n"
6847 "Do not advertise to any peer (well-known community)\n"
6848 "Do not export to next AS (well-known community)\n"
6849 "Exact match of the communities")
6850{
6851 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
6852}
6853
6854/* old command */
6855ALIAS (show_ipv6_mbgp_community_exact,
6856 show_ipv6_mbgp_community2_exact_cmd,
6857 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6858 SHOW_STR
6859 IPV6_STR
6860 MBGP_STR
6861 "Display routes matching the communities\n"
6862 "community number\n"
6863 "Do not send outside local AS (well-known community)\n"
6864 "Do not advertise to any peer (well-known community)\n"
6865 "Do not export to next AS (well-known community)\n"
6866 "community number\n"
6867 "Do not send outside local AS (well-known community)\n"
6868 "Do not advertise to any peer (well-known community)\n"
6869 "Do not export to next AS (well-known community)\n"
6870 "Exact match of the communities")
6871
6872/* old command */
6873ALIAS (show_ipv6_mbgp_community_exact,
6874 show_ipv6_mbgp_community3_exact_cmd,
6875 "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",
6876 SHOW_STR
6877 IPV6_STR
6878 MBGP_STR
6879 "Display routes matching the communities\n"
6880 "community number\n"
6881 "Do not send outside local AS (well-known community)\n"
6882 "Do not advertise to any peer (well-known community)\n"
6883 "Do not export to next AS (well-known community)\n"
6884 "community number\n"
6885 "Do not send outside local AS (well-known community)\n"
6886 "Do not advertise to any peer (well-known community)\n"
6887 "Do not export to next AS (well-known community)\n"
6888 "community number\n"
6889 "Do not send outside local AS (well-known community)\n"
6890 "Do not advertise to any peer (well-known community)\n"
6891 "Do not export to next AS (well-known community)\n"
6892 "Exact match of the communities")
6893
6894/* old command */
6895ALIAS (show_ipv6_mbgp_community_exact,
6896 show_ipv6_mbgp_community4_exact_cmd,
6897 "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",
6898 SHOW_STR
6899 IPV6_STR
6900 MBGP_STR
6901 "Display routes matching the communities\n"
6902 "community number\n"
6903 "Do not send outside local AS (well-known community)\n"
6904 "Do not advertise to any peer (well-known community)\n"
6905 "Do not export to next AS (well-known community)\n"
6906 "community number\n"
6907 "Do not send outside local AS (well-known community)\n"
6908 "Do not advertise to any peer (well-known community)\n"
6909 "Do not export to next AS (well-known community)\n"
6910 "community number\n"
6911 "Do not send outside local AS (well-known community)\n"
6912 "Do not advertise to any peer (well-known community)\n"
6913 "Do not export to next AS (well-known community)\n"
6914 "community number\n"
6915 "Do not send outside local AS (well-known community)\n"
6916 "Do not advertise to any peer (well-known community)\n"
6917 "Do not export to next AS (well-known community)\n"
6918 "Exact match of the communities")
6919#endif /* HAVE_IPV6 */
6920
6921int
6922bgp_show_community_list (struct vty *vty, char *com, int exact,
6923 u_int16_t afi, u_char safi)
6924{
6925 struct community_list *list;
6926
6927 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_AUTO);
6928 if (list == NULL)
6929 {
6930 vty_out (vty, "%% %s is not a valid community-list name%s", com,
6931 VTY_NEWLINE);
6932 return CMD_WARNING;
6933 }
6934
6935 vty->output_arg = list;
6936
6937 if (exact)
6938 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_list_exact);
6939
6940 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_list);
6941}
6942
6943DEFUN (show_ip_bgp_community_list,
6944 show_ip_bgp_community_list_cmd,
6945 "show ip bgp community-list WORD",
6946 SHOW_STR
6947 IP_STR
6948 BGP_STR
6949 "Display routes matching the community-list\n"
6950 "community-list name\n")
6951{
6952 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
6953}
6954
6955DEFUN (show_ip_bgp_ipv4_community_list,
6956 show_ip_bgp_ipv4_community_list_cmd,
6957 "show ip bgp ipv4 (unicast|multicast) community-list WORD",
6958 SHOW_STR
6959 IP_STR
6960 BGP_STR
6961 "Address family\n"
6962 "Address Family modifier\n"
6963 "Address Family modifier\n"
6964 "Display routes matching the community-list\n"
6965 "community-list name\n")
6966{
6967 if (strncmp (argv[0], "m", 1) == 0)
6968 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
6969
6970 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
6971}
6972
6973DEFUN (show_ip_bgp_community_list_exact,
6974 show_ip_bgp_community_list_exact_cmd,
6975 "show ip bgp community-list WORD exact-match",
6976 SHOW_STR
6977 IP_STR
6978 BGP_STR
6979 "Display routes matching the community-list\n"
6980 "community-list name\n"
6981 "Exact match of the communities\n")
6982{
6983 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
6984}
6985
6986DEFUN (show_ip_bgp_ipv4_community_list_exact,
6987 show_ip_bgp_ipv4_community_list_exact_cmd,
6988 "show ip bgp ipv4 (unicast|multicast) community-list WORD exact-match",
6989 SHOW_STR
6990 IP_STR
6991 BGP_STR
6992 "Address family\n"
6993 "Address Family modifier\n"
6994 "Address Family modifier\n"
6995 "Display routes matching the community-list\n"
6996 "community-list name\n"
6997 "Exact match of the communities\n")
6998{
6999 if (strncmp (argv[0], "m", 1) == 0)
7000 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
7001
7002 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
7003}
7004
7005#ifdef HAVE_IPV6
7006DEFUN (show_bgp_community_list,
7007 show_bgp_community_list_cmd,
7008 "show bgp community-list WORD",
7009 SHOW_STR
7010 BGP_STR
7011 "Display routes matching the community-list\n"
7012 "community-list name\n")
7013{
7014 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
7015}
7016
7017ALIAS (show_bgp_community_list,
7018 show_bgp_ipv6_community_list_cmd,
7019 "show bgp ipv6 community-list WORD",
7020 SHOW_STR
7021 BGP_STR
7022 "Address family\n"
7023 "Display routes matching the community-list\n"
7024 "community-list name\n")
7025
7026/* old command */
7027DEFUN (show_ipv6_bgp_community_list,
7028 show_ipv6_bgp_community_list_cmd,
7029 "show ipv6 bgp community-list WORD",
7030 SHOW_STR
7031 IPV6_STR
7032 BGP_STR
7033 "Display routes matching the community-list\n"
7034 "community-list name\n")
7035{
7036 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
7037}
7038
7039/* old command */
7040DEFUN (show_ipv6_mbgp_community_list,
7041 show_ipv6_mbgp_community_list_cmd,
7042 "show ipv6 mbgp community-list WORD",
7043 SHOW_STR
7044 IPV6_STR
7045 MBGP_STR
7046 "Display routes matching the community-list\n"
7047 "community-list name\n")
7048{
7049 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
7050}
7051
7052DEFUN (show_bgp_community_list_exact,
7053 show_bgp_community_list_exact_cmd,
7054 "show bgp community-list WORD exact-match",
7055 SHOW_STR
7056 BGP_STR
7057 "Display routes matching the community-list\n"
7058 "community-list name\n"
7059 "Exact match of the communities\n")
7060{
7061 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
7062}
7063
7064ALIAS (show_bgp_community_list_exact,
7065 show_bgp_ipv6_community_list_exact_cmd,
7066 "show bgp ipv6 community-list WORD exact-match",
7067 SHOW_STR
7068 BGP_STR
7069 "Address family\n"
7070 "Display routes matching the community-list\n"
7071 "community-list name\n"
7072 "Exact match of the communities\n")
7073
7074/* old command */
7075DEFUN (show_ipv6_bgp_community_list_exact,
7076 show_ipv6_bgp_community_list_exact_cmd,
7077 "show ipv6 bgp community-list WORD exact-match",
7078 SHOW_STR
7079 IPV6_STR
7080 BGP_STR
7081 "Display routes matching the community-list\n"
7082 "community-list name\n"
7083 "Exact match of the communities\n")
7084{
7085 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
7086}
7087
7088/* old command */
7089DEFUN (show_ipv6_mbgp_community_list_exact,
7090 show_ipv6_mbgp_community_list_exact_cmd,
7091 "show ipv6 mbgp community-list WORD exact-match",
7092 SHOW_STR
7093 IPV6_STR
7094 MBGP_STR
7095 "Display routes matching the community-list\n"
7096 "community-list name\n"
7097 "Exact match of the communities\n")
7098{
7099 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
7100}
7101#endif /* HAVE_IPV6 */
7102
7103void
7104bgp_show_prefix_longer_clean (struct vty *vty)
7105{
7106 struct prefix *p;
7107
7108 p = vty->output_arg;
7109 prefix_free (p);
7110}
7111
7112int
7113bgp_show_prefix_longer (struct vty *vty, char *prefix, afi_t afi,
7114 safi_t safi, enum bgp_show_type type)
7115{
7116 int ret;
7117 struct prefix *p;
7118
7119 p = prefix_new();
7120
7121 ret = str2prefix (prefix, p);
7122 if (! ret)
7123 {
7124 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
7125 return CMD_WARNING;
7126 }
7127
7128 vty->output_arg = p;
7129 vty->output_clean = bgp_show_prefix_longer_clean;
7130
7131 return bgp_show (vty, NULL, afi, safi, type);
7132}
7133
7134DEFUN (show_ip_bgp_prefix_longer,
7135 show_ip_bgp_prefix_longer_cmd,
7136 "show ip bgp A.B.C.D/M longer-prefixes",
7137 SHOW_STR
7138 IP_STR
7139 BGP_STR
7140 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7141 "Display route and more specific routes\n")
7142{
7143 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7144 bgp_show_type_prefix_longer);
7145}
7146
7147DEFUN (show_ip_bgp_flap_prefix_longer,
7148 show_ip_bgp_flap_prefix_longer_cmd,
7149 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
7150 SHOW_STR
7151 IP_STR
7152 BGP_STR
7153 "Display flap statistics of routes\n"
7154 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7155 "Display route and more specific routes\n")
7156{
7157 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7158 bgp_show_type_flap_prefix_longer);
7159}
7160
7161DEFUN (show_ip_bgp_ipv4_prefix_longer,
7162 show_ip_bgp_ipv4_prefix_longer_cmd,
7163 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
7164 SHOW_STR
7165 IP_STR
7166 BGP_STR
7167 "Address family\n"
7168 "Address Family modifier\n"
7169 "Address Family modifier\n"
7170 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7171 "Display route and more specific routes\n")
7172{
7173 if (strncmp (argv[0], "m", 1) == 0)
7174 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7175 bgp_show_type_prefix_longer);
7176
7177 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
7178 bgp_show_type_prefix_longer);
7179}
7180
7181DEFUN (show_ip_bgp_flap_address,
7182 show_ip_bgp_flap_address_cmd,
7183 "show ip bgp flap-statistics A.B.C.D",
7184 SHOW_STR
7185 IP_STR
7186 BGP_STR
7187 "Display flap statistics of routes\n"
7188 "Network in the BGP routing table to display\n")
7189{
7190 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7191 bgp_show_type_flap_address);
7192}
7193
7194DEFUN (show_ip_bgp_flap_prefix,
7195 show_ip_bgp_flap_prefix_cmd,
7196 "show ip bgp flap-statistics A.B.C.D/M",
7197 SHOW_STR
7198 IP_STR
7199 BGP_STR
7200 "Display flap statistics of routes\n"
7201 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7202{
7203 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7204 bgp_show_type_flap_prefix);
7205}
7206#ifdef HAVE_IPV6
7207DEFUN (show_bgp_prefix_longer,
7208 show_bgp_prefix_longer_cmd,
7209 "show bgp X:X::X:X/M longer-prefixes",
7210 SHOW_STR
7211 BGP_STR
7212 "IPv6 prefix <network>/<length>\n"
7213 "Display route and more specific routes\n")
7214{
7215 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7216 bgp_show_type_prefix_longer);
7217}
7218
7219ALIAS (show_bgp_prefix_longer,
7220 show_bgp_ipv6_prefix_longer_cmd,
7221 "show bgp ipv6 X:X::X:X/M longer-prefixes",
7222 SHOW_STR
7223 BGP_STR
7224 "Address family\n"
7225 "IPv6 prefix <network>/<length>\n"
7226 "Display route and more specific routes\n")
7227
7228/* old command */
7229DEFUN (show_ipv6_bgp_prefix_longer,
7230 show_ipv6_bgp_prefix_longer_cmd,
7231 "show ipv6 bgp X:X::X:X/M longer-prefixes",
7232 SHOW_STR
7233 IPV6_STR
7234 BGP_STR
7235 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7236 "Display route and more specific routes\n")
7237{
7238 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7239 bgp_show_type_prefix_longer);
7240}
7241
7242/* old command */
7243DEFUN (show_ipv6_mbgp_prefix_longer,
7244 show_ipv6_mbgp_prefix_longer_cmd,
7245 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
7246 SHOW_STR
7247 IPV6_STR
7248 MBGP_STR
7249 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7250 "Display route and more specific routes\n")
7251{
7252 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7253 bgp_show_type_prefix_longer);
7254}
7255#endif /* HAVE_IPV6 */
7256
7257void
7258show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
7259 int in)
7260{
7261 struct bgp_table *table;
7262 struct bgp_adj_in *ain;
7263 struct bgp_adj_out *adj;
7264 unsigned long output_count;
7265 struct bgp_node *rn;
7266 int header1 = 1;
7267 struct bgp *bgp;
7268 int header2 = 1;
7269
7270 bgp = bgp_get_default ();
7271
7272 if (! bgp)
7273 return;
7274
7275 table = bgp->rib[afi][safi];
7276
7277 output_count = 0;
7278
7279 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
7280 PEER_STATUS_DEFAULT_ORIGINATE))
7281 {
7282 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
7283 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
7284 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
7285
7286 vty_out (vty, "Originating default network 0.0.0.0%s%s",
7287 VTY_NEWLINE, VTY_NEWLINE);
7288 header1 = 0;
7289 }
7290
7291 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7292 if (in)
7293 {
7294 for (ain = rn->adj_in; ain; ain = ain->next)
7295 if (ain->peer == peer)
7296 {
7297 if (header1)
7298 {
7299 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
7300 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
7301 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
7302 header1 = 0;
7303 }
7304 if (header2)
7305 {
7306 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7307 header2 = 0;
7308 }
7309 if (ain->attr)
7310 {
7311 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
7312 output_count++;
7313 }
7314 }
7315 }
7316 else
7317 {
7318 for (adj = rn->adj_out; adj; adj = adj->next)
7319 if (adj->peer == peer)
7320 {
7321 if (header1)
7322 {
7323 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
7324 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
7325 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
7326 header1 = 0;
7327 }
7328 if (header2)
7329 {
7330 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7331 header2 = 0;
7332 }
7333 if (adj->attr)
7334 {
7335 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
7336 output_count++;
7337 }
7338 }
7339 }
7340
7341 if (output_count != 0)
7342 vty_out (vty, "%sTotal number of prefixes %ld%s",
7343 VTY_NEWLINE, output_count, VTY_NEWLINE);
7344}
7345
7346int
7347peer_adj_routes (struct vty *vty, char *ip_str, afi_t afi, safi_t safi, int in)
7348{
7349 int ret;
7350 struct peer *peer;
7351 union sockunion su;
7352
7353 ret = str2sockunion (ip_str, &su);
7354 if (ret < 0)
7355 {
7356 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
7357 return CMD_WARNING;
7358 }
7359 peer = peer_lookup (NULL, &su);
7360 if (! peer || ! peer->afc[afi][safi])
7361 {
7362 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
7363 return CMD_WARNING;
7364 }
7365
7366 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7367 {
7368 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
7369 VTY_NEWLINE);
7370 return CMD_WARNING;
7371 }
7372
7373 show_adj_route (vty, peer, afi, safi, in);
7374
7375 return CMD_SUCCESS;
7376}
7377
7378DEFUN (show_ip_bgp_neighbor_advertised_route,
7379 show_ip_bgp_neighbor_advertised_route_cmd,
7380 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7381 SHOW_STR
7382 IP_STR
7383 BGP_STR
7384 "Detailed information on TCP and BGP neighbor connections\n"
7385 "Neighbor to display information about\n"
7386 "Neighbor to display information about\n"
7387 "Display the routes advertised to a BGP neighbor\n")
7388{
7389 return peer_adj_routes (vty, argv[0], AFI_IP, SAFI_UNICAST, 0);
7390}
7391
7392DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
7393 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
7394 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7395 SHOW_STR
7396 IP_STR
7397 BGP_STR
7398 "Address family\n"
7399 "Address Family modifier\n"
7400 "Address Family modifier\n"
7401 "Detailed information on TCP and BGP neighbor connections\n"
7402 "Neighbor to display information about\n"
7403 "Neighbor to display information about\n"
7404 "Display the routes advertised to a BGP neighbor\n")
7405{
7406 if (strncmp (argv[0], "m", 1) == 0)
7407 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_MULTICAST, 0);
7408
7409 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_UNICAST, 0);
7410}
7411
7412#ifdef HAVE_IPV6
7413DEFUN (show_bgp_neighbor_advertised_route,
7414 show_bgp_neighbor_advertised_route_cmd,
7415 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7416 SHOW_STR
7417 BGP_STR
7418 "Detailed information on TCP and BGP neighbor connections\n"
7419 "Neighbor to display information about\n"
7420 "Neighbor to display information about\n"
7421 "Display the routes advertised to a BGP neighbor\n")
7422{
7423 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0);
7424}
7425
7426ALIAS (show_bgp_neighbor_advertised_route,
7427 show_bgp_ipv6_neighbor_advertised_route_cmd,
7428 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7429 SHOW_STR
7430 BGP_STR
7431 "Address family\n"
7432 "Detailed information on TCP and BGP neighbor connections\n"
7433 "Neighbor to display information about\n"
7434 "Neighbor to display information about\n"
7435 "Display the routes advertised to a BGP neighbor\n")
7436
7437/* old command */
7438DEFUN (ipv6_bgp_neighbor_advertised_route,
7439 ipv6_bgp_neighbor_advertised_route_cmd,
7440 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7441 SHOW_STR
7442 IPV6_STR
7443 BGP_STR
7444 "Detailed information on TCP and BGP neighbor connections\n"
7445 "Neighbor to display information about\n"
7446 "Neighbor to display information about\n"
7447 "Display the routes advertised to a BGP neighbor\n")
7448{
7449 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0);
7450}
7451
7452/* old command */
7453DEFUN (ipv6_mbgp_neighbor_advertised_route,
7454 ipv6_mbgp_neighbor_advertised_route_cmd,
7455 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7456 SHOW_STR
7457 IPV6_STR
7458 MBGP_STR
7459 "Detailed information on TCP and BGP neighbor connections\n"
7460 "Neighbor to display information about\n"
7461 "Neighbor to display information about\n"
7462 "Display the routes advertised to a BGP neighbor\n")
7463{
7464 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_MULTICAST, 0);
7465}
7466#endif /* HAVE_IPV6 */
7467
7468DEFUN (show_ip_bgp_neighbor_received_routes,
7469 show_ip_bgp_neighbor_received_routes_cmd,
7470 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7471 SHOW_STR
7472 IP_STR
7473 BGP_STR
7474 "Detailed information on TCP and BGP neighbor connections\n"
7475 "Neighbor to display information about\n"
7476 "Neighbor to display information about\n"
7477 "Display the received routes from neighbor\n")
7478{
7479 return peer_adj_routes (vty, argv[0], AFI_IP, SAFI_UNICAST, 1);
7480}
7481
7482DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
7483 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
7484 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
7485 SHOW_STR
7486 IP_STR
7487 BGP_STR
7488 "Address family\n"
7489 "Address Family modifier\n"
7490 "Address Family modifier\n"
7491 "Detailed information on TCP and BGP neighbor connections\n"
7492 "Neighbor to display information about\n"
7493 "Neighbor to display information about\n"
7494 "Display the received routes from neighbor\n")
7495{
7496 if (strncmp (argv[0], "m", 1) == 0)
7497 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_MULTICAST, 1);
7498
7499 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_UNICAST, 1);
7500}
7501
7502DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
7503 show_ip_bgp_neighbor_received_prefix_filter_cmd,
7504 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7505 SHOW_STR
7506 IP_STR
7507 BGP_STR
7508 "Detailed information on TCP and BGP neighbor connections\n"
7509 "Neighbor to display information about\n"
7510 "Neighbor to display information about\n"
7511 "Display information received from a BGP neighbor\n"
7512 "Display the prefixlist filter\n")
7513{
7514 char name[BUFSIZ];
7515 union sockunion *su;
7516 struct peer *peer;
7517 int count;
7518
7519 su = sockunion_str2su (argv[0]);
7520 if (su == NULL)
7521 return CMD_WARNING;
7522
7523 peer = peer_lookup (NULL, su);
7524 if (! peer)
7525 return CMD_WARNING;
7526
7527 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
7528 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
7529 if (count)
7530 {
7531 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
7532 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
7533 }
7534
7535 return CMD_SUCCESS;
7536}
7537
7538DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
7539 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
7540 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7541 SHOW_STR
7542 IP_STR
7543 BGP_STR
7544 "Address family\n"
7545 "Address Family modifier\n"
7546 "Address Family modifier\n"
7547 "Detailed information on TCP and BGP neighbor connections\n"
7548 "Neighbor to display information about\n"
7549 "Neighbor to display information about\n"
7550 "Display information received from a BGP neighbor\n"
7551 "Display the prefixlist filter\n")
7552{
7553 char name[BUFSIZ];
7554 union sockunion *su;
7555 struct peer *peer;
7556 int count;
7557
7558 su = sockunion_str2su (argv[1]);
7559 if (su == NULL)
7560 return CMD_WARNING;
7561
7562 peer = peer_lookup (NULL, su);
7563 if (! peer)
7564 return CMD_WARNING;
7565
7566 if (strncmp (argv[0], "m", 1) == 0)
7567 {
7568 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
7569 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
7570 if (count)
7571 {
7572 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
7573 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
7574 }
7575 }
7576 else
7577 {
7578 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
7579 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
7580 if (count)
7581 {
7582 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
7583 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
7584 }
7585 }
7586
7587 return CMD_SUCCESS;
7588}
7589
7590
7591#ifdef HAVE_IPV6
7592DEFUN (show_bgp_neighbor_received_routes,
7593 show_bgp_neighbor_received_routes_cmd,
7594 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7595 SHOW_STR
7596 BGP_STR
7597 "Detailed information on TCP and BGP neighbor connections\n"
7598 "Neighbor to display information about\n"
7599 "Neighbor to display information about\n"
7600 "Display the received routes from neighbor\n")
7601{
7602 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 1);
7603}
7604
7605ALIAS (show_bgp_neighbor_received_routes,
7606 show_bgp_ipv6_neighbor_received_routes_cmd,
7607 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
7608 SHOW_STR
7609 BGP_STR
7610 "Address family\n"
7611 "Detailed information on TCP and BGP neighbor connections\n"
7612 "Neighbor to display information about\n"
7613 "Neighbor to display information about\n"
7614 "Display the received routes from neighbor\n")
7615
7616DEFUN (show_bgp_neighbor_received_prefix_filter,
7617 show_bgp_neighbor_received_prefix_filter_cmd,
7618 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7619 SHOW_STR
7620 BGP_STR
7621 "Detailed information on TCP and BGP neighbor connections\n"
7622 "Neighbor to display information about\n"
7623 "Neighbor to display information about\n"
7624 "Display information received from a BGP neighbor\n"
7625 "Display the prefixlist filter\n")
7626{
7627 char name[BUFSIZ];
7628 union sockunion *su;
7629 struct peer *peer;
7630 int count;
7631
7632 su = sockunion_str2su (argv[0]);
7633 if (su == NULL)
7634 return CMD_WARNING;
7635
7636 peer = peer_lookup (NULL, su);
7637 if (! peer)
7638 return CMD_WARNING;
7639
7640 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
7641 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
7642 if (count)
7643 {
7644 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
7645 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
7646 }
7647
7648 return CMD_SUCCESS;
7649}
7650
7651ALIAS (show_bgp_neighbor_received_prefix_filter,
7652 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
7653 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7654 SHOW_STR
7655 BGP_STR
7656 "Address family\n"
7657 "Detailed information on TCP and BGP neighbor connections\n"
7658 "Neighbor to display information about\n"
7659 "Neighbor to display information about\n"
7660 "Display information received from a BGP neighbor\n"
7661 "Display the prefixlist filter\n")
7662
7663/* old command */
7664DEFUN (ipv6_bgp_neighbor_received_routes,
7665 ipv6_bgp_neighbor_received_routes_cmd,
7666 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7667 SHOW_STR
7668 IPV6_STR
7669 BGP_STR
7670 "Detailed information on TCP and BGP neighbor connections\n"
7671 "Neighbor to display information about\n"
7672 "Neighbor to display information about\n"
7673 "Display the received routes from neighbor\n")
7674{
7675 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 1);
7676}
7677
7678/* old command */
7679DEFUN (ipv6_mbgp_neighbor_received_routes,
7680 ipv6_mbgp_neighbor_received_routes_cmd,
7681 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7682 SHOW_STR
7683 IPV6_STR
7684 MBGP_STR
7685 "Detailed information on TCP and BGP neighbor connections\n"
7686 "Neighbor to display information about\n"
7687 "Neighbor to display information about\n"
7688 "Display the received routes from neighbor\n")
7689{
7690 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_MULTICAST, 1);
7691}
7692#endif /* HAVE_IPV6 */
7693
7694void
7695bgp_show_neighbor_route_clean (struct vty *vty)
7696{
7697 union sockunion *su;
7698
7699 su = vty->output_arg;
7700 XFREE (MTYPE_SOCKUNION, su);
7701}
7702
7703int
7704bgp_show_neighbor_route (struct vty *vty, char *ip_str, afi_t afi,
7705 safi_t safi, enum bgp_show_type type)
7706{
7707 union sockunion *su;
7708 struct peer *peer;
7709
7710 su = sockunion_str2su (ip_str);
7711 if (su == NULL)
7712 {
7713 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
7714 return CMD_WARNING;
7715 }
7716
7717 peer = peer_lookup (NULL, su);
7718 if (! peer || ! peer->afc[afi][safi])
7719 {
7720 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
7721 XFREE (MTYPE_SOCKUNION, su);
7722 return CMD_WARNING;
7723 }
7724
7725 vty->output_arg = su;
7726 vty->output_clean = bgp_show_neighbor_route_clean;
7727
7728 return bgp_show (vty, NULL, afi, safi, type);
7729}
7730
7731DEFUN (show_ip_bgp_neighbor_routes,
7732 show_ip_bgp_neighbor_routes_cmd,
7733 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
7734 SHOW_STR
7735 IP_STR
7736 BGP_STR
7737 "Detailed information on TCP and BGP neighbor connections\n"
7738 "Neighbor to display information about\n"
7739 "Neighbor to display information about\n"
7740 "Display routes learned from neighbor\n")
7741{
7742 return bgp_show_neighbor_route (vty, argv[0], AFI_IP, SAFI_UNICAST,
7743 bgp_show_type_neighbor);
7744}
7745
7746DEFUN (show_ip_bgp_neighbor_flap,
7747 show_ip_bgp_neighbor_flap_cmd,
7748 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
7749 SHOW_STR
7750 IP_STR
7751 BGP_STR
7752 "Detailed information on TCP and BGP neighbor connections\n"
7753 "Neighbor to display information about\n"
7754 "Neighbor to display information about\n"
7755 "Display flap statistics of the routes learned from neighbor\n")
7756{
7757 return bgp_show_neighbor_route (vty, argv[0], AFI_IP, SAFI_UNICAST,
7758 bgp_show_type_flap_neighbor);
7759}
7760
7761DEFUN (show_ip_bgp_neighbor_damp,
7762 show_ip_bgp_neighbor_damp_cmd,
7763 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
7764 SHOW_STR
7765 IP_STR
7766 BGP_STR
7767 "Detailed information on TCP and BGP neighbor connections\n"
7768 "Neighbor to display information about\n"
7769 "Neighbor to display information about\n"
7770 "Display the dampened routes received from neighbor\n")
7771{
7772 return bgp_show_neighbor_route (vty, argv[0], AFI_IP, SAFI_UNICAST,
7773 bgp_show_type_damp_neighbor);
7774}
7775
7776DEFUN (show_ip_bgp_ipv4_neighbor_routes,
7777 show_ip_bgp_ipv4_neighbor_routes_cmd,
7778 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
7779 SHOW_STR
7780 IP_STR
7781 BGP_STR
7782 "Address family\n"
7783 "Address Family modifier\n"
7784 "Address Family modifier\n"
7785 "Detailed information on TCP and BGP neighbor connections\n"
7786 "Neighbor to display information about\n"
7787 "Neighbor to display information about\n"
7788 "Display routes learned from neighbor\n")
7789{
7790 if (strncmp (argv[0], "m", 1) == 0)
7791 return bgp_show_neighbor_route (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7792 bgp_show_type_neighbor);
7793
7794 return bgp_show_neighbor_route (vty, argv[1], AFI_IP, SAFI_UNICAST,
7795 bgp_show_type_neighbor);
7796}
7797#ifdef HAVE_IPV6
7798DEFUN (show_bgp_neighbor_routes,
7799 show_bgp_neighbor_routes_cmd,
7800 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
7801 SHOW_STR
7802 BGP_STR
7803 "Detailed information on TCP and BGP neighbor connections\n"
7804 "Neighbor to display information about\n"
7805 "Neighbor to display information about\n"
7806 "Display routes learned from neighbor\n")
7807{
7808 return bgp_show_neighbor_route (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7809 bgp_show_type_neighbor);
7810}
7811
7812ALIAS (show_bgp_neighbor_routes,
7813 show_bgp_ipv6_neighbor_routes_cmd,
7814 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
7815 SHOW_STR
7816 BGP_STR
7817 "Address family\n"
7818 "Detailed information on TCP and BGP neighbor connections\n"
7819 "Neighbor to display information about\n"
7820 "Neighbor to display information about\n"
7821 "Display routes learned from neighbor\n")
7822
7823/* old command */
7824DEFUN (ipv6_bgp_neighbor_routes,
7825 ipv6_bgp_neighbor_routes_cmd,
7826 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
7827 SHOW_STR
7828 IPV6_STR
7829 BGP_STR
7830 "Detailed information on TCP and BGP neighbor connections\n"
7831 "Neighbor to display information about\n"
7832 "Neighbor to display information about\n"
7833 "Display routes learned from neighbor\n")
7834{
7835 return bgp_show_neighbor_route (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7836 bgp_show_type_neighbor);
7837}
7838
7839/* old command */
7840DEFUN (ipv6_mbgp_neighbor_routes,
7841 ipv6_mbgp_neighbor_routes_cmd,
7842 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
7843 SHOW_STR
7844 IPV6_STR
7845 MBGP_STR
7846 "Detailed information on TCP and BGP neighbor connections\n"
7847 "Neighbor to display information about\n"
7848 "Neighbor to display information about\n"
7849 "Display routes learned from neighbor\n")
7850{
7851 return bgp_show_neighbor_route (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7852 bgp_show_type_neighbor);
7853}
7854#endif /* HAVE_IPV6 */
7855
7856struct bgp_table *bgp_distance_table;
7857
7858struct bgp_distance
7859{
7860 /* Distance value for the IP source prefix. */
7861 u_char distance;
7862
7863 /* Name of the access-list to be matched. */
7864 char *access_list;
7865};
7866
7867struct bgp_distance *
7868bgp_distance_new ()
7869{
7870 struct bgp_distance *new;
7871 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
7872 memset (new, 0, sizeof (struct bgp_distance));
7873 return new;
7874}
7875
7876void
7877bgp_distance_free (struct bgp_distance *bdistance)
7878{
7879 XFREE (MTYPE_BGP_DISTANCE, bdistance);
7880}
7881
7882int
7883bgp_distance_set (struct vty *vty, char *distance_str, char *ip_str,
7884 char *access_list_str)
7885{
7886 int ret;
7887 struct prefix_ipv4 p;
7888 u_char distance;
7889 struct bgp_node *rn;
7890 struct bgp_distance *bdistance;
7891
7892 ret = str2prefix_ipv4 (ip_str, &p);
7893 if (ret == 0)
7894 {
7895 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
7896 return CMD_WARNING;
7897 }
7898
7899 distance = atoi (distance_str);
7900
7901 /* Get BGP distance node. */
7902 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
7903 if (rn->info)
7904 {
7905 bdistance = rn->info;
7906 bgp_unlock_node (rn);
7907 }
7908 else
7909 {
7910 bdistance = bgp_distance_new ();
7911 rn->info = bdistance;
7912 }
7913
7914 /* Set distance value. */
7915 bdistance->distance = distance;
7916
7917 /* Reset access-list configuration. */
7918 if (bdistance->access_list)
7919 {
7920 free (bdistance->access_list);
7921 bdistance->access_list = NULL;
7922 }
7923 if (access_list_str)
7924 bdistance->access_list = strdup (access_list_str);
7925
7926 return CMD_SUCCESS;
7927}
7928
7929int
7930bgp_distance_unset (struct vty *vty, char *distance_str, char *ip_str,
7931 char *access_list_str)
7932{
7933 int ret;
7934 struct prefix_ipv4 p;
7935 u_char distance;
7936 struct bgp_node *rn;
7937 struct bgp_distance *bdistance;
7938
7939 ret = str2prefix_ipv4 (ip_str, &p);
7940 if (ret == 0)
7941 {
7942 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
7943 return CMD_WARNING;
7944 }
7945
7946 distance = atoi (distance_str);
7947
7948 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
7949 if (! rn)
7950 {
7951 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
7952 return CMD_WARNING;
7953 }
7954
7955 bdistance = rn->info;
7956
7957 if (bdistance->access_list)
7958 free (bdistance->access_list);
7959 bgp_distance_free (bdistance);
7960
7961 rn->info = NULL;
7962 bgp_unlock_node (rn);
7963 bgp_unlock_node (rn);
7964
7965 return CMD_SUCCESS;
7966}
7967
7968void
7969bgp_distance_reset ()
7970{
7971 struct bgp_node *rn;
7972 struct bgp_distance *bdistance;
7973
7974 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
7975 if ((bdistance = rn->info) != NULL)
7976 {
7977 if (bdistance->access_list)
7978 free (bdistance->access_list);
7979 bgp_distance_free (bdistance);
7980 rn->info = NULL;
7981 bgp_unlock_node (rn);
7982 }
7983}
7984
7985/* Apply BGP information to distance method. */
7986u_char
7987bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
7988{
7989 struct bgp_node *rn;
7990 struct prefix_ipv4 q;
7991 struct peer *peer;
7992 struct bgp_distance *bdistance;
7993 struct access_list *alist;
7994 struct bgp_static *bgp_static;
7995
7996 if (! bgp)
7997 return 0;
7998
7999 if (p->family != AF_INET)
8000 return 0;
8001
8002 peer = rinfo->peer;
8003
8004 if (peer->su.sa.sa_family != AF_INET)
8005 return 0;
8006
8007 memset (&q, 0, sizeof (struct prefix_ipv4));
8008 q.family = AF_INET;
8009 q.prefix = peer->su.sin.sin_addr;
8010 q.prefixlen = IPV4_MAX_BITLEN;
8011
8012 /* Check source address. */
8013 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
8014 if (rn)
8015 {
8016 bdistance = rn->info;
8017 bgp_unlock_node (rn);
8018
8019 if (bdistance->access_list)
8020 {
8021 alist = access_list_lookup (AFI_IP, bdistance->access_list);
8022 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
8023 return bdistance->distance;
8024 }
8025 else
8026 return bdistance->distance;
8027 }
8028
8029 /* Backdoor check. */
8030 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
8031 if (rn)
8032 {
8033 bgp_static = rn->info;
8034 bgp_unlock_node (rn);
8035
8036 if (bgp_static->backdoor)
8037 {
8038 if (bgp->distance_local)
8039 return bgp->distance_local;
8040 else
8041 return ZEBRA_IBGP_DISTANCE_DEFAULT;
8042 }
8043 }
8044
8045 if (peer_sort (peer) == BGP_PEER_EBGP)
8046 {
8047 if (bgp->distance_ebgp)
8048 return bgp->distance_ebgp;
8049 return ZEBRA_EBGP_DISTANCE_DEFAULT;
8050 }
8051 else
8052 {
8053 if (bgp->distance_ibgp)
8054 return bgp->distance_ibgp;
8055 return ZEBRA_IBGP_DISTANCE_DEFAULT;
8056 }
8057}
8058
8059DEFUN (bgp_distance,
8060 bgp_distance_cmd,
8061 "distance bgp <1-255> <1-255> <1-255>",
8062 "Define an administrative distance\n"
8063 "BGP distance\n"
8064 "Distance for routes external to the AS\n"
8065 "Distance for routes internal to the AS\n"
8066 "Distance for local routes\n")
8067{
8068 struct bgp *bgp;
8069
8070 bgp = vty->index;
8071
8072 bgp->distance_ebgp = atoi (argv[0]);
8073 bgp->distance_ibgp = atoi (argv[1]);
8074 bgp->distance_local = atoi (argv[2]);
8075 return CMD_SUCCESS;
8076}
8077
8078DEFUN (no_bgp_distance,
8079 no_bgp_distance_cmd,
8080 "no distance bgp <1-255> <1-255> <1-255>",
8081 NO_STR
8082 "Define an administrative distance\n"
8083 "BGP distance\n"
8084 "Distance for routes external to the AS\n"
8085 "Distance for routes internal to the AS\n"
8086 "Distance for local routes\n")
8087{
8088 struct bgp *bgp;
8089
8090 bgp = vty->index;
8091
8092 bgp->distance_ebgp= 0;
8093 bgp->distance_ibgp = 0;
8094 bgp->distance_local = 0;
8095 return CMD_SUCCESS;
8096}
8097
8098ALIAS (no_bgp_distance,
8099 no_bgp_distance2_cmd,
8100 "no distance bgp",
8101 NO_STR
8102 "Define an administrative distance\n"
8103 "BGP distance\n")
8104
8105DEFUN (bgp_distance_source,
8106 bgp_distance_source_cmd,
8107 "distance <1-255> A.B.C.D/M",
8108 "Define an administrative distance\n"
8109 "Administrative distance\n"
8110 "IP source prefix\n")
8111{
8112 bgp_distance_set (vty, argv[0], argv[1], NULL);
8113 return CMD_SUCCESS;
8114}
8115
8116DEFUN (no_bgp_distance_source,
8117 no_bgp_distance_source_cmd,
8118 "no distance <1-255> A.B.C.D/M",
8119 NO_STR
8120 "Define an administrative distance\n"
8121 "Administrative distance\n"
8122 "IP source prefix\n")
8123{
8124 bgp_distance_unset (vty, argv[0], argv[1], NULL);
8125 return CMD_SUCCESS;
8126}
8127
8128DEFUN (bgp_distance_source_access_list,
8129 bgp_distance_source_access_list_cmd,
8130 "distance <1-255> A.B.C.D/M WORD",
8131 "Define an administrative distance\n"
8132 "Administrative distance\n"
8133 "IP source prefix\n"
8134 "Access list name\n")
8135{
8136 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
8137 return CMD_SUCCESS;
8138}
8139
8140DEFUN (no_bgp_distance_source_access_list,
8141 no_bgp_distance_source_access_list_cmd,
8142 "no distance <1-255> A.B.C.D/M WORD",
8143 NO_STR
8144 "Define an administrative distance\n"
8145 "Administrative distance\n"
8146 "IP source prefix\n"
8147 "Access list name\n")
8148{
8149 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
8150 return CMD_SUCCESS;
8151}
8152
8153DEFUN (bgp_damp_set,
8154 bgp_damp_set_cmd,
8155 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
8156 "BGP Specific commands\n"
8157 "Enable route-flap dampening\n"
8158 "Half-life time for the penalty\n"
8159 "Value to start reusing a route\n"
8160 "Value to start suppressing a route\n"
8161 "Maximum duration to suppress a stable route\n")
8162{
8163 struct bgp *bgp;
8164 int half = DEFAULT_HALF_LIFE * 60;
8165 int reuse = DEFAULT_REUSE;
8166 int suppress = DEFAULT_SUPPRESS;
8167 int max = 4 * half;
8168
8169 if (argc == 4)
8170 {
8171 half = atoi (argv[0]) * 60;
8172 reuse = atoi (argv[1]);
8173 suppress = atoi (argv[2]);
8174 max = atoi (argv[3]) * 60;
8175 }
8176 else if (argc == 1)
8177 {
8178 half = atoi (argv[0]) * 60;
8179 max = 4 * half;
8180 }
8181
8182 bgp = vty->index;
8183 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
8184 half, reuse, suppress, max);
8185}
8186
8187ALIAS (bgp_damp_set,
8188 bgp_damp_set2_cmd,
8189 "bgp dampening <1-45>",
8190 "BGP Specific commands\n"
8191 "Enable route-flap dampening\n"
8192 "Half-life time for the penalty\n")
8193
8194ALIAS (bgp_damp_set,
8195 bgp_damp_set3_cmd,
8196 "bgp dampening",
8197 "BGP Specific commands\n"
8198 "Enable route-flap dampening\n")
8199
8200DEFUN (bgp_damp_unset,
8201 bgp_damp_unset_cmd,
8202 "no bgp dampening",
8203 NO_STR
8204 "BGP Specific commands\n"
8205 "Enable route-flap dampening\n")
8206{
8207 struct bgp *bgp;
8208
8209 bgp = vty->index;
8210 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
8211}
8212
8213ALIAS (bgp_damp_unset,
8214 bgp_damp_unset2_cmd,
8215 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
8216 NO_STR
8217 "BGP Specific commands\n"
8218 "Enable route-flap dampening\n"
8219 "Half-life time for the penalty\n"
8220 "Value to start reusing a route\n"
8221 "Value to start suppressing a route\n"
8222 "Maximum duration to suppress a stable route\n")
8223
8224DEFUN (show_ip_bgp_dampened_paths,
8225 show_ip_bgp_dampened_paths_cmd,
8226 "show ip bgp dampened-paths",
8227 SHOW_STR
8228 IP_STR
8229 BGP_STR
8230 "Display paths suppressed due to dampening\n")
8231{
8232 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths);
8233}
8234
8235DEFUN (show_ip_bgp_flap_statistics,
8236 show_ip_bgp_flap_statistics_cmd,
8237 "show ip bgp flap-statistics",
8238 SHOW_STR
8239 IP_STR
8240 BGP_STR
8241 "Display flap statistics of routes\n")
8242{
8243 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_flap_statistics);
8244}
8245
8246/* Display specified route of BGP table. */
8247int
8248bgp_clear_damp_route (struct vty *vty, char *view_name, char *ip_str,
8249 afi_t afi, safi_t safi, struct prefix_rd *prd,
8250 int prefix_check)
8251{
8252 int ret;
8253 struct prefix match;
8254 struct bgp_node *rn;
8255 struct bgp_node *rm;
8256 struct bgp_info *ri;
8257 struct bgp_info *ri_temp;
8258 struct bgp *bgp;
8259 struct bgp_table *table;
8260
8261 /* BGP structure lookup. */
8262 if (view_name)
8263 {
8264 bgp = bgp_lookup_by_name (view_name);
8265 if (bgp == NULL)
8266 {
8267 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8268 return CMD_WARNING;
8269 }
8270 }
8271 else
8272 {
8273 bgp = bgp_get_default ();
8274 if (bgp == NULL)
8275 {
8276 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
8277 return CMD_WARNING;
8278 }
8279 }
8280
8281 /* Check IP address argument. */
8282 ret = str2prefix (ip_str, &match);
8283 if (! ret)
8284 {
8285 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
8286 return CMD_WARNING;
8287 }
8288
8289 match.family = afi2family (afi);
8290
8291 if (safi == SAFI_MPLS_VPN)
8292 {
8293 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
8294 {
8295 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8296 continue;
8297
8298 if ((table = rn->info) != NULL)
8299 if ((rm = bgp_node_match (table, &match)) != NULL)
8300 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
8301 {
8302 ri = rm->info;
8303 while (ri)
8304 {
8305 if (ri->damp_info)
8306 {
8307 ri_temp = ri->next;
8308 bgp_damp_info_free (ri->damp_info, 1);
8309 ri = ri_temp;
8310 }
8311 else
8312 ri = ri->next;
8313 }
8314 }
8315 }
8316 }
8317 else
8318 {
8319 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
8320 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8321 {
8322 ri = rn->info;
8323 while (ri)
8324 {
8325 if (ri->damp_info)
8326 {
8327 ri_temp = ri->next;
8328 bgp_damp_info_free (ri->damp_info, 1);
8329 ri = ri_temp;
8330 }
8331 else
8332 ri = ri->next;
8333 }
8334 }
8335 }
8336
8337 return CMD_SUCCESS;
8338}
8339
8340DEFUN (clear_ip_bgp_dampening,
8341 clear_ip_bgp_dampening_cmd,
8342 "clear ip bgp dampening",
8343 CLEAR_STR
8344 IP_STR
8345 BGP_STR
8346 "Clear route flap dampening information\n")
8347{
8348 bgp_damp_info_clean ();
8349 return CMD_SUCCESS;
8350}
8351
8352DEFUN (clear_ip_bgp_dampening_prefix,
8353 clear_ip_bgp_dampening_prefix_cmd,
8354 "clear ip bgp dampening A.B.C.D/M",
8355 CLEAR_STR
8356 IP_STR
8357 BGP_STR
8358 "Clear route flap dampening information\n"
8359 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8360{
8361 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
8362 SAFI_UNICAST, NULL, 1);
8363}
8364
8365DEFUN (clear_ip_bgp_dampening_address,
8366 clear_ip_bgp_dampening_address_cmd,
8367 "clear ip bgp dampening A.B.C.D",
8368 CLEAR_STR
8369 IP_STR
8370 BGP_STR
8371 "Clear route flap dampening information\n"
8372 "Network to clear damping information\n")
8373{
8374 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
8375 SAFI_UNICAST, NULL, 0);
8376}
8377
8378DEFUN (clear_ip_bgp_dampening_address_mask,
8379 clear_ip_bgp_dampening_address_mask_cmd,
8380 "clear ip bgp dampening A.B.C.D A.B.C.D",
8381 CLEAR_STR
8382 IP_STR
8383 BGP_STR
8384 "Clear route flap dampening information\n"
8385 "Network to clear damping information\n"
8386 "Network mask\n")
8387{
8388 int ret;
8389 char prefix_str[BUFSIZ];
8390
8391 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
8392 if (! ret)
8393 {
8394 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
8395 return CMD_WARNING;
8396 }
8397
8398 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
8399 SAFI_UNICAST, NULL, 0);
8400}
8401
8402int
8403bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
8404 afi_t afi, safi_t safi, int *write)
8405{
8406 struct bgp_node *prn;
8407 struct bgp_node *rn;
8408 struct bgp_table *table;
8409 struct prefix *p;
8410 struct prefix_rd *prd;
8411 struct bgp_static *bgp_static;
8412 u_int32_t label;
8413 char buf[SU_ADDRSTRLEN];
8414 char rdbuf[RD_ADDRSTRLEN];
8415
8416 /* Network configuration. */
8417 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
8418 if ((table = prn->info) != NULL)
8419 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8420 if ((bgp_static = rn->info) != NULL)
8421 {
8422 p = &rn->p;
8423 prd = (struct prefix_rd *) &prn->p;
8424
8425 /* "address-family" display. */
8426 bgp_config_write_family_header (vty, afi, safi, write);
8427
8428 /* "network" configuration display. */
8429 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
8430 label = decode_label (bgp_static->tag);
8431
8432 vty_out (vty, " network %s/%d rd %s tag %d",
8433 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
8434 p->prefixlen,
8435 rdbuf, label);
8436 vty_out (vty, "%s", VTY_NEWLINE);
8437 }
8438 return 0;
8439}
8440
8441/* Configuration of static route announcement and aggregate
8442 information. */
8443int
8444bgp_config_write_network (struct vty *vty, struct bgp *bgp,
8445 afi_t afi, safi_t safi, int *write)
8446{
8447 struct bgp_node *rn;
8448 struct prefix *p;
8449 struct bgp_static *bgp_static;
8450 struct bgp_aggregate *bgp_aggregate;
8451 char buf[SU_ADDRSTRLEN];
8452
8453 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8454 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
8455
8456 /* Network configuration. */
8457 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
8458 if ((bgp_static = rn->info) != NULL)
8459 {
8460 p = &rn->p;
8461
8462 /* "address-family" display. */
8463 bgp_config_write_family_header (vty, afi, safi, write);
8464
8465 /* "network" configuration display. */
8466 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
8467 {
8468 u_int32_t destination;
8469 struct in_addr netmask;
8470
8471 destination = ntohl (p->u.prefix4.s_addr);
8472 masklen2ip (p->prefixlen, &netmask);
8473 vty_out (vty, " network %s",
8474 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
8475
8476 if ((IN_CLASSC (destination) && p->prefixlen == 24)
8477 || (IN_CLASSB (destination) && p->prefixlen == 16)
8478 || (IN_CLASSA (destination) && p->prefixlen == 8)
8479 || p->u.prefix4.s_addr == 0)
8480 {
8481 /* Natural mask is not display. */
8482 }
8483 else
8484 vty_out (vty, " mask %s", inet_ntoa (netmask));
8485 }
8486 else
8487 {
8488 vty_out (vty, " network %s/%d",
8489 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
8490 p->prefixlen);
8491 }
8492
8493 if (bgp_static->rmap.name)
8494 vty_out (vty, " route-map %s", bgp_static->rmap.name);
8495 else if (bgp_static->backdoor)
8496 vty_out (vty, " backdoor");
8497
8498 vty_out (vty, "%s", VTY_NEWLINE);
8499 }
8500
8501 /* Aggregate-address configuration. */
8502 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
8503 if ((bgp_aggregate = rn->info) != NULL)
8504 {
8505 p = &rn->p;
8506
8507 /* "address-family" display. */
8508 bgp_config_write_family_header (vty, afi, safi, write);
8509
8510 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
8511 {
8512 struct in_addr netmask;
8513
8514 masklen2ip (p->prefixlen, &netmask);
8515 vty_out (vty, " aggregate-address %s %s",
8516 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
8517 inet_ntoa (netmask));
8518 }
8519 else
8520 {
8521 vty_out (vty, " aggregate-address %s/%d",
8522 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
8523 p->prefixlen);
8524 }
8525
8526 if (bgp_aggregate->as_set)
8527 vty_out (vty, " as-set");
8528
8529 if (bgp_aggregate->summary_only)
8530 vty_out (vty, " summary-only");
8531
8532 vty_out (vty, "%s", VTY_NEWLINE);
8533 }
8534
8535 return 0;
8536}
8537
8538int
8539bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
8540{
8541 struct bgp_node *rn;
8542 struct bgp_distance *bdistance;
8543
8544 /* Distance configuration. */
8545 if (bgp->distance_ebgp
8546 && bgp->distance_ibgp
8547 && bgp->distance_local
8548 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
8549 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
8550 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
8551 vty_out (vty, " distance bgp %d %d %d%s",
8552 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
8553 VTY_NEWLINE);
8554
8555 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
8556 if ((bdistance = rn->info) != NULL)
8557 {
8558 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
8559 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
8560 bdistance->access_list ? bdistance->access_list : "",
8561 VTY_NEWLINE);
8562 }
8563
8564 return 0;
8565}
8566
8567/* Allocate routing table structure and install commands. */
8568void
8569bgp_route_init ()
8570{
8571 /* Init BGP distance table. */
8572 bgp_distance_table = bgp_table_init ();
8573
8574 /* IPv4 BGP commands. */
8575 install_element (BGP_NODE, &bgp_network_cmd);
8576 install_element (BGP_NODE, &bgp_network_mask_cmd);
8577 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
8578 install_element (BGP_NODE, &bgp_network_route_map_cmd);
8579 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
8580 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
8581 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
8582 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
8583 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
8584 install_element (BGP_NODE, &no_bgp_network_cmd);
8585 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
8586 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
8587 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
8588 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
8589 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
8590 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
8591 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
8592 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
8593
8594 install_element (BGP_NODE, &aggregate_address_cmd);
8595 install_element (BGP_NODE, &aggregate_address_mask_cmd);
8596 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
8597 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
8598 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
8599 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
8600 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
8601 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
8602 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
8603 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
8604 install_element (BGP_NODE, &no_aggregate_address_cmd);
8605 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
8606 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
8607 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
8608 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
8609 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
8610 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
8611 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
8612 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
8613 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
8614
8615 /* IPv4 unicast configuration. */
8616 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
8617 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
8618 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
8619 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
8620 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
8621 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
8622 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
8623 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
8624 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
8625 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
8626 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
8627 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
8628 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
8629 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
8630 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
8631 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
8632 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
8633 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
8634 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
8635 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
8636 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
8637 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
8638 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
8639 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
8640 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
8641 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
8642 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
8643 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
8644 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
8645 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
8646 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
8647 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
8648
8649 /* IPv4 multicast configuration. */
8650 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
8651 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
8652 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
8653 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
8654 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
8655 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
8656 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
8657 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
8658 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
8659 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
8660 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
8661 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
8662 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
8663 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
8664 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
8665 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
8666 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
8667 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
8668 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
8669 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
8670 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
8671 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
8672 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
8673 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
8674 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
8675 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
8676 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
8677 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
8678 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
8679 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
8680 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
8681 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
8682
8683 install_element (VIEW_NODE, &show_ip_bgp_cmd);
8684 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
8685 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
8686 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
8687 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
8688 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
8689 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
8690 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
8691 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
8692 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
8693 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
8694 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
8695 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
8696 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
8697 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
8698 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
8699 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
8700 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
8701 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
8702 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
8703 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
8704 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
8705 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
8706 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
8707 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
8708 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
8709 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
8710 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
8711 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
8712 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
8713 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
8714 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
8715 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
8716 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
8717 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
8718 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
8719 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
8720 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
8721 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
8722 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
8723 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
8724 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
8725 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
8726 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
8727 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
8728 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
8729 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
8730 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8731 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
8732 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8733 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
8734 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
8735 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
8736 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
8737 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
8738 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
8739 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
8740 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
8741 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
8742 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
8743 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
8744 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
8745 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
8746 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
8747 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
8748 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
8749 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
8750
8751 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
8752 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
8753 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
8754 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
8755 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
8756 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
8757 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
8758 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
8759 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
8760 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
8761 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
8762 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
8763 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
8764 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
8765 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
8766 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
8767 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
8768 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
8769 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
8770 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
8771 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
8772 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
8773 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
8774 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
8775 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
8776 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
8777 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
8778 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
8779 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
8780 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
8781 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
8782 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
8783 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
8784 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
8785 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
8786 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
8787 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
8788 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
8789 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
8790 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
8791 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
8792 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
8793 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
8794 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
8795 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
8796 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
8797 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
8798 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8799 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
8800 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8801 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
8802 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
8803 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
8804 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
8805 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
8806 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
8807 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
8808 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
8809 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
8810 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
8811 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
8812 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
8813 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
8814 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
8815 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
8816 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
8817 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
8818
8819 /* BGP dampening clear commands */
8820 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
8821 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
8822 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
8823 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
8824
8825#ifdef HAVE_IPV6
8826 /* New config IPv6 BGP commands. */
8827 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
8828 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
8829 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
8830 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
8831
8832 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
8833 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
8834 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
8835 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
8836
8837 /* Old config IPv6 BGP commands. */
8838 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
8839 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
8840
8841 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
8842 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
8843 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
8844 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
8845
8846 install_element (VIEW_NODE, &show_bgp_cmd);
8847 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
8848 install_element (VIEW_NODE, &show_bgp_route_cmd);
8849 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
8850 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
8851 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
8852 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
8853 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
8854 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
8855 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
8856 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
8857 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
8858 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
8859 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
8860 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
8861 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
8862 install_element (VIEW_NODE, &show_bgp_community_cmd);
8863 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
8864 install_element (VIEW_NODE, &show_bgp_community2_cmd);
8865 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
8866 install_element (VIEW_NODE, &show_bgp_community3_cmd);
8867 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
8868 install_element (VIEW_NODE, &show_bgp_community4_cmd);
8869 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
8870 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
8871 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
8872 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
8873 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
8874 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
8875 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
8876 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
8877 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
8878 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
8879 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
8880 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
8881 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
8882 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
8883 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
8884 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
8885 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
8886 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
8887 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
8888 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
8889 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
8890 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
8891 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
8892
8893 install_element (ENABLE_NODE, &show_bgp_cmd);
8894 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
8895 install_element (ENABLE_NODE, &show_bgp_route_cmd);
8896 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
8897 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
8898 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
8899 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
8900 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
8901 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
8902 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
8903 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
8904 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
8905 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
8906 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
8907 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
8908 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
8909 install_element (ENABLE_NODE, &show_bgp_community_cmd);
8910 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
8911 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
8912 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
8913 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
8914 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
8915 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
8916 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
8917 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
8918 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
8919 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
8920 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
8921 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
8922 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
8923 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
8924 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
8925 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
8926 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
8927 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
8928 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
8929 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
8930 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
8931 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
8932 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
8933 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
8934 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
8935 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
8936 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
8937 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
8938 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
8939
8940 /* old command */
8941 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
8942 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
8943 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
8944 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
8945 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
8946 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
8947 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
8948 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
8949 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
8950 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
8951 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
8952 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
8953 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
8954 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
8955 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
8956 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
8957 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
8958 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
8959 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
8960 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
8961 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
8962 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
8963 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
8964 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
8965 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
8966 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
8967 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
8968 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
8969 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
8970 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
8971 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
8972 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
8973 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
8974 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
8975 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
8976 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
8977
8978 /* old command */
8979 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
8980 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
8981 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
8982 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
8983 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
8984 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
8985 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
8986 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
8987 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
8988 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
8989 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
8990 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
8991 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
8992 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
8993 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
8994 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
8995 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
8996 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
8997 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
8998 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
8999 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
9000 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
9001 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
9002 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
9003 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
9004 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
9005 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
9006 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
9007 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
9008 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
9009 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
9010 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
9011 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
9012 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
9013 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
9014 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
9015
9016 /* old command */
9017 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
9018 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
9019 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
9020 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
9021
9022 /* old command */
9023 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
9024 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
9025 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
9026 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
9027
9028 /* old command */
9029 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
9030 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
9031 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
9032 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
9033#endif /* HAVE_IPV6 */
9034
9035 install_element (BGP_NODE, &bgp_distance_cmd);
9036 install_element (BGP_NODE, &no_bgp_distance_cmd);
9037 install_element (BGP_NODE, &no_bgp_distance2_cmd);
9038 install_element (BGP_NODE, &bgp_distance_source_cmd);
9039 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
9040 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
9041 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
9042
9043 install_element (BGP_NODE, &bgp_damp_set_cmd);
9044 install_element (BGP_NODE, &bgp_damp_set2_cmd);
9045 install_element (BGP_NODE, &bgp_damp_set3_cmd);
9046 install_element (BGP_NODE, &bgp_damp_unset_cmd);
9047 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
9048 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
9049 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
9050 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
9051 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
9052 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
9053}