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