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