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