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