blob: b49bea9880b6644a63ae1f8767b8c134e347a0c1 [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 */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002517
2518 /* Tickle FSM to start moving again */
2519 BGP_EVENT_ADD (peer, BGP_Start);
paul200df112005-06-01 11:17:05 +00002520}
2521
2522static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002523bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002524{
Paul Jakma64e580a2006-02-21 01:09:01 +00002525#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2526 char wname[CLEAR_QUEUE_NAME_LEN];
2527
2528 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2529#undef CLEAR_QUEUE_NAME_LEN
2530
2531 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002532 {
2533 zlog_err ("%s: Failed to allocate work queue", __func__);
2534 exit (1);
2535 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002536 peer->clear_node_queue->spec.hold = 10;
2537 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2538 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2539 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2540 peer->clear_node_queue->spec.max_retries = 0;
2541
2542 /* we only 'lock' this peer reference when the queue is actually active */
2543 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002544}
2545
paul718e3742002-12-13 20:15:29 +00002546static void
2547bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002548 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002549{
2550 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002551
paul718e3742002-12-13 20:15:29 +00002552 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002553 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002554
hasso6cf159b2005-03-21 10:28:14 +00002555 /* If still no table => afi/safi isn't configured at all or smth. */
2556 if (! table)
2557 return;
2558
Paul Jakma64e580a2006-02-21 01:09:01 +00002559 if (peer->clear_node_queue == NULL)
2560 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002561
Paul Jakma64e580a2006-02-21 01:09:01 +00002562 /* bgp_fsm.c will not bring CLEARING sessions out of Idle this
2563 * protects against peers which flap faster than we can we clear,
2564 * which could lead to:
2565 *
2566 * a) race with routes from the new session being installed before
2567 * clear_route_node visits the node (to delete the route of that
2568 * peer)
2569 * b) resource exhaustion, clear_route_node likely leads to an entry
2570 * on the process_main queue. Fast-flapping could cause that queue
2571 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002572 */
Paul Jakma64e580a2006-02-21 01:09:01 +00002573 if (!CHECK_FLAG (peer->sflags, PEER_STATUS_CLEARING))
2574 {
2575 SET_FLAG (peer->sflags, PEER_STATUS_CLEARING);
2576 peer_lock (peer); /* bgp_clear_node_complete */
2577 }
paul200df112005-06-01 11:17:05 +00002578
paul718e3742002-12-13 20:15:29 +00002579 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2580 {
paul200df112005-06-01 11:17:05 +00002581 if (rn->info == NULL)
2582 continue;
2583
Paul Jakma64e580a2006-02-21 01:09:01 +00002584 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2585 work_queue_add (peer->clear_node_queue, rn);
paul718e3742002-12-13 20:15:29 +00002586 }
paul200df112005-06-01 11:17:05 +00002587 return;
paul718e3742002-12-13 20:15:29 +00002588}
2589
2590void
2591bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2592{
2593 struct bgp_node *rn;
2594 struct bgp_table *table;
paulfee0f4c2004-09-13 05:12:46 +00002595 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002596 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002597
paul718e3742002-12-13 20:15:29 +00002598 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002599 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002600 else
2601 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2602 rn = bgp_route_next (rn))
2603 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002604 bgp_clear_route_table (peer, afi, safi, table, NULL);
2605
paul1eb8ef22005-04-07 07:30:20 +00002606 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002607 {
2608 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2609 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2610 }
paul718e3742002-12-13 20:15:29 +00002611}
2612
2613void
2614bgp_clear_route_all (struct peer *peer)
2615{
2616 afi_t afi;
2617 safi_t safi;
2618
2619 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2620 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2621 bgp_clear_route (peer, afi, safi);
2622}
2623
2624void
2625bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2626{
2627 struct bgp_table *table;
2628 struct bgp_node *rn;
2629 struct bgp_adj_in *ain;
2630
2631 table = peer->bgp->rib[afi][safi];
2632
2633 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2634 for (ain = rn->adj_in; ain ; ain = ain->next)
2635 if (ain->peer == peer)
2636 {
2637 bgp_adj_in_remove (rn, ain);
2638 bgp_unlock_node (rn);
2639 break;
2640 }
2641}
hasso93406d82005-02-02 14:40:33 +00002642
2643void
2644bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2645{
2646 struct bgp_node *rn;
2647 struct bgp_info *ri;
2648 struct bgp_table *table;
2649
2650 table = peer->bgp->rib[afi][safi];
2651
2652 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2653 {
2654 for (ri = rn->info; ri; ri = ri->next)
2655 if (ri->peer == peer)
2656 {
2657 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2658 bgp_rib_remove (rn, ri, peer, afi, safi);
2659 break;
2660 }
2661 }
2662}
paul718e3742002-12-13 20:15:29 +00002663
2664/* Delete all kernel routes. */
2665void
paul545acaf2004-04-20 15:13:15 +00002666bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002667{
2668 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002669 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002670 struct bgp_node *rn;
2671 struct bgp_table *table;
2672 struct bgp_info *ri;
2673
paul1eb8ef22005-04-07 07:30:20 +00002674 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002675 {
2676 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2677
2678 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2679 for (ri = rn->info; ri; ri = ri->next)
2680 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2681 && ri->type == ZEBRA_ROUTE_BGP
2682 && ri->sub_type == BGP_ROUTE_NORMAL)
2683 bgp_zebra_withdraw (&rn->p, ri);
2684
2685 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2686
2687 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2688 for (ri = rn->info; ri; ri = ri->next)
2689 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2690 && ri->type == ZEBRA_ROUTE_BGP
2691 && ri->sub_type == BGP_ROUTE_NORMAL)
2692 bgp_zebra_withdraw (&rn->p, ri);
2693 }
2694}
2695
2696void
2697bgp_reset ()
2698{
2699 vty_reset ();
2700 bgp_zclient_reset ();
2701 access_list_reset ();
2702 prefix_list_reset ();
2703}
2704
2705/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2706 value. */
2707int
2708bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2709{
2710 u_char *pnt;
2711 u_char *lim;
2712 struct prefix p;
2713 int psize;
2714 int ret;
2715
2716 /* Check peer status. */
2717 if (peer->status != Established)
2718 return 0;
2719
2720 pnt = packet->nlri;
2721 lim = pnt + packet->length;
2722
2723 for (; pnt < lim; pnt += psize)
2724 {
2725 /* Clear prefix structure. */
2726 memset (&p, 0, sizeof (struct prefix));
2727
2728 /* Fetch prefix length. */
2729 p.prefixlen = *pnt++;
2730 p.family = afi2family (packet->afi);
2731
2732 /* Already checked in nlri_sanity_check(). We do double check
2733 here. */
2734 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2735 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2736 return -1;
2737
2738 /* Packet size overflow check. */
2739 psize = PSIZE (p.prefixlen);
2740
2741 /* When packet overflow occur return immediately. */
2742 if (pnt + psize > lim)
2743 return -1;
2744
2745 /* Fetch prefix from NLRI packet. */
2746 memcpy (&p.u.prefix, pnt, psize);
2747
2748 /* Check address. */
2749 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2750 {
2751 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2752 {
paulf5ba3872004-07-09 12:11:31 +00002753 /*
2754 * From draft-ietf-idr-bgp4-22, Section 6.3:
2755 * If a BGP router receives an UPDATE message with a
2756 * semantically incorrect NLRI field, in which a prefix is
2757 * semantically incorrect (eg. an unexpected multicast IP
2758 * address), it should ignore the prefix.
2759 */
paul718e3742002-12-13 20:15:29 +00002760 zlog (peer->log, LOG_ERR,
2761 "IPv4 unicast NLRI is multicast address %s",
2762 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002763
paul718e3742002-12-13 20:15:29 +00002764 return -1;
2765 }
2766 }
2767
2768#ifdef HAVE_IPV6
2769 /* Check address. */
2770 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2771 {
2772 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2773 {
2774 char buf[BUFSIZ];
2775
2776 zlog (peer->log, LOG_WARNING,
2777 "IPv6 link-local NLRI received %s ignore this NLRI",
2778 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2779
2780 continue;
2781 }
2782 }
2783#endif /* HAVE_IPV6 */
2784
2785 /* Normal process. */
2786 if (attr)
2787 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2788 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2789 else
2790 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2791 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2792
2793 /* Address family configuration mismatch or maximum-prefix count
2794 overflow. */
2795 if (ret < 0)
2796 return -1;
2797 }
2798
2799 /* Packet length consistency check. */
2800 if (pnt != lim)
2801 return -1;
2802
2803 return 0;
2804}
2805
2806/* NLRI encode syntax check routine. */
2807int
2808bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2809 bgp_size_t length)
2810{
2811 u_char *end;
2812 u_char prefixlen;
2813 int psize;
2814
2815 end = pnt + length;
2816
2817 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2818 syntactic validity. If the field is syntactically incorrect,
2819 then the Error Subcode is set to Invalid Network Field. */
2820
2821 while (pnt < end)
2822 {
2823 prefixlen = *pnt++;
2824
2825 /* Prefix length check. */
2826 if ((afi == AFI_IP && prefixlen > 32)
2827 || (afi == AFI_IP6 && prefixlen > 128))
2828 {
2829 plog_err (peer->log,
2830 "%s [Error] Update packet error (wrong prefix length %d)",
2831 peer->host, prefixlen);
2832 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2833 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2834 return -1;
2835 }
2836
2837 /* Packet size overflow check. */
2838 psize = PSIZE (prefixlen);
2839
2840 if (pnt + psize > end)
2841 {
2842 plog_err (peer->log,
2843 "%s [Error] Update packet error"
2844 " (prefix data overflow prefix size is %d)",
2845 peer->host, psize);
2846 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2847 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2848 return -1;
2849 }
2850
2851 pnt += psize;
2852 }
2853
2854 /* Packet length consistency check. */
2855 if (pnt != end)
2856 {
2857 plog_err (peer->log,
2858 "%s [Error] Update packet error"
2859 " (prefix length mismatch with total length)",
2860 peer->host);
2861 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2862 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2863 return -1;
2864 }
2865 return 0;
2866}
2867
paul94f2b392005-06-28 12:44:16 +00002868static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002869bgp_static_new ()
2870{
2871 struct bgp_static *new;
2872 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2873 memset (new, 0, sizeof (struct bgp_static));
2874 return new;
2875}
2876
paul94f2b392005-06-28 12:44:16 +00002877static void
paul718e3742002-12-13 20:15:29 +00002878bgp_static_free (struct bgp_static *bgp_static)
2879{
2880 if (bgp_static->rmap.name)
2881 free (bgp_static->rmap.name);
2882 XFREE (MTYPE_BGP_STATIC, bgp_static);
2883}
2884
paul94f2b392005-06-28 12:44:16 +00002885static void
paulfee0f4c2004-09-13 05:12:46 +00002886bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2887 struct prefix *p, afi_t afi, safi_t safi)
2888{
2889 struct bgp_node *rn;
2890 struct bgp_info *ri;
2891
2892 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2893
2894 /* Check selected route and self inserted route. */
2895 for (ri = rn->info; ri; ri = ri->next)
2896 if (ri->peer == bgp->peer_self
2897 && ri->type == ZEBRA_ROUTE_BGP
2898 && ri->sub_type == BGP_ROUTE_STATIC)
2899 break;
2900
2901 /* Withdraw static BGP route from routing table. */
2902 if (ri)
2903 {
2904 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2905 bgp_process (bgp, rn, afi, safi);
2906 bgp_info_delete (rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00002907 }
2908
2909 /* Unlock bgp_node_lookup. */
2910 bgp_unlock_node (rn);
2911}
2912
paul94f2b392005-06-28 12:44:16 +00002913static void
paulfee0f4c2004-09-13 05:12:46 +00002914bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2915 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2916{
2917 struct bgp_node *rn;
2918 struct bgp_info *ri;
2919 struct bgp_info *new;
2920 struct bgp_info info;
2921 struct attr new_attr;
2922 struct attr *attr_new;
2923 struct attr attr;
2924 struct bgp *bgp;
2925 int ret;
2926 char buf[SU_ADDRSTRLEN];
2927
2928 bgp = rsclient->bgp;
2929
2930 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2931
2932 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2933 if (bgp_static)
2934 {
2935 attr.nexthop = bgp_static->igpnexthop;
2936 attr.med = bgp_static->igpmetric;
2937 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
2938 }
2939
2940 new_attr = attr;
2941
2942 /* Apply network route-map for export to this rsclient. */
2943 if (bgp_static->rmap.name)
2944 {
2945 info.peer = rsclient;
2946 info.attr = &new_attr;
2947
2948 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2949 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2950
2951 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2952
2953 rsclient->rmap_type = 0;
2954
2955 if (ret == RMAP_DENYMATCH)
2956 {
2957 /* Free uninterned attribute. */
2958 bgp_attr_flush (&new_attr);
2959
2960 /* Unintern original. */
2961 aspath_unintern (attr.aspath);
2962 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2963
2964 return;
2965 }
2966 attr_new = bgp_attr_intern (&new_attr);
2967 }
2968 else
2969 attr_new = bgp_attr_intern (&attr);
2970
2971 new_attr = *attr_new;
2972
2973 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2974
2975 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2976{
2977 /* This BGP update is filtered. Log the reason then update BGP entry. */
2978 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002979 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002980 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
2981 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2982 p->prefixlen, rsclient->host);
2983
2984 bgp->peer_self->rmap_type = 0;
2985
2986 bgp_attr_unintern (attr_new);
2987 aspath_unintern (attr.aspath);
2988
2989 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2990
2991 return;
2992 }
2993
2994 bgp->peer_self->rmap_type = 0;
2995
2996 bgp_attr_unintern (attr_new);
2997 attr_new = bgp_attr_intern (&new_attr);
2998
2999 for (ri = rn->info; ri; ri = ri->next)
3000 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3001 && ri->sub_type == BGP_ROUTE_STATIC)
3002 break;
3003
3004 if (ri)
3005 {
3006 if (attrhash_cmp (ri->attr, attr_new))
3007 {
3008 bgp_unlock_node (rn);
3009 bgp_attr_unintern (attr_new);
3010 aspath_unintern (attr.aspath);
3011 return;
3012 }
3013 else
3014 {
3015 /* The attribute is changed. */
3016 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3017
3018 /* Rewrite BGP route information. */
3019 bgp_attr_unintern (ri->attr);
3020 ri->attr = attr_new;
3021 ri->uptime = time (NULL);
3022
3023 /* Process change. */
3024 bgp_process (bgp, rn, afi, safi);
3025 bgp_unlock_node (rn);
3026 aspath_unintern (attr.aspath);
3027 return;
3028 }
3029}
3030
3031 /* Make new BGP info. */
3032 new = bgp_info_new ();
3033 new->type = ZEBRA_ROUTE_BGP;
3034 new->sub_type = BGP_ROUTE_STATIC;
3035 new->peer = bgp->peer_self;
3036 SET_FLAG (new->flags, BGP_INFO_VALID);
3037 new->attr = attr_new;
3038 new->uptime = time (NULL);
3039
3040 /* Register new BGP information. */
3041 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003042
3043 /* route_node_get lock */
3044 bgp_unlock_node (rn);
3045
paulfee0f4c2004-09-13 05:12:46 +00003046 /* Process change. */
3047 bgp_process (bgp, rn, afi, safi);
3048
3049 /* Unintern original. */
3050 aspath_unintern (attr.aspath);
3051}
3052
paul94f2b392005-06-28 12:44:16 +00003053static void
paulfee0f4c2004-09-13 05:12:46 +00003054bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003055 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3056{
3057 struct bgp_node *rn;
3058 struct bgp_info *ri;
3059 struct bgp_info *new;
3060 struct bgp_info info;
3061 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003062 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003063 struct attr *attr_new;
3064 int ret;
3065
paulfee0f4c2004-09-13 05:12:46 +00003066 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003067
3068 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3069 if (bgp_static)
3070 {
3071 attr.nexthop = bgp_static->igpnexthop;
3072 attr.med = bgp_static->igpmetric;
3073 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3074 }
3075
3076 /* Apply route-map. */
3077 if (bgp_static->rmap.name)
3078 {
paul286e1e72003-08-08 00:24:31 +00003079 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003080 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003081 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003082
paulfee0f4c2004-09-13 05:12:46 +00003083 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3084
paul718e3742002-12-13 20:15:29 +00003085 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003086
paulfee0f4c2004-09-13 05:12:46 +00003087 bgp->peer_self->rmap_type = 0;
3088
paul718e3742002-12-13 20:15:29 +00003089 if (ret == RMAP_DENYMATCH)
3090 {
3091 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003092 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003093
3094 /* Unintern original. */
3095 aspath_unintern (attr.aspath);
3096 bgp_static_withdraw (bgp, p, afi, safi);
3097 return;
3098 }
paul286e1e72003-08-08 00:24:31 +00003099 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003100 }
paul286e1e72003-08-08 00:24:31 +00003101 else
3102 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003103
3104 for (ri = rn->info; ri; ri = ri->next)
3105 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3106 && ri->sub_type == BGP_ROUTE_STATIC)
3107 break;
3108
3109 if (ri)
3110 {
3111 if (attrhash_cmp (ri->attr, attr_new))
3112 {
3113 bgp_unlock_node (rn);
3114 bgp_attr_unintern (attr_new);
3115 aspath_unintern (attr.aspath);
3116 return;
3117 }
3118 else
3119 {
3120 /* The attribute is changed. */
3121 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3122
3123 /* Rewrite BGP route information. */
3124 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3125 bgp_attr_unintern (ri->attr);
3126 ri->attr = attr_new;
3127 ri->uptime = time (NULL);
3128
3129 /* Process change. */
3130 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3131 bgp_process (bgp, rn, afi, safi);
3132 bgp_unlock_node (rn);
3133 aspath_unintern (attr.aspath);
3134 return;
3135 }
3136 }
3137
3138 /* Make new BGP info. */
3139 new = bgp_info_new ();
3140 new->type = ZEBRA_ROUTE_BGP;
3141 new->sub_type = BGP_ROUTE_STATIC;
3142 new->peer = bgp->peer_self;
3143 SET_FLAG (new->flags, BGP_INFO_VALID);
3144 new->attr = attr_new;
3145 new->uptime = time (NULL);
3146
3147 /* Aggregate address increment. */
3148 bgp_aggregate_increment (bgp, p, new, afi, safi);
3149
3150 /* Register new BGP information. */
3151 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003152
3153 /* route_node_get lock */
3154 bgp_unlock_node (rn);
3155
paul718e3742002-12-13 20:15:29 +00003156 /* Process change. */
3157 bgp_process (bgp, rn, afi, safi);
3158
3159 /* Unintern original. */
3160 aspath_unintern (attr.aspath);
3161}
3162
3163void
paulfee0f4c2004-09-13 05:12:46 +00003164bgp_static_update (struct bgp *bgp, struct prefix *p,
3165 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3166{
3167 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003168 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003169
3170 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3171
paul1eb8ef22005-04-07 07:30:20 +00003172 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003173 {
3174 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3175 }
3176}
3177
paul94f2b392005-06-28 12:44:16 +00003178static void
paul718e3742002-12-13 20:15:29 +00003179bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3180 u_char safi, struct prefix_rd *prd, u_char *tag)
3181{
3182 struct bgp_node *rn;
3183 struct bgp_info *new;
3184
paulfee0f4c2004-09-13 05:12:46 +00003185 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003186
3187 /* Make new BGP info. */
3188 new = bgp_info_new ();
3189 new->type = ZEBRA_ROUTE_BGP;
3190 new->sub_type = BGP_ROUTE_STATIC;
3191 new->peer = bgp->peer_self;
3192 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3193 SET_FLAG (new->flags, BGP_INFO_VALID);
3194 new->uptime = time (NULL);
3195 memcpy (new->tag, tag, 3);
3196
3197 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003198 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003199
3200 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003201 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003202
paul200df112005-06-01 11:17:05 +00003203 /* route_node_get lock */
3204 bgp_unlock_node (rn);
3205
paul718e3742002-12-13 20:15:29 +00003206 /* Process change. */
3207 bgp_process (bgp, rn, afi, safi);
3208}
3209
3210void
3211bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3212 safi_t safi)
3213{
3214 struct bgp_node *rn;
3215 struct bgp_info *ri;
3216
paulfee0f4c2004-09-13 05:12:46 +00003217 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003218
3219 /* Check selected route and self inserted route. */
3220 for (ri = rn->info; ri; ri = ri->next)
3221 if (ri->peer == bgp->peer_self
3222 && ri->type == ZEBRA_ROUTE_BGP
3223 && ri->sub_type == BGP_ROUTE_STATIC)
3224 break;
3225
3226 /* Withdraw static BGP route from routing table. */
3227 if (ri)
3228 {
3229 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3230 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3231 bgp_process (bgp, rn, afi, safi);
3232 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003233 }
3234
3235 /* Unlock bgp_node_lookup. */
3236 bgp_unlock_node (rn);
3237}
3238
3239void
paulfee0f4c2004-09-13 05:12:46 +00003240bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3241{
3242 struct bgp_static *bgp_static;
3243 struct bgp *bgp;
3244 struct bgp_node *rn;
3245 struct prefix *p;
3246
3247 bgp = rsclient->bgp;
3248
3249 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3250 if ((bgp_static = rn->info) != NULL)
3251 {
3252 p = &rn->p;
3253
3254 bgp_static_update_rsclient (rsclient, p, bgp_static,
3255 afi, safi);
3256 }
3257}
3258
paul94f2b392005-06-28 12:44:16 +00003259static void
paul718e3742002-12-13 20:15:29 +00003260bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3261 u_char safi, struct prefix_rd *prd, u_char *tag)
3262{
3263 struct bgp_node *rn;
3264 struct bgp_info *ri;
3265
paulfee0f4c2004-09-13 05:12:46 +00003266 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003267
3268 /* Check selected route and self inserted route. */
3269 for (ri = rn->info; ri; ri = ri->next)
3270 if (ri->peer == bgp->peer_self
3271 && ri->type == ZEBRA_ROUTE_BGP
3272 && ri->sub_type == BGP_ROUTE_STATIC)
3273 break;
3274
3275 /* Withdraw static BGP route from routing table. */
3276 if (ri)
3277 {
3278 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3279 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3280 bgp_process (bgp, rn, afi, safi);
3281 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003282 }
3283
3284 /* Unlock bgp_node_lookup. */
3285 bgp_unlock_node (rn);
3286}
3287
3288/* Configure static BGP network. When user don't run zebra, static
3289 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003290static int
paulfd79ac92004-10-13 05:06:08 +00003291bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3292 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003293{
3294 int ret;
3295 struct prefix p;
3296 struct bgp_static *bgp_static;
3297 struct bgp_node *rn;
3298 int need_update = 0;
3299
3300 /* Convert IP prefix string to struct prefix. */
3301 ret = str2prefix (ip_str, &p);
3302 if (! ret)
3303 {
3304 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3305 return CMD_WARNING;
3306 }
3307#ifdef HAVE_IPV6
3308 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3309 {
3310 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3311 VTY_NEWLINE);
3312 return CMD_WARNING;
3313 }
3314#endif /* HAVE_IPV6 */
3315
3316 apply_mask (&p);
3317
3318 /* Set BGP static route configuration. */
3319 rn = bgp_node_get (bgp->route[afi][safi], &p);
3320
3321 if (rn->info)
3322 {
3323 /* Configuration change. */
3324 bgp_static = rn->info;
3325
3326 /* Check previous routes are installed into BGP. */
3327 if (! bgp_static->backdoor && bgp_static->valid)
3328 need_update = 1;
3329
3330 bgp_static->backdoor = backdoor;
3331 if (rmap)
3332 {
3333 if (bgp_static->rmap.name)
3334 free (bgp_static->rmap.name);
3335 bgp_static->rmap.name = strdup (rmap);
3336 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3337 }
3338 else
3339 {
3340 if (bgp_static->rmap.name)
3341 free (bgp_static->rmap.name);
3342 bgp_static->rmap.name = NULL;
3343 bgp_static->rmap.map = NULL;
3344 bgp_static->valid = 0;
3345 }
3346 bgp_unlock_node (rn);
3347 }
3348 else
3349 {
3350 /* New configuration. */
3351 bgp_static = bgp_static_new ();
3352 bgp_static->backdoor = backdoor;
3353 bgp_static->valid = 0;
3354 bgp_static->igpmetric = 0;
3355 bgp_static->igpnexthop.s_addr = 0;
3356 if (rmap)
3357 {
3358 if (bgp_static->rmap.name)
3359 free (bgp_static->rmap.name);
3360 bgp_static->rmap.name = strdup (rmap);
3361 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3362 }
3363 rn->info = bgp_static;
3364 }
3365
3366 /* If BGP scan is not enabled, we should install this route here. */
3367 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3368 {
3369 bgp_static->valid = 1;
3370
3371 if (need_update)
3372 bgp_static_withdraw (bgp, &p, afi, safi);
3373
3374 if (! bgp_static->backdoor)
3375 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3376 }
3377
3378 return CMD_SUCCESS;
3379}
3380
3381/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003382static int
paulfd79ac92004-10-13 05:06:08 +00003383bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003384 u_int16_t afi, u_char safi)
3385{
3386 int ret;
3387 struct prefix p;
3388 struct bgp_static *bgp_static;
3389 struct bgp_node *rn;
3390
3391 /* Convert IP prefix string to struct prefix. */
3392 ret = str2prefix (ip_str, &p);
3393 if (! ret)
3394 {
3395 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3396 return CMD_WARNING;
3397 }
3398#ifdef HAVE_IPV6
3399 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3400 {
3401 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3402 VTY_NEWLINE);
3403 return CMD_WARNING;
3404 }
3405#endif /* HAVE_IPV6 */
3406
3407 apply_mask (&p);
3408
3409 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3410 if (! rn)
3411 {
3412 vty_out (vty, "%% Can't find specified static route configuration.%s",
3413 VTY_NEWLINE);
3414 return CMD_WARNING;
3415 }
3416
3417 bgp_static = rn->info;
3418
3419 /* Update BGP RIB. */
3420 if (! bgp_static->backdoor)
3421 bgp_static_withdraw (bgp, &p, afi, safi);
3422
3423 /* Clear configuration. */
3424 bgp_static_free (bgp_static);
3425 rn->info = NULL;
3426 bgp_unlock_node (rn);
3427 bgp_unlock_node (rn);
3428
3429 return CMD_SUCCESS;
3430}
3431
3432/* Called from bgp_delete(). Delete all static routes from the BGP
3433 instance. */
3434void
3435bgp_static_delete (struct bgp *bgp)
3436{
3437 afi_t afi;
3438 safi_t safi;
3439 struct bgp_node *rn;
3440 struct bgp_node *rm;
3441 struct bgp_table *table;
3442 struct bgp_static *bgp_static;
3443
3444 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3445 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3446 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3447 if (rn->info != NULL)
3448 {
3449 if (safi == SAFI_MPLS_VPN)
3450 {
3451 table = rn->info;
3452
3453 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3454 {
3455 bgp_static = rn->info;
3456 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3457 AFI_IP, SAFI_MPLS_VPN,
3458 (struct prefix_rd *)&rn->p,
3459 bgp_static->tag);
3460 bgp_static_free (bgp_static);
3461 rn->info = NULL;
3462 bgp_unlock_node (rn);
3463 }
3464 }
3465 else
3466 {
3467 bgp_static = rn->info;
3468 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3469 bgp_static_free (bgp_static);
3470 rn->info = NULL;
3471 bgp_unlock_node (rn);
3472 }
3473 }
3474}
3475
3476int
paulfd79ac92004-10-13 05:06:08 +00003477bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3478 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003479{
3480 int ret;
3481 struct prefix p;
3482 struct prefix_rd prd;
3483 struct bgp *bgp;
3484 struct bgp_node *prn;
3485 struct bgp_node *rn;
3486 struct bgp_table *table;
3487 struct bgp_static *bgp_static;
3488 u_char tag[3];
3489
3490 bgp = vty->index;
3491
3492 ret = str2prefix (ip_str, &p);
3493 if (! ret)
3494 {
3495 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3496 return CMD_WARNING;
3497 }
3498 apply_mask (&p);
3499
3500 ret = str2prefix_rd (rd_str, &prd);
3501 if (! ret)
3502 {
3503 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3504 return CMD_WARNING;
3505 }
3506
3507 ret = str2tag (tag_str, tag);
3508 if (! ret)
3509 {
3510 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3511 return CMD_WARNING;
3512 }
3513
3514 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3515 (struct prefix *)&prd);
3516 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003517 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003518 else
3519 bgp_unlock_node (prn);
3520 table = prn->info;
3521
3522 rn = bgp_node_get (table, &p);
3523
3524 if (rn->info)
3525 {
3526 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3527 bgp_unlock_node (rn);
3528 }
3529 else
3530 {
3531 /* New configuration. */
3532 bgp_static = bgp_static_new ();
3533 bgp_static->valid = 1;
3534 memcpy (bgp_static->tag, tag, 3);
3535 rn->info = bgp_static;
3536
3537 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3538 }
3539
3540 return CMD_SUCCESS;
3541}
3542
3543/* Configure static BGP network. */
3544int
paulfd79ac92004-10-13 05:06:08 +00003545bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3546 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003547{
3548 int ret;
3549 struct bgp *bgp;
3550 struct prefix p;
3551 struct prefix_rd prd;
3552 struct bgp_node *prn;
3553 struct bgp_node *rn;
3554 struct bgp_table *table;
3555 struct bgp_static *bgp_static;
3556 u_char tag[3];
3557
3558 bgp = vty->index;
3559
3560 /* Convert IP prefix string to struct prefix. */
3561 ret = str2prefix (ip_str, &p);
3562 if (! ret)
3563 {
3564 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3565 return CMD_WARNING;
3566 }
3567 apply_mask (&p);
3568
3569 ret = str2prefix_rd (rd_str, &prd);
3570 if (! ret)
3571 {
3572 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3573 return CMD_WARNING;
3574 }
3575
3576 ret = str2tag (tag_str, tag);
3577 if (! ret)
3578 {
3579 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3580 return CMD_WARNING;
3581 }
3582
3583 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3584 (struct prefix *)&prd);
3585 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003586 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003587 else
3588 bgp_unlock_node (prn);
3589 table = prn->info;
3590
3591 rn = bgp_node_lookup (table, &p);
3592
3593 if (rn)
3594 {
3595 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3596
3597 bgp_static = rn->info;
3598 bgp_static_free (bgp_static);
3599 rn->info = NULL;
3600 bgp_unlock_node (rn);
3601 bgp_unlock_node (rn);
3602 }
3603 else
3604 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3605
3606 return CMD_SUCCESS;
3607}
3608
3609DEFUN (bgp_network,
3610 bgp_network_cmd,
3611 "network A.B.C.D/M",
3612 "Specify a network to announce via BGP\n"
3613 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3614{
3615 return bgp_static_set (vty, vty->index, argv[0],
3616 AFI_IP, bgp_node_safi (vty), NULL, 0);
3617}
3618
3619DEFUN (bgp_network_route_map,
3620 bgp_network_route_map_cmd,
3621 "network A.B.C.D/M route-map WORD",
3622 "Specify a network to announce via BGP\n"
3623 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3624 "Route-map to modify the attributes\n"
3625 "Name of the route map\n")
3626{
3627 return bgp_static_set (vty, vty->index, argv[0],
3628 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3629}
3630
3631DEFUN (bgp_network_backdoor,
3632 bgp_network_backdoor_cmd,
3633 "network A.B.C.D/M backdoor",
3634 "Specify a network to announce via BGP\n"
3635 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3636 "Specify a BGP backdoor route\n")
3637{
3638 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3639}
3640
3641DEFUN (bgp_network_mask,
3642 bgp_network_mask_cmd,
3643 "network A.B.C.D mask A.B.C.D",
3644 "Specify a network to announce via BGP\n"
3645 "Network number\n"
3646 "Network mask\n"
3647 "Network mask\n")
3648{
3649 int ret;
3650 char prefix_str[BUFSIZ];
3651
3652 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3653 if (! ret)
3654 {
3655 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3656 return CMD_WARNING;
3657 }
3658
3659 return bgp_static_set (vty, vty->index, prefix_str,
3660 AFI_IP, bgp_node_safi (vty), NULL, 0);
3661}
3662
3663DEFUN (bgp_network_mask_route_map,
3664 bgp_network_mask_route_map_cmd,
3665 "network A.B.C.D mask A.B.C.D route-map WORD",
3666 "Specify a network to announce via BGP\n"
3667 "Network number\n"
3668 "Network mask\n"
3669 "Network mask\n"
3670 "Route-map to modify the attributes\n"
3671 "Name of the route map\n")
3672{
3673 int ret;
3674 char prefix_str[BUFSIZ];
3675
3676 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3677 if (! ret)
3678 {
3679 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3680 return CMD_WARNING;
3681 }
3682
3683 return bgp_static_set (vty, vty->index, prefix_str,
3684 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3685}
3686
3687DEFUN (bgp_network_mask_backdoor,
3688 bgp_network_mask_backdoor_cmd,
3689 "network A.B.C.D mask A.B.C.D backdoor",
3690 "Specify a network to announce via BGP\n"
3691 "Network number\n"
3692 "Network mask\n"
3693 "Network mask\n"
3694 "Specify a BGP backdoor route\n")
3695{
3696 int ret;
3697 char prefix_str[BUFSIZ];
3698
3699 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3700 if (! ret)
3701 {
3702 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3703 return CMD_WARNING;
3704 }
3705
3706 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3707}
3708
3709DEFUN (bgp_network_mask_natural,
3710 bgp_network_mask_natural_cmd,
3711 "network A.B.C.D",
3712 "Specify a network to announce via BGP\n"
3713 "Network number\n")
3714{
3715 int ret;
3716 char prefix_str[BUFSIZ];
3717
3718 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3719 if (! ret)
3720 {
3721 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3722 return CMD_WARNING;
3723 }
3724
3725 return bgp_static_set (vty, vty->index, prefix_str,
3726 AFI_IP, bgp_node_safi (vty), NULL, 0);
3727}
3728
3729DEFUN (bgp_network_mask_natural_route_map,
3730 bgp_network_mask_natural_route_map_cmd,
3731 "network A.B.C.D route-map WORD",
3732 "Specify a network to announce via BGP\n"
3733 "Network number\n"
3734 "Route-map to modify the attributes\n"
3735 "Name of the route map\n")
3736{
3737 int ret;
3738 char prefix_str[BUFSIZ];
3739
3740 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3741 if (! ret)
3742 {
3743 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3744 return CMD_WARNING;
3745 }
3746
3747 return bgp_static_set (vty, vty->index, prefix_str,
3748 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3749}
3750
3751DEFUN (bgp_network_mask_natural_backdoor,
3752 bgp_network_mask_natural_backdoor_cmd,
3753 "network A.B.C.D backdoor",
3754 "Specify a network to announce via BGP\n"
3755 "Network number\n"
3756 "Specify a BGP backdoor route\n")
3757{
3758 int ret;
3759 char prefix_str[BUFSIZ];
3760
3761 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3762 if (! ret)
3763 {
3764 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3765 return CMD_WARNING;
3766 }
3767
3768 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3769}
3770
3771DEFUN (no_bgp_network,
3772 no_bgp_network_cmd,
3773 "no network A.B.C.D/M",
3774 NO_STR
3775 "Specify a network to announce via BGP\n"
3776 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3777{
3778 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3779 bgp_node_safi (vty));
3780}
3781
3782ALIAS (no_bgp_network,
3783 no_bgp_network_route_map_cmd,
3784 "no network A.B.C.D/M route-map WORD",
3785 NO_STR
3786 "Specify a network to announce via BGP\n"
3787 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3788 "Route-map to modify the attributes\n"
3789 "Name of the route map\n")
3790
3791ALIAS (no_bgp_network,
3792 no_bgp_network_backdoor_cmd,
3793 "no network A.B.C.D/M backdoor",
3794 NO_STR
3795 "Specify a network to announce via BGP\n"
3796 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3797 "Specify a BGP backdoor route\n")
3798
3799DEFUN (no_bgp_network_mask,
3800 no_bgp_network_mask_cmd,
3801 "no network A.B.C.D mask A.B.C.D",
3802 NO_STR
3803 "Specify a network to announce via BGP\n"
3804 "Network number\n"
3805 "Network mask\n"
3806 "Network mask\n")
3807{
3808 int ret;
3809 char prefix_str[BUFSIZ];
3810
3811 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3812 if (! ret)
3813 {
3814 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3815 return CMD_WARNING;
3816 }
3817
3818 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3819 bgp_node_safi (vty));
3820}
3821
3822ALIAS (no_bgp_network_mask,
3823 no_bgp_network_mask_route_map_cmd,
3824 "no network A.B.C.D mask A.B.C.D route-map WORD",
3825 NO_STR
3826 "Specify a network to announce via BGP\n"
3827 "Network number\n"
3828 "Network mask\n"
3829 "Network mask\n"
3830 "Route-map to modify the attributes\n"
3831 "Name of the route map\n")
3832
3833ALIAS (no_bgp_network_mask,
3834 no_bgp_network_mask_backdoor_cmd,
3835 "no network A.B.C.D mask A.B.C.D backdoor",
3836 NO_STR
3837 "Specify a network to announce via BGP\n"
3838 "Network number\n"
3839 "Network mask\n"
3840 "Network mask\n"
3841 "Specify a BGP backdoor route\n")
3842
3843DEFUN (no_bgp_network_mask_natural,
3844 no_bgp_network_mask_natural_cmd,
3845 "no network A.B.C.D",
3846 NO_STR
3847 "Specify a network to announce via BGP\n"
3848 "Network number\n")
3849{
3850 int ret;
3851 char prefix_str[BUFSIZ];
3852
3853 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3854 if (! ret)
3855 {
3856 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3857 return CMD_WARNING;
3858 }
3859
3860 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3861 bgp_node_safi (vty));
3862}
3863
3864ALIAS (no_bgp_network_mask_natural,
3865 no_bgp_network_mask_natural_route_map_cmd,
3866 "no network A.B.C.D route-map WORD",
3867 NO_STR
3868 "Specify a network to announce via BGP\n"
3869 "Network number\n"
3870 "Route-map to modify the attributes\n"
3871 "Name of the route map\n")
3872
3873ALIAS (no_bgp_network_mask_natural,
3874 no_bgp_network_mask_natural_backdoor_cmd,
3875 "no network A.B.C.D backdoor",
3876 NO_STR
3877 "Specify a network to announce via BGP\n"
3878 "Network number\n"
3879 "Specify a BGP backdoor route\n")
3880
3881#ifdef HAVE_IPV6
3882DEFUN (ipv6_bgp_network,
3883 ipv6_bgp_network_cmd,
3884 "network X:X::X:X/M",
3885 "Specify a network to announce via BGP\n"
3886 "IPv6 prefix <network>/<length>\n")
3887{
3888 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3889}
3890
3891DEFUN (ipv6_bgp_network_route_map,
3892 ipv6_bgp_network_route_map_cmd,
3893 "network X:X::X:X/M route-map WORD",
3894 "Specify a network to announce via BGP\n"
3895 "IPv6 prefix <network>/<length>\n"
3896 "Route-map to modify the attributes\n"
3897 "Name of the route map\n")
3898{
3899 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3900 bgp_node_safi (vty), argv[1], 0);
3901}
3902
3903DEFUN (no_ipv6_bgp_network,
3904 no_ipv6_bgp_network_cmd,
3905 "no network X:X::X:X/M",
3906 NO_STR
3907 "Specify a network to announce via BGP\n"
3908 "IPv6 prefix <network>/<length>\n")
3909{
3910 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3911}
3912
3913ALIAS (no_ipv6_bgp_network,
3914 no_ipv6_bgp_network_route_map_cmd,
3915 "no network X:X::X:X/M route-map WORD",
3916 NO_STR
3917 "Specify a network to announce via BGP\n"
3918 "IPv6 prefix <network>/<length>\n"
3919 "Route-map to modify the attributes\n"
3920 "Name of the route map\n")
3921
3922ALIAS (ipv6_bgp_network,
3923 old_ipv6_bgp_network_cmd,
3924 "ipv6 bgp network X:X::X:X/M",
3925 IPV6_STR
3926 BGP_STR
3927 "Specify a network to announce via BGP\n"
3928 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3929
3930ALIAS (no_ipv6_bgp_network,
3931 old_no_ipv6_bgp_network_cmd,
3932 "no ipv6 bgp network X:X::X:X/M",
3933 NO_STR
3934 IPV6_STR
3935 BGP_STR
3936 "Specify a network to announce via BGP\n"
3937 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3938#endif /* HAVE_IPV6 */
3939
3940/* Aggreagete address:
3941
3942 advertise-map Set condition to advertise attribute
3943 as-set Generate AS set path information
3944 attribute-map Set attributes of aggregate
3945 route-map Set parameters of aggregate
3946 summary-only Filter more specific routes from updates
3947 suppress-map Conditionally filter more specific routes from updates
3948 <cr>
3949 */
3950struct bgp_aggregate
3951{
3952 /* Summary-only flag. */
3953 u_char summary_only;
3954
3955 /* AS set generation. */
3956 u_char as_set;
3957
3958 /* Route-map for aggregated route. */
3959 struct route_map *map;
3960
3961 /* Suppress-count. */
3962 unsigned long count;
3963
3964 /* SAFI configuration. */
3965 safi_t safi;
3966};
3967
paul94f2b392005-06-28 12:44:16 +00003968static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00003969bgp_aggregate_new ()
3970{
3971 struct bgp_aggregate *new;
3972 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3973 memset (new, 0, sizeof (struct bgp_aggregate));
3974 return new;
3975}
3976
paul94f2b392005-06-28 12:44:16 +00003977static void
paul718e3742002-12-13 20:15:29 +00003978bgp_aggregate_free (struct bgp_aggregate *aggregate)
3979{
3980 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
3981}
3982
paul94f2b392005-06-28 12:44:16 +00003983static void
paul718e3742002-12-13 20:15:29 +00003984bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
3985 afi_t afi, safi_t safi, struct bgp_info *del,
3986 struct bgp_aggregate *aggregate)
3987{
3988 struct bgp_table *table;
3989 struct bgp_node *top;
3990 struct bgp_node *rn;
3991 u_char origin;
3992 struct aspath *aspath = NULL;
3993 struct aspath *asmerge = NULL;
3994 struct community *community = NULL;
3995 struct community *commerge = NULL;
3996 struct in_addr nexthop;
3997 u_int32_t med = 0;
3998 struct bgp_info *ri;
3999 struct bgp_info *new;
4000 int first = 1;
4001 unsigned long match = 0;
4002
4003 /* Record adding route's nexthop and med. */
4004 if (rinew)
4005 {
4006 nexthop = rinew->attr->nexthop;
4007 med = rinew->attr->med;
4008 }
4009
4010 /* ORIGIN attribute: If at least one route among routes that are
4011 aggregated has ORIGIN with the value INCOMPLETE, then the
4012 aggregated route must have the ORIGIN attribute with the value
4013 INCOMPLETE. Otherwise, if at least one route among routes that
4014 are aggregated has ORIGIN with the value EGP, then the aggregated
4015 route must have the origin attribute with the value EGP. In all
4016 other case the value of the ORIGIN attribute of the aggregated
4017 route is INTERNAL. */
4018 origin = BGP_ORIGIN_IGP;
4019
4020 table = bgp->rib[afi][safi];
4021
4022 top = bgp_node_get (table, p);
4023 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4024 if (rn->p.prefixlen > p->prefixlen)
4025 {
4026 match = 0;
4027
4028 for (ri = rn->info; ri; ri = ri->next)
4029 {
4030 if (BGP_INFO_HOLDDOWN (ri))
4031 continue;
4032
4033 if (del && ri == del)
4034 continue;
4035
4036 if (! rinew && first)
4037 {
4038 nexthop = ri->attr->nexthop;
4039 med = ri->attr->med;
4040 first = 0;
4041 }
4042
4043#ifdef AGGREGATE_NEXTHOP_CHECK
4044 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4045 || ri->attr->med != med)
4046 {
4047 if (aspath)
4048 aspath_free (aspath);
4049 if (community)
4050 community_free (community);
4051 bgp_unlock_node (rn);
4052 bgp_unlock_node (top);
4053 return;
4054 }
4055#endif /* AGGREGATE_NEXTHOP_CHECK */
4056
4057 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4058 {
4059 if (aggregate->summary_only)
4060 {
4061 ri->suppress++;
4062 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4063 match++;
4064 }
4065
4066 aggregate->count++;
4067
4068 if (aggregate->as_set)
4069 {
4070 if (origin < ri->attr->origin)
4071 origin = ri->attr->origin;
4072
4073 if (aspath)
4074 {
4075 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4076 aspath_free (aspath);
4077 aspath = asmerge;
4078 }
4079 else
4080 aspath = aspath_dup (ri->attr->aspath);
4081
4082 if (ri->attr->community)
4083 {
4084 if (community)
4085 {
4086 commerge = community_merge (community,
4087 ri->attr->community);
4088 community = community_uniq_sort (commerge);
4089 community_free (commerge);
4090 }
4091 else
4092 community = community_dup (ri->attr->community);
4093 }
4094 }
4095 }
4096 }
4097 if (match)
4098 bgp_process (bgp, rn, afi, safi);
4099 }
4100 bgp_unlock_node (top);
4101
4102 if (rinew)
4103 {
4104 aggregate->count++;
4105
4106 if (aggregate->summary_only)
4107 rinew->suppress++;
4108
4109 if (aggregate->as_set)
4110 {
4111 if (origin < rinew->attr->origin)
4112 origin = rinew->attr->origin;
4113
4114 if (aspath)
4115 {
4116 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4117 aspath_free (aspath);
4118 aspath = asmerge;
4119 }
4120 else
4121 aspath = aspath_dup (rinew->attr->aspath);
4122
4123 if (rinew->attr->community)
4124 {
4125 if (community)
4126 {
4127 commerge = community_merge (community,
4128 rinew->attr->community);
4129 community = community_uniq_sort (commerge);
4130 community_free (commerge);
4131 }
4132 else
4133 community = community_dup (rinew->attr->community);
4134 }
4135 }
4136 }
4137
4138 if (aggregate->count > 0)
4139 {
4140 rn = bgp_node_get (table, p);
4141 new = bgp_info_new ();
4142 new->type = ZEBRA_ROUTE_BGP;
4143 new->sub_type = BGP_ROUTE_AGGREGATE;
4144 new->peer = bgp->peer_self;
4145 SET_FLAG (new->flags, BGP_INFO_VALID);
4146 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4147 new->uptime = time (NULL);
4148
4149 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004150 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004151 bgp_process (bgp, rn, afi, safi);
4152 }
4153 else
4154 {
4155 if (aspath)
4156 aspath_free (aspath);
4157 if (community)
4158 community_free (community);
4159 }
4160}
4161
4162void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4163 struct bgp_aggregate *);
4164
4165void
4166bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4167 struct bgp_info *ri, afi_t afi, safi_t safi)
4168{
4169 struct bgp_node *child;
4170 struct bgp_node *rn;
4171 struct bgp_aggregate *aggregate;
4172
4173 /* MPLS-VPN aggregation is not yet supported. */
4174 if (safi == SAFI_MPLS_VPN)
4175 return;
4176
4177 if (p->prefixlen == 0)
4178 return;
4179
4180 if (BGP_INFO_HOLDDOWN (ri))
4181 return;
4182
4183 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4184
4185 /* Aggregate address configuration check. */
4186 for (rn = child; rn; rn = rn->parent)
4187 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4188 {
4189 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004190 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004191 }
4192 bgp_unlock_node (child);
4193}
4194
4195void
4196bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4197 struct bgp_info *del, afi_t afi, safi_t safi)
4198{
4199 struct bgp_node *child;
4200 struct bgp_node *rn;
4201 struct bgp_aggregate *aggregate;
4202
4203 /* MPLS-VPN aggregation is not yet supported. */
4204 if (safi == SAFI_MPLS_VPN)
4205 return;
4206
4207 if (p->prefixlen == 0)
4208 return;
4209
4210 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4211
4212 /* Aggregate address configuration check. */
4213 for (rn = child; rn; rn = rn->parent)
4214 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4215 {
4216 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004217 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004218 }
4219 bgp_unlock_node (child);
4220}
4221
paul94f2b392005-06-28 12:44:16 +00004222static void
paul718e3742002-12-13 20:15:29 +00004223bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4224 struct bgp_aggregate *aggregate)
4225{
4226 struct bgp_table *table;
4227 struct bgp_node *top;
4228 struct bgp_node *rn;
4229 struct bgp_info *new;
4230 struct bgp_info *ri;
4231 unsigned long match;
4232 u_char origin = BGP_ORIGIN_IGP;
4233 struct aspath *aspath = NULL;
4234 struct aspath *asmerge = NULL;
4235 struct community *community = NULL;
4236 struct community *commerge = NULL;
4237
4238 table = bgp->rib[afi][safi];
4239
4240 /* Sanity check. */
4241 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4242 return;
4243 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4244 return;
4245
4246 /* If routes exists below this node, generate aggregate routes. */
4247 top = bgp_node_get (table, p);
4248 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4249 if (rn->p.prefixlen > p->prefixlen)
4250 {
4251 match = 0;
4252
4253 for (ri = rn->info; ri; ri = ri->next)
4254 {
4255 if (BGP_INFO_HOLDDOWN (ri))
4256 continue;
4257
4258 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4259 {
4260 /* summary-only aggregate route suppress aggregated
4261 route announcement. */
4262 if (aggregate->summary_only)
4263 {
4264 ri->suppress++;
4265 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4266 match++;
4267 }
4268 /* as-set aggregate route generate origin, as path,
4269 community aggregation. */
4270 if (aggregate->as_set)
4271 {
4272 if (origin < ri->attr->origin)
4273 origin = ri->attr->origin;
4274
4275 if (aspath)
4276 {
4277 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4278 aspath_free (aspath);
4279 aspath = asmerge;
4280 }
4281 else
4282 aspath = aspath_dup (ri->attr->aspath);
4283
4284 if (ri->attr->community)
4285 {
4286 if (community)
4287 {
4288 commerge = community_merge (community,
4289 ri->attr->community);
4290 community = community_uniq_sort (commerge);
4291 community_free (commerge);
4292 }
4293 else
4294 community = community_dup (ri->attr->community);
4295 }
4296 }
4297 aggregate->count++;
4298 }
4299 }
4300
4301 /* If this node is suppressed, process the change. */
4302 if (match)
4303 bgp_process (bgp, rn, afi, safi);
4304 }
4305 bgp_unlock_node (top);
4306
4307 /* Add aggregate route to BGP table. */
4308 if (aggregate->count)
4309 {
4310 rn = bgp_node_get (table, p);
4311
4312 new = bgp_info_new ();
4313 new->type = ZEBRA_ROUTE_BGP;
4314 new->sub_type = BGP_ROUTE_AGGREGATE;
4315 new->peer = bgp->peer_self;
4316 SET_FLAG (new->flags, BGP_INFO_VALID);
4317 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4318 new->uptime = time (NULL);
4319
4320 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004321 bgp_unlock_node (rn);
4322
paul718e3742002-12-13 20:15:29 +00004323 /* Process change. */
4324 bgp_process (bgp, rn, afi, safi);
4325 }
4326}
4327
4328void
4329bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4330 safi_t safi, struct bgp_aggregate *aggregate)
4331{
4332 struct bgp_table *table;
4333 struct bgp_node *top;
4334 struct bgp_node *rn;
4335 struct bgp_info *ri;
4336 unsigned long match;
4337
4338 table = bgp->rib[afi][safi];
4339
4340 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4341 return;
4342 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4343 return;
4344
4345 /* If routes exists below this node, generate aggregate routes. */
4346 top = bgp_node_get (table, p);
4347 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4348 if (rn->p.prefixlen > p->prefixlen)
4349 {
4350 match = 0;
4351
4352 for (ri = rn->info; ri; ri = ri->next)
4353 {
4354 if (BGP_INFO_HOLDDOWN (ri))
4355 continue;
4356
4357 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4358 {
4359 if (aggregate->summary_only)
4360 {
4361 ri->suppress--;
4362
4363 if (ri->suppress == 0)
4364 {
4365 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4366 match++;
4367 }
4368 }
4369 aggregate->count--;
4370 }
4371 }
4372
4373 /* If this node is suppressed, process the change. */
4374 if (match)
4375 bgp_process (bgp, rn, afi, safi);
4376 }
4377 bgp_unlock_node (top);
4378
4379 /* Delete aggregate route from BGP table. */
4380 rn = bgp_node_get (table, p);
4381
4382 for (ri = rn->info; ri; ri = ri->next)
4383 if (ri->peer == bgp->peer_self
4384 && ri->type == ZEBRA_ROUTE_BGP
4385 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4386 break;
4387
4388 /* Withdraw static BGP route from routing table. */
4389 if (ri)
4390 {
4391 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4392 bgp_process (bgp, rn, afi, safi);
4393 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004394 }
4395
4396 /* Unlock bgp_node_lookup. */
4397 bgp_unlock_node (rn);
4398}
4399
4400/* Aggregate route attribute. */
4401#define AGGREGATE_SUMMARY_ONLY 1
4402#define AGGREGATE_AS_SET 1
4403
paul94f2b392005-06-28 12:44:16 +00004404static int
paulfd79ac92004-10-13 05:06:08 +00004405bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4406 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004407 u_char summary_only, u_char as_set)
4408{
4409 int ret;
4410 struct prefix p;
4411 struct bgp_node *rn;
4412 struct bgp *bgp;
4413 struct bgp_aggregate *aggregate;
4414
4415 /* Convert string to prefix structure. */
4416 ret = str2prefix (prefix_str, &p);
4417 if (!ret)
4418 {
4419 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4420 return CMD_WARNING;
4421 }
4422 apply_mask (&p);
4423
4424 /* Get BGP structure. */
4425 bgp = vty->index;
4426
4427 /* Old configuration check. */
4428 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4429
4430 if (rn->info)
4431 {
4432 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4433 bgp_unlock_node (rn);
4434 return CMD_WARNING;
4435 }
4436
4437 /* Make aggregate address structure. */
4438 aggregate = bgp_aggregate_new ();
4439 aggregate->summary_only = summary_only;
4440 aggregate->as_set = as_set;
4441 aggregate->safi = safi;
4442 rn->info = aggregate;
4443
4444 /* Aggregate address insert into BGP routing table. */
4445 if (safi & SAFI_UNICAST)
4446 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4447 if (safi & SAFI_MULTICAST)
4448 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4449
4450 return CMD_SUCCESS;
4451}
4452
paul94f2b392005-06-28 12:44:16 +00004453static int
paulfd79ac92004-10-13 05:06:08 +00004454bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4455 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004456{
4457 int ret;
4458 struct prefix p;
4459 struct bgp_node *rn;
4460 struct bgp *bgp;
4461 struct bgp_aggregate *aggregate;
4462
4463 /* Convert string to prefix structure. */
4464 ret = str2prefix (prefix_str, &p);
4465 if (!ret)
4466 {
4467 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4468 return CMD_WARNING;
4469 }
4470 apply_mask (&p);
4471
4472 /* Get BGP structure. */
4473 bgp = vty->index;
4474
4475 /* Old configuration check. */
4476 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4477 if (! rn)
4478 {
4479 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4480 VTY_NEWLINE);
4481 return CMD_WARNING;
4482 }
4483
4484 aggregate = rn->info;
4485 if (aggregate->safi & SAFI_UNICAST)
4486 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4487 if (aggregate->safi & SAFI_MULTICAST)
4488 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4489
4490 /* Unlock aggregate address configuration. */
4491 rn->info = NULL;
4492 bgp_aggregate_free (aggregate);
4493 bgp_unlock_node (rn);
4494 bgp_unlock_node (rn);
4495
4496 return CMD_SUCCESS;
4497}
4498
4499DEFUN (aggregate_address,
4500 aggregate_address_cmd,
4501 "aggregate-address A.B.C.D/M",
4502 "Configure BGP aggregate entries\n"
4503 "Aggregate prefix\n")
4504{
4505 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4506}
4507
4508DEFUN (aggregate_address_mask,
4509 aggregate_address_mask_cmd,
4510 "aggregate-address A.B.C.D A.B.C.D",
4511 "Configure BGP aggregate entries\n"
4512 "Aggregate address\n"
4513 "Aggregate mask\n")
4514{
4515 int ret;
4516 char prefix_str[BUFSIZ];
4517
4518 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4519
4520 if (! ret)
4521 {
4522 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4523 return CMD_WARNING;
4524 }
4525
4526 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4527 0, 0);
4528}
4529
4530DEFUN (aggregate_address_summary_only,
4531 aggregate_address_summary_only_cmd,
4532 "aggregate-address A.B.C.D/M summary-only",
4533 "Configure BGP aggregate entries\n"
4534 "Aggregate prefix\n"
4535 "Filter more specific routes from updates\n")
4536{
4537 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4538 AGGREGATE_SUMMARY_ONLY, 0);
4539}
4540
4541DEFUN (aggregate_address_mask_summary_only,
4542 aggregate_address_mask_summary_only_cmd,
4543 "aggregate-address A.B.C.D A.B.C.D summary-only",
4544 "Configure BGP aggregate entries\n"
4545 "Aggregate address\n"
4546 "Aggregate mask\n"
4547 "Filter more specific routes from updates\n")
4548{
4549 int ret;
4550 char prefix_str[BUFSIZ];
4551
4552 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4553
4554 if (! ret)
4555 {
4556 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4557 return CMD_WARNING;
4558 }
4559
4560 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4561 AGGREGATE_SUMMARY_ONLY, 0);
4562}
4563
4564DEFUN (aggregate_address_as_set,
4565 aggregate_address_as_set_cmd,
4566 "aggregate-address A.B.C.D/M as-set",
4567 "Configure BGP aggregate entries\n"
4568 "Aggregate prefix\n"
4569 "Generate AS set path information\n")
4570{
4571 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4572 0, AGGREGATE_AS_SET);
4573}
4574
4575DEFUN (aggregate_address_mask_as_set,
4576 aggregate_address_mask_as_set_cmd,
4577 "aggregate-address A.B.C.D A.B.C.D as-set",
4578 "Configure BGP aggregate entries\n"
4579 "Aggregate address\n"
4580 "Aggregate mask\n"
4581 "Generate AS set path information\n")
4582{
4583 int ret;
4584 char prefix_str[BUFSIZ];
4585
4586 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4587
4588 if (! ret)
4589 {
4590 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4591 return CMD_WARNING;
4592 }
4593
4594 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4595 0, AGGREGATE_AS_SET);
4596}
4597
4598
4599DEFUN (aggregate_address_as_set_summary,
4600 aggregate_address_as_set_summary_cmd,
4601 "aggregate-address A.B.C.D/M as-set summary-only",
4602 "Configure BGP aggregate entries\n"
4603 "Aggregate prefix\n"
4604 "Generate AS set path information\n"
4605 "Filter more specific routes from updates\n")
4606{
4607 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4608 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4609}
4610
4611ALIAS (aggregate_address_as_set_summary,
4612 aggregate_address_summary_as_set_cmd,
4613 "aggregate-address A.B.C.D/M summary-only as-set",
4614 "Configure BGP aggregate entries\n"
4615 "Aggregate prefix\n"
4616 "Filter more specific routes from updates\n"
4617 "Generate AS set path information\n")
4618
4619DEFUN (aggregate_address_mask_as_set_summary,
4620 aggregate_address_mask_as_set_summary_cmd,
4621 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4622 "Configure BGP aggregate entries\n"
4623 "Aggregate address\n"
4624 "Aggregate mask\n"
4625 "Generate AS set path information\n"
4626 "Filter more specific routes from updates\n")
4627{
4628 int ret;
4629 char prefix_str[BUFSIZ];
4630
4631 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4632
4633 if (! ret)
4634 {
4635 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4636 return CMD_WARNING;
4637 }
4638
4639 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4640 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4641}
4642
4643ALIAS (aggregate_address_mask_as_set_summary,
4644 aggregate_address_mask_summary_as_set_cmd,
4645 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4646 "Configure BGP aggregate entries\n"
4647 "Aggregate address\n"
4648 "Aggregate mask\n"
4649 "Filter more specific routes from updates\n"
4650 "Generate AS set path information\n")
4651
4652DEFUN (no_aggregate_address,
4653 no_aggregate_address_cmd,
4654 "no aggregate-address A.B.C.D/M",
4655 NO_STR
4656 "Configure BGP aggregate entries\n"
4657 "Aggregate prefix\n")
4658{
4659 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4660}
4661
4662ALIAS (no_aggregate_address,
4663 no_aggregate_address_summary_only_cmd,
4664 "no aggregate-address A.B.C.D/M summary-only",
4665 NO_STR
4666 "Configure BGP aggregate entries\n"
4667 "Aggregate prefix\n"
4668 "Filter more specific routes from updates\n")
4669
4670ALIAS (no_aggregate_address,
4671 no_aggregate_address_as_set_cmd,
4672 "no aggregate-address A.B.C.D/M as-set",
4673 NO_STR
4674 "Configure BGP aggregate entries\n"
4675 "Aggregate prefix\n"
4676 "Generate AS set path information\n")
4677
4678ALIAS (no_aggregate_address,
4679 no_aggregate_address_as_set_summary_cmd,
4680 "no aggregate-address A.B.C.D/M as-set summary-only",
4681 NO_STR
4682 "Configure BGP aggregate entries\n"
4683 "Aggregate prefix\n"
4684 "Generate AS set path information\n"
4685 "Filter more specific routes from updates\n")
4686
4687ALIAS (no_aggregate_address,
4688 no_aggregate_address_summary_as_set_cmd,
4689 "no aggregate-address A.B.C.D/M summary-only as-set",
4690 NO_STR
4691 "Configure BGP aggregate entries\n"
4692 "Aggregate prefix\n"
4693 "Filter more specific routes from updates\n"
4694 "Generate AS set path information\n")
4695
4696DEFUN (no_aggregate_address_mask,
4697 no_aggregate_address_mask_cmd,
4698 "no aggregate-address A.B.C.D A.B.C.D",
4699 NO_STR
4700 "Configure BGP aggregate entries\n"
4701 "Aggregate address\n"
4702 "Aggregate mask\n")
4703{
4704 int ret;
4705 char prefix_str[BUFSIZ];
4706
4707 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4708
4709 if (! ret)
4710 {
4711 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4712 return CMD_WARNING;
4713 }
4714
4715 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4716}
4717
4718ALIAS (no_aggregate_address_mask,
4719 no_aggregate_address_mask_summary_only_cmd,
4720 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4721 NO_STR
4722 "Configure BGP aggregate entries\n"
4723 "Aggregate address\n"
4724 "Aggregate mask\n"
4725 "Filter more specific routes from updates\n")
4726
4727ALIAS (no_aggregate_address_mask,
4728 no_aggregate_address_mask_as_set_cmd,
4729 "no aggregate-address A.B.C.D A.B.C.D as-set",
4730 NO_STR
4731 "Configure BGP aggregate entries\n"
4732 "Aggregate address\n"
4733 "Aggregate mask\n"
4734 "Generate AS set path information\n")
4735
4736ALIAS (no_aggregate_address_mask,
4737 no_aggregate_address_mask_as_set_summary_cmd,
4738 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4739 NO_STR
4740 "Configure BGP aggregate entries\n"
4741 "Aggregate address\n"
4742 "Aggregate mask\n"
4743 "Generate AS set path information\n"
4744 "Filter more specific routes from updates\n")
4745
4746ALIAS (no_aggregate_address_mask,
4747 no_aggregate_address_mask_summary_as_set_cmd,
4748 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4749 NO_STR
4750 "Configure BGP aggregate entries\n"
4751 "Aggregate address\n"
4752 "Aggregate mask\n"
4753 "Filter more specific routes from updates\n"
4754 "Generate AS set path information\n")
4755
4756#ifdef HAVE_IPV6
4757DEFUN (ipv6_aggregate_address,
4758 ipv6_aggregate_address_cmd,
4759 "aggregate-address X:X::X:X/M",
4760 "Configure BGP aggregate entries\n"
4761 "Aggregate prefix\n")
4762{
4763 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4764}
4765
4766DEFUN (ipv6_aggregate_address_summary_only,
4767 ipv6_aggregate_address_summary_only_cmd,
4768 "aggregate-address X:X::X:X/M summary-only",
4769 "Configure BGP aggregate entries\n"
4770 "Aggregate prefix\n"
4771 "Filter more specific routes from updates\n")
4772{
4773 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4774 AGGREGATE_SUMMARY_ONLY, 0);
4775}
4776
4777DEFUN (no_ipv6_aggregate_address,
4778 no_ipv6_aggregate_address_cmd,
4779 "no aggregate-address X:X::X:X/M",
4780 NO_STR
4781 "Configure BGP aggregate entries\n"
4782 "Aggregate prefix\n")
4783{
4784 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4785}
4786
4787DEFUN (no_ipv6_aggregate_address_summary_only,
4788 no_ipv6_aggregate_address_summary_only_cmd,
4789 "no aggregate-address X:X::X:X/M summary-only",
4790 NO_STR
4791 "Configure BGP aggregate entries\n"
4792 "Aggregate prefix\n"
4793 "Filter more specific routes from updates\n")
4794{
4795 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4796}
4797
4798ALIAS (ipv6_aggregate_address,
4799 old_ipv6_aggregate_address_cmd,
4800 "ipv6 bgp aggregate-address X:X::X:X/M",
4801 IPV6_STR
4802 BGP_STR
4803 "Configure BGP aggregate entries\n"
4804 "Aggregate prefix\n")
4805
4806ALIAS (ipv6_aggregate_address_summary_only,
4807 old_ipv6_aggregate_address_summary_only_cmd,
4808 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4809 IPV6_STR
4810 BGP_STR
4811 "Configure BGP aggregate entries\n"
4812 "Aggregate prefix\n"
4813 "Filter more specific routes from updates\n")
4814
4815ALIAS (no_ipv6_aggregate_address,
4816 old_no_ipv6_aggregate_address_cmd,
4817 "no ipv6 bgp aggregate-address X:X::X:X/M",
4818 NO_STR
4819 IPV6_STR
4820 BGP_STR
4821 "Configure BGP aggregate entries\n"
4822 "Aggregate prefix\n")
4823
4824ALIAS (no_ipv6_aggregate_address_summary_only,
4825 old_no_ipv6_aggregate_address_summary_only_cmd,
4826 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4827 NO_STR
4828 IPV6_STR
4829 BGP_STR
4830 "Configure BGP aggregate entries\n"
4831 "Aggregate prefix\n"
4832 "Filter more specific routes from updates\n")
4833#endif /* HAVE_IPV6 */
4834
4835/* Redistribute route treatment. */
4836void
4837bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4838 u_int32_t metric, u_char type)
4839{
4840 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004841 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004842 struct bgp_info *new;
4843 struct bgp_info *bi;
4844 struct bgp_info info;
4845 struct bgp_node *bn;
4846 struct attr attr;
4847 struct attr attr_new;
4848 struct attr *new_attr;
4849 afi_t afi;
4850 int ret;
4851
4852 /* Make default attribute. */
4853 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4854 if (nexthop)
4855 attr.nexthop = *nexthop;
4856
4857 attr.med = metric;
4858 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4859
paul1eb8ef22005-04-07 07:30:20 +00004860 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004861 {
4862 afi = family2afi (p->family);
4863
4864 if (bgp->redist[afi][type])
4865 {
4866 /* Copy attribute for modification. */
4867 attr_new = attr;
4868
4869 if (bgp->redist_metric_flag[afi][type])
4870 attr_new.med = bgp->redist_metric[afi][type];
4871
4872 /* Apply route-map. */
4873 if (bgp->rmap[afi][type].map)
4874 {
4875 info.peer = bgp->peer_self;
4876 info.attr = &attr_new;
4877
paulfee0f4c2004-09-13 05:12:46 +00004878 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4879
paul718e3742002-12-13 20:15:29 +00004880 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4881 &info);
paulfee0f4c2004-09-13 05:12:46 +00004882
4883 bgp->peer_self->rmap_type = 0;
4884
paul718e3742002-12-13 20:15:29 +00004885 if (ret == RMAP_DENYMATCH)
4886 {
4887 /* Free uninterned attribute. */
4888 bgp_attr_flush (&attr_new);
4889
4890 /* Unintern original. */
4891 aspath_unintern (attr.aspath);
4892 bgp_redistribute_delete (p, type);
4893 return;
4894 }
4895 }
4896
paulfee0f4c2004-09-13 05:12:46 +00004897 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004898 new_attr = bgp_attr_intern (&attr_new);
4899
4900 for (bi = bn->info; bi; bi = bi->next)
4901 if (bi->peer == bgp->peer_self
4902 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4903 break;
4904
4905 if (bi)
4906 {
4907 if (attrhash_cmp (bi->attr, new_attr))
4908 {
4909 bgp_attr_unintern (new_attr);
4910 aspath_unintern (attr.aspath);
4911 bgp_unlock_node (bn);
4912 return;
4913 }
4914 else
4915 {
4916 /* The attribute is changed. */
4917 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4918
4919 /* Rewrite BGP route information. */
4920 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4921 bgp_attr_unintern (bi->attr);
4922 bi->attr = new_attr;
4923 bi->uptime = time (NULL);
4924
4925 /* Process change. */
4926 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4927 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4928 bgp_unlock_node (bn);
4929 aspath_unintern (attr.aspath);
4930 return;
4931 }
4932 }
4933
4934 new = bgp_info_new ();
4935 new->type = type;
4936 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4937 new->peer = bgp->peer_self;
4938 SET_FLAG (new->flags, BGP_INFO_VALID);
4939 new->attr = new_attr;
4940 new->uptime = time (NULL);
4941
4942 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4943 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004944 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004945 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4946 }
4947 }
4948
4949 /* Unintern original. */
4950 aspath_unintern (attr.aspath);
4951}
4952
4953void
4954bgp_redistribute_delete (struct prefix *p, u_char type)
4955{
4956 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004957 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004958 afi_t afi;
4959 struct bgp_node *rn;
4960 struct bgp_info *ri;
4961
paul1eb8ef22005-04-07 07:30:20 +00004962 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004963 {
4964 afi = family2afi (p->family);
4965
4966 if (bgp->redist[afi][type])
4967 {
paulfee0f4c2004-09-13 05:12:46 +00004968 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004969
4970 for (ri = rn->info; ri; ri = ri->next)
4971 if (ri->peer == bgp->peer_self
4972 && ri->type == type)
4973 break;
4974
4975 if (ri)
4976 {
4977 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4978 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4979 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4980 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004981 }
4982 bgp_unlock_node (rn);
4983 }
4984 }
4985}
4986
4987/* Withdraw specified route type's route. */
4988void
4989bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
4990{
4991 struct bgp_node *rn;
4992 struct bgp_info *ri;
4993 struct bgp_table *table;
4994
4995 table = bgp->rib[afi][SAFI_UNICAST];
4996
4997 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4998 {
4999 for (ri = rn->info; ri; ri = ri->next)
5000 if (ri->peer == bgp->peer_self
5001 && ri->type == type)
5002 break;
5003
5004 if (ri)
5005 {
5006 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5007 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
5008 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5009 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00005010 }
5011 }
5012}
5013
5014/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005015static void
paul718e3742002-12-13 20:15:29 +00005016route_vty_out_route (struct prefix *p, struct vty *vty)
5017{
5018 int len;
5019 u_int32_t destination;
5020 char buf[BUFSIZ];
5021
5022 if (p->family == AF_INET)
5023 {
5024 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5025 destination = ntohl (p->u.prefix4.s_addr);
5026
5027 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5028 || (IN_CLASSB (destination) && p->prefixlen == 16)
5029 || (IN_CLASSA (destination) && p->prefixlen == 8)
5030 || p->u.prefix4.s_addr == 0)
5031 {
5032 /* When mask is natural, mask is not displayed. */
5033 }
5034 else
5035 len += vty_out (vty, "/%d", p->prefixlen);
5036 }
5037 else
5038 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5039 p->prefixlen);
5040
5041 len = 17 - len;
5042 if (len < 1)
5043 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5044 else
5045 vty_out (vty, "%*s", len, " ");
5046}
5047
paul718e3742002-12-13 20:15:29 +00005048enum bgp_display_type
5049{
5050 normal_list,
5051};
5052
paulb40d9392005-08-22 22:34:41 +00005053/* Print the short form route status for a bgp_info */
5054static void
5055route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005056{
paulb40d9392005-08-22 22:34:41 +00005057 /* Route status display. */
5058 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5059 vty_out (vty, "R");
5060 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005061 vty_out (vty, "S");
5062 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005063 vty_out (vty, "s");
5064 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5065 vty_out (vty, "*");
5066 else
5067 vty_out (vty, " ");
5068
5069 /* Selected */
5070 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5071 vty_out (vty, "h");
5072 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5073 vty_out (vty, "d");
5074 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5075 vty_out (vty, ">");
5076 else
5077 vty_out (vty, " ");
5078
5079 /* Internal route. */
5080 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5081 vty_out (vty, "i");
5082 else
paulb40d9392005-08-22 22:34:41 +00005083 vty_out (vty, " ");
5084}
5085
5086/* called from terminal list command */
5087void
5088route_vty_out (struct vty *vty, struct prefix *p,
5089 struct bgp_info *binfo, int display, safi_t safi)
5090{
5091 struct attr *attr;
5092
5093 /* short status lead text */
5094 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005095
5096 /* print prefix and mask */
5097 if (! display)
5098 route_vty_out_route (p, vty);
5099 else
5100 vty_out (vty, "%*s", 17, " ");
5101
5102 /* Print attribute */
5103 attr = binfo->attr;
5104 if (attr)
5105 {
5106 if (p->family == AF_INET)
5107 {
5108 if (safi == SAFI_MPLS_VPN)
5109 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5110 else
5111 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5112 }
5113#ifdef HAVE_IPV6
5114 else if (p->family == AF_INET6)
5115 {
5116 int len;
5117 char buf[BUFSIZ];
5118
5119 len = vty_out (vty, "%s",
5120 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5121 len = 16 - len;
5122 if (len < 1)
5123 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5124 else
5125 vty_out (vty, "%*s", len, " ");
5126 }
5127#endif /* HAVE_IPV6 */
5128
5129 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5130 vty_out (vty, "%10d", attr->med);
5131 else
5132 vty_out (vty, " ");
5133
5134 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5135 vty_out (vty, "%7d", attr->local_pref);
5136 else
5137 vty_out (vty, " ");
5138
5139 vty_out (vty, "%7u ",attr->weight);
5140
5141 /* Print aspath */
5142 if (attr->aspath)
5143 aspath_print_vty (vty, attr->aspath);
5144
5145 /* Print origin */
5146 if (strlen (attr->aspath->str) == 0)
5147 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5148 else
5149 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5150 }
5151 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005152}
5153
5154/* called from terminal list command */
5155void
5156route_vty_out_tmp (struct vty *vty, struct prefix *p,
5157 struct attr *attr, safi_t safi)
5158{
5159 /* Route status display. */
5160 vty_out (vty, "*");
5161 vty_out (vty, ">");
5162 vty_out (vty, " ");
5163
5164 /* print prefix and mask */
5165 route_vty_out_route (p, vty);
5166
5167 /* Print attribute */
5168 if (attr)
5169 {
5170 if (p->family == AF_INET)
5171 {
5172 if (safi == SAFI_MPLS_VPN)
5173 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5174 else
5175 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5176 }
5177#ifdef HAVE_IPV6
5178 else if (p->family == AF_INET6)
5179 {
5180 int len;
5181 char buf[BUFSIZ];
5182
5183 len = vty_out (vty, "%s",
5184 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5185 len = 16 - len;
5186 if (len < 1)
5187 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5188 else
5189 vty_out (vty, "%*s", len, " ");
5190 }
5191#endif /* HAVE_IPV6 */
5192
5193 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5194 vty_out (vty, "%10d", attr->med);
5195 else
5196 vty_out (vty, " ");
5197
5198 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5199 vty_out (vty, "%7d", attr->local_pref);
5200 else
5201 vty_out (vty, " ");
5202
5203 vty_out (vty, "%7d ",attr->weight);
5204
5205 /* Print aspath */
5206 if (attr->aspath)
5207 aspath_print_vty (vty, attr->aspath);
5208
5209 /* Print origin */
5210 if (strlen (attr->aspath->str) == 0)
5211 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5212 else
5213 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5214 }
5215
5216 vty_out (vty, "%s", VTY_NEWLINE);
5217}
5218
ajs5a646652004-11-05 01:25:55 +00005219void
paul718e3742002-12-13 20:15:29 +00005220route_vty_out_tag (struct vty *vty, struct prefix *p,
5221 struct bgp_info *binfo, int display, safi_t safi)
5222{
5223 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005224 u_int32_t label = 0;
5225
paulb40d9392005-08-22 22:34:41 +00005226 /* short status lead text */
5227 route_vty_short_status_out (vty, binfo);
5228
paul718e3742002-12-13 20:15:29 +00005229 /* print prefix and mask */
5230 if (! display)
5231 route_vty_out_route (p, vty);
5232 else
5233 vty_out (vty, "%*s", 17, " ");
5234
5235 /* Print attribute */
5236 attr = binfo->attr;
5237 if (attr)
5238 {
5239 if (p->family == AF_INET)
5240 {
5241 if (safi == SAFI_MPLS_VPN)
5242 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5243 else
5244 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5245 }
5246#ifdef HAVE_IPV6
5247 else if (p->family == AF_INET6)
5248 {
5249 char buf[BUFSIZ];
5250 char buf1[BUFSIZ];
5251 if (attr->mp_nexthop_len == 16)
5252 vty_out (vty, "%s",
5253 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5254 else if (attr->mp_nexthop_len == 32)
5255 vty_out (vty, "%s(%s)",
5256 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5257 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5258
5259 }
5260#endif /* HAVE_IPV6 */
5261 }
5262
5263 label = decode_label (binfo->tag);
5264
5265 vty_out (vty, "notag/%d", label);
5266
5267 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005268}
5269
5270/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005271static void
paul718e3742002-12-13 20:15:29 +00005272damp_route_vty_out (struct vty *vty, struct prefix *p,
5273 struct bgp_info *binfo, int display, safi_t safi)
5274{
5275 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005276 int len;
5277
paulb40d9392005-08-22 22:34:41 +00005278 /* short status lead text */
5279 route_vty_short_status_out (vty, binfo);
5280
paul718e3742002-12-13 20:15:29 +00005281 /* print prefix and mask */
5282 if (! display)
5283 route_vty_out_route (p, vty);
5284 else
5285 vty_out (vty, "%*s", 17, " ");
5286
5287 len = vty_out (vty, "%s", binfo->peer->host);
5288 len = 17 - len;
5289 if (len < 1)
5290 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5291 else
5292 vty_out (vty, "%*s", len, " ");
5293
5294 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5295
5296 /* Print attribute */
5297 attr = binfo->attr;
5298 if (attr)
5299 {
5300 /* Print aspath */
5301 if (attr->aspath)
5302 aspath_print_vty (vty, attr->aspath);
5303
5304 /* Print origin */
5305 if (strlen (attr->aspath->str) == 0)
5306 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5307 else
5308 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5309 }
5310 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005311}
5312
5313#define BGP_UPTIME_LEN 25
5314
5315/* flap route */
ajs5a646652004-11-05 01:25:55 +00005316static void
paul718e3742002-12-13 20:15:29 +00005317flap_route_vty_out (struct vty *vty, struct prefix *p,
5318 struct bgp_info *binfo, int display, safi_t safi)
5319{
5320 struct attr *attr;
5321 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005322 char timebuf[BGP_UPTIME_LEN];
5323 int len;
5324
paul718e3742002-12-13 20:15:29 +00005325 bdi = binfo->damp_info;
5326
paulb40d9392005-08-22 22:34:41 +00005327 /* short status lead text */
5328 route_vty_short_status_out (vty, binfo);
5329
paul718e3742002-12-13 20:15:29 +00005330 /* print prefix and mask */
5331 if (! display)
5332 route_vty_out_route (p, vty);
5333 else
5334 vty_out (vty, "%*s", 17, " ");
5335
5336 len = vty_out (vty, "%s", binfo->peer->host);
5337 len = 16 - len;
5338 if (len < 1)
5339 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5340 else
5341 vty_out (vty, "%*s", len, " ");
5342
5343 len = vty_out (vty, "%d", bdi->flap);
5344 len = 5 - len;
5345 if (len < 1)
5346 vty_out (vty, " ");
5347 else
5348 vty_out (vty, "%*s ", len, " ");
5349
5350 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5351 timebuf, BGP_UPTIME_LEN));
5352
5353 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5354 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5355 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5356 else
5357 vty_out (vty, "%*s ", 8, " ");
5358
5359 /* Print attribute */
5360 attr = binfo->attr;
5361 if (attr)
5362 {
5363 /* Print aspath */
5364 if (attr->aspath)
5365 aspath_print_vty (vty, attr->aspath);
5366
5367 /* Print origin */
5368 if (strlen (attr->aspath->str) == 0)
5369 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5370 else
5371 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5372 }
5373 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005374}
5375
paul94f2b392005-06-28 12:44:16 +00005376static void
paul718e3742002-12-13 20:15:29 +00005377route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5378 struct bgp_info *binfo, afi_t afi, safi_t safi)
5379{
5380 char buf[INET6_ADDRSTRLEN];
5381 char buf1[BUFSIZ];
5382 struct attr *attr;
5383 int sockunion_vty_out (struct vty *, union sockunion *);
5384
5385 attr = binfo->attr;
5386
5387 if (attr)
5388 {
5389 /* Line1 display AS-path, Aggregator */
5390 if (attr->aspath)
5391 {
5392 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005393 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005394 vty_out (vty, "Local");
5395 else
5396 aspath_print_vty (vty, attr->aspath);
5397 }
5398
paulb40d9392005-08-22 22:34:41 +00005399 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5400 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005401 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5402 vty_out (vty, ", (stale)");
5403 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5404 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5405 inet_ntoa (attr->aggregator_addr));
5406 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5407 vty_out (vty, ", (Received from a RR-client)");
5408 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5409 vty_out (vty, ", (Received from a RS-client)");
5410 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5411 vty_out (vty, ", (history entry)");
5412 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5413 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005414 vty_out (vty, "%s", VTY_NEWLINE);
5415
5416 /* Line2 display Next-hop, Neighbor, Router-id */
5417 if (p->family == AF_INET)
5418 {
5419 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5420 inet_ntoa (attr->mp_nexthop_global_in) :
5421 inet_ntoa (attr->nexthop));
5422 }
5423#ifdef HAVE_IPV6
5424 else
5425 {
5426 vty_out (vty, " %s",
5427 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5428 buf, INET6_ADDRSTRLEN));
5429 }
5430#endif /* HAVE_IPV6 */
5431
5432 if (binfo->peer == bgp->peer_self)
5433 {
5434 vty_out (vty, " from %s ",
5435 p->family == AF_INET ? "0.0.0.0" : "::");
5436 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5437 }
5438 else
5439 {
5440 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5441 vty_out (vty, " (inaccessible)");
5442 else if (binfo->igpmetric)
5443 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005444 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005445 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5446 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5447 else
5448 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5449 }
5450 vty_out (vty, "%s", VTY_NEWLINE);
5451
5452#ifdef HAVE_IPV6
5453 /* display nexthop local */
5454 if (attr->mp_nexthop_len == 32)
5455 {
5456 vty_out (vty, " (%s)%s",
5457 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5458 buf, INET6_ADDRSTRLEN),
5459 VTY_NEWLINE);
5460 }
5461#endif /* HAVE_IPV6 */
5462
5463 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5464 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5465
5466 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5467 vty_out (vty, ", metric %d", attr->med);
5468
5469 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5470 vty_out (vty, ", localpref %d", attr->local_pref);
5471 else
5472 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5473
5474 if (attr->weight != 0)
5475 vty_out (vty, ", weight %d", attr->weight);
5476
5477 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5478 vty_out (vty, ", valid");
5479
5480 if (binfo->peer != bgp->peer_self)
5481 {
5482 if (binfo->peer->as == binfo->peer->local_as)
5483 vty_out (vty, ", internal");
5484 else
5485 vty_out (vty, ", %s",
5486 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5487 }
5488 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5489 vty_out (vty, ", aggregated, local");
5490 else if (binfo->type != ZEBRA_ROUTE_BGP)
5491 vty_out (vty, ", sourced");
5492 else
5493 vty_out (vty, ", sourced, local");
5494
5495 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5496 vty_out (vty, ", atomic-aggregate");
5497
5498 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5499 vty_out (vty, ", best");
5500
5501 vty_out (vty, "%s", VTY_NEWLINE);
5502
5503 /* Line 4 display Community */
5504 if (attr->community)
5505 vty_out (vty, " Community: %s%s", attr->community->str,
5506 VTY_NEWLINE);
5507
5508 /* Line 5 display Extended-community */
5509 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5510 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5511 VTY_NEWLINE);
5512
5513 /* Line 6 display Originator, Cluster-id */
5514 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5515 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5516 {
5517 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5518 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5519
5520 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5521 {
5522 int i;
5523 vty_out (vty, ", Cluster list: ");
5524 for (i = 0; i < attr->cluster->length / 4; i++)
5525 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5526 }
5527 vty_out (vty, "%s", VTY_NEWLINE);
5528 }
5529
5530 if (binfo->damp_info)
5531 bgp_damp_info_vty (vty, binfo);
5532
5533 /* Line 7 display Uptime */
5534 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5535 }
5536 vty_out (vty, "%s", VTY_NEWLINE);
5537}
5538
paulb40d9392005-08-22 22:34:41 +00005539#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 +00005540#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005541#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5542#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5543#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5544
5545enum bgp_show_type
5546{
5547 bgp_show_type_normal,
5548 bgp_show_type_regexp,
5549 bgp_show_type_prefix_list,
5550 bgp_show_type_filter_list,
5551 bgp_show_type_route_map,
5552 bgp_show_type_neighbor,
5553 bgp_show_type_cidr_only,
5554 bgp_show_type_prefix_longer,
5555 bgp_show_type_community_all,
5556 bgp_show_type_community,
5557 bgp_show_type_community_exact,
5558 bgp_show_type_community_list,
5559 bgp_show_type_community_list_exact,
5560 bgp_show_type_flap_statistics,
5561 bgp_show_type_flap_address,
5562 bgp_show_type_flap_prefix,
5563 bgp_show_type_flap_cidr_only,
5564 bgp_show_type_flap_regexp,
5565 bgp_show_type_flap_filter_list,
5566 bgp_show_type_flap_prefix_list,
5567 bgp_show_type_flap_prefix_longer,
5568 bgp_show_type_flap_route_map,
5569 bgp_show_type_flap_neighbor,
5570 bgp_show_type_dampend_paths,
5571 bgp_show_type_damp_neighbor
5572};
5573
ajs5a646652004-11-05 01:25:55 +00005574static int
paulfee0f4c2004-09-13 05:12:46 +00005575bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005576 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005577{
paul718e3742002-12-13 20:15:29 +00005578 struct bgp_info *ri;
5579 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005580 int header = 1;
paul718e3742002-12-13 20:15:29 +00005581 int display;
ajs5a646652004-11-05 01:25:55 +00005582 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005583
5584 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005585 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005586
paul718e3742002-12-13 20:15:29 +00005587 /* Start processing of routes. */
5588 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5589 if (rn->info != NULL)
5590 {
5591 display = 0;
5592
5593 for (ri = rn->info; ri; ri = ri->next)
5594 {
ajs5a646652004-11-05 01:25:55 +00005595 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005596 || type == bgp_show_type_flap_address
5597 || type == bgp_show_type_flap_prefix
5598 || type == bgp_show_type_flap_cidr_only
5599 || type == bgp_show_type_flap_regexp
5600 || type == bgp_show_type_flap_filter_list
5601 || type == bgp_show_type_flap_prefix_list
5602 || type == bgp_show_type_flap_prefix_longer
5603 || type == bgp_show_type_flap_route_map
5604 || type == bgp_show_type_flap_neighbor
5605 || type == bgp_show_type_dampend_paths
5606 || type == bgp_show_type_damp_neighbor)
5607 {
5608 if (! ri->damp_info)
5609 continue;
5610 }
5611 if (type == bgp_show_type_regexp
5612 || type == bgp_show_type_flap_regexp)
5613 {
ajs5a646652004-11-05 01:25:55 +00005614 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005615
5616 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5617 continue;
5618 }
5619 if (type == bgp_show_type_prefix_list
5620 || type == bgp_show_type_flap_prefix_list)
5621 {
ajs5a646652004-11-05 01:25:55 +00005622 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005623
5624 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5625 continue;
5626 }
5627 if (type == bgp_show_type_filter_list
5628 || type == bgp_show_type_flap_filter_list)
5629 {
ajs5a646652004-11-05 01:25:55 +00005630 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005631
5632 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5633 continue;
5634 }
5635 if (type == bgp_show_type_route_map
5636 || type == bgp_show_type_flap_route_map)
5637 {
ajs5a646652004-11-05 01:25:55 +00005638 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005639 struct bgp_info binfo;
5640 struct attr dummy_attr;
5641 int ret;
5642
5643 dummy_attr = *ri->attr;
5644 binfo.peer = ri->peer;
5645 binfo.attr = &dummy_attr;
5646
5647 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5648
5649 if (ret == RMAP_DENYMATCH)
5650 continue;
5651 }
5652 if (type == bgp_show_type_neighbor
5653 || type == bgp_show_type_flap_neighbor
5654 || type == bgp_show_type_damp_neighbor)
5655 {
ajs5a646652004-11-05 01:25:55 +00005656 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005657
5658 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5659 continue;
5660 }
5661 if (type == bgp_show_type_cidr_only
5662 || type == bgp_show_type_flap_cidr_only)
5663 {
5664 u_int32_t destination;
5665
5666 destination = ntohl (rn->p.u.prefix4.s_addr);
5667 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5668 continue;
5669 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5670 continue;
5671 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5672 continue;
5673 }
5674 if (type == bgp_show_type_prefix_longer
5675 || type == bgp_show_type_flap_prefix_longer)
5676 {
ajs5a646652004-11-05 01:25:55 +00005677 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005678
5679 if (! prefix_match (p, &rn->p))
5680 continue;
5681 }
5682 if (type == bgp_show_type_community_all)
5683 {
5684 if (! ri->attr->community)
5685 continue;
5686 }
5687 if (type == bgp_show_type_community)
5688 {
ajs5a646652004-11-05 01:25:55 +00005689 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005690
5691 if (! ri->attr->community ||
5692 ! community_match (ri->attr->community, com))
5693 continue;
5694 }
5695 if (type == bgp_show_type_community_exact)
5696 {
ajs5a646652004-11-05 01:25:55 +00005697 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005698
5699 if (! ri->attr->community ||
5700 ! community_cmp (ri->attr->community, com))
5701 continue;
5702 }
5703 if (type == bgp_show_type_community_list)
5704 {
ajs5a646652004-11-05 01:25:55 +00005705 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005706
5707 if (! community_list_match (ri->attr->community, list))
5708 continue;
5709 }
5710 if (type == bgp_show_type_community_list_exact)
5711 {
ajs5a646652004-11-05 01:25:55 +00005712 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005713
5714 if (! community_list_exact_match (ri->attr->community, list))
5715 continue;
5716 }
5717 if (type == bgp_show_type_flap_address
5718 || type == bgp_show_type_flap_prefix)
5719 {
ajs5a646652004-11-05 01:25:55 +00005720 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005721
5722 if (! prefix_match (&rn->p, p))
5723 continue;
5724
5725 if (type == bgp_show_type_flap_prefix)
5726 if (p->prefixlen != rn->p.prefixlen)
5727 continue;
5728 }
5729 if (type == bgp_show_type_dampend_paths
5730 || type == bgp_show_type_damp_neighbor)
5731 {
5732 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5733 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5734 continue;
5735 }
5736
5737 if (header)
5738 {
hasso93406d82005-02-02 14:40:33 +00005739 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5740 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5741 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005742 if (type == bgp_show_type_dampend_paths
5743 || type == bgp_show_type_damp_neighbor)
5744 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5745 else if (type == bgp_show_type_flap_statistics
5746 || type == bgp_show_type_flap_address
5747 || type == bgp_show_type_flap_prefix
5748 || type == bgp_show_type_flap_cidr_only
5749 || type == bgp_show_type_flap_regexp
5750 || type == bgp_show_type_flap_filter_list
5751 || type == bgp_show_type_flap_prefix_list
5752 || type == bgp_show_type_flap_prefix_longer
5753 || type == bgp_show_type_flap_route_map
5754 || type == bgp_show_type_flap_neighbor)
5755 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5756 else
5757 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005758 header = 0;
5759 }
5760
5761 if (type == bgp_show_type_dampend_paths
5762 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005763 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005764 else if (type == bgp_show_type_flap_statistics
5765 || type == bgp_show_type_flap_address
5766 || type == bgp_show_type_flap_prefix
5767 || type == bgp_show_type_flap_cidr_only
5768 || type == bgp_show_type_flap_regexp
5769 || type == bgp_show_type_flap_filter_list
5770 || type == bgp_show_type_flap_prefix_list
5771 || type == bgp_show_type_flap_prefix_longer
5772 || type == bgp_show_type_flap_route_map
5773 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005774 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005775 else
ajs5a646652004-11-05 01:25:55 +00005776 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005777 display++;
5778 }
5779 if (display)
ajs5a646652004-11-05 01:25:55 +00005780 output_count++;
paul718e3742002-12-13 20:15:29 +00005781 }
5782
5783 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005784 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005785 {
5786 if (type == bgp_show_type_normal)
5787 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5788 }
5789 else
5790 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005791 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005792
5793 return CMD_SUCCESS;
5794}
5795
ajs5a646652004-11-05 01:25:55 +00005796static int
paulfee0f4c2004-09-13 05:12:46 +00005797bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005798 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005799{
5800 struct bgp_table *table;
5801
5802 if (bgp == NULL) {
5803 bgp = bgp_get_default ();
5804 }
5805
5806 if (bgp == NULL)
5807 {
5808 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5809 return CMD_WARNING;
5810 }
5811
5812
5813 table = bgp->rib[afi][safi];
5814
ajs5a646652004-11-05 01:25:55 +00005815 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005816}
5817
paul718e3742002-12-13 20:15:29 +00005818/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005819static void
paul718e3742002-12-13 20:15:29 +00005820route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5821 struct bgp_node *rn,
5822 struct prefix_rd *prd, afi_t afi, safi_t safi)
5823{
5824 struct bgp_info *ri;
5825 struct prefix *p;
5826 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005827 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005828 char buf1[INET6_ADDRSTRLEN];
5829 char buf2[INET6_ADDRSTRLEN];
5830 int count = 0;
5831 int best = 0;
5832 int suppress = 0;
5833 int no_export = 0;
5834 int no_advertise = 0;
5835 int local_as = 0;
5836 int first = 0;
5837
5838 p = &rn->p;
5839 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5840 (safi == SAFI_MPLS_VPN ?
5841 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5842 safi == SAFI_MPLS_VPN ? ":" : "",
5843 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5844 p->prefixlen, VTY_NEWLINE);
5845
5846 for (ri = rn->info; ri; ri = ri->next)
5847 {
5848 count++;
5849 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5850 {
5851 best = count;
5852 if (ri->suppress)
5853 suppress = 1;
5854 if (ri->attr->community != NULL)
5855 {
5856 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5857 no_advertise = 1;
5858 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5859 no_export = 1;
5860 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5861 local_as = 1;
5862 }
5863 }
5864 }
5865
5866 vty_out (vty, "Paths: (%d available", count);
5867 if (best)
5868 {
5869 vty_out (vty, ", best #%d", best);
5870 if (safi == SAFI_UNICAST)
5871 vty_out (vty, ", table Default-IP-Routing-Table");
5872 }
5873 else
5874 vty_out (vty, ", no best path");
5875 if (no_advertise)
5876 vty_out (vty, ", not advertised to any peer");
5877 else if (no_export)
5878 vty_out (vty, ", not advertised to EBGP peer");
5879 else if (local_as)
5880 vty_out (vty, ", not advertised outside local AS");
5881 if (suppress)
5882 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5883 vty_out (vty, ")%s", VTY_NEWLINE);
5884
5885 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005886 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005887 {
5888 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5889 {
5890 if (! first)
5891 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5892 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5893 first = 1;
5894 }
5895 }
5896 if (! first)
5897 vty_out (vty, " Not advertised to any peer");
5898 vty_out (vty, "%s", VTY_NEWLINE);
5899}
5900
5901/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005902static int
paulfee0f4c2004-09-13 05:12:46 +00005903bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005904 struct bgp_table *rib, const char *ip_str,
5905 afi_t afi, safi_t safi, struct prefix_rd *prd,
5906 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005907{
5908 int ret;
5909 int header;
5910 int display = 0;
5911 struct prefix match;
5912 struct bgp_node *rn;
5913 struct bgp_node *rm;
5914 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005915 struct bgp_table *table;
5916
paul718e3742002-12-13 20:15:29 +00005917 /* Check IP address argument. */
5918 ret = str2prefix (ip_str, &match);
5919 if (! ret)
5920 {
5921 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5922 return CMD_WARNING;
5923 }
5924
5925 match.family = afi2family (afi);
5926
5927 if (safi == SAFI_MPLS_VPN)
5928 {
paulfee0f4c2004-09-13 05:12:46 +00005929 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005930 {
5931 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5932 continue;
5933
5934 if ((table = rn->info) != NULL)
5935 {
5936 header = 1;
5937
5938 if ((rm = bgp_node_match (table, &match)) != NULL)
5939 {
5940 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5941 continue;
5942
5943 for (ri = rm->info; ri; ri = ri->next)
5944 {
5945 if (header)
5946 {
5947 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5948 AFI_IP, SAFI_MPLS_VPN);
5949
5950 header = 0;
5951 }
5952 display++;
5953 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5954 }
5955 }
5956 }
5957 }
5958 }
5959 else
5960 {
5961 header = 1;
5962
paulfee0f4c2004-09-13 05:12:46 +00005963 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005964 {
5965 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5966 {
5967 for (ri = rn->info; ri; ri = ri->next)
5968 {
5969 if (header)
5970 {
5971 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5972 header = 0;
5973 }
5974 display++;
5975 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5976 }
5977 }
5978 }
5979 }
5980
5981 if (! display)
5982 {
5983 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5984 return CMD_WARNING;
5985 }
5986
5987 return CMD_SUCCESS;
5988}
5989
paulfee0f4c2004-09-13 05:12:46 +00005990/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00005991static int
paulfd79ac92004-10-13 05:06:08 +00005992bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00005993 afi_t afi, safi_t safi, struct prefix_rd *prd,
5994 int prefix_check)
5995{
5996 struct bgp *bgp;
5997
5998 /* BGP structure lookup. */
5999 if (view_name)
6000 {
6001 bgp = bgp_lookup_by_name (view_name);
6002 if (bgp == NULL)
6003 {
6004 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6005 return CMD_WARNING;
6006 }
6007 }
6008 else
6009 {
6010 bgp = bgp_get_default ();
6011 if (bgp == NULL)
6012 {
6013 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6014 return CMD_WARNING;
6015 }
6016 }
6017
6018 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6019 afi, safi, prd, prefix_check);
6020}
6021
paul718e3742002-12-13 20:15:29 +00006022/* BGP route print out function. */
6023DEFUN (show_ip_bgp,
6024 show_ip_bgp_cmd,
6025 "show ip bgp",
6026 SHOW_STR
6027 IP_STR
6028 BGP_STR)
6029{
ajs5a646652004-11-05 01:25:55 +00006030 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006031}
6032
6033DEFUN (show_ip_bgp_ipv4,
6034 show_ip_bgp_ipv4_cmd,
6035 "show ip bgp ipv4 (unicast|multicast)",
6036 SHOW_STR
6037 IP_STR
6038 BGP_STR
6039 "Address family\n"
6040 "Address Family modifier\n"
6041 "Address Family modifier\n")
6042{
6043 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006044 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6045 NULL);
paul718e3742002-12-13 20:15:29 +00006046
ajs5a646652004-11-05 01:25:55 +00006047 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006048}
6049
6050DEFUN (show_ip_bgp_route,
6051 show_ip_bgp_route_cmd,
6052 "show ip bgp A.B.C.D",
6053 SHOW_STR
6054 IP_STR
6055 BGP_STR
6056 "Network in the BGP routing table to display\n")
6057{
6058 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6059}
6060
6061DEFUN (show_ip_bgp_ipv4_route,
6062 show_ip_bgp_ipv4_route_cmd,
6063 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6064 SHOW_STR
6065 IP_STR
6066 BGP_STR
6067 "Address family\n"
6068 "Address Family modifier\n"
6069 "Address Family modifier\n"
6070 "Network in the BGP routing table to display\n")
6071{
6072 if (strncmp (argv[0], "m", 1) == 0)
6073 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6074
6075 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6076}
6077
6078DEFUN (show_ip_bgp_vpnv4_all_route,
6079 show_ip_bgp_vpnv4_all_route_cmd,
6080 "show ip bgp vpnv4 all A.B.C.D",
6081 SHOW_STR
6082 IP_STR
6083 BGP_STR
6084 "Display VPNv4 NLRI specific information\n"
6085 "Display information about all VPNv4 NLRIs\n"
6086 "Network in the BGP routing table to display\n")
6087{
6088 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6089}
6090
6091DEFUN (show_ip_bgp_vpnv4_rd_route,
6092 show_ip_bgp_vpnv4_rd_route_cmd,
6093 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6094 SHOW_STR
6095 IP_STR
6096 BGP_STR
6097 "Display VPNv4 NLRI specific information\n"
6098 "Display information for a route distinguisher\n"
6099 "VPN Route Distinguisher\n"
6100 "Network in the BGP routing table to display\n")
6101{
6102 int ret;
6103 struct prefix_rd prd;
6104
6105 ret = str2prefix_rd (argv[0], &prd);
6106 if (! ret)
6107 {
6108 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6109 return CMD_WARNING;
6110 }
6111 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6112}
6113
6114DEFUN (show_ip_bgp_prefix,
6115 show_ip_bgp_prefix_cmd,
6116 "show ip bgp A.B.C.D/M",
6117 SHOW_STR
6118 IP_STR
6119 BGP_STR
6120 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6121{
6122 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6123}
6124
6125DEFUN (show_ip_bgp_ipv4_prefix,
6126 show_ip_bgp_ipv4_prefix_cmd,
6127 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6128 SHOW_STR
6129 IP_STR
6130 BGP_STR
6131 "Address family\n"
6132 "Address Family modifier\n"
6133 "Address Family modifier\n"
6134 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6135{
6136 if (strncmp (argv[0], "m", 1) == 0)
6137 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6138
6139 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6140}
6141
6142DEFUN (show_ip_bgp_vpnv4_all_prefix,
6143 show_ip_bgp_vpnv4_all_prefix_cmd,
6144 "show ip bgp vpnv4 all A.B.C.D/M",
6145 SHOW_STR
6146 IP_STR
6147 BGP_STR
6148 "Display VPNv4 NLRI specific information\n"
6149 "Display information about all VPNv4 NLRIs\n"
6150 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6151{
6152 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6153}
6154
6155DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6156 show_ip_bgp_vpnv4_rd_prefix_cmd,
6157 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6158 SHOW_STR
6159 IP_STR
6160 BGP_STR
6161 "Display VPNv4 NLRI specific information\n"
6162 "Display information for a route distinguisher\n"
6163 "VPN Route Distinguisher\n"
6164 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6165{
6166 int ret;
6167 struct prefix_rd prd;
6168
6169 ret = str2prefix_rd (argv[0], &prd);
6170 if (! ret)
6171 {
6172 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6173 return CMD_WARNING;
6174 }
6175 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6176}
6177
6178DEFUN (show_ip_bgp_view,
6179 show_ip_bgp_view_cmd,
6180 "show ip bgp view WORD",
6181 SHOW_STR
6182 IP_STR
6183 BGP_STR
6184 "BGP view\n"
6185 "BGP view name\n")
6186{
paulbb46e942003-10-24 19:02:03 +00006187 struct bgp *bgp;
6188
6189 /* BGP structure lookup. */
6190 bgp = bgp_lookup_by_name (argv[0]);
6191 if (bgp == NULL)
6192 {
6193 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6194 return CMD_WARNING;
6195 }
6196
ajs5a646652004-11-05 01:25:55 +00006197 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006198}
6199
6200DEFUN (show_ip_bgp_view_route,
6201 show_ip_bgp_view_route_cmd,
6202 "show ip bgp view WORD A.B.C.D",
6203 SHOW_STR
6204 IP_STR
6205 BGP_STR
6206 "BGP view\n"
6207 "BGP view name\n"
6208 "Network in the BGP routing table to display\n")
6209{
6210 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6211}
6212
6213DEFUN (show_ip_bgp_view_prefix,
6214 show_ip_bgp_view_prefix_cmd,
6215 "show ip bgp view WORD A.B.C.D/M",
6216 SHOW_STR
6217 IP_STR
6218 BGP_STR
6219 "BGP view\n"
6220 "BGP view name\n"
6221 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6222{
6223 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6224}
6225
6226#ifdef HAVE_IPV6
6227DEFUN (show_bgp,
6228 show_bgp_cmd,
6229 "show bgp",
6230 SHOW_STR
6231 BGP_STR)
6232{
ajs5a646652004-11-05 01:25:55 +00006233 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6234 NULL);
paul718e3742002-12-13 20:15:29 +00006235}
6236
6237ALIAS (show_bgp,
6238 show_bgp_ipv6_cmd,
6239 "show bgp ipv6",
6240 SHOW_STR
6241 BGP_STR
6242 "Address family\n")
6243
6244/* old command */
6245DEFUN (show_ipv6_bgp,
6246 show_ipv6_bgp_cmd,
6247 "show ipv6 bgp",
6248 SHOW_STR
6249 IP_STR
6250 BGP_STR)
6251{
ajs5a646652004-11-05 01:25:55 +00006252 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6253 NULL);
paul718e3742002-12-13 20:15:29 +00006254}
6255
6256DEFUN (show_bgp_route,
6257 show_bgp_route_cmd,
6258 "show bgp X:X::X:X",
6259 SHOW_STR
6260 BGP_STR
6261 "Network in the BGP routing table to display\n")
6262{
6263 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6264}
6265
6266ALIAS (show_bgp_route,
6267 show_bgp_ipv6_route_cmd,
6268 "show bgp ipv6 X:X::X:X",
6269 SHOW_STR
6270 BGP_STR
6271 "Address family\n"
6272 "Network in the BGP routing table to display\n")
6273
6274/* old command */
6275DEFUN (show_ipv6_bgp_route,
6276 show_ipv6_bgp_route_cmd,
6277 "show ipv6 bgp X:X::X:X",
6278 SHOW_STR
6279 IP_STR
6280 BGP_STR
6281 "Network in the BGP routing table to display\n")
6282{
6283 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6284}
6285
6286DEFUN (show_bgp_prefix,
6287 show_bgp_prefix_cmd,
6288 "show bgp X:X::X:X/M",
6289 SHOW_STR
6290 BGP_STR
6291 "IPv6 prefix <network>/<length>\n")
6292{
6293 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6294}
6295
6296ALIAS (show_bgp_prefix,
6297 show_bgp_ipv6_prefix_cmd,
6298 "show bgp ipv6 X:X::X:X/M",
6299 SHOW_STR
6300 BGP_STR
6301 "Address family\n"
6302 "IPv6 prefix <network>/<length>\n")
6303
6304/* old command */
6305DEFUN (show_ipv6_bgp_prefix,
6306 show_ipv6_bgp_prefix_cmd,
6307 "show ipv6 bgp X:X::X:X/M",
6308 SHOW_STR
6309 IP_STR
6310 BGP_STR
6311 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6312{
6313 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6314}
6315
paulbb46e942003-10-24 19:02:03 +00006316DEFUN (show_bgp_view,
6317 show_bgp_view_cmd,
6318 "show bgp view WORD",
6319 SHOW_STR
6320 BGP_STR
6321 "BGP view\n"
6322 "View name\n")
6323{
6324 struct bgp *bgp;
6325
6326 /* BGP structure lookup. */
6327 bgp = bgp_lookup_by_name (argv[0]);
6328 if (bgp == NULL)
6329 {
6330 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6331 return CMD_WARNING;
6332 }
6333
ajs5a646652004-11-05 01:25:55 +00006334 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006335}
6336
6337ALIAS (show_bgp_view,
6338 show_bgp_view_ipv6_cmd,
6339 "show bgp view WORD ipv6",
6340 SHOW_STR
6341 BGP_STR
6342 "BGP view\n"
6343 "View name\n"
6344 "Address family\n")
6345
6346DEFUN (show_bgp_view_route,
6347 show_bgp_view_route_cmd,
6348 "show bgp view WORD X:X::X:X",
6349 SHOW_STR
6350 BGP_STR
6351 "BGP view\n"
6352 "View name\n"
6353 "Network in the BGP routing table to display\n")
6354{
6355 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6356}
6357
6358ALIAS (show_bgp_view_route,
6359 show_bgp_view_ipv6_route_cmd,
6360 "show bgp view WORD ipv6 X:X::X:X",
6361 SHOW_STR
6362 BGP_STR
6363 "BGP view\n"
6364 "View name\n"
6365 "Address family\n"
6366 "Network in the BGP routing table to display\n")
6367
6368DEFUN (show_bgp_view_prefix,
6369 show_bgp_view_prefix_cmd,
6370 "show bgp view WORD X:X::X:X/M",
6371 SHOW_STR
6372 BGP_STR
6373 "BGP view\n"
6374 "View name\n"
6375 "IPv6 prefix <network>/<length>\n")
6376{
6377 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6378}
6379
6380ALIAS (show_bgp_view_prefix,
6381 show_bgp_view_ipv6_prefix_cmd,
6382 "show bgp view WORD ipv6 X:X::X:X/M",
6383 SHOW_STR
6384 BGP_STR
6385 "BGP view\n"
6386 "View name\n"
6387 "Address family\n"
6388 "IPv6 prefix <network>/<length>\n")
6389
paul718e3742002-12-13 20:15:29 +00006390/* old command */
6391DEFUN (show_ipv6_mbgp,
6392 show_ipv6_mbgp_cmd,
6393 "show ipv6 mbgp",
6394 SHOW_STR
6395 IP_STR
6396 MBGP_STR)
6397{
ajs5a646652004-11-05 01:25:55 +00006398 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6399 NULL);
paul718e3742002-12-13 20:15:29 +00006400}
6401
6402/* old command */
6403DEFUN (show_ipv6_mbgp_route,
6404 show_ipv6_mbgp_route_cmd,
6405 "show ipv6 mbgp X:X::X:X",
6406 SHOW_STR
6407 IP_STR
6408 MBGP_STR
6409 "Network in the MBGP routing table to display\n")
6410{
6411 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6412}
6413
6414/* old command */
6415DEFUN (show_ipv6_mbgp_prefix,
6416 show_ipv6_mbgp_prefix_cmd,
6417 "show ipv6 mbgp X:X::X:X/M",
6418 SHOW_STR
6419 IP_STR
6420 MBGP_STR
6421 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6422{
6423 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6424}
6425#endif
6426
paul718e3742002-12-13 20:15:29 +00006427
paul94f2b392005-06-28 12:44:16 +00006428static int
paulfd79ac92004-10-13 05:06:08 +00006429bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006430 safi_t safi, enum bgp_show_type type)
6431{
6432 int i;
6433 struct buffer *b;
6434 char *regstr;
6435 int first;
6436 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006437 int rc;
paul718e3742002-12-13 20:15:29 +00006438
6439 first = 0;
6440 b = buffer_new (1024);
6441 for (i = 0; i < argc; i++)
6442 {
6443 if (first)
6444 buffer_putc (b, ' ');
6445 else
6446 {
6447 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6448 continue;
6449 first = 1;
6450 }
6451
6452 buffer_putstr (b, argv[i]);
6453 }
6454 buffer_putc (b, '\0');
6455
6456 regstr = buffer_getstr (b);
6457 buffer_free (b);
6458
6459 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006460 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006461 if (! regex)
6462 {
6463 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6464 VTY_NEWLINE);
6465 return CMD_WARNING;
6466 }
6467
ajs5a646652004-11-05 01:25:55 +00006468 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6469 bgp_regex_free (regex);
6470 return rc;
paul718e3742002-12-13 20:15:29 +00006471}
6472
6473DEFUN (show_ip_bgp_regexp,
6474 show_ip_bgp_regexp_cmd,
6475 "show ip bgp regexp .LINE",
6476 SHOW_STR
6477 IP_STR
6478 BGP_STR
6479 "Display routes matching the AS path regular expression\n"
6480 "A regular-expression to match the BGP AS paths\n")
6481{
6482 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6483 bgp_show_type_regexp);
6484}
6485
6486DEFUN (show_ip_bgp_flap_regexp,
6487 show_ip_bgp_flap_regexp_cmd,
6488 "show ip bgp flap-statistics regexp .LINE",
6489 SHOW_STR
6490 IP_STR
6491 BGP_STR
6492 "Display flap statistics of routes\n"
6493 "Display routes matching the AS path regular expression\n"
6494 "A regular-expression to match the BGP AS paths\n")
6495{
6496 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6497 bgp_show_type_flap_regexp);
6498}
6499
6500DEFUN (show_ip_bgp_ipv4_regexp,
6501 show_ip_bgp_ipv4_regexp_cmd,
6502 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6503 SHOW_STR
6504 IP_STR
6505 BGP_STR
6506 "Address family\n"
6507 "Address Family modifier\n"
6508 "Address Family modifier\n"
6509 "Display routes matching the AS path regular expression\n"
6510 "A regular-expression to match the BGP AS paths\n")
6511{
6512 if (strncmp (argv[0], "m", 1) == 0)
6513 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6514 bgp_show_type_regexp);
6515
6516 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6517 bgp_show_type_regexp);
6518}
6519
6520#ifdef HAVE_IPV6
6521DEFUN (show_bgp_regexp,
6522 show_bgp_regexp_cmd,
6523 "show bgp regexp .LINE",
6524 SHOW_STR
6525 BGP_STR
6526 "Display routes matching the AS path regular expression\n"
6527 "A regular-expression to match the BGP AS paths\n")
6528{
6529 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6530 bgp_show_type_regexp);
6531}
6532
6533ALIAS (show_bgp_regexp,
6534 show_bgp_ipv6_regexp_cmd,
6535 "show bgp ipv6 regexp .LINE",
6536 SHOW_STR
6537 BGP_STR
6538 "Address family\n"
6539 "Display routes matching the AS path regular expression\n"
6540 "A regular-expression to match the BGP AS paths\n")
6541
6542/* old command */
6543DEFUN (show_ipv6_bgp_regexp,
6544 show_ipv6_bgp_regexp_cmd,
6545 "show ipv6 bgp regexp .LINE",
6546 SHOW_STR
6547 IP_STR
6548 BGP_STR
6549 "Display routes matching the AS path regular expression\n"
6550 "A regular-expression to match the BGP AS paths\n")
6551{
6552 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6553 bgp_show_type_regexp);
6554}
6555
6556/* old command */
6557DEFUN (show_ipv6_mbgp_regexp,
6558 show_ipv6_mbgp_regexp_cmd,
6559 "show ipv6 mbgp regexp .LINE",
6560 SHOW_STR
6561 IP_STR
6562 BGP_STR
6563 "Display routes matching the AS path regular expression\n"
6564 "A regular-expression to match the MBGP AS paths\n")
6565{
6566 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6567 bgp_show_type_regexp);
6568}
6569#endif /* HAVE_IPV6 */
6570
paul94f2b392005-06-28 12:44:16 +00006571static int
paulfd79ac92004-10-13 05:06:08 +00006572bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006573 safi_t safi, enum bgp_show_type type)
6574{
6575 struct prefix_list *plist;
6576
6577 plist = prefix_list_lookup (afi, prefix_list_str);
6578 if (plist == NULL)
6579 {
6580 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6581 prefix_list_str, VTY_NEWLINE);
6582 return CMD_WARNING;
6583 }
6584
ajs5a646652004-11-05 01:25:55 +00006585 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006586}
6587
6588DEFUN (show_ip_bgp_prefix_list,
6589 show_ip_bgp_prefix_list_cmd,
6590 "show ip bgp prefix-list WORD",
6591 SHOW_STR
6592 IP_STR
6593 BGP_STR
6594 "Display routes conforming to the prefix-list\n"
6595 "IP prefix-list name\n")
6596{
6597 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6598 bgp_show_type_prefix_list);
6599}
6600
6601DEFUN (show_ip_bgp_flap_prefix_list,
6602 show_ip_bgp_flap_prefix_list_cmd,
6603 "show ip bgp flap-statistics prefix-list WORD",
6604 SHOW_STR
6605 IP_STR
6606 BGP_STR
6607 "Display flap statistics of routes\n"
6608 "Display routes conforming to the prefix-list\n"
6609 "IP prefix-list name\n")
6610{
6611 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6612 bgp_show_type_flap_prefix_list);
6613}
6614
6615DEFUN (show_ip_bgp_ipv4_prefix_list,
6616 show_ip_bgp_ipv4_prefix_list_cmd,
6617 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6618 SHOW_STR
6619 IP_STR
6620 BGP_STR
6621 "Address family\n"
6622 "Address Family modifier\n"
6623 "Address Family modifier\n"
6624 "Display routes conforming to the prefix-list\n"
6625 "IP prefix-list name\n")
6626{
6627 if (strncmp (argv[0], "m", 1) == 0)
6628 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6629 bgp_show_type_prefix_list);
6630
6631 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6632 bgp_show_type_prefix_list);
6633}
6634
6635#ifdef HAVE_IPV6
6636DEFUN (show_bgp_prefix_list,
6637 show_bgp_prefix_list_cmd,
6638 "show bgp prefix-list WORD",
6639 SHOW_STR
6640 BGP_STR
6641 "Display routes conforming to the prefix-list\n"
6642 "IPv6 prefix-list name\n")
6643{
6644 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6645 bgp_show_type_prefix_list);
6646}
6647
6648ALIAS (show_bgp_prefix_list,
6649 show_bgp_ipv6_prefix_list_cmd,
6650 "show bgp ipv6 prefix-list WORD",
6651 SHOW_STR
6652 BGP_STR
6653 "Address family\n"
6654 "Display routes conforming to the prefix-list\n"
6655 "IPv6 prefix-list name\n")
6656
6657/* old command */
6658DEFUN (show_ipv6_bgp_prefix_list,
6659 show_ipv6_bgp_prefix_list_cmd,
6660 "show ipv6 bgp prefix-list WORD",
6661 SHOW_STR
6662 IPV6_STR
6663 BGP_STR
6664 "Display routes matching the prefix-list\n"
6665 "IPv6 prefix-list name\n")
6666{
6667 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6668 bgp_show_type_prefix_list);
6669}
6670
6671/* old command */
6672DEFUN (show_ipv6_mbgp_prefix_list,
6673 show_ipv6_mbgp_prefix_list_cmd,
6674 "show ipv6 mbgp prefix-list WORD",
6675 SHOW_STR
6676 IPV6_STR
6677 MBGP_STR
6678 "Display routes matching the prefix-list\n"
6679 "IPv6 prefix-list name\n")
6680{
6681 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6682 bgp_show_type_prefix_list);
6683}
6684#endif /* HAVE_IPV6 */
6685
paul94f2b392005-06-28 12:44:16 +00006686static int
paulfd79ac92004-10-13 05:06:08 +00006687bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006688 safi_t safi, enum bgp_show_type type)
6689{
6690 struct as_list *as_list;
6691
6692 as_list = as_list_lookup (filter);
6693 if (as_list == NULL)
6694 {
6695 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6696 return CMD_WARNING;
6697 }
6698
ajs5a646652004-11-05 01:25:55 +00006699 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006700}
6701
6702DEFUN (show_ip_bgp_filter_list,
6703 show_ip_bgp_filter_list_cmd,
6704 "show ip bgp filter-list WORD",
6705 SHOW_STR
6706 IP_STR
6707 BGP_STR
6708 "Display routes conforming to the filter-list\n"
6709 "Regular expression access list name\n")
6710{
6711 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6712 bgp_show_type_filter_list);
6713}
6714
6715DEFUN (show_ip_bgp_flap_filter_list,
6716 show_ip_bgp_flap_filter_list_cmd,
6717 "show ip bgp flap-statistics filter-list WORD",
6718 SHOW_STR
6719 IP_STR
6720 BGP_STR
6721 "Display flap statistics of routes\n"
6722 "Display routes conforming to the filter-list\n"
6723 "Regular expression access list name\n")
6724{
6725 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6726 bgp_show_type_flap_filter_list);
6727}
6728
6729DEFUN (show_ip_bgp_ipv4_filter_list,
6730 show_ip_bgp_ipv4_filter_list_cmd,
6731 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6732 SHOW_STR
6733 IP_STR
6734 BGP_STR
6735 "Address family\n"
6736 "Address Family modifier\n"
6737 "Address Family modifier\n"
6738 "Display routes conforming to the filter-list\n"
6739 "Regular expression access list name\n")
6740{
6741 if (strncmp (argv[0], "m", 1) == 0)
6742 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6743 bgp_show_type_filter_list);
6744
6745 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6746 bgp_show_type_filter_list);
6747}
6748
6749#ifdef HAVE_IPV6
6750DEFUN (show_bgp_filter_list,
6751 show_bgp_filter_list_cmd,
6752 "show bgp filter-list WORD",
6753 SHOW_STR
6754 BGP_STR
6755 "Display routes conforming to the filter-list\n"
6756 "Regular expression access list name\n")
6757{
6758 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6759 bgp_show_type_filter_list);
6760}
6761
6762ALIAS (show_bgp_filter_list,
6763 show_bgp_ipv6_filter_list_cmd,
6764 "show bgp ipv6 filter-list WORD",
6765 SHOW_STR
6766 BGP_STR
6767 "Address family\n"
6768 "Display routes conforming to the filter-list\n"
6769 "Regular expression access list name\n")
6770
6771/* old command */
6772DEFUN (show_ipv6_bgp_filter_list,
6773 show_ipv6_bgp_filter_list_cmd,
6774 "show ipv6 bgp filter-list WORD",
6775 SHOW_STR
6776 IPV6_STR
6777 BGP_STR
6778 "Display routes conforming to the filter-list\n"
6779 "Regular expression access list name\n")
6780{
6781 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6782 bgp_show_type_filter_list);
6783}
6784
6785/* old command */
6786DEFUN (show_ipv6_mbgp_filter_list,
6787 show_ipv6_mbgp_filter_list_cmd,
6788 "show ipv6 mbgp filter-list WORD",
6789 SHOW_STR
6790 IPV6_STR
6791 MBGP_STR
6792 "Display routes conforming to the filter-list\n"
6793 "Regular expression access list name\n")
6794{
6795 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6796 bgp_show_type_filter_list);
6797}
6798#endif /* HAVE_IPV6 */
6799
paul94f2b392005-06-28 12:44:16 +00006800static int
paulfd79ac92004-10-13 05:06:08 +00006801bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006802 safi_t safi, enum bgp_show_type type)
6803{
6804 struct route_map *rmap;
6805
6806 rmap = route_map_lookup_by_name (rmap_str);
6807 if (! rmap)
6808 {
6809 vty_out (vty, "%% %s is not a valid route-map name%s",
6810 rmap_str, VTY_NEWLINE);
6811 return CMD_WARNING;
6812 }
6813
ajs5a646652004-11-05 01:25:55 +00006814 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006815}
6816
6817DEFUN (show_ip_bgp_route_map,
6818 show_ip_bgp_route_map_cmd,
6819 "show ip bgp route-map WORD",
6820 SHOW_STR
6821 IP_STR
6822 BGP_STR
6823 "Display routes matching the route-map\n"
6824 "A route-map to match on\n")
6825{
6826 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6827 bgp_show_type_route_map);
6828}
6829
6830DEFUN (show_ip_bgp_flap_route_map,
6831 show_ip_bgp_flap_route_map_cmd,
6832 "show ip bgp flap-statistics route-map WORD",
6833 SHOW_STR
6834 IP_STR
6835 BGP_STR
6836 "Display flap statistics of routes\n"
6837 "Display routes matching the route-map\n"
6838 "A route-map to match on\n")
6839{
6840 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6841 bgp_show_type_flap_route_map);
6842}
6843
6844DEFUN (show_ip_bgp_ipv4_route_map,
6845 show_ip_bgp_ipv4_route_map_cmd,
6846 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6847 SHOW_STR
6848 IP_STR
6849 BGP_STR
6850 "Address family\n"
6851 "Address Family modifier\n"
6852 "Address Family modifier\n"
6853 "Display routes matching the route-map\n"
6854 "A route-map to match on\n")
6855{
6856 if (strncmp (argv[0], "m", 1) == 0)
6857 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6858 bgp_show_type_route_map);
6859
6860 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6861 bgp_show_type_route_map);
6862}
6863
6864DEFUN (show_bgp_route_map,
6865 show_bgp_route_map_cmd,
6866 "show bgp route-map WORD",
6867 SHOW_STR
6868 BGP_STR
6869 "Display routes matching the route-map\n"
6870 "A route-map to match on\n")
6871{
6872 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6873 bgp_show_type_route_map);
6874}
6875
6876ALIAS (show_bgp_route_map,
6877 show_bgp_ipv6_route_map_cmd,
6878 "show bgp ipv6 route-map WORD",
6879 SHOW_STR
6880 BGP_STR
6881 "Address family\n"
6882 "Display routes matching the route-map\n"
6883 "A route-map to match on\n")
6884
6885DEFUN (show_ip_bgp_cidr_only,
6886 show_ip_bgp_cidr_only_cmd,
6887 "show ip bgp cidr-only",
6888 SHOW_STR
6889 IP_STR
6890 BGP_STR
6891 "Display only routes with non-natural netmasks\n")
6892{
6893 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006894 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006895}
6896
6897DEFUN (show_ip_bgp_flap_cidr_only,
6898 show_ip_bgp_flap_cidr_only_cmd,
6899 "show ip bgp flap-statistics cidr-only",
6900 SHOW_STR
6901 IP_STR
6902 BGP_STR
6903 "Display flap statistics of routes\n"
6904 "Display only routes with non-natural netmasks\n")
6905{
6906 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006907 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006908}
6909
6910DEFUN (show_ip_bgp_ipv4_cidr_only,
6911 show_ip_bgp_ipv4_cidr_only_cmd,
6912 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6913 SHOW_STR
6914 IP_STR
6915 BGP_STR
6916 "Address family\n"
6917 "Address Family modifier\n"
6918 "Address Family modifier\n"
6919 "Display only routes with non-natural netmasks\n")
6920{
6921 if (strncmp (argv[0], "m", 1) == 0)
6922 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006923 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006924
6925 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006926 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006927}
6928
6929DEFUN (show_ip_bgp_community_all,
6930 show_ip_bgp_community_all_cmd,
6931 "show ip bgp community",
6932 SHOW_STR
6933 IP_STR
6934 BGP_STR
6935 "Display routes matching the communities\n")
6936{
6937 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006938 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006939}
6940
6941DEFUN (show_ip_bgp_ipv4_community_all,
6942 show_ip_bgp_ipv4_community_all_cmd,
6943 "show ip bgp ipv4 (unicast|multicast) community",
6944 SHOW_STR
6945 IP_STR
6946 BGP_STR
6947 "Address family\n"
6948 "Address Family modifier\n"
6949 "Address Family modifier\n"
6950 "Display routes matching the communities\n")
6951{
6952 if (strncmp (argv[0], "m", 1) == 0)
6953 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006954 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006955
6956 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006957 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006958}
6959
6960#ifdef HAVE_IPV6
6961DEFUN (show_bgp_community_all,
6962 show_bgp_community_all_cmd,
6963 "show bgp community",
6964 SHOW_STR
6965 BGP_STR
6966 "Display routes matching the communities\n")
6967{
6968 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006969 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006970}
6971
6972ALIAS (show_bgp_community_all,
6973 show_bgp_ipv6_community_all_cmd,
6974 "show bgp ipv6 community",
6975 SHOW_STR
6976 BGP_STR
6977 "Address family\n"
6978 "Display routes matching the communities\n")
6979
6980/* old command */
6981DEFUN (show_ipv6_bgp_community_all,
6982 show_ipv6_bgp_community_all_cmd,
6983 "show ipv6 bgp community",
6984 SHOW_STR
6985 IPV6_STR
6986 BGP_STR
6987 "Display routes matching the communities\n")
6988{
6989 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006990 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006991}
6992
6993/* old command */
6994DEFUN (show_ipv6_mbgp_community_all,
6995 show_ipv6_mbgp_community_all_cmd,
6996 "show ipv6 mbgp community",
6997 SHOW_STR
6998 IPV6_STR
6999 MBGP_STR
7000 "Display routes matching the communities\n")
7001{
7002 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007003 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007004}
7005#endif /* HAVE_IPV6 */
7006
paul94f2b392005-06-28 12:44:16 +00007007static int
paulfd79ac92004-10-13 05:06:08 +00007008bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7009 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007010{
7011 struct community *com;
7012 struct buffer *b;
7013 int i;
7014 char *str;
7015 int first = 0;
7016
7017 b = buffer_new (1024);
7018 for (i = 0; i < argc; i++)
7019 {
7020 if (first)
7021 buffer_putc (b, ' ');
7022 else
7023 {
7024 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7025 continue;
7026 first = 1;
7027 }
7028
7029 buffer_putstr (b, argv[i]);
7030 }
7031 buffer_putc (b, '\0');
7032
7033 str = buffer_getstr (b);
7034 buffer_free (b);
7035
7036 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007037 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007038 if (! com)
7039 {
7040 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7041 return CMD_WARNING;
7042 }
7043
ajs5a646652004-11-05 01:25:55 +00007044 return bgp_show (vty, NULL, afi, safi,
7045 (exact ? bgp_show_type_community_exact :
7046 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007047}
7048
7049DEFUN (show_ip_bgp_community,
7050 show_ip_bgp_community_cmd,
7051 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7052 SHOW_STR
7053 IP_STR
7054 BGP_STR
7055 "Display routes matching the communities\n"
7056 "community number\n"
7057 "Do not send outside local AS (well-known community)\n"
7058 "Do not advertise to any peer (well-known community)\n"
7059 "Do not export to next AS (well-known community)\n")
7060{
7061 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7062}
7063
7064ALIAS (show_ip_bgp_community,
7065 show_ip_bgp_community2_cmd,
7066 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7067 SHOW_STR
7068 IP_STR
7069 BGP_STR
7070 "Display routes matching the communities\n"
7071 "community number\n"
7072 "Do not send outside local AS (well-known community)\n"
7073 "Do not advertise to any peer (well-known community)\n"
7074 "Do not export to next AS (well-known community)\n"
7075 "community number\n"
7076 "Do not send outside local AS (well-known community)\n"
7077 "Do not advertise to any peer (well-known community)\n"
7078 "Do not export to next AS (well-known community)\n")
7079
7080ALIAS (show_ip_bgp_community,
7081 show_ip_bgp_community3_cmd,
7082 "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)",
7083 SHOW_STR
7084 IP_STR
7085 BGP_STR
7086 "Display routes matching the communities\n"
7087 "community number\n"
7088 "Do not send outside local AS (well-known community)\n"
7089 "Do not advertise to any peer (well-known community)\n"
7090 "Do not export to next AS (well-known community)\n"
7091 "community number\n"
7092 "Do not send outside local AS (well-known community)\n"
7093 "Do not advertise to any peer (well-known community)\n"
7094 "Do not export to next AS (well-known community)\n"
7095 "community number\n"
7096 "Do not send outside local AS (well-known community)\n"
7097 "Do not advertise to any peer (well-known community)\n"
7098 "Do not export to next AS (well-known community)\n")
7099
7100ALIAS (show_ip_bgp_community,
7101 show_ip_bgp_community4_cmd,
7102 "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)",
7103 SHOW_STR
7104 IP_STR
7105 BGP_STR
7106 "Display routes matching the communities\n"
7107 "community number\n"
7108 "Do not send outside local AS (well-known community)\n"
7109 "Do not advertise to any peer (well-known community)\n"
7110 "Do not export to next AS (well-known community)\n"
7111 "community number\n"
7112 "Do not send outside local AS (well-known community)\n"
7113 "Do not advertise to any peer (well-known community)\n"
7114 "Do not export to next AS (well-known community)\n"
7115 "community number\n"
7116 "Do not send outside local AS (well-known community)\n"
7117 "Do not advertise to any peer (well-known community)\n"
7118 "Do not export to next AS (well-known community)\n"
7119 "community number\n"
7120 "Do not send outside local AS (well-known community)\n"
7121 "Do not advertise to any peer (well-known community)\n"
7122 "Do not export to next AS (well-known community)\n")
7123
7124DEFUN (show_ip_bgp_ipv4_community,
7125 show_ip_bgp_ipv4_community_cmd,
7126 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7127 SHOW_STR
7128 IP_STR
7129 BGP_STR
7130 "Address family\n"
7131 "Address Family modifier\n"
7132 "Address Family modifier\n"
7133 "Display routes matching the communities\n"
7134 "community number\n"
7135 "Do not send outside local AS (well-known community)\n"
7136 "Do not advertise to any peer (well-known community)\n"
7137 "Do not export to next AS (well-known community)\n")
7138{
7139 if (strncmp (argv[0], "m", 1) == 0)
7140 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7141
7142 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7143}
7144
7145ALIAS (show_ip_bgp_ipv4_community,
7146 show_ip_bgp_ipv4_community2_cmd,
7147 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7148 SHOW_STR
7149 IP_STR
7150 BGP_STR
7151 "Address family\n"
7152 "Address Family modifier\n"
7153 "Address Family modifier\n"
7154 "Display routes matching the communities\n"
7155 "community number\n"
7156 "Do not send outside local AS (well-known community)\n"
7157 "Do not advertise to any peer (well-known community)\n"
7158 "Do not export to next AS (well-known community)\n"
7159 "community number\n"
7160 "Do not send outside local AS (well-known community)\n"
7161 "Do not advertise to any peer (well-known community)\n"
7162 "Do not export to next AS (well-known community)\n")
7163
7164ALIAS (show_ip_bgp_ipv4_community,
7165 show_ip_bgp_ipv4_community3_cmd,
7166 "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)",
7167 SHOW_STR
7168 IP_STR
7169 BGP_STR
7170 "Address family\n"
7171 "Address Family modifier\n"
7172 "Address Family modifier\n"
7173 "Display routes matching the communities\n"
7174 "community number\n"
7175 "Do not send outside local AS (well-known community)\n"
7176 "Do not advertise to any peer (well-known community)\n"
7177 "Do not export to next AS (well-known community)\n"
7178 "community number\n"
7179 "Do not send outside local AS (well-known community)\n"
7180 "Do not advertise to any peer (well-known community)\n"
7181 "Do not export to next AS (well-known community)\n"
7182 "community number\n"
7183 "Do not send outside local AS (well-known community)\n"
7184 "Do not advertise to any peer (well-known community)\n"
7185 "Do not export to next AS (well-known community)\n")
7186
7187ALIAS (show_ip_bgp_ipv4_community,
7188 show_ip_bgp_ipv4_community4_cmd,
7189 "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)",
7190 SHOW_STR
7191 IP_STR
7192 BGP_STR
7193 "Address family\n"
7194 "Address Family modifier\n"
7195 "Address Family modifier\n"
7196 "Display routes matching the communities\n"
7197 "community number\n"
7198 "Do not send outside local AS (well-known community)\n"
7199 "Do not advertise to any peer (well-known community)\n"
7200 "Do not export to next AS (well-known community)\n"
7201 "community number\n"
7202 "Do not send outside local AS (well-known community)\n"
7203 "Do not advertise to any peer (well-known community)\n"
7204 "Do not export to next AS (well-known community)\n"
7205 "community number\n"
7206 "Do not send outside local AS (well-known community)\n"
7207 "Do not advertise to any peer (well-known community)\n"
7208 "Do not export to next AS (well-known community)\n"
7209 "community number\n"
7210 "Do not send outside local AS (well-known community)\n"
7211 "Do not advertise to any peer (well-known community)\n"
7212 "Do not export to next AS (well-known community)\n")
7213
7214DEFUN (show_ip_bgp_community_exact,
7215 show_ip_bgp_community_exact_cmd,
7216 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7217 SHOW_STR
7218 IP_STR
7219 BGP_STR
7220 "Display routes matching the communities\n"
7221 "community number\n"
7222 "Do not send outside local AS (well-known community)\n"
7223 "Do not advertise to any peer (well-known community)\n"
7224 "Do not export to next AS (well-known community)\n"
7225 "Exact match of the communities")
7226{
7227 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7228}
7229
7230ALIAS (show_ip_bgp_community_exact,
7231 show_ip_bgp_community2_exact_cmd,
7232 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7233 SHOW_STR
7234 IP_STR
7235 BGP_STR
7236 "Display routes matching the communities\n"
7237 "community number\n"
7238 "Do not send outside local AS (well-known community)\n"
7239 "Do not advertise to any peer (well-known community)\n"
7240 "Do not export to next AS (well-known community)\n"
7241 "community number\n"
7242 "Do not send outside local AS (well-known community)\n"
7243 "Do not advertise to any peer (well-known community)\n"
7244 "Do not export to next AS (well-known community)\n"
7245 "Exact match of the communities")
7246
7247ALIAS (show_ip_bgp_community_exact,
7248 show_ip_bgp_community3_exact_cmd,
7249 "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",
7250 SHOW_STR
7251 IP_STR
7252 BGP_STR
7253 "Display routes matching the communities\n"
7254 "community number\n"
7255 "Do not send outside local AS (well-known community)\n"
7256 "Do not advertise to any peer (well-known community)\n"
7257 "Do not export to next AS (well-known community)\n"
7258 "community number\n"
7259 "Do not send outside local AS (well-known community)\n"
7260 "Do not advertise to any peer (well-known community)\n"
7261 "Do not export to next AS (well-known community)\n"
7262 "community number\n"
7263 "Do not send outside local AS (well-known community)\n"
7264 "Do not advertise to any peer (well-known community)\n"
7265 "Do not export to next AS (well-known community)\n"
7266 "Exact match of the communities")
7267
7268ALIAS (show_ip_bgp_community_exact,
7269 show_ip_bgp_community4_exact_cmd,
7270 "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",
7271 SHOW_STR
7272 IP_STR
7273 BGP_STR
7274 "Display routes matching the communities\n"
7275 "community number\n"
7276 "Do not send outside local AS (well-known community)\n"
7277 "Do not advertise to any peer (well-known community)\n"
7278 "Do not export to next AS (well-known community)\n"
7279 "community number\n"
7280 "Do not send outside local AS (well-known community)\n"
7281 "Do not advertise to any peer (well-known community)\n"
7282 "Do not export to next AS (well-known community)\n"
7283 "community number\n"
7284 "Do not send outside local AS (well-known community)\n"
7285 "Do not advertise to any peer (well-known community)\n"
7286 "Do not export to next AS (well-known community)\n"
7287 "community number\n"
7288 "Do not send outside local AS (well-known community)\n"
7289 "Do not advertise to any peer (well-known community)\n"
7290 "Do not export to next AS (well-known community)\n"
7291 "Exact match of the communities")
7292
7293DEFUN (show_ip_bgp_ipv4_community_exact,
7294 show_ip_bgp_ipv4_community_exact_cmd,
7295 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7296 SHOW_STR
7297 IP_STR
7298 BGP_STR
7299 "Address family\n"
7300 "Address Family modifier\n"
7301 "Address Family modifier\n"
7302 "Display routes matching the communities\n"
7303 "community number\n"
7304 "Do not send outside local AS (well-known community)\n"
7305 "Do not advertise to any peer (well-known community)\n"
7306 "Do not export to next AS (well-known community)\n"
7307 "Exact match of the communities")
7308{
7309 if (strncmp (argv[0], "m", 1) == 0)
7310 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7311
7312 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7313}
7314
7315ALIAS (show_ip_bgp_ipv4_community_exact,
7316 show_ip_bgp_ipv4_community2_exact_cmd,
7317 "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",
7318 SHOW_STR
7319 IP_STR
7320 BGP_STR
7321 "Address family\n"
7322 "Address Family modifier\n"
7323 "Address Family modifier\n"
7324 "Display routes matching the communities\n"
7325 "community number\n"
7326 "Do not send outside local AS (well-known community)\n"
7327 "Do not advertise to any peer (well-known community)\n"
7328 "Do not export to next AS (well-known community)\n"
7329 "community number\n"
7330 "Do not send outside local AS (well-known community)\n"
7331 "Do not advertise to any peer (well-known community)\n"
7332 "Do not export to next AS (well-known community)\n"
7333 "Exact match of the communities")
7334
7335ALIAS (show_ip_bgp_ipv4_community_exact,
7336 show_ip_bgp_ipv4_community3_exact_cmd,
7337 "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",
7338 SHOW_STR
7339 IP_STR
7340 BGP_STR
7341 "Address family\n"
7342 "Address Family modifier\n"
7343 "Address Family modifier\n"
7344 "Display routes matching the communities\n"
7345 "community number\n"
7346 "Do not send outside local AS (well-known community)\n"
7347 "Do not advertise to any peer (well-known community)\n"
7348 "Do not export to next AS (well-known community)\n"
7349 "community number\n"
7350 "Do not send outside local AS (well-known community)\n"
7351 "Do not advertise to any peer (well-known community)\n"
7352 "Do not export to next AS (well-known community)\n"
7353 "community number\n"
7354 "Do not send outside local AS (well-known community)\n"
7355 "Do not advertise to any peer (well-known community)\n"
7356 "Do not export to next AS (well-known community)\n"
7357 "Exact match of the communities")
7358
7359ALIAS (show_ip_bgp_ipv4_community_exact,
7360 show_ip_bgp_ipv4_community4_exact_cmd,
7361 "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",
7362 SHOW_STR
7363 IP_STR
7364 BGP_STR
7365 "Address family\n"
7366 "Address Family modifier\n"
7367 "Address Family modifier\n"
7368 "Display routes matching the communities\n"
7369 "community number\n"
7370 "Do not send outside local AS (well-known community)\n"
7371 "Do not advertise to any peer (well-known community)\n"
7372 "Do not export to next AS (well-known community)\n"
7373 "community number\n"
7374 "Do not send outside local AS (well-known community)\n"
7375 "Do not advertise to any peer (well-known community)\n"
7376 "Do not export to next AS (well-known community)\n"
7377 "community number\n"
7378 "Do not send outside local AS (well-known community)\n"
7379 "Do not advertise to any peer (well-known community)\n"
7380 "Do not export to next AS (well-known community)\n"
7381 "community number\n"
7382 "Do not send outside local AS (well-known community)\n"
7383 "Do not advertise to any peer (well-known community)\n"
7384 "Do not export to next AS (well-known community)\n"
7385 "Exact match of the communities")
7386
7387#ifdef HAVE_IPV6
7388DEFUN (show_bgp_community,
7389 show_bgp_community_cmd,
7390 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7391 SHOW_STR
7392 BGP_STR
7393 "Display routes matching the communities\n"
7394 "community number\n"
7395 "Do not send outside local AS (well-known community)\n"
7396 "Do not advertise to any peer (well-known community)\n"
7397 "Do not export to next AS (well-known community)\n")
7398{
7399 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7400}
7401
7402ALIAS (show_bgp_community,
7403 show_bgp_ipv6_community_cmd,
7404 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7405 SHOW_STR
7406 BGP_STR
7407 "Address family\n"
7408 "Display routes matching the communities\n"
7409 "community number\n"
7410 "Do not send outside local AS (well-known community)\n"
7411 "Do not advertise to any peer (well-known community)\n"
7412 "Do not export to next AS (well-known community)\n")
7413
7414ALIAS (show_bgp_community,
7415 show_bgp_community2_cmd,
7416 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7417 SHOW_STR
7418 BGP_STR
7419 "Display routes matching the communities\n"
7420 "community number\n"
7421 "Do not send outside local AS (well-known community)\n"
7422 "Do not advertise to any peer (well-known community)\n"
7423 "Do not export to next AS (well-known community)\n"
7424 "community number\n"
7425 "Do not send outside local AS (well-known community)\n"
7426 "Do not advertise to any peer (well-known community)\n"
7427 "Do not export to next AS (well-known community)\n")
7428
7429ALIAS (show_bgp_community,
7430 show_bgp_ipv6_community2_cmd,
7431 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7432 SHOW_STR
7433 BGP_STR
7434 "Address family\n"
7435 "Display routes matching the communities\n"
7436 "community number\n"
7437 "Do not send outside local AS (well-known community)\n"
7438 "Do not advertise to any peer (well-known community)\n"
7439 "Do not export to next AS (well-known community)\n"
7440 "community number\n"
7441 "Do not send outside local AS (well-known community)\n"
7442 "Do not advertise to any peer (well-known community)\n"
7443 "Do not export to next AS (well-known community)\n")
7444
7445ALIAS (show_bgp_community,
7446 show_bgp_community3_cmd,
7447 "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)",
7448 SHOW_STR
7449 BGP_STR
7450 "Display routes matching the communities\n"
7451 "community number\n"
7452 "Do not send outside local AS (well-known community)\n"
7453 "Do not advertise to any peer (well-known community)\n"
7454 "Do not export to next AS (well-known community)\n"
7455 "community number\n"
7456 "Do not send outside local AS (well-known community)\n"
7457 "Do not advertise to any peer (well-known community)\n"
7458 "Do not export to next AS (well-known community)\n"
7459 "community number\n"
7460 "Do not send outside local AS (well-known community)\n"
7461 "Do not advertise to any peer (well-known community)\n"
7462 "Do not export to next AS (well-known community)\n")
7463
7464ALIAS (show_bgp_community,
7465 show_bgp_ipv6_community3_cmd,
7466 "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)",
7467 SHOW_STR
7468 BGP_STR
7469 "Address family\n"
7470 "Display routes matching the communities\n"
7471 "community number\n"
7472 "Do not send outside local AS (well-known community)\n"
7473 "Do not advertise to any peer (well-known community)\n"
7474 "Do not export to next AS (well-known community)\n"
7475 "community number\n"
7476 "Do not send outside local AS (well-known community)\n"
7477 "Do not advertise to any peer (well-known community)\n"
7478 "Do not export to next AS (well-known community)\n"
7479 "community number\n"
7480 "Do not send outside local AS (well-known community)\n"
7481 "Do not advertise to any peer (well-known community)\n"
7482 "Do not export to next AS (well-known community)\n")
7483
7484ALIAS (show_bgp_community,
7485 show_bgp_community4_cmd,
7486 "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)",
7487 SHOW_STR
7488 BGP_STR
7489 "Display routes matching the communities\n"
7490 "community number\n"
7491 "Do not send outside local AS (well-known community)\n"
7492 "Do not advertise to any peer (well-known community)\n"
7493 "Do not export to next AS (well-known community)\n"
7494 "community number\n"
7495 "Do not send outside local AS (well-known community)\n"
7496 "Do not advertise to any peer (well-known community)\n"
7497 "Do not export to next AS (well-known community)\n"
7498 "community number\n"
7499 "Do not send outside local AS (well-known community)\n"
7500 "Do not advertise to any peer (well-known community)\n"
7501 "Do not export to next AS (well-known community)\n"
7502 "community number\n"
7503 "Do not send outside local AS (well-known community)\n"
7504 "Do not advertise to any peer (well-known community)\n"
7505 "Do not export to next AS (well-known community)\n")
7506
7507ALIAS (show_bgp_community,
7508 show_bgp_ipv6_community4_cmd,
7509 "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)",
7510 SHOW_STR
7511 BGP_STR
7512 "Address family\n"
7513 "Display routes matching the communities\n"
7514 "community number\n"
7515 "Do not send outside local AS (well-known community)\n"
7516 "Do not advertise to any peer (well-known community)\n"
7517 "Do not export to next AS (well-known community)\n"
7518 "community number\n"
7519 "Do not send outside local AS (well-known community)\n"
7520 "Do not advertise to any peer (well-known community)\n"
7521 "Do not export to next AS (well-known community)\n"
7522 "community number\n"
7523 "Do not send outside local AS (well-known community)\n"
7524 "Do not advertise to any peer (well-known community)\n"
7525 "Do not export to next AS (well-known community)\n"
7526 "community number\n"
7527 "Do not send outside local AS (well-known community)\n"
7528 "Do not advertise to any peer (well-known community)\n"
7529 "Do not export to next AS (well-known community)\n")
7530
7531/* old command */
7532DEFUN (show_ipv6_bgp_community,
7533 show_ipv6_bgp_community_cmd,
7534 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7535 SHOW_STR
7536 IPV6_STR
7537 BGP_STR
7538 "Display routes matching the communities\n"
7539 "community number\n"
7540 "Do not send outside local AS (well-known community)\n"
7541 "Do not advertise to any peer (well-known community)\n"
7542 "Do not export to next AS (well-known community)\n")
7543{
7544 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7545}
7546
7547/* old command */
7548ALIAS (show_ipv6_bgp_community,
7549 show_ipv6_bgp_community2_cmd,
7550 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7551 SHOW_STR
7552 IPV6_STR
7553 BGP_STR
7554 "Display routes matching the communities\n"
7555 "community number\n"
7556 "Do not send outside local AS (well-known community)\n"
7557 "Do not advertise to any peer (well-known community)\n"
7558 "Do not export to next AS (well-known community)\n"
7559 "community number\n"
7560 "Do not send outside local AS (well-known community)\n"
7561 "Do not advertise to any peer (well-known community)\n"
7562 "Do not export to next AS (well-known community)\n")
7563
7564/* old command */
7565ALIAS (show_ipv6_bgp_community,
7566 show_ipv6_bgp_community3_cmd,
7567 "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)",
7568 SHOW_STR
7569 IPV6_STR
7570 BGP_STR
7571 "Display routes matching the communities\n"
7572 "community number\n"
7573 "Do not send outside local AS (well-known community)\n"
7574 "Do not advertise to any peer (well-known community)\n"
7575 "Do not export to next AS (well-known community)\n"
7576 "community number\n"
7577 "Do not send outside local AS (well-known community)\n"
7578 "Do not advertise to any peer (well-known community)\n"
7579 "Do not export to next AS (well-known community)\n"
7580 "community number\n"
7581 "Do not send outside local AS (well-known community)\n"
7582 "Do not advertise to any peer (well-known community)\n"
7583 "Do not export to next AS (well-known community)\n")
7584
7585/* old command */
7586ALIAS (show_ipv6_bgp_community,
7587 show_ipv6_bgp_community4_cmd,
7588 "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)",
7589 SHOW_STR
7590 IPV6_STR
7591 BGP_STR
7592 "Display routes matching the communities\n"
7593 "community number\n"
7594 "Do not send outside local AS (well-known community)\n"
7595 "Do not advertise to any peer (well-known community)\n"
7596 "Do not export to next AS (well-known community)\n"
7597 "community number\n"
7598 "Do not send outside local AS (well-known community)\n"
7599 "Do not advertise to any peer (well-known community)\n"
7600 "Do not export to next AS (well-known community)\n"
7601 "community number\n"
7602 "Do not send outside local AS (well-known community)\n"
7603 "Do not advertise to any peer (well-known community)\n"
7604 "Do not export to next AS (well-known community)\n"
7605 "community number\n"
7606 "Do not send outside local AS (well-known community)\n"
7607 "Do not advertise to any peer (well-known community)\n"
7608 "Do not export to next AS (well-known community)\n")
7609
7610DEFUN (show_bgp_community_exact,
7611 show_bgp_community_exact_cmd,
7612 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7613 SHOW_STR
7614 BGP_STR
7615 "Display routes matching the communities\n"
7616 "community number\n"
7617 "Do not send outside local AS (well-known community)\n"
7618 "Do not advertise to any peer (well-known community)\n"
7619 "Do not export to next AS (well-known community)\n"
7620 "Exact match of the communities")
7621{
7622 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7623}
7624
7625ALIAS (show_bgp_community_exact,
7626 show_bgp_ipv6_community_exact_cmd,
7627 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7628 SHOW_STR
7629 BGP_STR
7630 "Address family\n"
7631 "Display routes matching the communities\n"
7632 "community number\n"
7633 "Do not send outside local AS (well-known community)\n"
7634 "Do not advertise to any peer (well-known community)\n"
7635 "Do not export to next AS (well-known community)\n"
7636 "Exact match of the communities")
7637
7638ALIAS (show_bgp_community_exact,
7639 show_bgp_community2_exact_cmd,
7640 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7641 SHOW_STR
7642 BGP_STR
7643 "Display routes matching the communities\n"
7644 "community number\n"
7645 "Do not send outside local AS (well-known community)\n"
7646 "Do not advertise to any peer (well-known community)\n"
7647 "Do not export to next AS (well-known community)\n"
7648 "community number\n"
7649 "Do not send outside local AS (well-known community)\n"
7650 "Do not advertise to any peer (well-known community)\n"
7651 "Do not export to next AS (well-known community)\n"
7652 "Exact match of the communities")
7653
7654ALIAS (show_bgp_community_exact,
7655 show_bgp_ipv6_community2_exact_cmd,
7656 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7657 SHOW_STR
7658 BGP_STR
7659 "Address family\n"
7660 "Display routes matching the communities\n"
7661 "community number\n"
7662 "Do not send outside local AS (well-known community)\n"
7663 "Do not advertise to any peer (well-known community)\n"
7664 "Do not export to next AS (well-known community)\n"
7665 "community number\n"
7666 "Do not send outside local AS (well-known community)\n"
7667 "Do not advertise to any peer (well-known community)\n"
7668 "Do not export to next AS (well-known community)\n"
7669 "Exact match of the communities")
7670
7671ALIAS (show_bgp_community_exact,
7672 show_bgp_community3_exact_cmd,
7673 "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",
7674 SHOW_STR
7675 BGP_STR
7676 "Display routes matching the communities\n"
7677 "community number\n"
7678 "Do not send outside local AS (well-known community)\n"
7679 "Do not advertise to any peer (well-known community)\n"
7680 "Do not export to next AS (well-known community)\n"
7681 "community number\n"
7682 "Do not send outside local AS (well-known community)\n"
7683 "Do not advertise to any peer (well-known community)\n"
7684 "Do not export to next AS (well-known community)\n"
7685 "community number\n"
7686 "Do not send outside local AS (well-known community)\n"
7687 "Do not advertise to any peer (well-known community)\n"
7688 "Do not export to next AS (well-known community)\n"
7689 "Exact match of the communities")
7690
7691ALIAS (show_bgp_community_exact,
7692 show_bgp_ipv6_community3_exact_cmd,
7693 "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",
7694 SHOW_STR
7695 BGP_STR
7696 "Address family\n"
7697 "Display routes matching the communities\n"
7698 "community number\n"
7699 "Do not send outside local AS (well-known community)\n"
7700 "Do not advertise to any peer (well-known community)\n"
7701 "Do not export to next AS (well-known community)\n"
7702 "community number\n"
7703 "Do not send outside local AS (well-known community)\n"
7704 "Do not advertise to any peer (well-known community)\n"
7705 "Do not export to next AS (well-known community)\n"
7706 "community number\n"
7707 "Do not send outside local AS (well-known community)\n"
7708 "Do not advertise to any peer (well-known community)\n"
7709 "Do not export to next AS (well-known community)\n"
7710 "Exact match of the communities")
7711
7712ALIAS (show_bgp_community_exact,
7713 show_bgp_community4_exact_cmd,
7714 "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",
7715 SHOW_STR
7716 BGP_STR
7717 "Display routes matching the communities\n"
7718 "community number\n"
7719 "Do not send outside local AS (well-known community)\n"
7720 "Do not advertise to any peer (well-known community)\n"
7721 "Do not export to next AS (well-known community)\n"
7722 "community number\n"
7723 "Do not send outside local AS (well-known community)\n"
7724 "Do not advertise to any peer (well-known community)\n"
7725 "Do not export to next AS (well-known community)\n"
7726 "community number\n"
7727 "Do not send outside local AS (well-known community)\n"
7728 "Do not advertise to any peer (well-known community)\n"
7729 "Do not export to next AS (well-known community)\n"
7730 "community number\n"
7731 "Do not send outside local AS (well-known community)\n"
7732 "Do not advertise to any peer (well-known community)\n"
7733 "Do not export to next AS (well-known community)\n"
7734 "Exact match of the communities")
7735
7736ALIAS (show_bgp_community_exact,
7737 show_bgp_ipv6_community4_exact_cmd,
7738 "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",
7739 SHOW_STR
7740 BGP_STR
7741 "Address family\n"
7742 "Display routes matching the communities\n"
7743 "community number\n"
7744 "Do not send outside local AS (well-known community)\n"
7745 "Do not advertise to any peer (well-known community)\n"
7746 "Do not export to next AS (well-known community)\n"
7747 "community number\n"
7748 "Do not send outside local AS (well-known community)\n"
7749 "Do not advertise to any peer (well-known community)\n"
7750 "Do not export to next AS (well-known community)\n"
7751 "community number\n"
7752 "Do not send outside local AS (well-known community)\n"
7753 "Do not advertise to any peer (well-known community)\n"
7754 "Do not export to next AS (well-known community)\n"
7755 "community number\n"
7756 "Do not send outside local AS (well-known community)\n"
7757 "Do not advertise to any peer (well-known community)\n"
7758 "Do not export to next AS (well-known community)\n"
7759 "Exact match of the communities")
7760
7761/* old command */
7762DEFUN (show_ipv6_bgp_community_exact,
7763 show_ipv6_bgp_community_exact_cmd,
7764 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7765 SHOW_STR
7766 IPV6_STR
7767 BGP_STR
7768 "Display routes matching the communities\n"
7769 "community number\n"
7770 "Do not send outside local AS (well-known community)\n"
7771 "Do not advertise to any peer (well-known community)\n"
7772 "Do not export to next AS (well-known community)\n"
7773 "Exact match of the communities")
7774{
7775 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7776}
7777
7778/* old command */
7779ALIAS (show_ipv6_bgp_community_exact,
7780 show_ipv6_bgp_community2_exact_cmd,
7781 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7782 SHOW_STR
7783 IPV6_STR
7784 BGP_STR
7785 "Display routes matching the communities\n"
7786 "community number\n"
7787 "Do not send outside local AS (well-known community)\n"
7788 "Do not advertise to any peer (well-known community)\n"
7789 "Do not export to next AS (well-known community)\n"
7790 "community number\n"
7791 "Do not send outside local AS (well-known community)\n"
7792 "Do not advertise to any peer (well-known community)\n"
7793 "Do not export to next AS (well-known community)\n"
7794 "Exact match of the communities")
7795
7796/* old command */
7797ALIAS (show_ipv6_bgp_community_exact,
7798 show_ipv6_bgp_community3_exact_cmd,
7799 "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",
7800 SHOW_STR
7801 IPV6_STR
7802 BGP_STR
7803 "Display routes matching the communities\n"
7804 "community number\n"
7805 "Do not send outside local AS (well-known community)\n"
7806 "Do not advertise to any peer (well-known community)\n"
7807 "Do not export to next AS (well-known community)\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "Exact match of the communities")
7817
7818/* old command */
7819ALIAS (show_ipv6_bgp_community_exact,
7820 show_ipv6_bgp_community4_exact_cmd,
7821 "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",
7822 SHOW_STR
7823 IPV6_STR
7824 BGP_STR
7825 "Display routes matching the communities\n"
7826 "community number\n"
7827 "Do not send outside local AS (well-known community)\n"
7828 "Do not advertise to any peer (well-known community)\n"
7829 "Do not export to next AS (well-known community)\n"
7830 "community number\n"
7831 "Do not send outside local AS (well-known community)\n"
7832 "Do not advertise to any peer (well-known community)\n"
7833 "Do not export to next AS (well-known community)\n"
7834 "community number\n"
7835 "Do not send outside local AS (well-known community)\n"
7836 "Do not advertise to any peer (well-known community)\n"
7837 "Do not export to next AS (well-known community)\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n"
7842 "Exact match of the communities")
7843
7844/* old command */
7845DEFUN (show_ipv6_mbgp_community,
7846 show_ipv6_mbgp_community_cmd,
7847 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7848 SHOW_STR
7849 IPV6_STR
7850 MBGP_STR
7851 "Display routes matching the communities\n"
7852 "community number\n"
7853 "Do not send outside local AS (well-known community)\n"
7854 "Do not advertise to any peer (well-known community)\n"
7855 "Do not export to next AS (well-known community)\n")
7856{
7857 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7858}
7859
7860/* old command */
7861ALIAS (show_ipv6_mbgp_community,
7862 show_ipv6_mbgp_community2_cmd,
7863 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7864 SHOW_STR
7865 IPV6_STR
7866 MBGP_STR
7867 "Display routes matching the communities\n"
7868 "community number\n"
7869 "Do not send outside local AS (well-known community)\n"
7870 "Do not advertise to any peer (well-known community)\n"
7871 "Do not export to next AS (well-known community)\n"
7872 "community number\n"
7873 "Do not send outside local AS (well-known community)\n"
7874 "Do not advertise to any peer (well-known community)\n"
7875 "Do not export to next AS (well-known community)\n")
7876
7877/* old command */
7878ALIAS (show_ipv6_mbgp_community,
7879 show_ipv6_mbgp_community3_cmd,
7880 "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)",
7881 SHOW_STR
7882 IPV6_STR
7883 MBGP_STR
7884 "Display routes matching the communities\n"
7885 "community number\n"
7886 "Do not send outside local AS (well-known community)\n"
7887 "Do not advertise to any peer (well-known community)\n"
7888 "Do not export to next AS (well-known community)\n"
7889 "community number\n"
7890 "Do not send outside local AS (well-known community)\n"
7891 "Do not advertise to any peer (well-known community)\n"
7892 "Do not export to next AS (well-known community)\n"
7893 "community number\n"
7894 "Do not send outside local AS (well-known community)\n"
7895 "Do not advertise to any peer (well-known community)\n"
7896 "Do not export to next AS (well-known community)\n")
7897
7898/* old command */
7899ALIAS (show_ipv6_mbgp_community,
7900 show_ipv6_mbgp_community4_cmd,
7901 "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)",
7902 SHOW_STR
7903 IPV6_STR
7904 MBGP_STR
7905 "Display routes matching the communities\n"
7906 "community number\n"
7907 "Do not send outside local AS (well-known community)\n"
7908 "Do not advertise to any peer (well-known community)\n"
7909 "Do not export to next AS (well-known community)\n"
7910 "community number\n"
7911 "Do not send outside local AS (well-known community)\n"
7912 "Do not advertise to any peer (well-known community)\n"
7913 "Do not export to next AS (well-known community)\n"
7914 "community number\n"
7915 "Do not send outside local AS (well-known community)\n"
7916 "Do not advertise to any peer (well-known community)\n"
7917 "Do not export to next AS (well-known community)\n"
7918 "community number\n"
7919 "Do not send outside local AS (well-known community)\n"
7920 "Do not advertise to any peer (well-known community)\n"
7921 "Do not export to next AS (well-known community)\n")
7922
7923/* old command */
7924DEFUN (show_ipv6_mbgp_community_exact,
7925 show_ipv6_mbgp_community_exact_cmd,
7926 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7927 SHOW_STR
7928 IPV6_STR
7929 MBGP_STR
7930 "Display routes matching the communities\n"
7931 "community number\n"
7932 "Do not send outside local AS (well-known community)\n"
7933 "Do not advertise to any peer (well-known community)\n"
7934 "Do not export to next AS (well-known community)\n"
7935 "Exact match of the communities")
7936{
7937 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7938}
7939
7940/* old command */
7941ALIAS (show_ipv6_mbgp_community_exact,
7942 show_ipv6_mbgp_community2_exact_cmd,
7943 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7944 SHOW_STR
7945 IPV6_STR
7946 MBGP_STR
7947 "Display routes matching the communities\n"
7948 "community number\n"
7949 "Do not send outside local AS (well-known community)\n"
7950 "Do not advertise to any peer (well-known community)\n"
7951 "Do not export to next AS (well-known community)\n"
7952 "community number\n"
7953 "Do not send outside local AS (well-known community)\n"
7954 "Do not advertise to any peer (well-known community)\n"
7955 "Do not export to next AS (well-known community)\n"
7956 "Exact match of the communities")
7957
7958/* old command */
7959ALIAS (show_ipv6_mbgp_community_exact,
7960 show_ipv6_mbgp_community3_exact_cmd,
7961 "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",
7962 SHOW_STR
7963 IPV6_STR
7964 MBGP_STR
7965 "Display routes matching the communities\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n"
7970 "community number\n"
7971 "Do not send outside local AS (well-known community)\n"
7972 "Do not advertise to any peer (well-known community)\n"
7973 "Do not export to next AS (well-known community)\n"
7974 "community number\n"
7975 "Do not send outside local AS (well-known community)\n"
7976 "Do not advertise to any peer (well-known community)\n"
7977 "Do not export to next AS (well-known community)\n"
7978 "Exact match of the communities")
7979
7980/* old command */
7981ALIAS (show_ipv6_mbgp_community_exact,
7982 show_ipv6_mbgp_community4_exact_cmd,
7983 "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",
7984 SHOW_STR
7985 IPV6_STR
7986 MBGP_STR
7987 "Display routes matching the communities\n"
7988 "community number\n"
7989 "Do not send outside local AS (well-known community)\n"
7990 "Do not advertise to any peer (well-known community)\n"
7991 "Do not export to next AS (well-known community)\n"
7992 "community number\n"
7993 "Do not send outside local AS (well-known community)\n"
7994 "Do not advertise to any peer (well-known community)\n"
7995 "Do not export to next AS (well-known community)\n"
7996 "community number\n"
7997 "Do not send outside local AS (well-known community)\n"
7998 "Do not advertise to any peer (well-known community)\n"
7999 "Do not export to next AS (well-known community)\n"
8000 "community number\n"
8001 "Do not send outside local AS (well-known community)\n"
8002 "Do not advertise to any peer (well-known community)\n"
8003 "Do not export to next AS (well-known community)\n"
8004 "Exact match of the communities")
8005#endif /* HAVE_IPV6 */
8006
paul94f2b392005-06-28 12:44:16 +00008007static int
paulfd79ac92004-10-13 05:06:08 +00008008bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008009 u_int16_t afi, u_char safi)
8010{
8011 struct community_list *list;
8012
hassofee6e4e2005-02-02 16:29:31 +00008013 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008014 if (list == NULL)
8015 {
8016 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8017 VTY_NEWLINE);
8018 return CMD_WARNING;
8019 }
8020
ajs5a646652004-11-05 01:25:55 +00008021 return bgp_show (vty, NULL, afi, safi,
8022 (exact ? bgp_show_type_community_list_exact :
8023 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008024}
8025
8026DEFUN (show_ip_bgp_community_list,
8027 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008028 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008029 SHOW_STR
8030 IP_STR
8031 BGP_STR
8032 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008033 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008034 "community-list name\n")
8035{
8036 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8037}
8038
8039DEFUN (show_ip_bgp_ipv4_community_list,
8040 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008041 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008042 SHOW_STR
8043 IP_STR
8044 BGP_STR
8045 "Address family\n"
8046 "Address Family modifier\n"
8047 "Address Family modifier\n"
8048 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008049 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008050 "community-list name\n")
8051{
8052 if (strncmp (argv[0], "m", 1) == 0)
8053 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8054
8055 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8056}
8057
8058DEFUN (show_ip_bgp_community_list_exact,
8059 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008060 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008061 SHOW_STR
8062 IP_STR
8063 BGP_STR
8064 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008065 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008066 "community-list name\n"
8067 "Exact match of the communities\n")
8068{
8069 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8070}
8071
8072DEFUN (show_ip_bgp_ipv4_community_list_exact,
8073 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008074 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008075 SHOW_STR
8076 IP_STR
8077 BGP_STR
8078 "Address family\n"
8079 "Address Family modifier\n"
8080 "Address Family modifier\n"
8081 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008082 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008083 "community-list name\n"
8084 "Exact match of the communities\n")
8085{
8086 if (strncmp (argv[0], "m", 1) == 0)
8087 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8088
8089 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8090}
8091
8092#ifdef HAVE_IPV6
8093DEFUN (show_bgp_community_list,
8094 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008095 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008096 SHOW_STR
8097 BGP_STR
8098 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008099 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008100 "community-list name\n")
8101{
8102 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8103}
8104
8105ALIAS (show_bgp_community_list,
8106 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008107 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008108 SHOW_STR
8109 BGP_STR
8110 "Address family\n"
8111 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008112 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008113 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008114
8115/* old command */
8116DEFUN (show_ipv6_bgp_community_list,
8117 show_ipv6_bgp_community_list_cmd,
8118 "show ipv6 bgp community-list WORD",
8119 SHOW_STR
8120 IPV6_STR
8121 BGP_STR
8122 "Display routes matching the community-list\n"
8123 "community-list name\n")
8124{
8125 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8126}
8127
8128/* old command */
8129DEFUN (show_ipv6_mbgp_community_list,
8130 show_ipv6_mbgp_community_list_cmd,
8131 "show ipv6 mbgp community-list WORD",
8132 SHOW_STR
8133 IPV6_STR
8134 MBGP_STR
8135 "Display routes matching the community-list\n"
8136 "community-list name\n")
8137{
8138 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8139}
8140
8141DEFUN (show_bgp_community_list_exact,
8142 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008143 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008144 SHOW_STR
8145 BGP_STR
8146 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008147 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008148 "community-list name\n"
8149 "Exact match of the communities\n")
8150{
8151 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8152}
8153
8154ALIAS (show_bgp_community_list_exact,
8155 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008156 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008157 SHOW_STR
8158 BGP_STR
8159 "Address family\n"
8160 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008161 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008162 "community-list name\n"
8163 "Exact match of the communities\n")
8164
8165/* old command */
8166DEFUN (show_ipv6_bgp_community_list_exact,
8167 show_ipv6_bgp_community_list_exact_cmd,
8168 "show ipv6 bgp community-list WORD exact-match",
8169 SHOW_STR
8170 IPV6_STR
8171 BGP_STR
8172 "Display routes matching the community-list\n"
8173 "community-list name\n"
8174 "Exact match of the communities\n")
8175{
8176 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8177}
8178
8179/* old command */
8180DEFUN (show_ipv6_mbgp_community_list_exact,
8181 show_ipv6_mbgp_community_list_exact_cmd,
8182 "show ipv6 mbgp community-list WORD exact-match",
8183 SHOW_STR
8184 IPV6_STR
8185 MBGP_STR
8186 "Display routes matching the community-list\n"
8187 "community-list name\n"
8188 "Exact match of the communities\n")
8189{
8190 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8191}
8192#endif /* HAVE_IPV6 */
8193
paul94f2b392005-06-28 12:44:16 +00008194static int
paulfd79ac92004-10-13 05:06:08 +00008195bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008196 safi_t safi, enum bgp_show_type type)
8197{
8198 int ret;
8199 struct prefix *p;
8200
8201 p = prefix_new();
8202
8203 ret = str2prefix (prefix, p);
8204 if (! ret)
8205 {
8206 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8207 return CMD_WARNING;
8208 }
8209
ajs5a646652004-11-05 01:25:55 +00008210 ret = bgp_show (vty, NULL, afi, safi, type, p);
8211 prefix_free(p);
8212 return ret;
paul718e3742002-12-13 20:15:29 +00008213}
8214
8215DEFUN (show_ip_bgp_prefix_longer,
8216 show_ip_bgp_prefix_longer_cmd,
8217 "show ip bgp A.B.C.D/M longer-prefixes",
8218 SHOW_STR
8219 IP_STR
8220 BGP_STR
8221 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8222 "Display route and more specific routes\n")
8223{
8224 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8225 bgp_show_type_prefix_longer);
8226}
8227
8228DEFUN (show_ip_bgp_flap_prefix_longer,
8229 show_ip_bgp_flap_prefix_longer_cmd,
8230 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8231 SHOW_STR
8232 IP_STR
8233 BGP_STR
8234 "Display flap statistics of routes\n"
8235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8236 "Display route and more specific routes\n")
8237{
8238 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8239 bgp_show_type_flap_prefix_longer);
8240}
8241
8242DEFUN (show_ip_bgp_ipv4_prefix_longer,
8243 show_ip_bgp_ipv4_prefix_longer_cmd,
8244 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8245 SHOW_STR
8246 IP_STR
8247 BGP_STR
8248 "Address family\n"
8249 "Address Family modifier\n"
8250 "Address Family modifier\n"
8251 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8252 "Display route and more specific routes\n")
8253{
8254 if (strncmp (argv[0], "m", 1) == 0)
8255 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8256 bgp_show_type_prefix_longer);
8257
8258 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8259 bgp_show_type_prefix_longer);
8260}
8261
8262DEFUN (show_ip_bgp_flap_address,
8263 show_ip_bgp_flap_address_cmd,
8264 "show ip bgp flap-statistics A.B.C.D",
8265 SHOW_STR
8266 IP_STR
8267 BGP_STR
8268 "Display flap statistics of routes\n"
8269 "Network in the BGP routing table to display\n")
8270{
8271 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8272 bgp_show_type_flap_address);
8273}
8274
8275DEFUN (show_ip_bgp_flap_prefix,
8276 show_ip_bgp_flap_prefix_cmd,
8277 "show ip bgp flap-statistics A.B.C.D/M",
8278 SHOW_STR
8279 IP_STR
8280 BGP_STR
8281 "Display flap statistics of routes\n"
8282 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8283{
8284 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8285 bgp_show_type_flap_prefix);
8286}
8287#ifdef HAVE_IPV6
8288DEFUN (show_bgp_prefix_longer,
8289 show_bgp_prefix_longer_cmd,
8290 "show bgp X:X::X:X/M longer-prefixes",
8291 SHOW_STR
8292 BGP_STR
8293 "IPv6 prefix <network>/<length>\n"
8294 "Display route and more specific routes\n")
8295{
8296 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8297 bgp_show_type_prefix_longer);
8298}
8299
8300ALIAS (show_bgp_prefix_longer,
8301 show_bgp_ipv6_prefix_longer_cmd,
8302 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8303 SHOW_STR
8304 BGP_STR
8305 "Address family\n"
8306 "IPv6 prefix <network>/<length>\n"
8307 "Display route and more specific routes\n")
8308
8309/* old command */
8310DEFUN (show_ipv6_bgp_prefix_longer,
8311 show_ipv6_bgp_prefix_longer_cmd,
8312 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8313 SHOW_STR
8314 IPV6_STR
8315 BGP_STR
8316 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8317 "Display route and more specific routes\n")
8318{
8319 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8320 bgp_show_type_prefix_longer);
8321}
8322
8323/* old command */
8324DEFUN (show_ipv6_mbgp_prefix_longer,
8325 show_ipv6_mbgp_prefix_longer_cmd,
8326 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8327 SHOW_STR
8328 IPV6_STR
8329 MBGP_STR
8330 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8331 "Display route and more specific routes\n")
8332{
8333 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8334 bgp_show_type_prefix_longer);
8335}
8336#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008337
paul94f2b392005-06-28 12:44:16 +00008338static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008339peer_lookup_in_view (struct vty *vty, const char *view_name,
8340 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008341{
8342 int ret;
8343 struct bgp *bgp;
8344 struct peer *peer;
8345 union sockunion su;
8346
8347 /* BGP structure lookup. */
8348 if (view_name)
8349 {
8350 bgp = bgp_lookup_by_name (view_name);
8351 if (! bgp)
8352 {
8353 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8354 return NULL;
8355 }
8356 }
paul5228ad22004-06-04 17:58:18 +00008357 else
paulbb46e942003-10-24 19:02:03 +00008358 {
8359 bgp = bgp_get_default ();
8360 if (! bgp)
8361 {
8362 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8363 return NULL;
8364 }
8365 }
8366
8367 /* Get peer sockunion. */
8368 ret = str2sockunion (ip_str, &su);
8369 if (ret < 0)
8370 {
8371 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8372 return NULL;
8373 }
8374
8375 /* Peer structure lookup. */
8376 peer = peer_lookup (bgp, &su);
8377 if (! peer)
8378 {
8379 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8380 return NULL;
8381 }
8382
8383 return peer;
8384}
8385
paul94f2b392005-06-28 12:44:16 +00008386static void
paul718e3742002-12-13 20:15:29 +00008387show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8388 int in)
8389{
8390 struct bgp_table *table;
8391 struct bgp_adj_in *ain;
8392 struct bgp_adj_out *adj;
8393 unsigned long output_count;
8394 struct bgp_node *rn;
8395 int header1 = 1;
8396 struct bgp *bgp;
8397 int header2 = 1;
8398
paulbb46e942003-10-24 19:02:03 +00008399 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008400
8401 if (! bgp)
8402 return;
8403
8404 table = bgp->rib[afi][safi];
8405
8406 output_count = 0;
8407
8408 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8409 PEER_STATUS_DEFAULT_ORIGINATE))
8410 {
8411 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 +00008412 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8413 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008414
8415 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8416 VTY_NEWLINE, VTY_NEWLINE);
8417 header1 = 0;
8418 }
8419
8420 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8421 if (in)
8422 {
8423 for (ain = rn->adj_in; ain; ain = ain->next)
8424 if (ain->peer == peer)
8425 {
8426 if (header1)
8427 {
8428 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 +00008429 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8430 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008431 header1 = 0;
8432 }
8433 if (header2)
8434 {
8435 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8436 header2 = 0;
8437 }
8438 if (ain->attr)
8439 {
8440 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8441 output_count++;
8442 }
8443 }
8444 }
8445 else
8446 {
8447 for (adj = rn->adj_out; adj; adj = adj->next)
8448 if (adj->peer == peer)
8449 {
8450 if (header1)
8451 {
8452 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 +00008453 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8454 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008455 header1 = 0;
8456 }
8457 if (header2)
8458 {
8459 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8460 header2 = 0;
8461 }
8462 if (adj->attr)
8463 {
8464 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8465 output_count++;
8466 }
8467 }
8468 }
8469
8470 if (output_count != 0)
8471 vty_out (vty, "%sTotal number of prefixes %ld%s",
8472 VTY_NEWLINE, output_count, VTY_NEWLINE);
8473}
8474
paul94f2b392005-06-28 12:44:16 +00008475static int
paulbb46e942003-10-24 19:02:03 +00008476peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8477{
paul718e3742002-12-13 20:15:29 +00008478 if (! peer || ! peer->afc[afi][safi])
8479 {
8480 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8481 return CMD_WARNING;
8482 }
8483
8484 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8485 {
8486 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8487 VTY_NEWLINE);
8488 return CMD_WARNING;
8489 }
8490
8491 show_adj_route (vty, peer, afi, safi, in);
8492
8493 return CMD_SUCCESS;
8494}
8495
8496DEFUN (show_ip_bgp_neighbor_advertised_route,
8497 show_ip_bgp_neighbor_advertised_route_cmd,
8498 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8499 SHOW_STR
8500 IP_STR
8501 BGP_STR
8502 "Detailed information on TCP and BGP neighbor connections\n"
8503 "Neighbor to display information about\n"
8504 "Neighbor to display information about\n"
8505 "Display the routes advertised to a BGP neighbor\n")
8506{
paulbb46e942003-10-24 19:02:03 +00008507 struct peer *peer;
8508
8509 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8510 if (! peer)
8511 return CMD_WARNING;
8512
8513 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008514}
8515
8516DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8517 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8518 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8519 SHOW_STR
8520 IP_STR
8521 BGP_STR
8522 "Address family\n"
8523 "Address Family modifier\n"
8524 "Address Family modifier\n"
8525 "Detailed information on TCP and BGP neighbor connections\n"
8526 "Neighbor to display information about\n"
8527 "Neighbor to display information about\n"
8528 "Display the routes advertised to a BGP neighbor\n")
8529{
paulbb46e942003-10-24 19:02:03 +00008530 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008531
paulbb46e942003-10-24 19:02:03 +00008532 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8533 if (! peer)
8534 return CMD_WARNING;
8535
8536 if (strncmp (argv[0], "m", 1) == 0)
8537 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8538
8539 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008540}
8541
8542#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008543DEFUN (show_bgp_view_neighbor_advertised_route,
8544 show_bgp_view_neighbor_advertised_route_cmd,
8545 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8546 SHOW_STR
8547 BGP_STR
8548 "BGP view\n"
8549 "View name\n"
8550 "Detailed information on TCP and BGP neighbor connections\n"
8551 "Neighbor to display information about\n"
8552 "Neighbor to display information about\n"
8553 "Display the routes advertised to a BGP neighbor\n")
8554{
8555 struct peer *peer;
8556
8557 if (argc == 2)
8558 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8559 else
8560 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8561
8562 if (! peer)
8563 return CMD_WARNING;
8564
8565 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8566}
8567
8568ALIAS (show_bgp_view_neighbor_advertised_route,
8569 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8570 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8571 SHOW_STR
8572 BGP_STR
8573 "BGP view\n"
8574 "View name\n"
8575 "Address family\n"
8576 "Detailed information on TCP and BGP neighbor connections\n"
8577 "Neighbor to display information about\n"
8578 "Neighbor to display information about\n"
8579 "Display the routes advertised to a BGP neighbor\n")
8580
8581DEFUN (show_bgp_view_neighbor_received_routes,
8582 show_bgp_view_neighbor_received_routes_cmd,
8583 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8584 SHOW_STR
8585 BGP_STR
8586 "BGP view\n"
8587 "View name\n"
8588 "Detailed information on TCP and BGP neighbor connections\n"
8589 "Neighbor to display information about\n"
8590 "Neighbor to display information about\n"
8591 "Display the received routes from neighbor\n")
8592{
8593 struct peer *peer;
8594
8595 if (argc == 2)
8596 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8597 else
8598 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8599
8600 if (! peer)
8601 return CMD_WARNING;
8602
8603 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8604}
8605
8606ALIAS (show_bgp_view_neighbor_received_routes,
8607 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8608 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8609 SHOW_STR
8610 BGP_STR
8611 "BGP view\n"
8612 "View name\n"
8613 "Address family\n"
8614 "Detailed information on TCP and BGP neighbor connections\n"
8615 "Neighbor to display information about\n"
8616 "Neighbor to display information about\n"
8617 "Display the received routes from neighbor\n")
8618
8619ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008620 show_bgp_neighbor_advertised_route_cmd,
8621 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8622 SHOW_STR
8623 BGP_STR
8624 "Detailed information on TCP and BGP neighbor connections\n"
8625 "Neighbor to display information about\n"
8626 "Neighbor to display information about\n"
8627 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008628
8629ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008630 show_bgp_ipv6_neighbor_advertised_route_cmd,
8631 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8632 SHOW_STR
8633 BGP_STR
8634 "Address family\n"
8635 "Detailed information on TCP and BGP neighbor connections\n"
8636 "Neighbor to display information about\n"
8637 "Neighbor to display information about\n"
8638 "Display the routes advertised to a BGP neighbor\n")
8639
8640/* old command */
paulbb46e942003-10-24 19:02:03 +00008641ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008642 ipv6_bgp_neighbor_advertised_route_cmd,
8643 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8644 SHOW_STR
8645 IPV6_STR
8646 BGP_STR
8647 "Detailed information on TCP and BGP neighbor connections\n"
8648 "Neighbor to display information about\n"
8649 "Neighbor to display information about\n"
8650 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008651
paul718e3742002-12-13 20:15:29 +00008652/* old command */
8653DEFUN (ipv6_mbgp_neighbor_advertised_route,
8654 ipv6_mbgp_neighbor_advertised_route_cmd,
8655 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8656 SHOW_STR
8657 IPV6_STR
8658 MBGP_STR
8659 "Detailed information on TCP and BGP neighbor connections\n"
8660 "Neighbor to display information about\n"
8661 "Neighbor to display information about\n"
8662 "Display the routes advertised to a BGP neighbor\n")
8663{
paulbb46e942003-10-24 19:02:03 +00008664 struct peer *peer;
8665
8666 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8667 if (! peer)
8668 return CMD_WARNING;
8669
8670 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008671}
8672#endif /* HAVE_IPV6 */
8673
8674DEFUN (show_ip_bgp_neighbor_received_routes,
8675 show_ip_bgp_neighbor_received_routes_cmd,
8676 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8677 SHOW_STR
8678 IP_STR
8679 BGP_STR
8680 "Detailed information on TCP and BGP neighbor connections\n"
8681 "Neighbor to display information about\n"
8682 "Neighbor to display information about\n"
8683 "Display the received routes from neighbor\n")
8684{
paulbb46e942003-10-24 19:02:03 +00008685 struct peer *peer;
8686
8687 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8688 if (! peer)
8689 return CMD_WARNING;
8690
8691 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008692}
8693
8694DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8695 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8696 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8697 SHOW_STR
8698 IP_STR
8699 BGP_STR
8700 "Address family\n"
8701 "Address Family modifier\n"
8702 "Address Family modifier\n"
8703 "Detailed information on TCP and BGP neighbor connections\n"
8704 "Neighbor to display information about\n"
8705 "Neighbor to display information about\n"
8706 "Display the received routes from neighbor\n")
8707{
paulbb46e942003-10-24 19:02:03 +00008708 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008709
paulbb46e942003-10-24 19:02:03 +00008710 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8711 if (! peer)
8712 return CMD_WARNING;
8713
8714 if (strncmp (argv[0], "m", 1) == 0)
8715 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8716
8717 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008718}
8719
8720DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8721 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8722 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8723 SHOW_STR
8724 IP_STR
8725 BGP_STR
8726 "Detailed information on TCP and BGP neighbor connections\n"
8727 "Neighbor to display information about\n"
8728 "Neighbor to display information about\n"
8729 "Display information received from a BGP neighbor\n"
8730 "Display the prefixlist filter\n")
8731{
8732 char name[BUFSIZ];
8733 union sockunion *su;
8734 struct peer *peer;
8735 int count;
8736
8737 su = sockunion_str2su (argv[0]);
8738 if (su == NULL)
8739 return CMD_WARNING;
8740
8741 peer = peer_lookup (NULL, su);
8742 if (! peer)
8743 return CMD_WARNING;
8744
8745 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8746 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8747 if (count)
8748 {
8749 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8750 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8751 }
8752
8753 return CMD_SUCCESS;
8754}
8755
8756DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8757 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8758 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8759 SHOW_STR
8760 IP_STR
8761 BGP_STR
8762 "Address family\n"
8763 "Address Family modifier\n"
8764 "Address Family modifier\n"
8765 "Detailed information on TCP and BGP neighbor connections\n"
8766 "Neighbor to display information about\n"
8767 "Neighbor to display information about\n"
8768 "Display information received from a BGP neighbor\n"
8769 "Display the prefixlist filter\n")
8770{
8771 char name[BUFSIZ];
8772 union sockunion *su;
8773 struct peer *peer;
8774 int count;
8775
8776 su = sockunion_str2su (argv[1]);
8777 if (su == NULL)
8778 return CMD_WARNING;
8779
8780 peer = peer_lookup (NULL, su);
8781 if (! peer)
8782 return CMD_WARNING;
8783
8784 if (strncmp (argv[0], "m", 1) == 0)
8785 {
8786 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8787 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8788 if (count)
8789 {
8790 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8791 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8792 }
8793 }
8794 else
8795 {
8796 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8797 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8798 if (count)
8799 {
8800 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8801 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8802 }
8803 }
8804
8805 return CMD_SUCCESS;
8806}
8807
8808
8809#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008810ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008811 show_bgp_neighbor_received_routes_cmd,
8812 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8813 SHOW_STR
8814 BGP_STR
8815 "Detailed information on TCP and BGP neighbor connections\n"
8816 "Neighbor to display information about\n"
8817 "Neighbor to display information about\n"
8818 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008819
paulbb46e942003-10-24 19:02:03 +00008820ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008821 show_bgp_ipv6_neighbor_received_routes_cmd,
8822 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8823 SHOW_STR
8824 BGP_STR
8825 "Address family\n"
8826 "Detailed information on TCP and BGP neighbor connections\n"
8827 "Neighbor to display information about\n"
8828 "Neighbor to display information about\n"
8829 "Display the received routes from neighbor\n")
8830
8831DEFUN (show_bgp_neighbor_received_prefix_filter,
8832 show_bgp_neighbor_received_prefix_filter_cmd,
8833 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8834 SHOW_STR
8835 BGP_STR
8836 "Detailed information on TCP and BGP neighbor connections\n"
8837 "Neighbor to display information about\n"
8838 "Neighbor to display information about\n"
8839 "Display information received from a BGP neighbor\n"
8840 "Display the prefixlist filter\n")
8841{
8842 char name[BUFSIZ];
8843 union sockunion *su;
8844 struct peer *peer;
8845 int count;
8846
8847 su = sockunion_str2su (argv[0]);
8848 if (su == NULL)
8849 return CMD_WARNING;
8850
8851 peer = peer_lookup (NULL, su);
8852 if (! peer)
8853 return CMD_WARNING;
8854
8855 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8856 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8857 if (count)
8858 {
8859 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8860 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8861 }
8862
8863 return CMD_SUCCESS;
8864}
8865
8866ALIAS (show_bgp_neighbor_received_prefix_filter,
8867 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8868 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8869 SHOW_STR
8870 BGP_STR
8871 "Address family\n"
8872 "Detailed information on TCP and BGP neighbor connections\n"
8873 "Neighbor to display information about\n"
8874 "Neighbor to display information about\n"
8875 "Display information received from a BGP neighbor\n"
8876 "Display the prefixlist filter\n")
8877
8878/* old command */
paulbb46e942003-10-24 19:02:03 +00008879ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008880 ipv6_bgp_neighbor_received_routes_cmd,
8881 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8882 SHOW_STR
8883 IPV6_STR
8884 BGP_STR
8885 "Detailed information on TCP and BGP neighbor connections\n"
8886 "Neighbor to display information about\n"
8887 "Neighbor to display information about\n"
8888 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008889
8890/* old command */
8891DEFUN (ipv6_mbgp_neighbor_received_routes,
8892 ipv6_mbgp_neighbor_received_routes_cmd,
8893 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8894 SHOW_STR
8895 IPV6_STR
8896 MBGP_STR
8897 "Detailed information on TCP and BGP neighbor connections\n"
8898 "Neighbor to display information about\n"
8899 "Neighbor to display information about\n"
8900 "Display the received routes from neighbor\n")
8901{
paulbb46e942003-10-24 19:02:03 +00008902 struct peer *peer;
8903
8904 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8905 if (! peer)
8906 return CMD_WARNING;
8907
8908 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00008909}
paulbb46e942003-10-24 19:02:03 +00008910
8911DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8912 show_bgp_view_neighbor_received_prefix_filter_cmd,
8913 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8914 SHOW_STR
8915 BGP_STR
8916 "BGP view\n"
8917 "View name\n"
8918 "Detailed information on TCP and BGP neighbor connections\n"
8919 "Neighbor to display information about\n"
8920 "Neighbor to display information about\n"
8921 "Display information received from a BGP neighbor\n"
8922 "Display the prefixlist filter\n")
8923{
8924 char name[BUFSIZ];
8925 union sockunion *su;
8926 struct peer *peer;
8927 struct bgp *bgp;
8928 int count;
8929
8930 /* BGP structure lookup. */
8931 bgp = bgp_lookup_by_name (argv[0]);
8932 if (bgp == NULL)
8933 {
8934 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8935 return CMD_WARNING;
8936 }
8937
8938 su = sockunion_str2su (argv[1]);
8939 if (su == NULL)
8940 return CMD_WARNING;
8941
8942 peer = peer_lookup (bgp, su);
8943 if (! peer)
8944 return CMD_WARNING;
8945
8946 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8947 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8948 if (count)
8949 {
8950 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8951 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8952 }
8953
8954 return CMD_SUCCESS;
8955}
8956
8957ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8958 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8959 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8960 SHOW_STR
8961 BGP_STR
8962 "BGP view\n"
8963 "View name\n"
8964 "Address family\n"
8965 "Detailed information on TCP and BGP neighbor connections\n"
8966 "Neighbor to display information about\n"
8967 "Neighbor to display information about\n"
8968 "Display information received from a BGP neighbor\n"
8969 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008970#endif /* HAVE_IPV6 */
8971
paul94f2b392005-06-28 12:44:16 +00008972static int
paulbb46e942003-10-24 19:02:03 +00008973bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008974 safi_t safi, enum bgp_show_type type)
8975{
paul718e3742002-12-13 20:15:29 +00008976 if (! peer || ! peer->afc[afi][safi])
8977 {
8978 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008979 return CMD_WARNING;
8980 }
8981
ajs5a646652004-11-05 01:25:55 +00008982 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00008983}
8984
8985DEFUN (show_ip_bgp_neighbor_routes,
8986 show_ip_bgp_neighbor_routes_cmd,
8987 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8988 SHOW_STR
8989 IP_STR
8990 BGP_STR
8991 "Detailed information on TCP and BGP neighbor connections\n"
8992 "Neighbor to display information about\n"
8993 "Neighbor to display information about\n"
8994 "Display routes learned from neighbor\n")
8995{
paulbb46e942003-10-24 19:02:03 +00008996 struct peer *peer;
8997
8998 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8999 if (! peer)
9000 return CMD_WARNING;
9001
9002 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009003 bgp_show_type_neighbor);
9004}
9005
9006DEFUN (show_ip_bgp_neighbor_flap,
9007 show_ip_bgp_neighbor_flap_cmd,
9008 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9009 SHOW_STR
9010 IP_STR
9011 BGP_STR
9012 "Detailed information on TCP and BGP neighbor connections\n"
9013 "Neighbor to display information about\n"
9014 "Neighbor to display information about\n"
9015 "Display flap statistics of the routes learned from neighbor\n")
9016{
paulbb46e942003-10-24 19:02:03 +00009017 struct peer *peer;
9018
9019 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9020 if (! peer)
9021 return CMD_WARNING;
9022
9023 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009024 bgp_show_type_flap_neighbor);
9025}
9026
9027DEFUN (show_ip_bgp_neighbor_damp,
9028 show_ip_bgp_neighbor_damp_cmd,
9029 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9030 SHOW_STR
9031 IP_STR
9032 BGP_STR
9033 "Detailed information on TCP and BGP neighbor connections\n"
9034 "Neighbor to display information about\n"
9035 "Neighbor to display information about\n"
9036 "Display the dampened routes received from neighbor\n")
9037{
paulbb46e942003-10-24 19:02:03 +00009038 struct peer *peer;
9039
9040 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9041 if (! peer)
9042 return CMD_WARNING;
9043
9044 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009045 bgp_show_type_damp_neighbor);
9046}
9047
9048DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9049 show_ip_bgp_ipv4_neighbor_routes_cmd,
9050 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9051 SHOW_STR
9052 IP_STR
9053 BGP_STR
9054 "Address family\n"
9055 "Address Family modifier\n"
9056 "Address Family modifier\n"
9057 "Detailed information on TCP and BGP neighbor connections\n"
9058 "Neighbor to display information about\n"
9059 "Neighbor to display information about\n"
9060 "Display routes learned from neighbor\n")
9061{
paulbb46e942003-10-24 19:02:03 +00009062 struct peer *peer;
9063
9064 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9065 if (! peer)
9066 return CMD_WARNING;
9067
paul718e3742002-12-13 20:15:29 +00009068 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009069 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009070 bgp_show_type_neighbor);
9071
paulbb46e942003-10-24 19:02:03 +00009072 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009073 bgp_show_type_neighbor);
9074}
paulbb46e942003-10-24 19:02:03 +00009075
paulfee0f4c2004-09-13 05:12:46 +00009076DEFUN (show_ip_bgp_view_rsclient,
9077 show_ip_bgp_view_rsclient_cmd,
9078 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9079 SHOW_STR
9080 IP_STR
9081 BGP_STR
9082 "BGP view\n"
9083 "BGP view name\n"
9084 "Information about Route Server Client\n"
9085 NEIGHBOR_ADDR_STR)
9086{
9087 struct bgp_table *table;
9088 struct peer *peer;
9089
9090 if (argc == 2)
9091 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9092 else
9093 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9094
9095 if (! peer)
9096 return CMD_WARNING;
9097
9098 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9099 {
9100 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9101 VTY_NEWLINE);
9102 return CMD_WARNING;
9103 }
9104
9105 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9106 PEER_FLAG_RSERVER_CLIENT))
9107 {
9108 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9109 VTY_NEWLINE);
9110 return CMD_WARNING;
9111 }
9112
9113 table = peer->rib[AFI_IP][SAFI_UNICAST];
9114
ajs5a646652004-11-05 01:25:55 +00009115 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009116}
9117
9118ALIAS (show_ip_bgp_view_rsclient,
9119 show_ip_bgp_rsclient_cmd,
9120 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9121 SHOW_STR
9122 IP_STR
9123 BGP_STR
9124 "Information about Route Server Client\n"
9125 NEIGHBOR_ADDR_STR)
9126
9127DEFUN (show_ip_bgp_view_rsclient_route,
9128 show_ip_bgp_view_rsclient_route_cmd,
9129 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9130 SHOW_STR
9131 IP_STR
9132 BGP_STR
9133 "BGP view\n"
9134 "BGP view name\n"
9135 "Information about Route Server Client\n"
9136 NEIGHBOR_ADDR_STR
9137 "Network in the BGP routing table to display\n")
9138{
9139 struct bgp *bgp;
9140 struct peer *peer;
9141
9142 /* BGP structure lookup. */
9143 if (argc == 3)
9144 {
9145 bgp = bgp_lookup_by_name (argv[0]);
9146 if (bgp == NULL)
9147 {
9148 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9149 return CMD_WARNING;
9150 }
9151 }
9152 else
9153 {
9154 bgp = bgp_get_default ();
9155 if (bgp == NULL)
9156 {
9157 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9158 return CMD_WARNING;
9159 }
9160 }
9161
9162 if (argc == 3)
9163 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9164 else
9165 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9166
9167 if (! peer)
9168 return CMD_WARNING;
9169
9170 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9171 {
9172 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9173 VTY_NEWLINE);
9174 return CMD_WARNING;
9175}
9176
9177 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9178 PEER_FLAG_RSERVER_CLIENT))
9179 {
9180 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9181 VTY_NEWLINE);
9182 return CMD_WARNING;
9183 }
9184
9185 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9186 (argc == 3) ? argv[2] : argv[1],
9187 AFI_IP, SAFI_UNICAST, NULL, 0);
9188}
9189
9190ALIAS (show_ip_bgp_view_rsclient_route,
9191 show_ip_bgp_rsclient_route_cmd,
9192 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9193 SHOW_STR
9194 IP_STR
9195 BGP_STR
9196 "Information about Route Server Client\n"
9197 NEIGHBOR_ADDR_STR
9198 "Network in the BGP routing table to display\n")
9199
9200DEFUN (show_ip_bgp_view_rsclient_prefix,
9201 show_ip_bgp_view_rsclient_prefix_cmd,
9202 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9203 SHOW_STR
9204 IP_STR
9205 BGP_STR
9206 "BGP view\n"
9207 "BGP view name\n"
9208 "Information about Route Server Client\n"
9209 NEIGHBOR_ADDR_STR
9210 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9211{
9212 struct bgp *bgp;
9213 struct peer *peer;
9214
9215 /* BGP structure lookup. */
9216 if (argc == 3)
9217 {
9218 bgp = bgp_lookup_by_name (argv[0]);
9219 if (bgp == NULL)
9220 {
9221 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9222 return CMD_WARNING;
9223 }
9224 }
9225 else
9226 {
9227 bgp = bgp_get_default ();
9228 if (bgp == NULL)
9229 {
9230 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9231 return CMD_WARNING;
9232 }
9233 }
9234
9235 if (argc == 3)
9236 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9237 else
9238 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9239
9240 if (! peer)
9241 return CMD_WARNING;
9242
9243 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9244 {
9245 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9246 VTY_NEWLINE);
9247 return CMD_WARNING;
9248}
9249
9250 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9251 PEER_FLAG_RSERVER_CLIENT))
9252{
9253 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9254 VTY_NEWLINE);
9255 return CMD_WARNING;
9256 }
9257
9258 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9259 (argc == 3) ? argv[2] : argv[1],
9260 AFI_IP, SAFI_UNICAST, NULL, 1);
9261}
9262
9263ALIAS (show_ip_bgp_view_rsclient_prefix,
9264 show_ip_bgp_rsclient_prefix_cmd,
9265 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9266 SHOW_STR
9267 IP_STR
9268 BGP_STR
9269 "Information about Route Server Client\n"
9270 NEIGHBOR_ADDR_STR
9271 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9272
9273
paul718e3742002-12-13 20:15:29 +00009274#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009275DEFUN (show_bgp_view_neighbor_routes,
9276 show_bgp_view_neighbor_routes_cmd,
9277 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9278 SHOW_STR
9279 BGP_STR
9280 "BGP view\n"
9281 "BGP view name\n"
9282 "Detailed information on TCP and BGP neighbor connections\n"
9283 "Neighbor to display information about\n"
9284 "Neighbor to display information about\n"
9285 "Display routes learned from neighbor\n")
9286{
9287 struct peer *peer;
9288
9289 if (argc == 2)
9290 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9291 else
9292 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9293
9294 if (! peer)
9295 return CMD_WARNING;
9296
9297 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9298 bgp_show_type_neighbor);
9299}
9300
9301ALIAS (show_bgp_view_neighbor_routes,
9302 show_bgp_view_ipv6_neighbor_routes_cmd,
9303 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9304 SHOW_STR
9305 BGP_STR
9306 "BGP view\n"
9307 "BGP view name\n"
9308 "Address family\n"
9309 "Detailed information on TCP and BGP neighbor connections\n"
9310 "Neighbor to display information about\n"
9311 "Neighbor to display information about\n"
9312 "Display routes learned from neighbor\n")
9313
9314DEFUN (show_bgp_view_neighbor_damp,
9315 show_bgp_view_neighbor_damp_cmd,
9316 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9317 SHOW_STR
9318 BGP_STR
9319 "BGP view\n"
9320 "BGP view name\n"
9321 "Detailed information on TCP and BGP neighbor connections\n"
9322 "Neighbor to display information about\n"
9323 "Neighbor to display information about\n"
9324 "Display the dampened routes received from neighbor\n")
9325{
9326 struct peer *peer;
9327
9328 if (argc == 2)
9329 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9330 else
9331 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9332
9333 if (! peer)
9334 return CMD_WARNING;
9335
9336 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9337 bgp_show_type_damp_neighbor);
9338}
9339
9340ALIAS (show_bgp_view_neighbor_damp,
9341 show_bgp_view_ipv6_neighbor_damp_cmd,
9342 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9343 SHOW_STR
9344 BGP_STR
9345 "BGP view\n"
9346 "BGP view name\n"
9347 "Address family\n"
9348 "Detailed information on TCP and BGP neighbor connections\n"
9349 "Neighbor to display information about\n"
9350 "Neighbor to display information about\n"
9351 "Display the dampened routes received from neighbor\n")
9352
9353DEFUN (show_bgp_view_neighbor_flap,
9354 show_bgp_view_neighbor_flap_cmd,
9355 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9356 SHOW_STR
9357 BGP_STR
9358 "BGP view\n"
9359 "BGP view name\n"
9360 "Detailed information on TCP and BGP neighbor connections\n"
9361 "Neighbor to display information about\n"
9362 "Neighbor to display information about\n"
9363 "Display flap statistics of the routes learned from neighbor\n")
9364{
9365 struct peer *peer;
9366
9367 if (argc == 2)
9368 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9369 else
9370 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9371
9372 if (! peer)
9373 return CMD_WARNING;
9374
9375 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9376 bgp_show_type_flap_neighbor);
9377}
9378
9379ALIAS (show_bgp_view_neighbor_flap,
9380 show_bgp_view_ipv6_neighbor_flap_cmd,
9381 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9382 SHOW_STR
9383 BGP_STR
9384 "BGP view\n"
9385 "BGP view name\n"
9386 "Address family\n"
9387 "Detailed information on TCP and BGP neighbor connections\n"
9388 "Neighbor to display information about\n"
9389 "Neighbor to display information about\n"
9390 "Display flap statistics of the routes learned from neighbor\n")
9391
9392ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009393 show_bgp_neighbor_routes_cmd,
9394 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9395 SHOW_STR
9396 BGP_STR
9397 "Detailed information on TCP and BGP neighbor connections\n"
9398 "Neighbor to display information about\n"
9399 "Neighbor to display information about\n"
9400 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009401
paulbb46e942003-10-24 19:02:03 +00009402
9403ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009404 show_bgp_ipv6_neighbor_routes_cmd,
9405 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9406 SHOW_STR
9407 BGP_STR
9408 "Address family\n"
9409 "Detailed information on TCP and BGP neighbor connections\n"
9410 "Neighbor to display information about\n"
9411 "Neighbor to display information about\n"
9412 "Display routes learned from neighbor\n")
9413
9414/* old command */
paulbb46e942003-10-24 19:02:03 +00009415ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009416 ipv6_bgp_neighbor_routes_cmd,
9417 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9418 SHOW_STR
9419 IPV6_STR
9420 BGP_STR
9421 "Detailed information on TCP and BGP neighbor connections\n"
9422 "Neighbor to display information about\n"
9423 "Neighbor to display information about\n"
9424 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009425
9426/* old command */
9427DEFUN (ipv6_mbgp_neighbor_routes,
9428 ipv6_mbgp_neighbor_routes_cmd,
9429 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9430 SHOW_STR
9431 IPV6_STR
9432 MBGP_STR
9433 "Detailed information on TCP and BGP neighbor connections\n"
9434 "Neighbor to display information about\n"
9435 "Neighbor to display information about\n"
9436 "Display routes learned from neighbor\n")
9437{
paulbb46e942003-10-24 19:02:03 +00009438 struct peer *peer;
9439
9440 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9441 if (! peer)
9442 return CMD_WARNING;
9443
9444 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009445 bgp_show_type_neighbor);
9446}
paulbb46e942003-10-24 19:02:03 +00009447
9448ALIAS (show_bgp_view_neighbor_flap,
9449 show_bgp_neighbor_flap_cmd,
9450 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9451 SHOW_STR
9452 BGP_STR
9453 "Detailed information on TCP and BGP neighbor connections\n"
9454 "Neighbor to display information about\n"
9455 "Neighbor to display information about\n"
9456 "Display flap statistics of the routes learned from neighbor\n")
9457
9458ALIAS (show_bgp_view_neighbor_flap,
9459 show_bgp_ipv6_neighbor_flap_cmd,
9460 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9461 SHOW_STR
9462 BGP_STR
9463 "Address family\n"
9464 "Detailed information on TCP and BGP neighbor connections\n"
9465 "Neighbor to display information about\n"
9466 "Neighbor to display information about\n"
9467 "Display flap statistics of the routes learned from neighbor\n")
9468
9469ALIAS (show_bgp_view_neighbor_damp,
9470 show_bgp_neighbor_damp_cmd,
9471 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9472 SHOW_STR
9473 BGP_STR
9474 "Detailed information on TCP and BGP neighbor connections\n"
9475 "Neighbor to display information about\n"
9476 "Neighbor to display information about\n"
9477 "Display the dampened routes received from neighbor\n")
9478
9479ALIAS (show_bgp_view_neighbor_damp,
9480 show_bgp_ipv6_neighbor_damp_cmd,
9481 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9482 SHOW_STR
9483 BGP_STR
9484 "Address family\n"
9485 "Detailed information on TCP and BGP neighbor connections\n"
9486 "Neighbor to display information about\n"
9487 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009488 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009489
9490DEFUN (show_bgp_view_rsclient,
9491 show_bgp_view_rsclient_cmd,
9492 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9493 SHOW_STR
9494 BGP_STR
9495 "BGP view\n"
9496 "BGP view name\n"
9497 "Information about Route Server Client\n"
9498 NEIGHBOR_ADDR_STR)
9499{
9500 struct bgp_table *table;
9501 struct peer *peer;
9502
9503 if (argc == 2)
9504 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9505 else
9506 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9507
9508 if (! peer)
9509 return CMD_WARNING;
9510
9511 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9512 {
9513 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9514 VTY_NEWLINE);
9515 return CMD_WARNING;
9516 }
9517
9518 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9519 PEER_FLAG_RSERVER_CLIENT))
9520 {
9521 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9522 VTY_NEWLINE);
9523 return CMD_WARNING;
9524 }
9525
9526 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9527
ajs5a646652004-11-05 01:25:55 +00009528 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009529}
9530
9531ALIAS (show_bgp_view_rsclient,
9532 show_bgp_rsclient_cmd,
9533 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9534 SHOW_STR
9535 BGP_STR
9536 "Information about Route Server Client\n"
9537 NEIGHBOR_ADDR_STR)
9538
9539DEFUN (show_bgp_view_rsclient_route,
9540 show_bgp_view_rsclient_route_cmd,
9541 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9542 SHOW_STR
9543 BGP_STR
9544 "BGP view\n"
9545 "BGP view name\n"
9546 "Information about Route Server Client\n"
9547 NEIGHBOR_ADDR_STR
9548 "Network in the BGP routing table to display\n")
9549{
9550 struct bgp *bgp;
9551 struct peer *peer;
9552
9553 /* BGP structure lookup. */
9554 if (argc == 3)
9555 {
9556 bgp = bgp_lookup_by_name (argv[0]);
9557 if (bgp == NULL)
9558 {
9559 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9560 return CMD_WARNING;
9561 }
9562 }
9563 else
9564 {
9565 bgp = bgp_get_default ();
9566 if (bgp == NULL)
9567 {
9568 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9569 return CMD_WARNING;
9570 }
9571 }
9572
9573 if (argc == 3)
9574 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9575 else
9576 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9577
9578 if (! peer)
9579 return CMD_WARNING;
9580
9581 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9582 {
9583 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9584 VTY_NEWLINE);
9585 return CMD_WARNING;
9586 }
9587
9588 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9589 PEER_FLAG_RSERVER_CLIENT))
9590 {
9591 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9592 VTY_NEWLINE);
9593 return CMD_WARNING;
9594 }
9595
9596 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9597 (argc == 3) ? argv[2] : argv[1],
9598 AFI_IP6, SAFI_UNICAST, NULL, 0);
9599}
9600
9601ALIAS (show_bgp_view_rsclient_route,
9602 show_bgp_rsclient_route_cmd,
9603 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9604 SHOW_STR
9605 BGP_STR
9606 "Information about Route Server Client\n"
9607 NEIGHBOR_ADDR_STR
9608 "Network in the BGP routing table to display\n")
9609
9610DEFUN (show_bgp_view_rsclient_prefix,
9611 show_bgp_view_rsclient_prefix_cmd,
9612 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9613 SHOW_STR
9614 BGP_STR
9615 "BGP view\n"
9616 "BGP view name\n"
9617 "Information about Route Server Client\n"
9618 NEIGHBOR_ADDR_STR
9619 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9620{
9621 struct bgp *bgp;
9622 struct peer *peer;
9623
9624 /* BGP structure lookup. */
9625 if (argc == 3)
9626 {
9627 bgp = bgp_lookup_by_name (argv[0]);
9628 if (bgp == NULL)
9629 {
9630 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9631 return CMD_WARNING;
9632 }
9633 }
9634 else
9635 {
9636 bgp = bgp_get_default ();
9637 if (bgp == NULL)
9638 {
9639 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9640 return CMD_WARNING;
9641 }
9642 }
9643
9644 if (argc == 3)
9645 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9646 else
9647 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9648
9649 if (! peer)
9650 return CMD_WARNING;
9651
9652 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9653 {
9654 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9655 VTY_NEWLINE);
9656 return CMD_WARNING;
9657 }
9658
9659 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9660 PEER_FLAG_RSERVER_CLIENT))
9661 {
9662 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9663 VTY_NEWLINE);
9664 return CMD_WARNING;
9665 }
9666
9667 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9668 (argc == 3) ? argv[2] : argv[1],
9669 AFI_IP6, SAFI_UNICAST, NULL, 1);
9670}
9671
9672ALIAS (show_bgp_view_rsclient_prefix,
9673 show_bgp_rsclient_prefix_cmd,
9674 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9675 SHOW_STR
9676 BGP_STR
9677 "Information about Route Server Client\n"
9678 NEIGHBOR_ADDR_STR
9679 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9680
paul718e3742002-12-13 20:15:29 +00009681#endif /* HAVE_IPV6 */
9682
9683struct bgp_table *bgp_distance_table;
9684
9685struct bgp_distance
9686{
9687 /* Distance value for the IP source prefix. */
9688 u_char distance;
9689
9690 /* Name of the access-list to be matched. */
9691 char *access_list;
9692};
9693
paul94f2b392005-06-28 12:44:16 +00009694static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +00009695bgp_distance_new ()
9696{
9697 struct bgp_distance *new;
9698 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9699 memset (new, 0, sizeof (struct bgp_distance));
9700 return new;
9701}
9702
paul94f2b392005-06-28 12:44:16 +00009703static void
paul718e3742002-12-13 20:15:29 +00009704bgp_distance_free (struct bgp_distance *bdistance)
9705{
9706 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9707}
9708
paul94f2b392005-06-28 12:44:16 +00009709static int
paulfd79ac92004-10-13 05:06:08 +00009710bgp_distance_set (struct vty *vty, const char *distance_str,
9711 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009712{
9713 int ret;
9714 struct prefix_ipv4 p;
9715 u_char distance;
9716 struct bgp_node *rn;
9717 struct bgp_distance *bdistance;
9718
9719 ret = str2prefix_ipv4 (ip_str, &p);
9720 if (ret == 0)
9721 {
9722 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9723 return CMD_WARNING;
9724 }
9725
9726 distance = atoi (distance_str);
9727
9728 /* Get BGP distance node. */
9729 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9730 if (rn->info)
9731 {
9732 bdistance = rn->info;
9733 bgp_unlock_node (rn);
9734 }
9735 else
9736 {
9737 bdistance = bgp_distance_new ();
9738 rn->info = bdistance;
9739 }
9740
9741 /* Set distance value. */
9742 bdistance->distance = distance;
9743
9744 /* Reset access-list configuration. */
9745 if (bdistance->access_list)
9746 {
9747 free (bdistance->access_list);
9748 bdistance->access_list = NULL;
9749 }
9750 if (access_list_str)
9751 bdistance->access_list = strdup (access_list_str);
9752
9753 return CMD_SUCCESS;
9754}
9755
paul94f2b392005-06-28 12:44:16 +00009756static int
paulfd79ac92004-10-13 05:06:08 +00009757bgp_distance_unset (struct vty *vty, const char *distance_str,
9758 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009759{
9760 int ret;
9761 struct prefix_ipv4 p;
9762 u_char distance;
9763 struct bgp_node *rn;
9764 struct bgp_distance *bdistance;
9765
9766 ret = str2prefix_ipv4 (ip_str, &p);
9767 if (ret == 0)
9768 {
9769 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9770 return CMD_WARNING;
9771 }
9772
9773 distance = atoi (distance_str);
9774
9775 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9776 if (! rn)
9777 {
9778 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9779 return CMD_WARNING;
9780 }
9781
9782 bdistance = rn->info;
9783
9784 if (bdistance->access_list)
9785 free (bdistance->access_list);
9786 bgp_distance_free (bdistance);
9787
9788 rn->info = NULL;
9789 bgp_unlock_node (rn);
9790 bgp_unlock_node (rn);
9791
9792 return CMD_SUCCESS;
9793}
9794
paul94f2b392005-06-28 12:44:16 +00009795static void
paul718e3742002-12-13 20:15:29 +00009796bgp_distance_reset ()
9797{
9798 struct bgp_node *rn;
9799 struct bgp_distance *bdistance;
9800
9801 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9802 if ((bdistance = rn->info) != NULL)
9803 {
9804 if (bdistance->access_list)
9805 free (bdistance->access_list);
9806 bgp_distance_free (bdistance);
9807 rn->info = NULL;
9808 bgp_unlock_node (rn);
9809 }
9810}
9811
9812/* Apply BGP information to distance method. */
9813u_char
9814bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9815{
9816 struct bgp_node *rn;
9817 struct prefix_ipv4 q;
9818 struct peer *peer;
9819 struct bgp_distance *bdistance;
9820 struct access_list *alist;
9821 struct bgp_static *bgp_static;
9822
9823 if (! bgp)
9824 return 0;
9825
9826 if (p->family != AF_INET)
9827 return 0;
9828
9829 peer = rinfo->peer;
9830
9831 if (peer->su.sa.sa_family != AF_INET)
9832 return 0;
9833
9834 memset (&q, 0, sizeof (struct prefix_ipv4));
9835 q.family = AF_INET;
9836 q.prefix = peer->su.sin.sin_addr;
9837 q.prefixlen = IPV4_MAX_BITLEN;
9838
9839 /* Check source address. */
9840 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9841 if (rn)
9842 {
9843 bdistance = rn->info;
9844 bgp_unlock_node (rn);
9845
9846 if (bdistance->access_list)
9847 {
9848 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9849 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9850 return bdistance->distance;
9851 }
9852 else
9853 return bdistance->distance;
9854 }
9855
9856 /* Backdoor check. */
9857 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9858 if (rn)
9859 {
9860 bgp_static = rn->info;
9861 bgp_unlock_node (rn);
9862
9863 if (bgp_static->backdoor)
9864 {
9865 if (bgp->distance_local)
9866 return bgp->distance_local;
9867 else
9868 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9869 }
9870 }
9871
9872 if (peer_sort (peer) == BGP_PEER_EBGP)
9873 {
9874 if (bgp->distance_ebgp)
9875 return bgp->distance_ebgp;
9876 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9877 }
9878 else
9879 {
9880 if (bgp->distance_ibgp)
9881 return bgp->distance_ibgp;
9882 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9883 }
9884}
9885
9886DEFUN (bgp_distance,
9887 bgp_distance_cmd,
9888 "distance bgp <1-255> <1-255> <1-255>",
9889 "Define an administrative distance\n"
9890 "BGP distance\n"
9891 "Distance for routes external to the AS\n"
9892 "Distance for routes internal to the AS\n"
9893 "Distance for local routes\n")
9894{
9895 struct bgp *bgp;
9896
9897 bgp = vty->index;
9898
9899 bgp->distance_ebgp = atoi (argv[0]);
9900 bgp->distance_ibgp = atoi (argv[1]);
9901 bgp->distance_local = atoi (argv[2]);
9902 return CMD_SUCCESS;
9903}
9904
9905DEFUN (no_bgp_distance,
9906 no_bgp_distance_cmd,
9907 "no distance bgp <1-255> <1-255> <1-255>",
9908 NO_STR
9909 "Define an administrative distance\n"
9910 "BGP distance\n"
9911 "Distance for routes external to the AS\n"
9912 "Distance for routes internal to the AS\n"
9913 "Distance for local routes\n")
9914{
9915 struct bgp *bgp;
9916
9917 bgp = vty->index;
9918
9919 bgp->distance_ebgp= 0;
9920 bgp->distance_ibgp = 0;
9921 bgp->distance_local = 0;
9922 return CMD_SUCCESS;
9923}
9924
9925ALIAS (no_bgp_distance,
9926 no_bgp_distance2_cmd,
9927 "no distance bgp",
9928 NO_STR
9929 "Define an administrative distance\n"
9930 "BGP distance\n")
9931
9932DEFUN (bgp_distance_source,
9933 bgp_distance_source_cmd,
9934 "distance <1-255> A.B.C.D/M",
9935 "Define an administrative distance\n"
9936 "Administrative distance\n"
9937 "IP source prefix\n")
9938{
9939 bgp_distance_set (vty, argv[0], argv[1], NULL);
9940 return CMD_SUCCESS;
9941}
9942
9943DEFUN (no_bgp_distance_source,
9944 no_bgp_distance_source_cmd,
9945 "no distance <1-255> A.B.C.D/M",
9946 NO_STR
9947 "Define an administrative distance\n"
9948 "Administrative distance\n"
9949 "IP source prefix\n")
9950{
9951 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9952 return CMD_SUCCESS;
9953}
9954
9955DEFUN (bgp_distance_source_access_list,
9956 bgp_distance_source_access_list_cmd,
9957 "distance <1-255> A.B.C.D/M WORD",
9958 "Define an administrative distance\n"
9959 "Administrative distance\n"
9960 "IP source prefix\n"
9961 "Access list name\n")
9962{
9963 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9964 return CMD_SUCCESS;
9965}
9966
9967DEFUN (no_bgp_distance_source_access_list,
9968 no_bgp_distance_source_access_list_cmd,
9969 "no distance <1-255> A.B.C.D/M WORD",
9970 NO_STR
9971 "Define an administrative distance\n"
9972 "Administrative distance\n"
9973 "IP source prefix\n"
9974 "Access list name\n")
9975{
9976 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9977 return CMD_SUCCESS;
9978}
9979
9980DEFUN (bgp_damp_set,
9981 bgp_damp_set_cmd,
9982 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9983 "BGP Specific commands\n"
9984 "Enable route-flap dampening\n"
9985 "Half-life time for the penalty\n"
9986 "Value to start reusing a route\n"
9987 "Value to start suppressing a route\n"
9988 "Maximum duration to suppress a stable route\n")
9989{
9990 struct bgp *bgp;
9991 int half = DEFAULT_HALF_LIFE * 60;
9992 int reuse = DEFAULT_REUSE;
9993 int suppress = DEFAULT_SUPPRESS;
9994 int max = 4 * half;
9995
9996 if (argc == 4)
9997 {
9998 half = atoi (argv[0]) * 60;
9999 reuse = atoi (argv[1]);
10000 suppress = atoi (argv[2]);
10001 max = atoi (argv[3]) * 60;
10002 }
10003 else if (argc == 1)
10004 {
10005 half = atoi (argv[0]) * 60;
10006 max = 4 * half;
10007 }
10008
10009 bgp = vty->index;
10010 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10011 half, reuse, suppress, max);
10012}
10013
10014ALIAS (bgp_damp_set,
10015 bgp_damp_set2_cmd,
10016 "bgp dampening <1-45>",
10017 "BGP Specific commands\n"
10018 "Enable route-flap dampening\n"
10019 "Half-life time for the penalty\n")
10020
10021ALIAS (bgp_damp_set,
10022 bgp_damp_set3_cmd,
10023 "bgp dampening",
10024 "BGP Specific commands\n"
10025 "Enable route-flap dampening\n")
10026
10027DEFUN (bgp_damp_unset,
10028 bgp_damp_unset_cmd,
10029 "no bgp dampening",
10030 NO_STR
10031 "BGP Specific commands\n"
10032 "Enable route-flap dampening\n")
10033{
10034 struct bgp *bgp;
10035
10036 bgp = vty->index;
10037 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10038}
10039
10040ALIAS (bgp_damp_unset,
10041 bgp_damp_unset2_cmd,
10042 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10043 NO_STR
10044 "BGP Specific commands\n"
10045 "Enable route-flap dampening\n"
10046 "Half-life time for the penalty\n"
10047 "Value to start reusing a route\n"
10048 "Value to start suppressing a route\n"
10049 "Maximum duration to suppress a stable route\n")
10050
10051DEFUN (show_ip_bgp_dampened_paths,
10052 show_ip_bgp_dampened_paths_cmd,
10053 "show ip bgp dampened-paths",
10054 SHOW_STR
10055 IP_STR
10056 BGP_STR
10057 "Display paths suppressed due to dampening\n")
10058{
ajs5a646652004-11-05 01:25:55 +000010059 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10060 NULL);
paul718e3742002-12-13 20:15:29 +000010061}
10062
10063DEFUN (show_ip_bgp_flap_statistics,
10064 show_ip_bgp_flap_statistics_cmd,
10065 "show ip bgp flap-statistics",
10066 SHOW_STR
10067 IP_STR
10068 BGP_STR
10069 "Display flap statistics of routes\n")
10070{
ajs5a646652004-11-05 01:25:55 +000010071 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10072 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010073}
10074
10075/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010076static int
paulfd79ac92004-10-13 05:06:08 +000010077bgp_clear_damp_route (struct vty *vty, const char *view_name,
10078 const char *ip_str, afi_t afi, safi_t safi,
10079 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010080{
10081 int ret;
10082 struct prefix match;
10083 struct bgp_node *rn;
10084 struct bgp_node *rm;
10085 struct bgp_info *ri;
10086 struct bgp_info *ri_temp;
10087 struct bgp *bgp;
10088 struct bgp_table *table;
10089
10090 /* BGP structure lookup. */
10091 if (view_name)
10092 {
10093 bgp = bgp_lookup_by_name (view_name);
10094 if (bgp == NULL)
10095 {
10096 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10097 return CMD_WARNING;
10098 }
10099 }
10100 else
10101 {
10102 bgp = bgp_get_default ();
10103 if (bgp == NULL)
10104 {
10105 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10106 return CMD_WARNING;
10107 }
10108 }
10109
10110 /* Check IP address argument. */
10111 ret = str2prefix (ip_str, &match);
10112 if (! ret)
10113 {
10114 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10115 return CMD_WARNING;
10116 }
10117
10118 match.family = afi2family (afi);
10119
10120 if (safi == SAFI_MPLS_VPN)
10121 {
10122 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10123 {
10124 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10125 continue;
10126
10127 if ((table = rn->info) != NULL)
10128 if ((rm = bgp_node_match (table, &match)) != NULL)
10129 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10130 {
10131 ri = rm->info;
10132 while (ri)
10133 {
10134 if (ri->damp_info)
10135 {
10136 ri_temp = ri->next;
10137 bgp_damp_info_free (ri->damp_info, 1);
10138 ri = ri_temp;
10139 }
10140 else
10141 ri = ri->next;
10142 }
10143 }
10144 }
10145 }
10146 else
10147 {
10148 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10149 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10150 {
10151 ri = rn->info;
10152 while (ri)
10153 {
10154 if (ri->damp_info)
10155 {
10156 ri_temp = ri->next;
10157 bgp_damp_info_free (ri->damp_info, 1);
10158 ri = ri_temp;
10159 }
10160 else
10161 ri = ri->next;
10162 }
10163 }
10164 }
10165
10166 return CMD_SUCCESS;
10167}
10168
10169DEFUN (clear_ip_bgp_dampening,
10170 clear_ip_bgp_dampening_cmd,
10171 "clear ip bgp dampening",
10172 CLEAR_STR
10173 IP_STR
10174 BGP_STR
10175 "Clear route flap dampening information\n")
10176{
10177 bgp_damp_info_clean ();
10178 return CMD_SUCCESS;
10179}
10180
10181DEFUN (clear_ip_bgp_dampening_prefix,
10182 clear_ip_bgp_dampening_prefix_cmd,
10183 "clear ip bgp dampening A.B.C.D/M",
10184 CLEAR_STR
10185 IP_STR
10186 BGP_STR
10187 "Clear route flap dampening information\n"
10188 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10189{
10190 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10191 SAFI_UNICAST, NULL, 1);
10192}
10193
10194DEFUN (clear_ip_bgp_dampening_address,
10195 clear_ip_bgp_dampening_address_cmd,
10196 "clear ip bgp dampening A.B.C.D",
10197 CLEAR_STR
10198 IP_STR
10199 BGP_STR
10200 "Clear route flap dampening information\n"
10201 "Network to clear damping information\n")
10202{
10203 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10204 SAFI_UNICAST, NULL, 0);
10205}
10206
10207DEFUN (clear_ip_bgp_dampening_address_mask,
10208 clear_ip_bgp_dampening_address_mask_cmd,
10209 "clear ip bgp dampening A.B.C.D A.B.C.D",
10210 CLEAR_STR
10211 IP_STR
10212 BGP_STR
10213 "Clear route flap dampening information\n"
10214 "Network to clear damping information\n"
10215 "Network mask\n")
10216{
10217 int ret;
10218 char prefix_str[BUFSIZ];
10219
10220 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10221 if (! ret)
10222 {
10223 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10224 return CMD_WARNING;
10225 }
10226
10227 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10228 SAFI_UNICAST, NULL, 0);
10229}
10230
paul94f2b392005-06-28 12:44:16 +000010231static int
paul718e3742002-12-13 20:15:29 +000010232bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10233 afi_t afi, safi_t safi, int *write)
10234{
10235 struct bgp_node *prn;
10236 struct bgp_node *rn;
10237 struct bgp_table *table;
10238 struct prefix *p;
10239 struct prefix_rd *prd;
10240 struct bgp_static *bgp_static;
10241 u_int32_t label;
10242 char buf[SU_ADDRSTRLEN];
10243 char rdbuf[RD_ADDRSTRLEN];
10244
10245 /* Network configuration. */
10246 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10247 if ((table = prn->info) != NULL)
10248 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10249 if ((bgp_static = rn->info) != NULL)
10250 {
10251 p = &rn->p;
10252 prd = (struct prefix_rd *) &prn->p;
10253
10254 /* "address-family" display. */
10255 bgp_config_write_family_header (vty, afi, safi, write);
10256
10257 /* "network" configuration display. */
10258 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10259 label = decode_label (bgp_static->tag);
10260
10261 vty_out (vty, " network %s/%d rd %s tag %d",
10262 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10263 p->prefixlen,
10264 rdbuf, label);
10265 vty_out (vty, "%s", VTY_NEWLINE);
10266 }
10267 return 0;
10268}
10269
10270/* Configuration of static route announcement and aggregate
10271 information. */
10272int
10273bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10274 afi_t afi, safi_t safi, int *write)
10275{
10276 struct bgp_node *rn;
10277 struct prefix *p;
10278 struct bgp_static *bgp_static;
10279 struct bgp_aggregate *bgp_aggregate;
10280 char buf[SU_ADDRSTRLEN];
10281
10282 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10283 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10284
10285 /* Network configuration. */
10286 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10287 if ((bgp_static = rn->info) != NULL)
10288 {
10289 p = &rn->p;
10290
10291 /* "address-family" display. */
10292 bgp_config_write_family_header (vty, afi, safi, write);
10293
10294 /* "network" configuration display. */
10295 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10296 {
10297 u_int32_t destination;
10298 struct in_addr netmask;
10299
10300 destination = ntohl (p->u.prefix4.s_addr);
10301 masklen2ip (p->prefixlen, &netmask);
10302 vty_out (vty, " network %s",
10303 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10304
10305 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10306 || (IN_CLASSB (destination) && p->prefixlen == 16)
10307 || (IN_CLASSA (destination) && p->prefixlen == 8)
10308 || p->u.prefix4.s_addr == 0)
10309 {
10310 /* Natural mask is not display. */
10311 }
10312 else
10313 vty_out (vty, " mask %s", inet_ntoa (netmask));
10314 }
10315 else
10316 {
10317 vty_out (vty, " network %s/%d",
10318 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10319 p->prefixlen);
10320 }
10321
10322 if (bgp_static->rmap.name)
10323 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10324 else if (bgp_static->backdoor)
10325 vty_out (vty, " backdoor");
10326
10327 vty_out (vty, "%s", VTY_NEWLINE);
10328 }
10329
10330 /* Aggregate-address configuration. */
10331 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10332 if ((bgp_aggregate = rn->info) != NULL)
10333 {
10334 p = &rn->p;
10335
10336 /* "address-family" display. */
10337 bgp_config_write_family_header (vty, afi, safi, write);
10338
10339 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10340 {
10341 struct in_addr netmask;
10342
10343 masklen2ip (p->prefixlen, &netmask);
10344 vty_out (vty, " aggregate-address %s %s",
10345 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10346 inet_ntoa (netmask));
10347 }
10348 else
10349 {
10350 vty_out (vty, " aggregate-address %s/%d",
10351 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10352 p->prefixlen);
10353 }
10354
10355 if (bgp_aggregate->as_set)
10356 vty_out (vty, " as-set");
10357
10358 if (bgp_aggregate->summary_only)
10359 vty_out (vty, " summary-only");
10360
10361 vty_out (vty, "%s", VTY_NEWLINE);
10362 }
10363
10364 return 0;
10365}
10366
10367int
10368bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10369{
10370 struct bgp_node *rn;
10371 struct bgp_distance *bdistance;
10372
10373 /* Distance configuration. */
10374 if (bgp->distance_ebgp
10375 && bgp->distance_ibgp
10376 && bgp->distance_local
10377 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10378 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10379 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10380 vty_out (vty, " distance bgp %d %d %d%s",
10381 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10382 VTY_NEWLINE);
10383
10384 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10385 if ((bdistance = rn->info) != NULL)
10386 {
10387 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10388 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10389 bdistance->access_list ? bdistance->access_list : "",
10390 VTY_NEWLINE);
10391 }
10392
10393 return 0;
10394}
10395
10396/* Allocate routing table structure and install commands. */
10397void
10398bgp_route_init ()
10399{
10400 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000010401 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010402
10403 /* IPv4 BGP commands. */
10404 install_element (BGP_NODE, &bgp_network_cmd);
10405 install_element (BGP_NODE, &bgp_network_mask_cmd);
10406 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10407 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10408 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10409 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10410 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10411 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10412 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10413 install_element (BGP_NODE, &no_bgp_network_cmd);
10414 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10415 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10416 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10417 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10418 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10419 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10420 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10421 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10422
10423 install_element (BGP_NODE, &aggregate_address_cmd);
10424 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10425 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10426 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10427 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10428 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10429 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10430 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10431 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10432 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10433 install_element (BGP_NODE, &no_aggregate_address_cmd);
10434 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10435 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10436 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10437 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10438 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10439 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10440 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10441 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10442 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10443
10444 /* IPv4 unicast configuration. */
10445 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10446 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10447 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10448 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10449 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10450 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10451 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10452 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10453 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10454 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10455 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10456 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10457 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10458 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10459 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10460 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10461 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10462 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10463 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10464 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10465 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10466 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10467 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10468 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10469 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10470 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10471 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10472 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10473 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10474 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10475 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10476 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10477
10478 /* IPv4 multicast configuration. */
10479 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10480 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10481 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10482 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10483 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10484 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10485 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10486 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10487 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10488 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10489 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10490 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10491 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10492 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10493 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10494 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10495 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10496 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10497 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10498 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10499 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10500 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10501 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10502 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10503 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10504 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10505 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10506 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10507 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10508 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10509 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10510 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10511
10512 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10513 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10514 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10516 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10517 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10518 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10520 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10521 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10522 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10523 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10524 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10525 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10526 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10527 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10529 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10531 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10533 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10535 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10536 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10537 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10538 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10539 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10540 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10543 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10545 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10546 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10547 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10548 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10549 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10550 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10551 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10553 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10554 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10555 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10556 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10557 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10558 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10559 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10560 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10561 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10562 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10563 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10564 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10565 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10566 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10567 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10568 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10569 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10570 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10571 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10572 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10573 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10574 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10575 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10576 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10577 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10578 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010579 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10580 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10581 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10582 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10583 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10584 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010585
10586 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10587 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10588 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10590 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10591 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10592 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10593 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10594 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10595 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10596 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10597 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10598 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10599 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10601 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10602 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10603 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10605 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10606 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10607 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10608 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10609 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10611 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10612 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10613 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10614 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10616 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10618 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10619 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10620 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10621 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10622 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10624 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10626 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10627 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10629 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10630 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10631 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10632 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10633 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10635 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10637 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10639 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10640 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10641 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10642 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10643 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10644 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10645 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10646 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10647 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10648 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10649 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10650 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10651 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10652 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010653 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10654 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10655 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10656 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10657 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10658 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010659
10660 /* BGP dampening clear commands */
10661 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10662 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10663 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10664 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10665
10666#ifdef HAVE_IPV6
10667 /* New config IPv6 BGP commands. */
10668 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10669 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10670 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10671 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10672
10673 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10674 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10675 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10676 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10677
10678 /* Old config IPv6 BGP commands. */
10679 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10680 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10681
10682 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10683 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10684 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10685 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10686
10687 install_element (VIEW_NODE, &show_bgp_cmd);
10688 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10689 install_element (VIEW_NODE, &show_bgp_route_cmd);
10690 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10691 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10692 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10693 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10694 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10695 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10696 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10697 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10698 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10699 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10700 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10701 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10702 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10703 install_element (VIEW_NODE, &show_bgp_community_cmd);
10704 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10705 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10706 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10707 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10708 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10709 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10710 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10711 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10712 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10713 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10714 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10715 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10716 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10717 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10718 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10719 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10720 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10721 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10722 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10723 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10724 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10725 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10726 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10727 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10728 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10729 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10730 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10731 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10732 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010733 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10734 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10735 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10736 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010737 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10738 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10739 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010740 install_element (VIEW_NODE, &show_bgp_view_cmd);
10741 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10742 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10743 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10744 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10745 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10746 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10747 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10748 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10749 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10750 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10751 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10752 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10753 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10754 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10755 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10756 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10757 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010758 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10759 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10760 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010761
10762 install_element (ENABLE_NODE, &show_bgp_cmd);
10763 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10764 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10765 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10766 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10767 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10768 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10769 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10770 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10771 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10772 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10773 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10774 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10775 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10776 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10777 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10778 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10779 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10780 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10781 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10782 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10783 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10784 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10785 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10786 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10787 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10788 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10789 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10790 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10791 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10792 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10793 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10794 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10795 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10796 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10797 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10798 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10799 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10800 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10801 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10802 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10803 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10804 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10805 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10806 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10807 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010808 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10809 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10810 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10811 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010812 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10813 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10814 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010815 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10816 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10817 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10818 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10819 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10820 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10821 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10822 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10823 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10824 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10825 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10826 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10827 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10828 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10829 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10830 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10831 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10832 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010833 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10834 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10835 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010836
10837 /* old command */
10838 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10839 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10840 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10841 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10842 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10843 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10844 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10845 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10846 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10847 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10848 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10849 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10850 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10851 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10852 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10853 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10854 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10855 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10856 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10857 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10858 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10859 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10860 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10861 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10862 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10863 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10864 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10865 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10866 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10867 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10868 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10869 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10870 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10871 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10872 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10873 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000010874
paul718e3742002-12-13 20:15:29 +000010875 /* old command */
10876 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10877 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10878 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10879 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10880 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10881 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10882 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10883 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10884 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10885 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10886 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10887 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10888 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10889 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10890 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10891 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10892 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10893 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10894 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10895 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10896 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10897 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10898 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10899 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10900 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10901 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10902 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10903 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10904 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10905 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10906 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10907 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10908 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10909 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10910 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10911 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10912
10913 /* old command */
10914 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10915 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10916 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10917 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10918
10919 /* old command */
10920 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10921 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10922 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10923 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10924
10925 /* old command */
10926 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10927 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10928 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10929 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10930#endif /* HAVE_IPV6 */
10931
10932 install_element (BGP_NODE, &bgp_distance_cmd);
10933 install_element (BGP_NODE, &no_bgp_distance_cmd);
10934 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10935 install_element (BGP_NODE, &bgp_distance_source_cmd);
10936 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10937 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10938 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10939
10940 install_element (BGP_NODE, &bgp_damp_set_cmd);
10941 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10942 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10943 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10944 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10945 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10946 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10947 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10948 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10949 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
10950}