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