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