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