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