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