blob: 0658cabe35db52f1457f17902853c53531aba7c0 [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)
74 prn->info = bgp_table_init ();
75 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;
608 struct bgp_info info;
609 struct peer *from;
610 struct bgp *bgp;
611 struct attr dummy_attr;
612 int transparent;
613 int reflect;
614
615 from = ri->peer;
616 filter = &peer->filter[afi][safi];
617 bgp = peer->bgp;
618
619#ifdef DISABLE_BGP_ANNOUNCE
620 return 0;
621#endif
622
paulfee0f4c2004-09-13 05:12:46 +0000623 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
624 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
625 return 0;
626
paul718e3742002-12-13 20:15:29 +0000627 /* Do not send back route to sender. */
628 if (from == peer)
629 return 0;
630
paul35be31b2004-05-01 18:17:04 +0000631 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
632 if (p->family == AF_INET
633 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
634 return 0;
635#ifdef HAVE_IPV6
636 if (p->family == AF_INET6
637 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
638 return 0;
639#endif
640
paul718e3742002-12-13 20:15:29 +0000641 /* Aggregate-address suppress check. */
642 if (ri->suppress)
643 if (! UNSUPPRESS_MAP_NAME (filter))
644 return 0;
645
646 /* Default route check. */
647 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
648 {
649 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
650 return 0;
651#ifdef HAVE_IPV6
652 else if (p->family == AF_INET6 && p->prefixlen == 0)
653 return 0;
654#endif /* HAVE_IPV6 */
655 }
656
paul286e1e72003-08-08 00:24:31 +0000657 /* Transparency check. */
658 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
659 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
660 transparent = 1;
661 else
662 transparent = 0;
663
paul718e3742002-12-13 20:15:29 +0000664 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000665 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000666 return 0;
667
668 /* If the attribute has originator-id and it is same as remote
669 peer's id. */
670 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
671 {
672 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
673 {
674 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000675 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000676 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
677 peer->host,
678 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
679 p->prefixlen);
680 return 0;
681 }
682 }
683
684 /* ORF prefix-list filter check */
685 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
686 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
687 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
688 if (peer->orf_plist[afi][safi])
689 {
690 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
691 return 0;
692 }
693
694 /* Output filter check. */
695 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
696 {
697 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000698 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000699 "%s [Update:SEND] %s/%d is filtered",
700 peer->host,
701 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
702 p->prefixlen);
703 return 0;
704 }
705
706#ifdef BGP_SEND_ASPATH_CHECK
707 /* AS path loop check. */
708 if (aspath_loop_check (ri->attr->aspath, peer->as))
709 {
710 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000711 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000712 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
713 peer->host, peer->as);
714 return 0;
715 }
716#endif /* BGP_SEND_ASPATH_CHECK */
717
718 /* If we're a CONFED we need to loop check the CONFED ID too */
719 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
720 {
721 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
722 {
723 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000724 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000725 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
726 peer->host,
727 bgp->confed_id);
728 return 0;
729 }
730 }
731
732 /* Route-Reflect check. */
733 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
734 reflect = 1;
735 else
736 reflect = 0;
737
738 /* IBGP reflection check. */
739 if (reflect)
740 {
741 /* A route from a Client peer. */
742 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
743 {
744 /* Reflect to all the Non-Client peers and also to the
745 Client peers other than the originator. Originator check
746 is already done. So there is noting to do. */
747 /* no bgp client-to-client reflection check. */
748 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
749 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
750 return 0;
751 }
752 else
753 {
754 /* A route from a Non-client peer. Reflect to all other
755 clients. */
756 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
757 return 0;
758 }
759 }
760
761 /* For modify attribute, copy it to temporary structure. */
762 *attr = *ri->attr;
763
764 /* If local-preference is not set. */
765 if ((peer_sort (peer) == BGP_PEER_IBGP
766 || peer_sort (peer) == BGP_PEER_CONFED)
767 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
768 {
769 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
770 attr->local_pref = bgp->default_local_pref;
771 }
772
paul718e3742002-12-13 20:15:29 +0000773 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
774 if (peer_sort (peer) == BGP_PEER_EBGP
775 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
776 {
777 if (ri->peer != bgp->peer_self && ! transparent
778 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
779 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
780 }
781
782 /* next-hop-set */
783 if (transparent || reflect
784 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
785 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000786#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000787 || (p->family == AF_INET6 &&
788 ! IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000789#endif /* HAVE_IPV6 */
790 )))
paul718e3742002-12-13 20:15:29 +0000791 {
792 /* NEXT-HOP Unchanged. */
793 }
794 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
795 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
796#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000797 || (p->family == AF_INET6 &&
798 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000799#endif /* HAVE_IPV6 */
800 || (peer_sort (peer) == BGP_PEER_EBGP
801 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
802 {
803 /* Set IPv4 nexthop. */
804 if (p->family == AF_INET)
805 {
806 if (safi == SAFI_MPLS_VPN)
807 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
808 else
809 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
810 }
811#ifdef HAVE_IPV6
812 /* Set IPv6 nexthop. */
813 if (p->family == AF_INET6)
814 {
815 /* IPv6 global nexthop must be included. */
816 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
817 IPV6_MAX_BYTELEN);
818 attr->mp_nexthop_len = 16;
819 }
820#endif /* HAVE_IPV6 */
821 }
822
823#ifdef HAVE_IPV6
824 if (p->family == AF_INET6)
825 {
paulfee0f4c2004-09-13 05:12:46 +0000826 /* Left nexthop_local unchanged if so configured. */
827 if ( CHECK_FLAG (peer->af_flags[afi][safi],
828 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
829 {
830 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
831 attr->mp_nexthop_len=32;
832 else
833 attr->mp_nexthop_len=16;
834 }
835
836 /* Default nexthop_local treatment for non-RS-Clients */
837 else
838 {
paul718e3742002-12-13 20:15:29 +0000839 /* Link-local address should not be transit to different peer. */
840 attr->mp_nexthop_len = 16;
841
842 /* Set link-local address for shared network peer. */
843 if (peer->shared_network
844 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
845 {
846 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
847 IPV6_MAX_BYTELEN);
848 attr->mp_nexthop_len = 32;
849 }
850
851 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
852 address.*/
853 if (reflect)
854 attr->mp_nexthop_len = 16;
855
856 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
857 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
858 attr->mp_nexthop_len = 16;
859 }
paulfee0f4c2004-09-13 05:12:46 +0000860
861 }
paul718e3742002-12-13 20:15:29 +0000862#endif /* HAVE_IPV6 */
863
864 /* If this is EBGP peer and remove-private-AS is set. */
865 if (peer_sort (peer) == BGP_PEER_EBGP
866 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
867 && aspath_private_as_check (attr->aspath))
868 attr->aspath = aspath_empty_get ();
869
870 /* Route map & unsuppress-map apply. */
871 if (ROUTE_MAP_OUT_NAME (filter)
872 || ri->suppress)
873 {
874 info.peer = peer;
875 info.attr = attr;
876
877 /* The route reflector is not allowed to modify the attributes
878 of the reflected IBGP routes. */
879 if (peer_sort (from) == BGP_PEER_IBGP
880 && peer_sort (peer) == BGP_PEER_IBGP)
881 {
882 dummy_attr = *attr;
883 info.attr = &dummy_attr;
884 }
paulac41b2a2003-08-12 05:32:27 +0000885
886 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
887
paul718e3742002-12-13 20:15:29 +0000888 if (ri->suppress)
889 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
890 else
891 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
892
paulac41b2a2003-08-12 05:32:27 +0000893 peer->rmap_type = 0;
894
paul718e3742002-12-13 20:15:29 +0000895 if (ret == RMAP_DENYMATCH)
896 {
897 bgp_attr_flush (attr);
898 return 0;
899 }
900 }
901 return 1;
902}
903
paul94f2b392005-06-28 12:44:16 +0000904static int
paulfee0f4c2004-09-13 05:12:46 +0000905bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
906 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000907{
paulfee0f4c2004-09-13 05:12:46 +0000908 int ret;
909 char buf[SU_ADDRSTRLEN];
910 struct bgp_filter *filter;
911 struct bgp_info info;
912 struct peer *from;
913 struct bgp *bgp;
914
915 from = ri->peer;
916 filter = &rsclient->filter[afi][safi];
917 bgp = rsclient->bgp;
918
919#ifdef DISABLE_BGP_ANNOUNCE
920 return 0;
921#endif
922
923 /* Do not send back route to sender. */
924 if (from == rsclient)
925 return 0;
926
927 /* Aggregate-address suppress check. */
928 if (ri->suppress)
929 if (! UNSUPPRESS_MAP_NAME (filter))
930 return 0;
931
932 /* Default route check. */
933 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
934 PEER_STATUS_DEFAULT_ORIGINATE))
935 {
936 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
937 return 0;
938#ifdef HAVE_IPV6
939 else if (p->family == AF_INET6 && p->prefixlen == 0)
940 return 0;
941#endif /* HAVE_IPV6 */
942 }
943
944 /* If the attribute has originator-id and it is same as remote
945 peer's id. */
946 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
947 {
948 if (IPV4_ADDR_SAME (&rsclient->remote_id, &ri->attr->originator_id))
949 {
950 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000951 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000952 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
953 rsclient->host,
954 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
955 p->prefixlen);
956 return 0;
957 }
958 }
959
960 /* ORF prefix-list filter check */
961 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
962 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
963 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
964 if (rsclient->orf_plist[afi][safi])
965 {
966 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
967 return 0;
968 }
969
970 /* Output filter check. */
971 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
972 {
973 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000974 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000975 "%s [Update:SEND] %s/%d is filtered",
976 rsclient->host,
977 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
978 p->prefixlen);
979 return 0;
980 }
981
982#ifdef BGP_SEND_ASPATH_CHECK
983 /* AS path loop check. */
984 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
985 {
986 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000987 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000988 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
989 rsclient->host, rsclient->as);
990 return 0;
991 }
992#endif /* BGP_SEND_ASPATH_CHECK */
993
994 /* For modify attribute, copy it to temporary structure. */
995 *attr = *ri->attr;
996
997 /* next-hop-set */
998 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
999#ifdef HAVE_IPV6
1000 || (p->family == AF_INET6 &&
1001 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
1002#endif /* HAVE_IPV6 */
1003 )
1004 {
1005 /* Set IPv4 nexthop. */
1006 if (p->family == AF_INET)
1007 {
1008 if (safi == SAFI_MPLS_VPN)
1009 memcpy (&attr->mp_nexthop_global_in, &rsclient->nexthop.v4,
1010 IPV4_MAX_BYTELEN);
1011 else
1012 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1013 }
1014#ifdef HAVE_IPV6
1015 /* Set IPv6 nexthop. */
1016 if (p->family == AF_INET6)
1017 {
1018 /* IPv6 global nexthop must be included. */
1019 memcpy (&attr->mp_nexthop_global, &rsclient->nexthop.v6_global,
1020
1021 IPV6_MAX_BYTELEN);
1022 attr->mp_nexthop_len = 16;
1023 }
1024#endif /* HAVE_IPV6 */
1025 }
1026
1027#ifdef HAVE_IPV6
1028 if (p->family == AF_INET6)
1029 {
1030 /* Left nexthop_local unchanged if so configured. */
1031 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1032 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1033 {
1034 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1035 attr->mp_nexthop_len=32;
1036 else
1037 attr->mp_nexthop_len=16;
1038 }
1039
1040 /* Default nexthop_local treatment for RS-Clients */
1041 else
1042 {
1043 /* Announcer and RS-Client are both in the same network */
1044 if (rsclient->shared_network && from->shared_network &&
1045 (rsclient->ifindex == from->ifindex))
1046 {
1047 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1048 attr->mp_nexthop_len=32;
1049 else
1050 attr->mp_nexthop_len=16;
1051 }
1052
1053 /* Set link-local address for shared network peer. */
1054 else if (rsclient->shared_network
1055 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1056 {
1057 memcpy (&attr->mp_nexthop_local, &rsclient->nexthop.v6_local,
1058 IPV6_MAX_BYTELEN);
1059 attr->mp_nexthop_len = 32;
1060 }
1061
1062 else
1063 attr->mp_nexthop_len = 16;
1064 }
1065
1066 }
1067#endif /* HAVE_IPV6 */
1068
1069
1070 /* If this is EBGP peer and remove-private-AS is set. */
1071 if (peer_sort (rsclient) == BGP_PEER_EBGP
1072 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1073 && aspath_private_as_check (attr->aspath))
1074 attr->aspath = aspath_empty_get ();
1075
1076 /* Route map & unsuppress-map apply. */
1077 if (ROUTE_MAP_OUT_NAME (filter) || ri->suppress)
1078 {
1079 info.peer = rsclient;
1080 info.attr = attr;
1081
1082 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1083
1084 if (ri->suppress)
1085 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1086 else
1087 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1088
1089 rsclient->rmap_type = 0;
1090
1091 if (ret == RMAP_DENYMATCH)
1092 {
1093 bgp_attr_flush (attr);
1094 return 0;
1095 }
1096 }
1097
1098 return 1;
1099}
1100
1101struct bgp_info_pair
1102{
1103 struct bgp_info *old;
1104 struct bgp_info *new;
1105};
1106
paul94f2b392005-06-28 12:44:16 +00001107static void
paulfee0f4c2004-09-13 05:12:46 +00001108bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1109{
paul718e3742002-12-13 20:15:29 +00001110 struct bgp_info *new_select;
1111 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001112 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001113 struct bgp_info *ri1;
1114 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001115 struct bgp_info *nextri = NULL;
1116
paul718e3742002-12-13 20:15:29 +00001117 /* bgp deterministic-med */
1118 new_select = NULL;
1119 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1120 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1121 {
1122 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1123 continue;
1124 if (BGP_INFO_HOLDDOWN (ri1))
1125 continue;
1126
1127 new_select = ri1;
1128 if (ri1->next)
1129 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1130 {
1131 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1132 continue;
1133 if (BGP_INFO_HOLDDOWN (ri2))
1134 continue;
1135
1136 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1137 || aspath_cmp_left_confed (ri1->attr->aspath,
1138 ri2->attr->aspath))
1139 {
1140 if (bgp_info_cmp (bgp, ri2, new_select))
1141 {
1142 UNSET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1143 new_select = ri2;
1144 }
1145
1146 SET_FLAG (ri2->flags, BGP_INFO_DMED_CHECK);
1147 }
1148 }
1149 SET_FLAG (new_select->flags, BGP_INFO_DMED_CHECK);
1150 SET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1151 }
1152
1153 /* Check old selected route and new selected route. */
1154 old_select = NULL;
1155 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001156 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001157 {
1158 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1159 old_select = ri;
1160
1161 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001162 {
1163 /* reap REMOVED routes, if needs be
1164 * selected route must stay for a while longer though
1165 */
1166 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1167 && (ri != old_select))
1168 bgp_info_reap (rn, ri);
1169
1170 continue;
1171 }
paul718e3742002-12-13 20:15:29 +00001172
1173 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1174 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1175 {
1176 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1177 continue;
1178 }
1179 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1180 UNSET_FLAG (ri->flags, BGP_INFO_DMED_SELECTED);
1181
1182 if (bgp_info_cmp (bgp, ri, new_select))
1183 new_select = ri;
1184 }
paulb40d9392005-08-22 22:34:41 +00001185
paulfee0f4c2004-09-13 05:12:46 +00001186 result->old = old_select;
1187 result->new = new_select;
1188
1189 return;
1190}
1191
paul94f2b392005-06-28 12:44:16 +00001192static int
paulfee0f4c2004-09-13 05:12:46 +00001193bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1194 struct bgp_node *rn, struct attr *attr, afi_t afi, safi_t safi)
1195 {
1196 struct prefix *p;
1197
1198 p = &rn->p;
1199
1200 /* Announce route to Established peer. */
1201 if (peer->status != Established)
1202 return 0;
1203
1204 /* Address family configuration check. */
1205 if (! peer->afc_nego[afi][safi])
1206 return 0;
1207
1208 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1209 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1210 PEER_STATUS_ORF_WAIT_REFRESH))
1211 return 0;
1212
1213 switch (rn->table->type)
1214 {
1215 case BGP_TABLE_MAIN:
1216 /* Announcement to peer->conf. If the route is filtered,
1217 withdraw it. */
1218 if (selected && bgp_announce_check (selected, peer, p, attr, afi, safi))
1219 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1220 else
1221 bgp_adj_out_unset (rn, peer, p, afi, safi);
1222 break;
1223 case BGP_TABLE_RSCLIENT:
1224 /* Announcement to peer->conf. If the route is filtered,
1225 withdraw it. */
1226 if (selected && bgp_announce_check_rsclient
1227 (selected, peer, p, attr, afi, safi))
1228 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1229 else
1230 bgp_adj_out_unset (rn, peer, p, afi, safi);
1231 break;
1232 }
1233 return 0;
paul200df112005-06-01 11:17:05 +00001234}
paulfee0f4c2004-09-13 05:12:46 +00001235
paul200df112005-06-01 11:17:05 +00001236struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001237{
paul200df112005-06-01 11:17:05 +00001238 struct bgp *bgp;
1239 struct bgp_node *rn;
1240 afi_t afi;
1241 safi_t safi;
1242};
1243
1244static wq_item_status
1245bgp_process_rsclient (struct bgp_process_queue *pq)
1246{
1247 struct bgp *bgp = pq->bgp;
1248 struct bgp_node *rn = pq->rn;
1249 afi_t afi = pq->afi;
1250 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001251 struct bgp_info *new_select;
1252 struct bgp_info *old_select;
1253 struct bgp_info_pair old_and_new;
1254 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001255 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001256 struct peer *rsclient = rn->table->owner;
1257
1258 /* we shouldn't run if the clear_route_node queue is still running
1259 * or scheduled to run, or we can race with session coming up
1260 * and adding routes back before we've cleared them
1261 */
1262 if (bm->clear_node_queue && bm->clear_node_queue->thread)
1263 return WQ_QUEUE_BLOCKED;
1264
paulfee0f4c2004-09-13 05:12:46 +00001265 /* Best path selection. */
1266 bgp_best_selection (bgp, rn, &old_and_new);
1267 new_select = old_and_new.new;
1268 old_select = old_and_new.old;
1269
paul200df112005-06-01 11:17:05 +00001270 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1271 {
1272 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1273 {
1274 /* Nothing to do. */
1275 if (old_select && old_select == new_select)
1276 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1277 continue;
paulfee0f4c2004-09-13 05:12:46 +00001278
paul200df112005-06-01 11:17:05 +00001279 if (old_select)
1280 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1281 if (new_select)
1282 {
1283 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1284 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1285 }
paulfee0f4c2004-09-13 05:12:46 +00001286
paul200df112005-06-01 11:17:05 +00001287 bgp_process_announce_selected (rsclient, new_select, rn, &attr,
1288 afi, safi);
1289 }
1290 }
1291 else
1292 {
hassob7395792005-08-26 12:58:38 +00001293 if (old_select)
1294 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1295 if (new_select)
1296 {
1297 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1298 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1299 }
paul200df112005-06-01 11:17:05 +00001300 bgp_process_announce_selected (rsclient, new_select, rn,
1301 &attr, afi, safi);
1302 }
paulfee0f4c2004-09-13 05:12:46 +00001303
paulb40d9392005-08-22 22:34:41 +00001304 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1305 bgp_info_reap (rn, old_select);
1306
paul200df112005-06-01 11:17:05 +00001307 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1308 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001309}
1310
paul200df112005-06-01 11:17:05 +00001311static wq_item_status
1312bgp_process_main (struct bgp_process_queue *pq)
1313{
1314 struct bgp *bgp = pq->bgp;
1315 struct bgp_node *rn = pq->rn;
1316 afi_t afi = pq->afi;
1317 safi_t safi = pq->safi;
1318 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001319 struct bgp_info *new_select;
1320 struct bgp_info *old_select;
1321 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001322 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001323 struct peer *peer;
1324 struct attr attr;
paul200df112005-06-01 11:17:05 +00001325
1326 /* we shouldn't run if the clear_route_node queue is still running
1327 * or scheduled to run, or we can race with session coming up
1328 * and adding routes back before we've cleared them
1329 */
1330 if (bm->clear_node_queue && bm->clear_node_queue->thread)
1331 return WQ_QUEUE_BLOCKED;
paulfee0f4c2004-09-13 05:12:46 +00001332
1333 /* Best path selection. */
1334 bgp_best_selection (bgp, rn, &old_and_new);
1335 old_select = old_and_new.old;
1336 new_select = old_and_new.new;
1337
1338 /* Nothing to do. */
1339 if (old_select && old_select == new_select)
1340 {
1341 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001342 {
1343 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1344 bgp_zebra_announce (p, old_select, bgp);
1345
1346 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1347 return WQ_SUCCESS;
1348 }
paulfee0f4c2004-09-13 05:12:46 +00001349 }
paul718e3742002-12-13 20:15:29 +00001350
hasso338b3422005-02-23 14:27:24 +00001351 if (old_select)
1352 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1353 if (new_select)
1354 {
1355 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1356 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1357 }
1358
1359
paul718e3742002-12-13 20:15:29 +00001360 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001361 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001362 {
paulfee0f4c2004-09-13 05:12:46 +00001363 bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi);
paul718e3742002-12-13 20:15:29 +00001364 }
1365
1366 /* FIB update. */
1367 if (safi == SAFI_UNICAST && ! bgp->name &&
1368 ! bgp_option_check (BGP_OPT_NO_FIB))
1369 {
1370 if (new_select
1371 && new_select->type == ZEBRA_ROUTE_BGP
1372 && new_select->sub_type == BGP_ROUTE_NORMAL)
1373 bgp_zebra_announce (p, new_select, bgp);
1374 else
1375 {
1376 /* Withdraw the route from the kernel. */
1377 if (old_select
1378 && old_select->type == ZEBRA_ROUTE_BGP
1379 && old_select->sub_type == BGP_ROUTE_NORMAL)
1380 bgp_zebra_withdraw (p, old_select);
1381 }
1382 }
paulb40d9392005-08-22 22:34:41 +00001383
1384 /* Reap old select bgp_info, it it has been removed */
1385 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1386 bgp_info_reap (rn, old_select);
1387
paul200df112005-06-01 11:17:05 +00001388 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1389 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001390}
1391
paul200df112005-06-01 11:17:05 +00001392static void
1393bgp_processq_del (struct bgp_process_queue *pq)
1394{
1395 bgp_unlock_node (pq->rn);
1396 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1397}
1398
1399static void
1400bgp_process_queue_init (void)
1401{
1402 bm->process_main_queue
1403 = work_queue_new (bm->master, "process_main_queue");
1404 bm->process_rsclient_queue
1405 = work_queue_new (bm->master, "process_rsclient_queue");
1406
1407 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1408 {
1409 zlog_err ("%s: Failed to allocate work queue", __func__);
1410 exit (1);
1411 }
1412
1413 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1414 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1415 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1416 bm->process_rsclient_queue->spec.del_item_data
1417 = bm->process_main_queue->spec.del_item_data;
1418 bm->process_main_queue->spec.max_retries
1419 = bm->process_main_queue->spec.max_retries = 0;
1420 bm->process_rsclient_queue->spec.hold
1421 = bm->process_main_queue->spec.hold = 500;
1422 bm->process_rsclient_queue->spec.delay
1423 = bm->process_main_queue->spec.delay = 10;
1424}
1425
1426void
paulfee0f4c2004-09-13 05:12:46 +00001427bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1428{
paul200df112005-06-01 11:17:05 +00001429 struct bgp_process_queue *pqnode;
1430
1431 /* already scheduled for processing? */
1432 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1433 return;
1434
1435 if ( (bm->process_main_queue == NULL) ||
1436 (bm->process_rsclient_queue == NULL) )
1437 bgp_process_queue_init ();
1438
1439 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1440 sizeof (struct bgp_process_queue));
1441 if (!pqnode)
1442 return;
1443
1444 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1445 pqnode->bgp = bgp;
1446 pqnode->afi = afi;
1447 pqnode->safi = safi;
1448
paulfee0f4c2004-09-13 05:12:46 +00001449 switch (rn->table->type)
1450 {
paul200df112005-06-01 11:17:05 +00001451 case BGP_TABLE_MAIN:
1452 work_queue_add (bm->process_main_queue, pqnode);
1453 break;
1454 case BGP_TABLE_RSCLIENT:
1455 work_queue_add (bm->process_rsclient_queue, pqnode);
1456 break;
paulfee0f4c2004-09-13 05:12:46 +00001457 }
paul200df112005-06-01 11:17:05 +00001458
1459 return;
paulfee0f4c2004-09-13 05:12:46 +00001460}
hasso0a486e52005-02-01 20:57:17 +00001461
paul94f2b392005-06-28 12:44:16 +00001462static int
hasso0a486e52005-02-01 20:57:17 +00001463bgp_maximum_prefix_restart_timer (struct thread *thread)
1464{
1465 struct peer *peer;
1466
1467 peer = THREAD_ARG (thread);
1468 peer->t_pmax_restart = NULL;
1469
1470 if (BGP_DEBUG (events, EVENTS))
1471 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1472 peer->host);
1473
1474 peer_clear (peer);
1475
1476 return 0;
1477}
1478
paulfee0f4c2004-09-13 05:12:46 +00001479int
paul5228ad22004-06-04 17:58:18 +00001480bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1481 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001482{
hassoe0701b72004-05-20 09:19:34 +00001483 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1484 return 0;
1485
1486 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001487 {
hassoe0701b72004-05-20 09:19:34 +00001488 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1489 && ! always)
1490 return 0;
paul718e3742002-12-13 20:15:29 +00001491
hassoe0701b72004-05-20 09:19:34 +00001492 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001493 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1494 "limit %ld", afi_safi_print (afi, safi), peer->host,
1495 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001496 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001497
hassoe0701b72004-05-20 09:19:34 +00001498 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1499 return 0;
paul718e3742002-12-13 20:15:29 +00001500
hassoe0701b72004-05-20 09:19:34 +00001501 {
paul5228ad22004-06-04 17:58:18 +00001502 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001503
1504 if (safi == SAFI_MPLS_VPN)
1505 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001506
1507 ndata[0] = (afi >> 8);
1508 ndata[1] = afi;
1509 ndata[2] = safi;
1510 ndata[3] = (peer->pmax[afi][safi] >> 24);
1511 ndata[4] = (peer->pmax[afi][safi] >> 16);
1512 ndata[5] = (peer->pmax[afi][safi] >> 8);
1513 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001514
1515 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1516 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1517 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1518 }
hasso0a486e52005-02-01 20:57:17 +00001519
1520 /* restart timer start */
1521 if (peer->pmax_restart[afi][safi])
1522 {
1523 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1524
1525 if (BGP_DEBUG (events, EVENTS))
1526 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1527 peer->host, peer->v_pmax_restart);
1528
1529 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1530 peer->v_pmax_restart);
1531 }
1532
hassoe0701b72004-05-20 09:19:34 +00001533 return 1;
paul718e3742002-12-13 20:15:29 +00001534 }
hassoe0701b72004-05-20 09:19:34 +00001535 else
1536 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1537
1538 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1539 {
1540 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1541 && ! always)
1542 return 0;
1543
1544 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001545 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1546 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1547 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001548 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1549 }
1550 else
1551 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001552 return 0;
1553}
1554
paulb40d9392005-08-22 22:34:41 +00001555/* Unconditionally remove the route from the RIB, without taking
1556 * damping into consideration (eg, because the session went down)
1557 */
paul94f2b392005-06-28 12:44:16 +00001558static void
paul718e3742002-12-13 20:15:29 +00001559bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1560 afi_t afi, safi_t safi)
1561{
paulb40d9392005-08-22 22:34:41 +00001562 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
1563 && rn->table->type == BGP_TABLE_MAIN)
paul718e3742002-12-13 20:15:29 +00001564 {
paulfee0f4c2004-09-13 05:12:46 +00001565 /* Ignore 'pcount' for RS-client tables */
1566 if ( rn->table->type == BGP_TABLE_MAIN)
1567 {
paulb40d9392005-08-22 22:34:41 +00001568 peer->pcount[afi][safi]--;
1569 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001570 }
paul718e3742002-12-13 20:15:29 +00001571 }
paulb40d9392005-08-22 22:34:41 +00001572 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001573 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00001574}
1575
paul94f2b392005-06-28 12:44:16 +00001576static void
paul718e3742002-12-13 20:15:29 +00001577bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001578 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001579{
paul718e3742002-12-13 20:15:29 +00001580 int status = BGP_DAMP_NONE;
1581
paulb40d9392005-08-22 22:34:41 +00001582 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
1583 && rn->table->type == BGP_TABLE_MAIN)
paul718e3742002-12-13 20:15:29 +00001584 {
paulb40d9392005-08-22 22:34:41 +00001585 /* Ignore 'pcount' for RS-client tables */
1586 if ( rn->table->type == BGP_TABLE_MAIN)
1587 {
1588 peer->pcount[afi][safi]--;
1589 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1590 }
paul718e3742002-12-13 20:15:29 +00001591 }
paulb40d9392005-08-22 22:34:41 +00001592
1593 /* apply dampening, if result is suppressed, we'll be retaining
1594 * the bgp_info in the RIB for historical reference.
1595 */
1596 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1597 && peer_sort (peer) == BGP_PEER_EBGP)
1598 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1599 == BGP_DAMP_SUPPRESSED)
1600 return;
paul718e3742002-12-13 20:15:29 +00001601
paul718e3742002-12-13 20:15:29 +00001602 bgp_process (peer->bgp, rn, afi, safi);
1603
paul718e3742002-12-13 20:15:29 +00001604 if (status != BGP_DAMP_USED)
paul200df112005-06-01 11:17:05 +00001605 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00001606}
1607
paul94f2b392005-06-28 12:44:16 +00001608static void
paulfee0f4c2004-09-13 05:12:46 +00001609bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1610 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1611 int sub_type, struct prefix_rd *prd, u_char *tag)
1612{
1613 struct bgp_node *rn;
1614 struct bgp *bgp;
1615 struct attr new_attr;
1616 struct attr *attr_new;
1617 struct attr *attr_new2;
1618 struct bgp_info *ri;
1619 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001620 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001621 char buf[SU_ADDRSTRLEN];
1622
1623 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1624 if (peer == rsclient)
1625 return;
1626
1627 bgp = peer->bgp;
1628 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1629
1630 /* Check previously received route. */
1631 for (ri = rn->info; ri; ri = ri->next)
1632 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1633 break;
1634
1635 /* AS path loop check. */
1636 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1637 {
1638 reason = "as-path contains our own AS;";
1639 goto filtered;
1640 }
1641
1642 /* Route reflector originator ID check. */
1643 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1644 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->originator_id))
1645 {
1646 reason = "originator is us;";
1647 goto filtered;
1648 }
1649
1650 new_attr = *attr;
1651
1652 /* Apply export policy. */
1653 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1654 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1655 {
1656 reason = "export-policy;";
1657 goto filtered;
1658 }
1659
1660 attr_new2 = bgp_attr_intern (&new_attr);
1661
1662 /* Apply import policy. */
1663 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1664 {
1665 bgp_attr_unintern (attr_new2);
1666
1667 reason = "import-policy;";
1668 goto filtered;
1669 }
1670
1671 attr_new = bgp_attr_intern (&new_attr);
1672 bgp_attr_unintern (attr_new2);
1673
1674 /* IPv4 unicast next hop check. */
1675 if (afi == AFI_IP && safi == SAFI_UNICAST)
1676 {
1677 /* Next hop must not be 0.0.0.0 nor Class E address. */
1678 if (new_attr.nexthop.s_addr == 0
1679 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1680 {
1681 bgp_attr_unintern (attr_new);
1682
1683 reason = "martian next-hop;";
1684 goto filtered;
1685 }
1686 }
1687
1688 /* If the update is implicit withdraw. */
1689 if (ri)
1690 {
1691 ri->uptime = time (NULL);
1692
1693 /* Same attribute comes in. */
1694 if (attrhash_cmp (ri->attr, attr_new))
1695 {
1696
1697 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1698
1699 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001700 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001701 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1702 peer->host,
1703 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1704 p->prefixlen, rsclient->host);
1705
1706 bgp_unlock_node (rn);
1707 bgp_attr_unintern (attr_new);
1708
1709 return;
1710 }
1711
1712 /* Received Logging. */
1713 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001714 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001715 peer->host,
1716 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1717 p->prefixlen, rsclient->host);
1718
1719 /* The attribute is changed. */
1720 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1721
1722 /* Update to new attribute. */
1723 bgp_attr_unintern (ri->attr);
1724 ri->attr = attr_new;
1725
1726 /* Update MPLS tag. */
1727 if (safi == SAFI_MPLS_VPN)
1728 memcpy (ri->tag, tag, 3);
1729
1730 SET_FLAG (ri->flags, BGP_INFO_VALID);
1731
1732 /* Process change. */
1733 bgp_process (bgp, rn, afi, safi);
1734 bgp_unlock_node (rn);
1735
1736 return;
1737 }
1738
1739 /* Received Logging. */
1740 if (BGP_DEBUG (update, UPDATE_IN))
1741 {
ajsd2c1f162004-12-08 21:10:20 +00001742 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001743 peer->host,
1744 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1745 p->prefixlen, rsclient->host);
1746 }
1747
1748 /* Make new BGP info. */
1749 new = bgp_info_new ();
1750 new->type = type;
1751 new->sub_type = sub_type;
1752 new->peer = peer;
1753 new->attr = attr_new;
1754 new->uptime = time (NULL);
1755
1756 /* Update MPLS tag. */
1757 if (safi == SAFI_MPLS_VPN)
1758 memcpy (new->tag, tag, 3);
1759
1760 SET_FLAG (new->flags, BGP_INFO_VALID);
1761
1762 /* Register new BGP information. */
1763 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001764
1765 /* route_node_get lock */
1766 bgp_unlock_node (rn);
1767
paulfee0f4c2004-09-13 05:12:46 +00001768 /* Process change. */
1769 bgp_process (bgp, rn, afi, safi);
1770
1771 return;
1772
1773 filtered:
1774
1775 /* This BGP update is filtered. Log the reason then update BGP entry. */
1776 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001777 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001778 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1779 peer->host,
1780 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1781 p->prefixlen, rsclient->host, reason);
1782
1783 if (ri)
paulb40d9392005-08-22 22:34:41 +00001784 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001785
1786 bgp_unlock_node (rn);
1787
1788 return;
1789}
1790
paul94f2b392005-06-28 12:44:16 +00001791static void
paulfee0f4c2004-09-13 05:12:46 +00001792bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1793 struct peer *peer, struct prefix *p, int type, int sub_type,
1794 struct prefix_rd *prd, u_char *tag)
1795 {
1796 struct bgp_node *rn;
1797 struct bgp_info *ri;
1798 char buf[SU_ADDRSTRLEN];
1799
1800 if (rsclient == peer)
1801 return;
1802
1803 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1804
1805 /* Lookup withdrawn route. */
1806 for (ri = rn->info; ri; ri = ri->next)
1807 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1808 break;
1809
1810 /* Withdraw specified route from routing table. */
1811 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001812 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001813 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001814 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001815 "%s Can't find the route %s/%d", peer->host,
1816 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1817 p->prefixlen);
1818
1819 /* Unlock bgp_node_get() lock. */
1820 bgp_unlock_node (rn);
1821 }
1822
paul94f2b392005-06-28 12:44:16 +00001823static int
paulfee0f4c2004-09-13 05:12:46 +00001824bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001825 afi_t afi, safi_t safi, int type, int sub_type,
1826 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1827{
1828 int ret;
1829 int aspath_loop_count = 0;
1830 struct bgp_node *rn;
1831 struct bgp *bgp;
1832 struct attr new_attr;
1833 struct attr *attr_new;
1834 struct bgp_info *ri;
1835 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001836 const char *reason;
paul718e3742002-12-13 20:15:29 +00001837 char buf[SU_ADDRSTRLEN];
1838
1839 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001840 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00001841
1842 /* When peer's soft reconfiguration enabled. Record input packet in
1843 Adj-RIBs-In. */
1844 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1845 && peer != bgp->peer_self && ! soft_reconfig)
1846 bgp_adj_in_set (rn, peer, attr);
1847
1848 /* Check previously received route. */
1849 for (ri = rn->info; ri; ri = ri->next)
1850 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1851 break;
1852
1853 /* AS path local-as loop check. */
1854 if (peer->change_local_as)
1855 {
1856 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1857 aspath_loop_count = 1;
1858
1859 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1860 {
1861 reason = "as-path contains our own AS;";
1862 goto filtered;
1863 }
1864 }
1865
1866 /* AS path loop check. */
1867 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1868 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1869 && aspath_loop_check(attr->aspath, bgp->confed_id)
1870 > peer->allowas_in[afi][safi]))
1871 {
1872 reason = "as-path contains our own AS;";
1873 goto filtered;
1874 }
1875
1876 /* Route reflector originator ID check. */
1877 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1878 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1879 {
1880 reason = "originator is us;";
1881 goto filtered;
1882 }
1883
1884 /* Route reflector cluster ID check. */
1885 if (bgp_cluster_filter (peer, attr))
1886 {
1887 reason = "reflected from the same cluster;";
1888 goto filtered;
1889 }
1890
1891 /* Apply incoming filter. */
1892 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1893 {
1894 reason = "filter;";
1895 goto filtered;
1896 }
1897
1898 /* Apply incoming route-map. */
1899 new_attr = *attr;
1900
1901 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1902 {
1903 reason = "route-map;";
1904 goto filtered;
1905 }
1906
1907 /* IPv4 unicast next hop check. */
1908 if (afi == AFI_IP && safi == SAFI_UNICAST)
1909 {
1910 /* If the peer is EBGP and nexthop is not on connected route,
1911 discard it. */
1912 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1913 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00001914 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00001915 {
1916 reason = "non-connected next-hop;";
1917 goto filtered;
1918 }
1919
1920 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1921 must not be my own address. */
1922 if (bgp_nexthop_self (afi, &new_attr)
1923 || new_attr.nexthop.s_addr == 0
1924 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1925 {
1926 reason = "martian next-hop;";
1927 goto filtered;
1928 }
1929 }
1930
1931 attr_new = bgp_attr_intern (&new_attr);
1932
1933 /* If the update is implicit withdraw. */
1934 if (ri)
1935 {
1936 ri->uptime = time (NULL);
1937
1938 /* Same attribute comes in. */
1939 if (attrhash_cmp (ri->attr, attr_new))
1940 {
1941 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1942
1943 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1944 && peer_sort (peer) == BGP_PEER_EBGP
1945 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1946 {
1947 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001948 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001949 peer->host,
1950 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1951 p->prefixlen);
1952
1953 peer->pcount[afi][safi]++;
1954 ret = bgp_damp_update (ri, rn, afi, safi);
1955 if (ret != BGP_DAMP_SUPPRESSED)
1956 {
1957 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1958 bgp_process (bgp, rn, afi, safi);
1959 }
1960 }
1961 else
1962 {
1963 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001964 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00001965 "%s rcvd %s/%d...duplicate ignored",
1966 peer->host,
1967 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1968 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00001969
1970 /* graceful restart STALE flag unset. */
1971 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1972 {
1973 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1974 peer->pcount[afi][safi]++;
1975 }
paul718e3742002-12-13 20:15:29 +00001976 }
1977
1978 bgp_unlock_node (rn);
1979 bgp_attr_unintern (attr_new);
1980 return 0;
1981 }
1982
1983 /* Received Logging. */
1984 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001985 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001986 peer->host,
1987 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1988 p->prefixlen);
1989
hasso93406d82005-02-02 14:40:33 +00001990 /* graceful restart STALE flag unset. */
1991 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1992 {
1993 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1994 peer->pcount[afi][safi]++;
1995 }
1996
paul718e3742002-12-13 20:15:29 +00001997 /* The attribute is changed. */
1998 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1999
2000 /* Update bgp route dampening information. */
2001 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2002 && peer_sort (peer) == BGP_PEER_EBGP)
2003 {
2004 /* This is implicit withdraw so we should update dampening
2005 information. */
2006 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2007 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2008 else
2009 peer->pcount[afi][safi]++;
2010 }
2011
2012 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2013
2014 /* Update to new attribute. */
2015 bgp_attr_unintern (ri->attr);
2016 ri->attr = attr_new;
2017
2018 /* Update MPLS tag. */
2019 if (safi == SAFI_MPLS_VPN)
2020 memcpy (ri->tag, tag, 3);
2021
2022 /* Update bgp route dampening information. */
2023 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2024 && peer_sort (peer) == BGP_PEER_EBGP)
2025 {
2026 /* Now we do normal update dampening. */
2027 ret = bgp_damp_update (ri, rn, afi, safi);
2028 if (ret == BGP_DAMP_SUPPRESSED)
2029 {
2030 bgp_unlock_node (rn);
2031 return 0;
2032 }
2033 }
2034
2035 /* Nexthop reachability check. */
2036 if ((afi == AFI_IP || afi == AFI_IP6)
2037 && safi == SAFI_UNICAST
2038 && (peer_sort (peer) == BGP_PEER_IBGP
2039 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002040 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002041 {
2042 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
2043 SET_FLAG (ri->flags, BGP_INFO_VALID);
2044 else
2045 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2046 }
2047 else
2048 SET_FLAG (ri->flags, BGP_INFO_VALID);
2049
2050 /* Process change. */
2051 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2052
2053 bgp_process (bgp, rn, afi, safi);
2054 bgp_unlock_node (rn);
2055 return 0;
2056 }
2057
2058 /* Received Logging. */
2059 if (BGP_DEBUG (update, UPDATE_IN))
2060 {
ajsd2c1f162004-12-08 21:10:20 +00002061 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002062 peer->host,
2063 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2064 p->prefixlen);
2065 }
2066
2067 /* Increment prefix counter */
2068 peer->pcount[afi][safi]++;
2069
2070 /* Make new BGP info. */
2071 new = bgp_info_new ();
2072 new->type = type;
2073 new->sub_type = sub_type;
2074 new->peer = peer;
2075 new->attr = attr_new;
2076 new->uptime = time (NULL);
2077
2078 /* Update MPLS tag. */
2079 if (safi == SAFI_MPLS_VPN)
2080 memcpy (new->tag, tag, 3);
2081
2082 /* Nexthop reachability check. */
2083 if ((afi == AFI_IP || afi == AFI_IP6)
2084 && safi == SAFI_UNICAST
2085 && (peer_sort (peer) == BGP_PEER_IBGP
2086 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002087 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002088 {
2089 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
2090 SET_FLAG (new->flags, BGP_INFO_VALID);
2091 else
2092 UNSET_FLAG (new->flags, BGP_INFO_VALID);
2093 }
2094 else
2095 SET_FLAG (new->flags, BGP_INFO_VALID);
2096
2097 /* Aggregate address increment. */
2098 bgp_aggregate_increment (bgp, p, new, afi, safi);
2099
2100 /* Register new BGP information. */
2101 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002102
2103 /* route_node_get lock */
2104 bgp_unlock_node (rn);
2105
paul718e3742002-12-13 20:15:29 +00002106 /* If maximum prefix count is configured and current prefix
2107 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002108 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2109 return -1;
paul718e3742002-12-13 20:15:29 +00002110
2111 /* Process change. */
2112 bgp_process (bgp, rn, afi, safi);
2113
2114 return 0;
2115
2116 /* This BGP update is filtered. Log the reason then update BGP
2117 entry. */
2118 filtered:
2119 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002120 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002121 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2122 peer->host,
2123 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2124 p->prefixlen, reason);
2125
2126 if (ri)
paulb40d9392005-08-22 22:34:41 +00002127 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002128
2129 bgp_unlock_node (rn);
2130
2131 return 0;
2132}
2133
2134int
paulfee0f4c2004-09-13 05:12:46 +00002135bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2136 afi_t afi, safi_t safi, int type, int sub_type,
2137 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2138{
2139 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002140 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002141 struct bgp *bgp;
2142 int ret;
2143
2144 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2145 soft_reconfig);
2146
2147 bgp = peer->bgp;
2148
2149 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002150 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002151 {
2152 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2153 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2154 sub_type, prd, tag);
2155 }
2156
2157 return ret;
2158}
2159
2160int
paul718e3742002-12-13 20:15:29 +00002161bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002162 afi_t afi, safi_t safi, int type, int sub_type,
2163 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002164{
2165 struct bgp *bgp;
2166 char buf[SU_ADDRSTRLEN];
2167 struct bgp_node *rn;
2168 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002169 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002170 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002171
2172 bgp = peer->bgp;
2173
paulfee0f4c2004-09-13 05:12:46 +00002174 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002175 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002176 {
2177 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2178 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2179 }
2180
paul718e3742002-12-13 20:15:29 +00002181 /* Logging. */
2182 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002183 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002184 peer->host,
2185 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2186 p->prefixlen);
2187
2188 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002189 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002190
2191 /* If peer is soft reconfiguration enabled. Record input packet for
2192 further calculation. */
2193 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2194 && peer != bgp->peer_self)
2195 bgp_adj_in_unset (rn, peer);
2196
2197 /* Lookup withdrawn route. */
2198 for (ri = rn->info; ri; ri = ri->next)
2199 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2200 break;
2201
2202 /* Withdraw specified route from routing table. */
2203 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002204 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002205 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002206 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002207 "%s Can't find the route %s/%d", peer->host,
2208 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2209 p->prefixlen);
2210
2211 /* Unlock bgp_node_get() lock. */
2212 bgp_unlock_node (rn);
2213
2214 return 0;
2215}
2216
2217void
2218bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2219{
2220 struct bgp *bgp;
2221 struct attr attr;
2222 struct aspath *aspath;
2223 struct prefix p;
2224 struct bgp_info binfo;
2225 struct peer *from;
2226 int ret = RMAP_DENYMATCH;
2227
2228 bgp = peer->bgp;
2229 from = bgp->peer_self;
2230
2231 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2232 aspath = attr.aspath;
2233 attr.local_pref = bgp->default_local_pref;
2234 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2235
2236 if (afi == AFI_IP)
2237 str2prefix ("0.0.0.0/0", &p);
2238#ifdef HAVE_IPV6
2239 else if (afi == AFI_IP6)
2240 {
2241 str2prefix ("::/0", &p);
2242
2243 /* IPv6 global nexthop must be included. */
2244 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2245 IPV6_MAX_BYTELEN);
2246 attr.mp_nexthop_len = 16;
2247
2248 /* If the peer is on shared nextwork and we have link-local
2249 nexthop set it. */
2250 if (peer->shared_network
2251 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2252 {
2253 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2254 IPV6_MAX_BYTELEN);
2255 attr.mp_nexthop_len = 32;
2256 }
2257 }
2258#endif /* HAVE_IPV6 */
2259 else
2260 return;
2261
2262 if (peer->default_rmap[afi][safi].name)
2263 {
2264 binfo.peer = bgp->peer_self;
2265 binfo.attr = &attr;
2266
paulfee0f4c2004-09-13 05:12:46 +00002267 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2268
paul718e3742002-12-13 20:15:29 +00002269 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2270 RMAP_BGP, &binfo);
2271
paulfee0f4c2004-09-13 05:12:46 +00002272 bgp->peer_self->rmap_type = 0;
2273
paul718e3742002-12-13 20:15:29 +00002274 if (ret == RMAP_DENYMATCH)
2275 {
2276 bgp_attr_flush (&attr);
2277 withdraw = 1;
2278 }
2279 }
2280
2281 if (withdraw)
2282 {
2283 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2284 bgp_default_withdraw_send (peer, afi, safi);
2285 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2286 }
2287 else
2288 {
2289 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2290 bgp_default_update_send (peer, &attr, afi, safi, from);
2291 }
2292
2293 aspath_unintern (aspath);
2294}
2295
2296static void
2297bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002298 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002299{
2300 struct bgp_node *rn;
2301 struct bgp_info *ri;
2302 struct attr attr;
2303
2304 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002305 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002306
2307 if (safi != SAFI_MPLS_VPN
2308 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2309 bgp_default_originate (peer, afi, safi, 0);
2310
2311 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2312 for (ri = rn->info; ri; ri = ri->next)
2313 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2314 {
paulfee0f4c2004-09-13 05:12:46 +00002315 if ( (rsclient) ?
2316 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2317 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002318 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2319 else
2320 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2321 }
2322}
2323
2324void
2325bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2326{
2327 struct bgp_node *rn;
2328 struct bgp_table *table;
2329
2330 if (peer->status != Established)
2331 return;
2332
2333 if (! peer->afc_nego[afi][safi])
2334 return;
2335
2336 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2337 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2338 return;
2339
2340 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002341 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002342 else
2343 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2344 rn = bgp_route_next(rn))
2345 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002346 bgp_announce_table (peer, afi, safi, table, 0);
2347
2348 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2349 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002350}
2351
2352void
2353bgp_announce_route_all (struct peer *peer)
2354{
2355 afi_t afi;
2356 safi_t safi;
2357
2358 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2359 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2360 bgp_announce_route (peer, afi, safi);
2361}
2362
2363static void
paulfee0f4c2004-09-13 05:12:46 +00002364bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2365 safi_t safi, struct bgp_table *table)
2366{
2367 struct bgp_node *rn;
2368 struct bgp_adj_in *ain;
2369
2370 if (! table)
2371 table = rsclient->bgp->rib[afi][safi];
2372
2373 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2374 for (ain = rn->adj_in; ain; ain = ain->next)
2375 {
2376 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2377 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2378 }
2379}
2380
2381void
2382bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2383{
2384 struct bgp_table *table;
2385 struct bgp_node *rn;
2386
2387 if (safi != SAFI_MPLS_VPN)
2388 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2389
2390 else
2391 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2392 rn = bgp_route_next (rn))
2393 if ((table = rn->info) != NULL)
2394 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2395}
2396
2397static void
paul718e3742002-12-13 20:15:29 +00002398bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2399 struct bgp_table *table)
2400{
2401 int ret;
2402 struct bgp_node *rn;
2403 struct bgp_adj_in *ain;
2404
2405 if (! table)
2406 table = peer->bgp->rib[afi][safi];
2407
2408 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2409 for (ain = rn->adj_in; ain; ain = ain->next)
2410 {
2411 if (ain->peer == peer)
2412 {
2413 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2414 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2415 NULL, NULL, 1);
2416 if (ret < 0)
2417 {
2418 bgp_unlock_node (rn);
2419 return;
2420 }
2421 continue;
2422 }
2423 }
2424}
2425
2426void
2427bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2428{
2429 struct bgp_node *rn;
2430 struct bgp_table *table;
2431
2432 if (peer->status != Established)
2433 return;
2434
2435 if (safi != SAFI_MPLS_VPN)
2436 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2437 else
2438 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2439 rn = bgp_route_next (rn))
2440 if ((table = rn->info) != NULL)
2441 bgp_soft_reconfig_table (peer, afi, safi, table);
2442}
2443
paul200df112005-06-01 11:17:05 +00002444struct bgp_clear_node_queue
2445{
2446 struct bgp_node *rn;
2447 struct peer *peer;
2448 afi_t afi;
2449 safi_t safi;
2450};
2451
2452static wq_item_status
2453bgp_clear_route_node (struct bgp_clear_node_queue *cq)
2454{
2455 struct bgp_adj_in *ain;
2456 struct bgp_adj_out *aout;
2457 struct bgp_info *ri;
2458
2459 assert (cq->rn && cq->peer);
2460
2461 for (ri = cq->rn->info; ri; ri = ri->next)
2462 if (ri->peer == cq->peer)
2463 {
2464 /* graceful restart STALE flag set. */
2465 if (CHECK_FLAG (cq->peer->sflags, PEER_STATUS_NSF_WAIT)
2466 && cq->peer->nsf[cq->afi][cq->safi]
2467 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2468 && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
2469 && ! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2470 {
2471 SET_FLAG (ri->flags, BGP_INFO_STALE);
2472 cq->peer->pcount[cq->afi][cq->safi]--;
2473 }
2474 else
2475 bgp_rib_remove (cq->rn, ri, cq->peer, cq->afi, cq->safi);
2476 break;
2477 }
2478 for (ain = cq->rn->adj_in; ain; ain = ain->next)
2479 if (ain->peer == cq->peer)
2480 {
2481 bgp_adj_in_remove (cq->rn, ain);
2482 bgp_unlock_node (cq->rn);
2483 break;
2484 }
2485 for (aout = cq->rn->adj_out; aout; aout = aout->next)
2486 if (aout->peer == cq->peer)
2487 {
2488 bgp_adj_out_remove (cq->rn, aout, cq->peer, cq->afi, cq->safi);
2489 bgp_unlock_node (cq->rn);
2490 break;
2491 }
2492 return WQ_SUCCESS;
2493}
2494
2495static void
2496bgp_clear_node_queue_del (struct bgp_clear_node_queue *cq)
2497{
2498 bgp_unlock_node (cq->rn);
2499 peer_unlock (cq->peer); /* bgp_clear_node_queue_del */
2500 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cq);
2501}
2502
2503static void
paul94f2b392005-06-28 12:44:16 +00002504bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002505{
2506 /* unplug the 2 processing queues */
2507 if (bm->process_main_queue)
2508 work_queue_unplug (bm->process_main_queue);
2509 if (bm->process_rsclient_queue)
2510 work_queue_unplug (bm->process_rsclient_queue);
2511}
2512
2513static void
2514bgp_clear_node_queue_init (void)
2515{
2516 if ( (bm->clear_node_queue
2517 = work_queue_new (bm->master, "clear_route_node")) == NULL)
2518 {
2519 zlog_err ("%s: Failed to allocate work queue", __func__);
2520 exit (1);
2521 }
2522 bm->clear_node_queue->spec.hold = 10;
2523 bm->clear_node_queue->spec.delay = 0; /* no gathering to be gained */
2524 bm->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2525 bm->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2526 bm->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2527 bm->clear_node_queue->spec.max_retries = 0;
2528}
2529
paul718e3742002-12-13 20:15:29 +00002530static void
2531bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002532 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002533{
paul200df112005-06-01 11:17:05 +00002534 struct bgp_clear_node_queue *cqnode;
paul718e3742002-12-13 20:15:29 +00002535 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002536
paul718e3742002-12-13 20:15:29 +00002537 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002538 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002539
hasso6cf159b2005-03-21 10:28:14 +00002540 /* If still no table => afi/safi isn't configured at all or smth. */
2541 if (! table)
2542 return;
2543
paul200df112005-06-01 11:17:05 +00002544 if (bm->clear_node_queue == NULL)
2545 bgp_clear_node_queue_init ();
2546
2547 /* plug the two bgp_process queues to avoid any chance of racing
2548 * with a session coming back up and adding routes before we've
2549 * cleared them all. We'll unplug them with completion callback.
2550 */
2551 if (bm->process_main_queue)
2552 work_queue_plug (bm->process_main_queue);
2553 if (bm->process_rsclient_queue)
2554 work_queue_plug (bm->process_rsclient_queue);
2555
paul718e3742002-12-13 20:15:29 +00002556 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2557 {
paul200df112005-06-01 11:17:05 +00002558 if (rn->info == NULL)
2559 continue;
2560
2561 if ( (cqnode = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2562 sizeof (struct bgp_clear_node_queue))) == NULL)
2563 continue;
2564
2565 cqnode->rn = bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2566 cqnode->afi = afi;
2567 cqnode->safi = safi;
2568 cqnode->peer = peer_lock (peer); /* bgp_clear_node_queue_del */
2569 work_queue_add (bm->clear_node_queue, cqnode);
paul718e3742002-12-13 20:15:29 +00002570 }
paul200df112005-06-01 11:17:05 +00002571 return;
paul718e3742002-12-13 20:15:29 +00002572}
2573
2574void
2575bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2576{
2577 struct bgp_node *rn;
2578 struct bgp_table *table;
paulfee0f4c2004-09-13 05:12:46 +00002579 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002580 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002581
paul718e3742002-12-13 20:15:29 +00002582 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002583 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002584 else
2585 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2586 rn = bgp_route_next (rn))
2587 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002588 bgp_clear_route_table (peer, afi, safi, table, NULL);
2589
paul1eb8ef22005-04-07 07:30:20 +00002590 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002591 {
2592 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2593 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2594 }
paul718e3742002-12-13 20:15:29 +00002595}
2596
2597void
2598bgp_clear_route_all (struct peer *peer)
2599{
2600 afi_t afi;
2601 safi_t safi;
2602
2603 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2604 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2605 bgp_clear_route (peer, afi, safi);
2606}
2607
2608void
2609bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2610{
2611 struct bgp_table *table;
2612 struct bgp_node *rn;
2613 struct bgp_adj_in *ain;
2614
2615 table = peer->bgp->rib[afi][safi];
2616
2617 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2618 for (ain = rn->adj_in; ain ; ain = ain->next)
2619 if (ain->peer == peer)
2620 {
2621 bgp_adj_in_remove (rn, ain);
2622 bgp_unlock_node (rn);
2623 break;
2624 }
2625}
hasso93406d82005-02-02 14:40:33 +00002626
2627void
2628bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2629{
2630 struct bgp_node *rn;
2631 struct bgp_info *ri;
2632 struct bgp_table *table;
2633
2634 table = peer->bgp->rib[afi][safi];
2635
2636 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2637 {
2638 for (ri = rn->info; ri; ri = ri->next)
2639 if (ri->peer == peer)
2640 {
2641 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2642 bgp_rib_remove (rn, ri, peer, afi, safi);
2643 break;
2644 }
2645 }
2646}
paul718e3742002-12-13 20:15:29 +00002647
2648/* Delete all kernel routes. */
2649void
paul545acaf2004-04-20 15:13:15 +00002650bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002651{
2652 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002653 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002654 struct bgp_node *rn;
2655 struct bgp_table *table;
2656 struct bgp_info *ri;
2657
paul1eb8ef22005-04-07 07:30:20 +00002658 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002659 {
2660 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2661
2662 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2663 for (ri = rn->info; ri; ri = ri->next)
2664 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2665 && ri->type == ZEBRA_ROUTE_BGP
2666 && ri->sub_type == BGP_ROUTE_NORMAL)
2667 bgp_zebra_withdraw (&rn->p, ri);
2668
2669 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2670
2671 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2672 for (ri = rn->info; ri; ri = ri->next)
2673 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2674 && ri->type == ZEBRA_ROUTE_BGP
2675 && ri->sub_type == BGP_ROUTE_NORMAL)
2676 bgp_zebra_withdraw (&rn->p, ri);
2677 }
2678}
2679
2680void
2681bgp_reset ()
2682{
2683 vty_reset ();
2684 bgp_zclient_reset ();
2685 access_list_reset ();
2686 prefix_list_reset ();
2687}
2688
2689/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2690 value. */
2691int
2692bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2693{
2694 u_char *pnt;
2695 u_char *lim;
2696 struct prefix p;
2697 int psize;
2698 int ret;
2699
2700 /* Check peer status. */
2701 if (peer->status != Established)
2702 return 0;
2703
2704 pnt = packet->nlri;
2705 lim = pnt + packet->length;
2706
2707 for (; pnt < lim; pnt += psize)
2708 {
2709 /* Clear prefix structure. */
2710 memset (&p, 0, sizeof (struct prefix));
2711
2712 /* Fetch prefix length. */
2713 p.prefixlen = *pnt++;
2714 p.family = afi2family (packet->afi);
2715
2716 /* Already checked in nlri_sanity_check(). We do double check
2717 here. */
2718 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2719 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2720 return -1;
2721
2722 /* Packet size overflow check. */
2723 psize = PSIZE (p.prefixlen);
2724
2725 /* When packet overflow occur return immediately. */
2726 if (pnt + psize > lim)
2727 return -1;
2728
2729 /* Fetch prefix from NLRI packet. */
2730 memcpy (&p.u.prefix, pnt, psize);
2731
2732 /* Check address. */
2733 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2734 {
2735 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2736 {
paulf5ba3872004-07-09 12:11:31 +00002737 /*
2738 * From draft-ietf-idr-bgp4-22, Section 6.3:
2739 * If a BGP router receives an UPDATE message with a
2740 * semantically incorrect NLRI field, in which a prefix is
2741 * semantically incorrect (eg. an unexpected multicast IP
2742 * address), it should ignore the prefix.
2743 */
paul718e3742002-12-13 20:15:29 +00002744 zlog (peer->log, LOG_ERR,
2745 "IPv4 unicast NLRI is multicast address %s",
2746 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002747
paul718e3742002-12-13 20:15:29 +00002748 return -1;
2749 }
2750 }
2751
2752#ifdef HAVE_IPV6
2753 /* Check address. */
2754 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2755 {
2756 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2757 {
2758 char buf[BUFSIZ];
2759
2760 zlog (peer->log, LOG_WARNING,
2761 "IPv6 link-local NLRI received %s ignore this NLRI",
2762 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2763
2764 continue;
2765 }
2766 }
2767#endif /* HAVE_IPV6 */
2768
2769 /* Normal process. */
2770 if (attr)
2771 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2772 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2773 else
2774 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2775 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2776
2777 /* Address family configuration mismatch or maximum-prefix count
2778 overflow. */
2779 if (ret < 0)
2780 return -1;
2781 }
2782
2783 /* Packet length consistency check. */
2784 if (pnt != lim)
2785 return -1;
2786
2787 return 0;
2788}
2789
2790/* NLRI encode syntax check routine. */
2791int
2792bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2793 bgp_size_t length)
2794{
2795 u_char *end;
2796 u_char prefixlen;
2797 int psize;
2798
2799 end = pnt + length;
2800
2801 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2802 syntactic validity. If the field is syntactically incorrect,
2803 then the Error Subcode is set to Invalid Network Field. */
2804
2805 while (pnt < end)
2806 {
2807 prefixlen = *pnt++;
2808
2809 /* Prefix length check. */
2810 if ((afi == AFI_IP && prefixlen > 32)
2811 || (afi == AFI_IP6 && prefixlen > 128))
2812 {
2813 plog_err (peer->log,
2814 "%s [Error] Update packet error (wrong prefix length %d)",
2815 peer->host, prefixlen);
2816 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2817 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2818 return -1;
2819 }
2820
2821 /* Packet size overflow check. */
2822 psize = PSIZE (prefixlen);
2823
2824 if (pnt + psize > end)
2825 {
2826 plog_err (peer->log,
2827 "%s [Error] Update packet error"
2828 " (prefix data overflow prefix size is %d)",
2829 peer->host, psize);
2830 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2831 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2832 return -1;
2833 }
2834
2835 pnt += psize;
2836 }
2837
2838 /* Packet length consistency check. */
2839 if (pnt != end)
2840 {
2841 plog_err (peer->log,
2842 "%s [Error] Update packet error"
2843 " (prefix length mismatch with total length)",
2844 peer->host);
2845 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2846 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2847 return -1;
2848 }
2849 return 0;
2850}
2851
paul94f2b392005-06-28 12:44:16 +00002852static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002853bgp_static_new ()
2854{
2855 struct bgp_static *new;
2856 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2857 memset (new, 0, sizeof (struct bgp_static));
2858 return new;
2859}
2860
paul94f2b392005-06-28 12:44:16 +00002861static void
paul718e3742002-12-13 20:15:29 +00002862bgp_static_free (struct bgp_static *bgp_static)
2863{
2864 if (bgp_static->rmap.name)
2865 free (bgp_static->rmap.name);
2866 XFREE (MTYPE_BGP_STATIC, bgp_static);
2867}
2868
paul94f2b392005-06-28 12:44:16 +00002869static void
paulfee0f4c2004-09-13 05:12:46 +00002870bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2871 struct prefix *p, afi_t afi, safi_t safi)
2872{
2873 struct bgp_node *rn;
2874 struct bgp_info *ri;
2875
2876 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2877
2878 /* Check selected route and self inserted route. */
2879 for (ri = rn->info; ri; ri = ri->next)
2880 if (ri->peer == bgp->peer_self
2881 && ri->type == ZEBRA_ROUTE_BGP
2882 && ri->sub_type == BGP_ROUTE_STATIC)
2883 break;
2884
2885 /* Withdraw static BGP route from routing table. */
2886 if (ri)
2887 {
2888 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2889 bgp_process (bgp, rn, afi, safi);
2890 bgp_info_delete (rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00002891 }
2892
2893 /* Unlock bgp_node_lookup. */
2894 bgp_unlock_node (rn);
2895}
2896
paul94f2b392005-06-28 12:44:16 +00002897static void
paulfee0f4c2004-09-13 05:12:46 +00002898bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2899 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2900{
2901 struct bgp_node *rn;
2902 struct bgp_info *ri;
2903 struct bgp_info *new;
2904 struct bgp_info info;
2905 struct attr new_attr;
2906 struct attr *attr_new;
2907 struct attr attr;
2908 struct bgp *bgp;
2909 int ret;
2910 char buf[SU_ADDRSTRLEN];
2911
2912 bgp = rsclient->bgp;
2913
2914 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2915
2916 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2917 if (bgp_static)
2918 {
2919 attr.nexthop = bgp_static->igpnexthop;
2920 attr.med = bgp_static->igpmetric;
2921 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
2922 }
2923
2924 new_attr = attr;
2925
2926 /* Apply network route-map for export to this rsclient. */
2927 if (bgp_static->rmap.name)
2928 {
2929 info.peer = rsclient;
2930 info.attr = &new_attr;
2931
2932 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2933 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2934
2935 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2936
2937 rsclient->rmap_type = 0;
2938
2939 if (ret == RMAP_DENYMATCH)
2940 {
2941 /* Free uninterned attribute. */
2942 bgp_attr_flush (&new_attr);
2943
2944 /* Unintern original. */
2945 aspath_unintern (attr.aspath);
2946 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2947
2948 return;
2949 }
2950 attr_new = bgp_attr_intern (&new_attr);
2951 }
2952 else
2953 attr_new = bgp_attr_intern (&attr);
2954
2955 new_attr = *attr_new;
2956
2957 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2958
2959 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2960{
2961 /* This BGP update is filtered. Log the reason then update BGP entry. */
2962 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002963 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002964 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
2965 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2966 p->prefixlen, rsclient->host);
2967
2968 bgp->peer_self->rmap_type = 0;
2969
2970 bgp_attr_unintern (attr_new);
2971 aspath_unintern (attr.aspath);
2972
2973 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2974
2975 return;
2976 }
2977
2978 bgp->peer_self->rmap_type = 0;
2979
2980 bgp_attr_unintern (attr_new);
2981 attr_new = bgp_attr_intern (&new_attr);
2982
2983 for (ri = rn->info; ri; ri = ri->next)
2984 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
2985 && ri->sub_type == BGP_ROUTE_STATIC)
2986 break;
2987
2988 if (ri)
2989 {
2990 if (attrhash_cmp (ri->attr, attr_new))
2991 {
2992 bgp_unlock_node (rn);
2993 bgp_attr_unintern (attr_new);
2994 aspath_unintern (attr.aspath);
2995 return;
2996 }
2997 else
2998 {
2999 /* The attribute is changed. */
3000 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3001
3002 /* Rewrite BGP route information. */
3003 bgp_attr_unintern (ri->attr);
3004 ri->attr = attr_new;
3005 ri->uptime = time (NULL);
3006
3007 /* Process change. */
3008 bgp_process (bgp, rn, afi, safi);
3009 bgp_unlock_node (rn);
3010 aspath_unintern (attr.aspath);
3011 return;
3012 }
3013}
3014
3015 /* Make new BGP info. */
3016 new = bgp_info_new ();
3017 new->type = ZEBRA_ROUTE_BGP;
3018 new->sub_type = BGP_ROUTE_STATIC;
3019 new->peer = bgp->peer_self;
3020 SET_FLAG (new->flags, BGP_INFO_VALID);
3021 new->attr = attr_new;
3022 new->uptime = time (NULL);
3023
3024 /* Register new BGP information. */
3025 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003026
3027 /* route_node_get lock */
3028 bgp_unlock_node (rn);
3029
paulfee0f4c2004-09-13 05:12:46 +00003030 /* Process change. */
3031 bgp_process (bgp, rn, afi, safi);
3032
3033 /* Unintern original. */
3034 aspath_unintern (attr.aspath);
3035}
3036
paul94f2b392005-06-28 12:44:16 +00003037static void
paulfee0f4c2004-09-13 05:12:46 +00003038bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003039 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3040{
3041 struct bgp_node *rn;
3042 struct bgp_info *ri;
3043 struct bgp_info *new;
3044 struct bgp_info info;
3045 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003046 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003047 struct attr *attr_new;
3048 int ret;
3049
paulfee0f4c2004-09-13 05:12:46 +00003050 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003051
3052 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3053 if (bgp_static)
3054 {
3055 attr.nexthop = bgp_static->igpnexthop;
3056 attr.med = bgp_static->igpmetric;
3057 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3058 }
3059
3060 /* Apply route-map. */
3061 if (bgp_static->rmap.name)
3062 {
paul286e1e72003-08-08 00:24:31 +00003063 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003064 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003065 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003066
paulfee0f4c2004-09-13 05:12:46 +00003067 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3068
paul718e3742002-12-13 20:15:29 +00003069 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003070
paulfee0f4c2004-09-13 05:12:46 +00003071 bgp->peer_self->rmap_type = 0;
3072
paul718e3742002-12-13 20:15:29 +00003073 if (ret == RMAP_DENYMATCH)
3074 {
3075 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003076 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003077
3078 /* Unintern original. */
3079 aspath_unintern (attr.aspath);
3080 bgp_static_withdraw (bgp, p, afi, safi);
3081 return;
3082 }
paul286e1e72003-08-08 00:24:31 +00003083 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003084 }
paul286e1e72003-08-08 00:24:31 +00003085 else
3086 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003087
3088 for (ri = rn->info; ri; ri = ri->next)
3089 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3090 && ri->sub_type == BGP_ROUTE_STATIC)
3091 break;
3092
3093 if (ri)
3094 {
3095 if (attrhash_cmp (ri->attr, attr_new))
3096 {
3097 bgp_unlock_node (rn);
3098 bgp_attr_unintern (attr_new);
3099 aspath_unintern (attr.aspath);
3100 return;
3101 }
3102 else
3103 {
3104 /* The attribute is changed. */
3105 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3106
3107 /* Rewrite BGP route information. */
3108 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3109 bgp_attr_unintern (ri->attr);
3110 ri->attr = attr_new;
3111 ri->uptime = time (NULL);
3112
3113 /* Process change. */
3114 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3115 bgp_process (bgp, rn, afi, safi);
3116 bgp_unlock_node (rn);
3117 aspath_unintern (attr.aspath);
3118 return;
3119 }
3120 }
3121
3122 /* Make new BGP info. */
3123 new = bgp_info_new ();
3124 new->type = ZEBRA_ROUTE_BGP;
3125 new->sub_type = BGP_ROUTE_STATIC;
3126 new->peer = bgp->peer_self;
3127 SET_FLAG (new->flags, BGP_INFO_VALID);
3128 new->attr = attr_new;
3129 new->uptime = time (NULL);
3130
3131 /* Aggregate address increment. */
3132 bgp_aggregate_increment (bgp, p, new, afi, safi);
3133
3134 /* Register new BGP information. */
3135 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003136
3137 /* route_node_get lock */
3138 bgp_unlock_node (rn);
3139
paul718e3742002-12-13 20:15:29 +00003140 /* Process change. */
3141 bgp_process (bgp, rn, afi, safi);
3142
3143 /* Unintern original. */
3144 aspath_unintern (attr.aspath);
3145}
3146
3147void
paulfee0f4c2004-09-13 05:12:46 +00003148bgp_static_update (struct bgp *bgp, struct prefix *p,
3149 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3150{
3151 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003152 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003153
3154 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3155
paul1eb8ef22005-04-07 07:30:20 +00003156 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003157 {
3158 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3159 }
3160}
3161
paul94f2b392005-06-28 12:44:16 +00003162static void
paul718e3742002-12-13 20:15:29 +00003163bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3164 u_char safi, struct prefix_rd *prd, u_char *tag)
3165{
3166 struct bgp_node *rn;
3167 struct bgp_info *new;
3168
paulfee0f4c2004-09-13 05:12:46 +00003169 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003170
3171 /* Make new BGP info. */
3172 new = bgp_info_new ();
3173 new->type = ZEBRA_ROUTE_BGP;
3174 new->sub_type = BGP_ROUTE_STATIC;
3175 new->peer = bgp->peer_self;
3176 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3177 SET_FLAG (new->flags, BGP_INFO_VALID);
3178 new->uptime = time (NULL);
3179 memcpy (new->tag, tag, 3);
3180
3181 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003182 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003183
3184 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003185 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003186
paul200df112005-06-01 11:17:05 +00003187 /* route_node_get lock */
3188 bgp_unlock_node (rn);
3189
paul718e3742002-12-13 20:15:29 +00003190 /* Process change. */
3191 bgp_process (bgp, rn, afi, safi);
3192}
3193
3194void
3195bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3196 safi_t safi)
3197{
3198 struct bgp_node *rn;
3199 struct bgp_info *ri;
3200
paulfee0f4c2004-09-13 05:12:46 +00003201 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003202
3203 /* Check selected route and self inserted route. */
3204 for (ri = rn->info; ri; ri = ri->next)
3205 if (ri->peer == bgp->peer_self
3206 && ri->type == ZEBRA_ROUTE_BGP
3207 && ri->sub_type == BGP_ROUTE_STATIC)
3208 break;
3209
3210 /* Withdraw static BGP route from routing table. */
3211 if (ri)
3212 {
3213 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3214 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3215 bgp_process (bgp, rn, afi, safi);
3216 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003217 }
3218
3219 /* Unlock bgp_node_lookup. */
3220 bgp_unlock_node (rn);
3221}
3222
3223void
paulfee0f4c2004-09-13 05:12:46 +00003224bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3225{
3226 struct bgp_static *bgp_static;
3227 struct bgp *bgp;
3228 struct bgp_node *rn;
3229 struct prefix *p;
3230
3231 bgp = rsclient->bgp;
3232
3233 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3234 if ((bgp_static = rn->info) != NULL)
3235 {
3236 p = &rn->p;
3237
3238 bgp_static_update_rsclient (rsclient, p, bgp_static,
3239 afi, safi);
3240 }
3241}
3242
paul94f2b392005-06-28 12:44:16 +00003243static void
paul718e3742002-12-13 20:15:29 +00003244bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3245 u_char safi, struct prefix_rd *prd, u_char *tag)
3246{
3247 struct bgp_node *rn;
3248 struct bgp_info *ri;
3249
paulfee0f4c2004-09-13 05:12:46 +00003250 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003251
3252 /* Check selected route and self inserted route. */
3253 for (ri = rn->info; ri; ri = ri->next)
3254 if (ri->peer == bgp->peer_self
3255 && ri->type == ZEBRA_ROUTE_BGP
3256 && ri->sub_type == BGP_ROUTE_STATIC)
3257 break;
3258
3259 /* Withdraw static BGP route from routing table. */
3260 if (ri)
3261 {
3262 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3263 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3264 bgp_process (bgp, rn, afi, safi);
3265 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003266 }
3267
3268 /* Unlock bgp_node_lookup. */
3269 bgp_unlock_node (rn);
3270}
3271
3272/* Configure static BGP network. When user don't run zebra, static
3273 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003274static int
paulfd79ac92004-10-13 05:06:08 +00003275bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3276 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003277{
3278 int ret;
3279 struct prefix p;
3280 struct bgp_static *bgp_static;
3281 struct bgp_node *rn;
3282 int need_update = 0;
3283
3284 /* Convert IP prefix string to struct prefix. */
3285 ret = str2prefix (ip_str, &p);
3286 if (! ret)
3287 {
3288 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3289 return CMD_WARNING;
3290 }
3291#ifdef HAVE_IPV6
3292 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3293 {
3294 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3295 VTY_NEWLINE);
3296 return CMD_WARNING;
3297 }
3298#endif /* HAVE_IPV6 */
3299
3300 apply_mask (&p);
3301
3302 /* Set BGP static route configuration. */
3303 rn = bgp_node_get (bgp->route[afi][safi], &p);
3304
3305 if (rn->info)
3306 {
3307 /* Configuration change. */
3308 bgp_static = rn->info;
3309
3310 /* Check previous routes are installed into BGP. */
3311 if (! bgp_static->backdoor && bgp_static->valid)
3312 need_update = 1;
3313
3314 bgp_static->backdoor = backdoor;
3315 if (rmap)
3316 {
3317 if (bgp_static->rmap.name)
3318 free (bgp_static->rmap.name);
3319 bgp_static->rmap.name = strdup (rmap);
3320 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3321 }
3322 else
3323 {
3324 if (bgp_static->rmap.name)
3325 free (bgp_static->rmap.name);
3326 bgp_static->rmap.name = NULL;
3327 bgp_static->rmap.map = NULL;
3328 bgp_static->valid = 0;
3329 }
3330 bgp_unlock_node (rn);
3331 }
3332 else
3333 {
3334 /* New configuration. */
3335 bgp_static = bgp_static_new ();
3336 bgp_static->backdoor = backdoor;
3337 bgp_static->valid = 0;
3338 bgp_static->igpmetric = 0;
3339 bgp_static->igpnexthop.s_addr = 0;
3340 if (rmap)
3341 {
3342 if (bgp_static->rmap.name)
3343 free (bgp_static->rmap.name);
3344 bgp_static->rmap.name = strdup (rmap);
3345 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3346 }
3347 rn->info = bgp_static;
3348 }
3349
3350 /* If BGP scan is not enabled, we should install this route here. */
3351 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3352 {
3353 bgp_static->valid = 1;
3354
3355 if (need_update)
3356 bgp_static_withdraw (bgp, &p, afi, safi);
3357
3358 if (! bgp_static->backdoor)
3359 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3360 }
3361
3362 return CMD_SUCCESS;
3363}
3364
3365/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003366static int
paulfd79ac92004-10-13 05:06:08 +00003367bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003368 u_int16_t afi, u_char safi)
3369{
3370 int ret;
3371 struct prefix p;
3372 struct bgp_static *bgp_static;
3373 struct bgp_node *rn;
3374
3375 /* Convert IP prefix string to struct prefix. */
3376 ret = str2prefix (ip_str, &p);
3377 if (! ret)
3378 {
3379 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3380 return CMD_WARNING;
3381 }
3382#ifdef HAVE_IPV6
3383 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3384 {
3385 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3386 VTY_NEWLINE);
3387 return CMD_WARNING;
3388 }
3389#endif /* HAVE_IPV6 */
3390
3391 apply_mask (&p);
3392
3393 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3394 if (! rn)
3395 {
3396 vty_out (vty, "%% Can't find specified static route configuration.%s",
3397 VTY_NEWLINE);
3398 return CMD_WARNING;
3399 }
3400
3401 bgp_static = rn->info;
3402
3403 /* Update BGP RIB. */
3404 if (! bgp_static->backdoor)
3405 bgp_static_withdraw (bgp, &p, afi, safi);
3406
3407 /* Clear configuration. */
3408 bgp_static_free (bgp_static);
3409 rn->info = NULL;
3410 bgp_unlock_node (rn);
3411 bgp_unlock_node (rn);
3412
3413 return CMD_SUCCESS;
3414}
3415
3416/* Called from bgp_delete(). Delete all static routes from the BGP
3417 instance. */
3418void
3419bgp_static_delete (struct bgp *bgp)
3420{
3421 afi_t afi;
3422 safi_t safi;
3423 struct bgp_node *rn;
3424 struct bgp_node *rm;
3425 struct bgp_table *table;
3426 struct bgp_static *bgp_static;
3427
3428 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3429 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3430 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3431 if (rn->info != NULL)
3432 {
3433 if (safi == SAFI_MPLS_VPN)
3434 {
3435 table = rn->info;
3436
3437 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3438 {
3439 bgp_static = rn->info;
3440 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3441 AFI_IP, SAFI_MPLS_VPN,
3442 (struct prefix_rd *)&rn->p,
3443 bgp_static->tag);
3444 bgp_static_free (bgp_static);
3445 rn->info = NULL;
3446 bgp_unlock_node (rn);
3447 }
3448 }
3449 else
3450 {
3451 bgp_static = rn->info;
3452 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3453 bgp_static_free (bgp_static);
3454 rn->info = NULL;
3455 bgp_unlock_node (rn);
3456 }
3457 }
3458}
3459
3460int
paulfd79ac92004-10-13 05:06:08 +00003461bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3462 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003463{
3464 int ret;
3465 struct prefix p;
3466 struct prefix_rd prd;
3467 struct bgp *bgp;
3468 struct bgp_node *prn;
3469 struct bgp_node *rn;
3470 struct bgp_table *table;
3471 struct bgp_static *bgp_static;
3472 u_char tag[3];
3473
3474 bgp = vty->index;
3475
3476 ret = str2prefix (ip_str, &p);
3477 if (! ret)
3478 {
3479 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3480 return CMD_WARNING;
3481 }
3482 apply_mask (&p);
3483
3484 ret = str2prefix_rd (rd_str, &prd);
3485 if (! ret)
3486 {
3487 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3488 return CMD_WARNING;
3489 }
3490
3491 ret = str2tag (tag_str, tag);
3492 if (! ret)
3493 {
3494 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3495 return CMD_WARNING;
3496 }
3497
3498 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3499 (struct prefix *)&prd);
3500 if (prn->info == NULL)
3501 prn->info = bgp_table_init ();
3502 else
3503 bgp_unlock_node (prn);
3504 table = prn->info;
3505
3506 rn = bgp_node_get (table, &p);
3507
3508 if (rn->info)
3509 {
3510 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3511 bgp_unlock_node (rn);
3512 }
3513 else
3514 {
3515 /* New configuration. */
3516 bgp_static = bgp_static_new ();
3517 bgp_static->valid = 1;
3518 memcpy (bgp_static->tag, tag, 3);
3519 rn->info = bgp_static;
3520
3521 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3522 }
3523
3524 return CMD_SUCCESS;
3525}
3526
3527/* Configure static BGP network. */
3528int
paulfd79ac92004-10-13 05:06:08 +00003529bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3530 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003531{
3532 int ret;
3533 struct bgp *bgp;
3534 struct prefix p;
3535 struct prefix_rd prd;
3536 struct bgp_node *prn;
3537 struct bgp_node *rn;
3538 struct bgp_table *table;
3539 struct bgp_static *bgp_static;
3540 u_char tag[3];
3541
3542 bgp = vty->index;
3543
3544 /* Convert IP prefix string to struct prefix. */
3545 ret = str2prefix (ip_str, &p);
3546 if (! ret)
3547 {
3548 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3549 return CMD_WARNING;
3550 }
3551 apply_mask (&p);
3552
3553 ret = str2prefix_rd (rd_str, &prd);
3554 if (! ret)
3555 {
3556 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3557 return CMD_WARNING;
3558 }
3559
3560 ret = str2tag (tag_str, tag);
3561 if (! ret)
3562 {
3563 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3564 return CMD_WARNING;
3565 }
3566
3567 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3568 (struct prefix *)&prd);
3569 if (prn->info == NULL)
3570 prn->info = bgp_table_init ();
3571 else
3572 bgp_unlock_node (prn);
3573 table = prn->info;
3574
3575 rn = bgp_node_lookup (table, &p);
3576
3577 if (rn)
3578 {
3579 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3580
3581 bgp_static = rn->info;
3582 bgp_static_free (bgp_static);
3583 rn->info = NULL;
3584 bgp_unlock_node (rn);
3585 bgp_unlock_node (rn);
3586 }
3587 else
3588 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3589
3590 return CMD_SUCCESS;
3591}
3592
3593DEFUN (bgp_network,
3594 bgp_network_cmd,
3595 "network A.B.C.D/M",
3596 "Specify a network to announce via BGP\n"
3597 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3598{
3599 return bgp_static_set (vty, vty->index, argv[0],
3600 AFI_IP, bgp_node_safi (vty), NULL, 0);
3601}
3602
3603DEFUN (bgp_network_route_map,
3604 bgp_network_route_map_cmd,
3605 "network A.B.C.D/M route-map WORD",
3606 "Specify a network to announce via BGP\n"
3607 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3608 "Route-map to modify the attributes\n"
3609 "Name of the route map\n")
3610{
3611 return bgp_static_set (vty, vty->index, argv[0],
3612 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3613}
3614
3615DEFUN (bgp_network_backdoor,
3616 bgp_network_backdoor_cmd,
3617 "network A.B.C.D/M backdoor",
3618 "Specify a network to announce via BGP\n"
3619 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3620 "Specify a BGP backdoor route\n")
3621{
3622 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3623}
3624
3625DEFUN (bgp_network_mask,
3626 bgp_network_mask_cmd,
3627 "network A.B.C.D mask A.B.C.D",
3628 "Specify a network to announce via BGP\n"
3629 "Network number\n"
3630 "Network mask\n"
3631 "Network mask\n")
3632{
3633 int ret;
3634 char prefix_str[BUFSIZ];
3635
3636 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3637 if (! ret)
3638 {
3639 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3640 return CMD_WARNING;
3641 }
3642
3643 return bgp_static_set (vty, vty->index, prefix_str,
3644 AFI_IP, bgp_node_safi (vty), NULL, 0);
3645}
3646
3647DEFUN (bgp_network_mask_route_map,
3648 bgp_network_mask_route_map_cmd,
3649 "network A.B.C.D mask A.B.C.D route-map WORD",
3650 "Specify a network to announce via BGP\n"
3651 "Network number\n"
3652 "Network mask\n"
3653 "Network mask\n"
3654 "Route-map to modify the attributes\n"
3655 "Name of the route map\n")
3656{
3657 int ret;
3658 char prefix_str[BUFSIZ];
3659
3660 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3661 if (! ret)
3662 {
3663 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3664 return CMD_WARNING;
3665 }
3666
3667 return bgp_static_set (vty, vty->index, prefix_str,
3668 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3669}
3670
3671DEFUN (bgp_network_mask_backdoor,
3672 bgp_network_mask_backdoor_cmd,
3673 "network A.B.C.D mask A.B.C.D backdoor",
3674 "Specify a network to announce via BGP\n"
3675 "Network number\n"
3676 "Network mask\n"
3677 "Network mask\n"
3678 "Specify a BGP backdoor route\n")
3679{
3680 int ret;
3681 char prefix_str[BUFSIZ];
3682
3683 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3684 if (! ret)
3685 {
3686 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3687 return CMD_WARNING;
3688 }
3689
3690 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3691}
3692
3693DEFUN (bgp_network_mask_natural,
3694 bgp_network_mask_natural_cmd,
3695 "network A.B.C.D",
3696 "Specify a network to announce via BGP\n"
3697 "Network number\n")
3698{
3699 int ret;
3700 char prefix_str[BUFSIZ];
3701
3702 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3703 if (! ret)
3704 {
3705 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3706 return CMD_WARNING;
3707 }
3708
3709 return bgp_static_set (vty, vty->index, prefix_str,
3710 AFI_IP, bgp_node_safi (vty), NULL, 0);
3711}
3712
3713DEFUN (bgp_network_mask_natural_route_map,
3714 bgp_network_mask_natural_route_map_cmd,
3715 "network A.B.C.D route-map WORD",
3716 "Specify a network to announce via BGP\n"
3717 "Network number\n"
3718 "Route-map to modify the attributes\n"
3719 "Name of the route map\n")
3720{
3721 int ret;
3722 char prefix_str[BUFSIZ];
3723
3724 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3725 if (! ret)
3726 {
3727 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3728 return CMD_WARNING;
3729 }
3730
3731 return bgp_static_set (vty, vty->index, prefix_str,
3732 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3733}
3734
3735DEFUN (bgp_network_mask_natural_backdoor,
3736 bgp_network_mask_natural_backdoor_cmd,
3737 "network A.B.C.D backdoor",
3738 "Specify a network to announce via BGP\n"
3739 "Network number\n"
3740 "Specify a BGP backdoor route\n")
3741{
3742 int ret;
3743 char prefix_str[BUFSIZ];
3744
3745 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3746 if (! ret)
3747 {
3748 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3749 return CMD_WARNING;
3750 }
3751
3752 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3753}
3754
3755DEFUN (no_bgp_network,
3756 no_bgp_network_cmd,
3757 "no network A.B.C.D/M",
3758 NO_STR
3759 "Specify a network to announce via BGP\n"
3760 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3761{
3762 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3763 bgp_node_safi (vty));
3764}
3765
3766ALIAS (no_bgp_network,
3767 no_bgp_network_route_map_cmd,
3768 "no network A.B.C.D/M route-map WORD",
3769 NO_STR
3770 "Specify a network to announce via BGP\n"
3771 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3772 "Route-map to modify the attributes\n"
3773 "Name of the route map\n")
3774
3775ALIAS (no_bgp_network,
3776 no_bgp_network_backdoor_cmd,
3777 "no network A.B.C.D/M backdoor",
3778 NO_STR
3779 "Specify a network to announce via BGP\n"
3780 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3781 "Specify a BGP backdoor route\n")
3782
3783DEFUN (no_bgp_network_mask,
3784 no_bgp_network_mask_cmd,
3785 "no network A.B.C.D mask A.B.C.D",
3786 NO_STR
3787 "Specify a network to announce via BGP\n"
3788 "Network number\n"
3789 "Network mask\n"
3790 "Network mask\n")
3791{
3792 int ret;
3793 char prefix_str[BUFSIZ];
3794
3795 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3796 if (! ret)
3797 {
3798 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3799 return CMD_WARNING;
3800 }
3801
3802 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3803 bgp_node_safi (vty));
3804}
3805
3806ALIAS (no_bgp_network_mask,
3807 no_bgp_network_mask_route_map_cmd,
3808 "no network A.B.C.D mask A.B.C.D route-map WORD",
3809 NO_STR
3810 "Specify a network to announce via BGP\n"
3811 "Network number\n"
3812 "Network mask\n"
3813 "Network mask\n"
3814 "Route-map to modify the attributes\n"
3815 "Name of the route map\n")
3816
3817ALIAS (no_bgp_network_mask,
3818 no_bgp_network_mask_backdoor_cmd,
3819 "no network A.B.C.D mask A.B.C.D backdoor",
3820 NO_STR
3821 "Specify a network to announce via BGP\n"
3822 "Network number\n"
3823 "Network mask\n"
3824 "Network mask\n"
3825 "Specify a BGP backdoor route\n")
3826
3827DEFUN (no_bgp_network_mask_natural,
3828 no_bgp_network_mask_natural_cmd,
3829 "no network A.B.C.D",
3830 NO_STR
3831 "Specify a network to announce via BGP\n"
3832 "Network number\n")
3833{
3834 int ret;
3835 char prefix_str[BUFSIZ];
3836
3837 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3838 if (! ret)
3839 {
3840 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3841 return CMD_WARNING;
3842 }
3843
3844 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3845 bgp_node_safi (vty));
3846}
3847
3848ALIAS (no_bgp_network_mask_natural,
3849 no_bgp_network_mask_natural_route_map_cmd,
3850 "no network A.B.C.D route-map WORD",
3851 NO_STR
3852 "Specify a network to announce via BGP\n"
3853 "Network number\n"
3854 "Route-map to modify the attributes\n"
3855 "Name of the route map\n")
3856
3857ALIAS (no_bgp_network_mask_natural,
3858 no_bgp_network_mask_natural_backdoor_cmd,
3859 "no network A.B.C.D backdoor",
3860 NO_STR
3861 "Specify a network to announce via BGP\n"
3862 "Network number\n"
3863 "Specify a BGP backdoor route\n")
3864
3865#ifdef HAVE_IPV6
3866DEFUN (ipv6_bgp_network,
3867 ipv6_bgp_network_cmd,
3868 "network X:X::X:X/M",
3869 "Specify a network to announce via BGP\n"
3870 "IPv6 prefix <network>/<length>\n")
3871{
3872 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3873}
3874
3875DEFUN (ipv6_bgp_network_route_map,
3876 ipv6_bgp_network_route_map_cmd,
3877 "network X:X::X:X/M route-map WORD",
3878 "Specify a network to announce via BGP\n"
3879 "IPv6 prefix <network>/<length>\n"
3880 "Route-map to modify the attributes\n"
3881 "Name of the route map\n")
3882{
3883 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3884 bgp_node_safi (vty), argv[1], 0);
3885}
3886
3887DEFUN (no_ipv6_bgp_network,
3888 no_ipv6_bgp_network_cmd,
3889 "no network X:X::X:X/M",
3890 NO_STR
3891 "Specify a network to announce via BGP\n"
3892 "IPv6 prefix <network>/<length>\n")
3893{
3894 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3895}
3896
3897ALIAS (no_ipv6_bgp_network,
3898 no_ipv6_bgp_network_route_map_cmd,
3899 "no network X:X::X:X/M route-map WORD",
3900 NO_STR
3901 "Specify a network to announce via BGP\n"
3902 "IPv6 prefix <network>/<length>\n"
3903 "Route-map to modify the attributes\n"
3904 "Name of the route map\n")
3905
3906ALIAS (ipv6_bgp_network,
3907 old_ipv6_bgp_network_cmd,
3908 "ipv6 bgp network X:X::X:X/M",
3909 IPV6_STR
3910 BGP_STR
3911 "Specify a network to announce via BGP\n"
3912 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3913
3914ALIAS (no_ipv6_bgp_network,
3915 old_no_ipv6_bgp_network_cmd,
3916 "no ipv6 bgp network X:X::X:X/M",
3917 NO_STR
3918 IPV6_STR
3919 BGP_STR
3920 "Specify a network to announce via BGP\n"
3921 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3922#endif /* HAVE_IPV6 */
3923
3924/* Aggreagete address:
3925
3926 advertise-map Set condition to advertise attribute
3927 as-set Generate AS set path information
3928 attribute-map Set attributes of aggregate
3929 route-map Set parameters of aggregate
3930 summary-only Filter more specific routes from updates
3931 suppress-map Conditionally filter more specific routes from updates
3932 <cr>
3933 */
3934struct bgp_aggregate
3935{
3936 /* Summary-only flag. */
3937 u_char summary_only;
3938
3939 /* AS set generation. */
3940 u_char as_set;
3941
3942 /* Route-map for aggregated route. */
3943 struct route_map *map;
3944
3945 /* Suppress-count. */
3946 unsigned long count;
3947
3948 /* SAFI configuration. */
3949 safi_t safi;
3950};
3951
paul94f2b392005-06-28 12:44:16 +00003952static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00003953bgp_aggregate_new ()
3954{
3955 struct bgp_aggregate *new;
3956 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3957 memset (new, 0, sizeof (struct bgp_aggregate));
3958 return new;
3959}
3960
paul94f2b392005-06-28 12:44:16 +00003961static void
paul718e3742002-12-13 20:15:29 +00003962bgp_aggregate_free (struct bgp_aggregate *aggregate)
3963{
3964 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
3965}
3966
paul94f2b392005-06-28 12:44:16 +00003967static void
paul718e3742002-12-13 20:15:29 +00003968bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
3969 afi_t afi, safi_t safi, struct bgp_info *del,
3970 struct bgp_aggregate *aggregate)
3971{
3972 struct bgp_table *table;
3973 struct bgp_node *top;
3974 struct bgp_node *rn;
3975 u_char origin;
3976 struct aspath *aspath = NULL;
3977 struct aspath *asmerge = NULL;
3978 struct community *community = NULL;
3979 struct community *commerge = NULL;
3980 struct in_addr nexthop;
3981 u_int32_t med = 0;
3982 struct bgp_info *ri;
3983 struct bgp_info *new;
3984 int first = 1;
3985 unsigned long match = 0;
3986
3987 /* Record adding route's nexthop and med. */
3988 if (rinew)
3989 {
3990 nexthop = rinew->attr->nexthop;
3991 med = rinew->attr->med;
3992 }
3993
3994 /* ORIGIN attribute: If at least one route among routes that are
3995 aggregated has ORIGIN with the value INCOMPLETE, then the
3996 aggregated route must have the ORIGIN attribute with the value
3997 INCOMPLETE. Otherwise, if at least one route among routes that
3998 are aggregated has ORIGIN with the value EGP, then the aggregated
3999 route must have the origin attribute with the value EGP. In all
4000 other case the value of the ORIGIN attribute of the aggregated
4001 route is INTERNAL. */
4002 origin = BGP_ORIGIN_IGP;
4003
4004 table = bgp->rib[afi][safi];
4005
4006 top = bgp_node_get (table, p);
4007 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4008 if (rn->p.prefixlen > p->prefixlen)
4009 {
4010 match = 0;
4011
4012 for (ri = rn->info; ri; ri = ri->next)
4013 {
4014 if (BGP_INFO_HOLDDOWN (ri))
4015 continue;
4016
4017 if (del && ri == del)
4018 continue;
4019
4020 if (! rinew && first)
4021 {
4022 nexthop = ri->attr->nexthop;
4023 med = ri->attr->med;
4024 first = 0;
4025 }
4026
4027#ifdef AGGREGATE_NEXTHOP_CHECK
4028 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4029 || ri->attr->med != med)
4030 {
4031 if (aspath)
4032 aspath_free (aspath);
4033 if (community)
4034 community_free (community);
4035 bgp_unlock_node (rn);
4036 bgp_unlock_node (top);
4037 return;
4038 }
4039#endif /* AGGREGATE_NEXTHOP_CHECK */
4040
4041 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4042 {
4043 if (aggregate->summary_only)
4044 {
4045 ri->suppress++;
4046 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4047 match++;
4048 }
4049
4050 aggregate->count++;
4051
4052 if (aggregate->as_set)
4053 {
4054 if (origin < ri->attr->origin)
4055 origin = ri->attr->origin;
4056
4057 if (aspath)
4058 {
4059 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4060 aspath_free (aspath);
4061 aspath = asmerge;
4062 }
4063 else
4064 aspath = aspath_dup (ri->attr->aspath);
4065
4066 if (ri->attr->community)
4067 {
4068 if (community)
4069 {
4070 commerge = community_merge (community,
4071 ri->attr->community);
4072 community = community_uniq_sort (commerge);
4073 community_free (commerge);
4074 }
4075 else
4076 community = community_dup (ri->attr->community);
4077 }
4078 }
4079 }
4080 }
4081 if (match)
4082 bgp_process (bgp, rn, afi, safi);
4083 }
4084 bgp_unlock_node (top);
4085
4086 if (rinew)
4087 {
4088 aggregate->count++;
4089
4090 if (aggregate->summary_only)
4091 rinew->suppress++;
4092
4093 if (aggregate->as_set)
4094 {
4095 if (origin < rinew->attr->origin)
4096 origin = rinew->attr->origin;
4097
4098 if (aspath)
4099 {
4100 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4101 aspath_free (aspath);
4102 aspath = asmerge;
4103 }
4104 else
4105 aspath = aspath_dup (rinew->attr->aspath);
4106
4107 if (rinew->attr->community)
4108 {
4109 if (community)
4110 {
4111 commerge = community_merge (community,
4112 rinew->attr->community);
4113 community = community_uniq_sort (commerge);
4114 community_free (commerge);
4115 }
4116 else
4117 community = community_dup (rinew->attr->community);
4118 }
4119 }
4120 }
4121
4122 if (aggregate->count > 0)
4123 {
4124 rn = bgp_node_get (table, p);
4125 new = bgp_info_new ();
4126 new->type = ZEBRA_ROUTE_BGP;
4127 new->sub_type = BGP_ROUTE_AGGREGATE;
4128 new->peer = bgp->peer_self;
4129 SET_FLAG (new->flags, BGP_INFO_VALID);
4130 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4131 new->uptime = time (NULL);
4132
4133 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004134 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004135 bgp_process (bgp, rn, afi, safi);
4136 }
4137 else
4138 {
4139 if (aspath)
4140 aspath_free (aspath);
4141 if (community)
4142 community_free (community);
4143 }
4144}
4145
4146void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4147 struct bgp_aggregate *);
4148
4149void
4150bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4151 struct bgp_info *ri, afi_t afi, safi_t safi)
4152{
4153 struct bgp_node *child;
4154 struct bgp_node *rn;
4155 struct bgp_aggregate *aggregate;
4156
4157 /* MPLS-VPN aggregation is not yet supported. */
4158 if (safi == SAFI_MPLS_VPN)
4159 return;
4160
4161 if (p->prefixlen == 0)
4162 return;
4163
4164 if (BGP_INFO_HOLDDOWN (ri))
4165 return;
4166
4167 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4168
4169 /* Aggregate address configuration check. */
4170 for (rn = child; rn; rn = rn->parent)
4171 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4172 {
4173 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004174 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004175 }
4176 bgp_unlock_node (child);
4177}
4178
4179void
4180bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4181 struct bgp_info *del, afi_t afi, safi_t safi)
4182{
4183 struct bgp_node *child;
4184 struct bgp_node *rn;
4185 struct bgp_aggregate *aggregate;
4186
4187 /* MPLS-VPN aggregation is not yet supported. */
4188 if (safi == SAFI_MPLS_VPN)
4189 return;
4190
4191 if (p->prefixlen == 0)
4192 return;
4193
4194 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4195
4196 /* Aggregate address configuration check. */
4197 for (rn = child; rn; rn = rn->parent)
4198 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4199 {
4200 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004201 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004202 }
4203 bgp_unlock_node (child);
4204}
4205
paul94f2b392005-06-28 12:44:16 +00004206static void
paul718e3742002-12-13 20:15:29 +00004207bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4208 struct bgp_aggregate *aggregate)
4209{
4210 struct bgp_table *table;
4211 struct bgp_node *top;
4212 struct bgp_node *rn;
4213 struct bgp_info *new;
4214 struct bgp_info *ri;
4215 unsigned long match;
4216 u_char origin = BGP_ORIGIN_IGP;
4217 struct aspath *aspath = NULL;
4218 struct aspath *asmerge = NULL;
4219 struct community *community = NULL;
4220 struct community *commerge = NULL;
4221
4222 table = bgp->rib[afi][safi];
4223
4224 /* Sanity check. */
4225 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4226 return;
4227 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4228 return;
4229
4230 /* If routes exists below this node, generate aggregate routes. */
4231 top = bgp_node_get (table, p);
4232 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4233 if (rn->p.prefixlen > p->prefixlen)
4234 {
4235 match = 0;
4236
4237 for (ri = rn->info; ri; ri = ri->next)
4238 {
4239 if (BGP_INFO_HOLDDOWN (ri))
4240 continue;
4241
4242 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4243 {
4244 /* summary-only aggregate route suppress aggregated
4245 route announcement. */
4246 if (aggregate->summary_only)
4247 {
4248 ri->suppress++;
4249 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4250 match++;
4251 }
4252 /* as-set aggregate route generate origin, as path,
4253 community aggregation. */
4254 if (aggregate->as_set)
4255 {
4256 if (origin < ri->attr->origin)
4257 origin = ri->attr->origin;
4258
4259 if (aspath)
4260 {
4261 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4262 aspath_free (aspath);
4263 aspath = asmerge;
4264 }
4265 else
4266 aspath = aspath_dup (ri->attr->aspath);
4267
4268 if (ri->attr->community)
4269 {
4270 if (community)
4271 {
4272 commerge = community_merge (community,
4273 ri->attr->community);
4274 community = community_uniq_sort (commerge);
4275 community_free (commerge);
4276 }
4277 else
4278 community = community_dup (ri->attr->community);
4279 }
4280 }
4281 aggregate->count++;
4282 }
4283 }
4284
4285 /* If this node is suppressed, process the change. */
4286 if (match)
4287 bgp_process (bgp, rn, afi, safi);
4288 }
4289 bgp_unlock_node (top);
4290
4291 /* Add aggregate route to BGP table. */
4292 if (aggregate->count)
4293 {
4294 rn = bgp_node_get (table, p);
4295
4296 new = bgp_info_new ();
4297 new->type = ZEBRA_ROUTE_BGP;
4298 new->sub_type = BGP_ROUTE_AGGREGATE;
4299 new->peer = bgp->peer_self;
4300 SET_FLAG (new->flags, BGP_INFO_VALID);
4301 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4302 new->uptime = time (NULL);
4303
4304 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004305 bgp_unlock_node (rn);
4306
paul718e3742002-12-13 20:15:29 +00004307 /* Process change. */
4308 bgp_process (bgp, rn, afi, safi);
4309 }
4310}
4311
4312void
4313bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4314 safi_t safi, struct bgp_aggregate *aggregate)
4315{
4316 struct bgp_table *table;
4317 struct bgp_node *top;
4318 struct bgp_node *rn;
4319 struct bgp_info *ri;
4320 unsigned long match;
4321
4322 table = bgp->rib[afi][safi];
4323
4324 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4325 return;
4326 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4327 return;
4328
4329 /* If routes exists below this node, generate aggregate routes. */
4330 top = bgp_node_get (table, p);
4331 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4332 if (rn->p.prefixlen > p->prefixlen)
4333 {
4334 match = 0;
4335
4336 for (ri = rn->info; ri; ri = ri->next)
4337 {
4338 if (BGP_INFO_HOLDDOWN (ri))
4339 continue;
4340
4341 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4342 {
4343 if (aggregate->summary_only)
4344 {
4345 ri->suppress--;
4346
4347 if (ri->suppress == 0)
4348 {
4349 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4350 match++;
4351 }
4352 }
4353 aggregate->count--;
4354 }
4355 }
4356
4357 /* If this node is suppressed, process the change. */
4358 if (match)
4359 bgp_process (bgp, rn, afi, safi);
4360 }
4361 bgp_unlock_node (top);
4362
4363 /* Delete aggregate route from BGP table. */
4364 rn = bgp_node_get (table, p);
4365
4366 for (ri = rn->info; ri; ri = ri->next)
4367 if (ri->peer == bgp->peer_self
4368 && ri->type == ZEBRA_ROUTE_BGP
4369 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4370 break;
4371
4372 /* Withdraw static BGP route from routing table. */
4373 if (ri)
4374 {
4375 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4376 bgp_process (bgp, rn, afi, safi);
4377 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004378 }
4379
4380 /* Unlock bgp_node_lookup. */
4381 bgp_unlock_node (rn);
4382}
4383
4384/* Aggregate route attribute. */
4385#define AGGREGATE_SUMMARY_ONLY 1
4386#define AGGREGATE_AS_SET 1
4387
paul94f2b392005-06-28 12:44:16 +00004388static int
paulfd79ac92004-10-13 05:06:08 +00004389bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4390 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004391 u_char summary_only, u_char as_set)
4392{
4393 int ret;
4394 struct prefix p;
4395 struct bgp_node *rn;
4396 struct bgp *bgp;
4397 struct bgp_aggregate *aggregate;
4398
4399 /* Convert string to prefix structure. */
4400 ret = str2prefix (prefix_str, &p);
4401 if (!ret)
4402 {
4403 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4404 return CMD_WARNING;
4405 }
4406 apply_mask (&p);
4407
4408 /* Get BGP structure. */
4409 bgp = vty->index;
4410
4411 /* Old configuration check. */
4412 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4413
4414 if (rn->info)
4415 {
4416 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4417 bgp_unlock_node (rn);
4418 return CMD_WARNING;
4419 }
4420
4421 /* Make aggregate address structure. */
4422 aggregate = bgp_aggregate_new ();
4423 aggregate->summary_only = summary_only;
4424 aggregate->as_set = as_set;
4425 aggregate->safi = safi;
4426 rn->info = aggregate;
4427
4428 /* Aggregate address insert into BGP routing table. */
4429 if (safi & SAFI_UNICAST)
4430 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4431 if (safi & SAFI_MULTICAST)
4432 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4433
4434 return CMD_SUCCESS;
4435}
4436
paul94f2b392005-06-28 12:44:16 +00004437static int
paulfd79ac92004-10-13 05:06:08 +00004438bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4439 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004440{
4441 int ret;
4442 struct prefix p;
4443 struct bgp_node *rn;
4444 struct bgp *bgp;
4445 struct bgp_aggregate *aggregate;
4446
4447 /* Convert string to prefix structure. */
4448 ret = str2prefix (prefix_str, &p);
4449 if (!ret)
4450 {
4451 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4452 return CMD_WARNING;
4453 }
4454 apply_mask (&p);
4455
4456 /* Get BGP structure. */
4457 bgp = vty->index;
4458
4459 /* Old configuration check. */
4460 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4461 if (! rn)
4462 {
4463 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4464 VTY_NEWLINE);
4465 return CMD_WARNING;
4466 }
4467
4468 aggregate = rn->info;
4469 if (aggregate->safi & SAFI_UNICAST)
4470 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4471 if (aggregate->safi & SAFI_MULTICAST)
4472 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4473
4474 /* Unlock aggregate address configuration. */
4475 rn->info = NULL;
4476 bgp_aggregate_free (aggregate);
4477 bgp_unlock_node (rn);
4478 bgp_unlock_node (rn);
4479
4480 return CMD_SUCCESS;
4481}
4482
4483DEFUN (aggregate_address,
4484 aggregate_address_cmd,
4485 "aggregate-address A.B.C.D/M",
4486 "Configure BGP aggregate entries\n"
4487 "Aggregate prefix\n")
4488{
4489 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4490}
4491
4492DEFUN (aggregate_address_mask,
4493 aggregate_address_mask_cmd,
4494 "aggregate-address A.B.C.D A.B.C.D",
4495 "Configure BGP aggregate entries\n"
4496 "Aggregate address\n"
4497 "Aggregate mask\n")
4498{
4499 int ret;
4500 char prefix_str[BUFSIZ];
4501
4502 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4503
4504 if (! ret)
4505 {
4506 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4507 return CMD_WARNING;
4508 }
4509
4510 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4511 0, 0);
4512}
4513
4514DEFUN (aggregate_address_summary_only,
4515 aggregate_address_summary_only_cmd,
4516 "aggregate-address A.B.C.D/M summary-only",
4517 "Configure BGP aggregate entries\n"
4518 "Aggregate prefix\n"
4519 "Filter more specific routes from updates\n")
4520{
4521 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4522 AGGREGATE_SUMMARY_ONLY, 0);
4523}
4524
4525DEFUN (aggregate_address_mask_summary_only,
4526 aggregate_address_mask_summary_only_cmd,
4527 "aggregate-address A.B.C.D A.B.C.D summary-only",
4528 "Configure BGP aggregate entries\n"
4529 "Aggregate address\n"
4530 "Aggregate mask\n"
4531 "Filter more specific routes from updates\n")
4532{
4533 int ret;
4534 char prefix_str[BUFSIZ];
4535
4536 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4537
4538 if (! ret)
4539 {
4540 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4541 return CMD_WARNING;
4542 }
4543
4544 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4545 AGGREGATE_SUMMARY_ONLY, 0);
4546}
4547
4548DEFUN (aggregate_address_as_set,
4549 aggregate_address_as_set_cmd,
4550 "aggregate-address A.B.C.D/M as-set",
4551 "Configure BGP aggregate entries\n"
4552 "Aggregate prefix\n"
4553 "Generate AS set path information\n")
4554{
4555 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4556 0, AGGREGATE_AS_SET);
4557}
4558
4559DEFUN (aggregate_address_mask_as_set,
4560 aggregate_address_mask_as_set_cmd,
4561 "aggregate-address A.B.C.D A.B.C.D as-set",
4562 "Configure BGP aggregate entries\n"
4563 "Aggregate address\n"
4564 "Aggregate mask\n"
4565 "Generate AS set path information\n")
4566{
4567 int ret;
4568 char prefix_str[BUFSIZ];
4569
4570 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4571
4572 if (! ret)
4573 {
4574 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4575 return CMD_WARNING;
4576 }
4577
4578 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4579 0, AGGREGATE_AS_SET);
4580}
4581
4582
4583DEFUN (aggregate_address_as_set_summary,
4584 aggregate_address_as_set_summary_cmd,
4585 "aggregate-address A.B.C.D/M as-set summary-only",
4586 "Configure BGP aggregate entries\n"
4587 "Aggregate prefix\n"
4588 "Generate AS set path information\n"
4589 "Filter more specific routes from updates\n")
4590{
4591 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4592 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4593}
4594
4595ALIAS (aggregate_address_as_set_summary,
4596 aggregate_address_summary_as_set_cmd,
4597 "aggregate-address A.B.C.D/M summary-only as-set",
4598 "Configure BGP aggregate entries\n"
4599 "Aggregate prefix\n"
4600 "Filter more specific routes from updates\n"
4601 "Generate AS set path information\n")
4602
4603DEFUN (aggregate_address_mask_as_set_summary,
4604 aggregate_address_mask_as_set_summary_cmd,
4605 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4606 "Configure BGP aggregate entries\n"
4607 "Aggregate address\n"
4608 "Aggregate mask\n"
4609 "Generate AS set path information\n"
4610 "Filter more specific routes from updates\n")
4611{
4612 int ret;
4613 char prefix_str[BUFSIZ];
4614
4615 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4616
4617 if (! ret)
4618 {
4619 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4620 return CMD_WARNING;
4621 }
4622
4623 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4624 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4625}
4626
4627ALIAS (aggregate_address_mask_as_set_summary,
4628 aggregate_address_mask_summary_as_set_cmd,
4629 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4630 "Configure BGP aggregate entries\n"
4631 "Aggregate address\n"
4632 "Aggregate mask\n"
4633 "Filter more specific routes from updates\n"
4634 "Generate AS set path information\n")
4635
4636DEFUN (no_aggregate_address,
4637 no_aggregate_address_cmd,
4638 "no aggregate-address A.B.C.D/M",
4639 NO_STR
4640 "Configure BGP aggregate entries\n"
4641 "Aggregate prefix\n")
4642{
4643 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4644}
4645
4646ALIAS (no_aggregate_address,
4647 no_aggregate_address_summary_only_cmd,
4648 "no aggregate-address A.B.C.D/M summary-only",
4649 NO_STR
4650 "Configure BGP aggregate entries\n"
4651 "Aggregate prefix\n"
4652 "Filter more specific routes from updates\n")
4653
4654ALIAS (no_aggregate_address,
4655 no_aggregate_address_as_set_cmd,
4656 "no aggregate-address A.B.C.D/M as-set",
4657 NO_STR
4658 "Configure BGP aggregate entries\n"
4659 "Aggregate prefix\n"
4660 "Generate AS set path information\n")
4661
4662ALIAS (no_aggregate_address,
4663 no_aggregate_address_as_set_summary_cmd,
4664 "no aggregate-address A.B.C.D/M as-set summary-only",
4665 NO_STR
4666 "Configure BGP aggregate entries\n"
4667 "Aggregate prefix\n"
4668 "Generate AS set path information\n"
4669 "Filter more specific routes from updates\n")
4670
4671ALIAS (no_aggregate_address,
4672 no_aggregate_address_summary_as_set_cmd,
4673 "no aggregate-address A.B.C.D/M summary-only as-set",
4674 NO_STR
4675 "Configure BGP aggregate entries\n"
4676 "Aggregate prefix\n"
4677 "Filter more specific routes from updates\n"
4678 "Generate AS set path information\n")
4679
4680DEFUN (no_aggregate_address_mask,
4681 no_aggregate_address_mask_cmd,
4682 "no aggregate-address A.B.C.D A.B.C.D",
4683 NO_STR
4684 "Configure BGP aggregate entries\n"
4685 "Aggregate address\n"
4686 "Aggregate mask\n")
4687{
4688 int ret;
4689 char prefix_str[BUFSIZ];
4690
4691 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4692
4693 if (! ret)
4694 {
4695 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4696 return CMD_WARNING;
4697 }
4698
4699 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4700}
4701
4702ALIAS (no_aggregate_address_mask,
4703 no_aggregate_address_mask_summary_only_cmd,
4704 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4705 NO_STR
4706 "Configure BGP aggregate entries\n"
4707 "Aggregate address\n"
4708 "Aggregate mask\n"
4709 "Filter more specific routes from updates\n")
4710
4711ALIAS (no_aggregate_address_mask,
4712 no_aggregate_address_mask_as_set_cmd,
4713 "no aggregate-address A.B.C.D A.B.C.D as-set",
4714 NO_STR
4715 "Configure BGP aggregate entries\n"
4716 "Aggregate address\n"
4717 "Aggregate mask\n"
4718 "Generate AS set path information\n")
4719
4720ALIAS (no_aggregate_address_mask,
4721 no_aggregate_address_mask_as_set_summary_cmd,
4722 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4723 NO_STR
4724 "Configure BGP aggregate entries\n"
4725 "Aggregate address\n"
4726 "Aggregate mask\n"
4727 "Generate AS set path information\n"
4728 "Filter more specific routes from updates\n")
4729
4730ALIAS (no_aggregate_address_mask,
4731 no_aggregate_address_mask_summary_as_set_cmd,
4732 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4733 NO_STR
4734 "Configure BGP aggregate entries\n"
4735 "Aggregate address\n"
4736 "Aggregate mask\n"
4737 "Filter more specific routes from updates\n"
4738 "Generate AS set path information\n")
4739
4740#ifdef HAVE_IPV6
4741DEFUN (ipv6_aggregate_address,
4742 ipv6_aggregate_address_cmd,
4743 "aggregate-address X:X::X:X/M",
4744 "Configure BGP aggregate entries\n"
4745 "Aggregate prefix\n")
4746{
4747 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4748}
4749
4750DEFUN (ipv6_aggregate_address_summary_only,
4751 ipv6_aggregate_address_summary_only_cmd,
4752 "aggregate-address X:X::X:X/M summary-only",
4753 "Configure BGP aggregate entries\n"
4754 "Aggregate prefix\n"
4755 "Filter more specific routes from updates\n")
4756{
4757 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4758 AGGREGATE_SUMMARY_ONLY, 0);
4759}
4760
4761DEFUN (no_ipv6_aggregate_address,
4762 no_ipv6_aggregate_address_cmd,
4763 "no aggregate-address X:X::X:X/M",
4764 NO_STR
4765 "Configure BGP aggregate entries\n"
4766 "Aggregate prefix\n")
4767{
4768 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4769}
4770
4771DEFUN (no_ipv6_aggregate_address_summary_only,
4772 no_ipv6_aggregate_address_summary_only_cmd,
4773 "no aggregate-address X:X::X:X/M summary-only",
4774 NO_STR
4775 "Configure BGP aggregate entries\n"
4776 "Aggregate prefix\n"
4777 "Filter more specific routes from updates\n")
4778{
4779 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4780}
4781
4782ALIAS (ipv6_aggregate_address,
4783 old_ipv6_aggregate_address_cmd,
4784 "ipv6 bgp aggregate-address X:X::X:X/M",
4785 IPV6_STR
4786 BGP_STR
4787 "Configure BGP aggregate entries\n"
4788 "Aggregate prefix\n")
4789
4790ALIAS (ipv6_aggregate_address_summary_only,
4791 old_ipv6_aggregate_address_summary_only_cmd,
4792 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4793 IPV6_STR
4794 BGP_STR
4795 "Configure BGP aggregate entries\n"
4796 "Aggregate prefix\n"
4797 "Filter more specific routes from updates\n")
4798
4799ALIAS (no_ipv6_aggregate_address,
4800 old_no_ipv6_aggregate_address_cmd,
4801 "no ipv6 bgp aggregate-address X:X::X:X/M",
4802 NO_STR
4803 IPV6_STR
4804 BGP_STR
4805 "Configure BGP aggregate entries\n"
4806 "Aggregate prefix\n")
4807
4808ALIAS (no_ipv6_aggregate_address_summary_only,
4809 old_no_ipv6_aggregate_address_summary_only_cmd,
4810 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4811 NO_STR
4812 IPV6_STR
4813 BGP_STR
4814 "Configure BGP aggregate entries\n"
4815 "Aggregate prefix\n"
4816 "Filter more specific routes from updates\n")
4817#endif /* HAVE_IPV6 */
4818
4819/* Redistribute route treatment. */
4820void
4821bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4822 u_int32_t metric, u_char type)
4823{
4824 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004825 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004826 struct bgp_info *new;
4827 struct bgp_info *bi;
4828 struct bgp_info info;
4829 struct bgp_node *bn;
4830 struct attr attr;
4831 struct attr attr_new;
4832 struct attr *new_attr;
4833 afi_t afi;
4834 int ret;
4835
4836 /* Make default attribute. */
4837 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4838 if (nexthop)
4839 attr.nexthop = *nexthop;
4840
4841 attr.med = metric;
4842 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4843
paul1eb8ef22005-04-07 07:30:20 +00004844 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004845 {
4846 afi = family2afi (p->family);
4847
4848 if (bgp->redist[afi][type])
4849 {
4850 /* Copy attribute for modification. */
4851 attr_new = attr;
4852
4853 if (bgp->redist_metric_flag[afi][type])
4854 attr_new.med = bgp->redist_metric[afi][type];
4855
4856 /* Apply route-map. */
4857 if (bgp->rmap[afi][type].map)
4858 {
4859 info.peer = bgp->peer_self;
4860 info.attr = &attr_new;
4861
paulfee0f4c2004-09-13 05:12:46 +00004862 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4863
paul718e3742002-12-13 20:15:29 +00004864 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4865 &info);
paulfee0f4c2004-09-13 05:12:46 +00004866
4867 bgp->peer_self->rmap_type = 0;
4868
paul718e3742002-12-13 20:15:29 +00004869 if (ret == RMAP_DENYMATCH)
4870 {
4871 /* Free uninterned attribute. */
4872 bgp_attr_flush (&attr_new);
4873
4874 /* Unintern original. */
4875 aspath_unintern (attr.aspath);
4876 bgp_redistribute_delete (p, type);
4877 return;
4878 }
4879 }
4880
paulfee0f4c2004-09-13 05:12:46 +00004881 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004882 new_attr = bgp_attr_intern (&attr_new);
4883
4884 for (bi = bn->info; bi; bi = bi->next)
4885 if (bi->peer == bgp->peer_self
4886 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4887 break;
4888
4889 if (bi)
4890 {
4891 if (attrhash_cmp (bi->attr, new_attr))
4892 {
4893 bgp_attr_unintern (new_attr);
4894 aspath_unintern (attr.aspath);
4895 bgp_unlock_node (bn);
4896 return;
4897 }
4898 else
4899 {
4900 /* The attribute is changed. */
4901 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4902
4903 /* Rewrite BGP route information. */
4904 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4905 bgp_attr_unintern (bi->attr);
4906 bi->attr = new_attr;
4907 bi->uptime = time (NULL);
4908
4909 /* Process change. */
4910 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4911 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4912 bgp_unlock_node (bn);
4913 aspath_unintern (attr.aspath);
4914 return;
4915 }
4916 }
4917
4918 new = bgp_info_new ();
4919 new->type = type;
4920 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4921 new->peer = bgp->peer_self;
4922 SET_FLAG (new->flags, BGP_INFO_VALID);
4923 new->attr = new_attr;
4924 new->uptime = time (NULL);
4925
4926 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4927 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004928 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004929 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4930 }
4931 }
4932
4933 /* Unintern original. */
4934 aspath_unintern (attr.aspath);
4935}
4936
4937void
4938bgp_redistribute_delete (struct prefix *p, u_char type)
4939{
4940 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004941 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004942 afi_t afi;
4943 struct bgp_node *rn;
4944 struct bgp_info *ri;
4945
paul1eb8ef22005-04-07 07:30:20 +00004946 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004947 {
4948 afi = family2afi (p->family);
4949
4950 if (bgp->redist[afi][type])
4951 {
paulfee0f4c2004-09-13 05:12:46 +00004952 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004953
4954 for (ri = rn->info; ri; ri = ri->next)
4955 if (ri->peer == bgp->peer_self
4956 && ri->type == type)
4957 break;
4958
4959 if (ri)
4960 {
4961 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4962 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4963 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4964 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004965 }
4966 bgp_unlock_node (rn);
4967 }
4968 }
4969}
4970
4971/* Withdraw specified route type's route. */
4972void
4973bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
4974{
4975 struct bgp_node *rn;
4976 struct bgp_info *ri;
4977 struct bgp_table *table;
4978
4979 table = bgp->rib[afi][SAFI_UNICAST];
4980
4981 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4982 {
4983 for (ri = rn->info; ri; ri = ri->next)
4984 if (ri->peer == bgp->peer_self
4985 && ri->type == type)
4986 break;
4987
4988 if (ri)
4989 {
4990 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
4991 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4992 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4993 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004994 }
4995 }
4996}
4997
4998/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00004999static void
paul718e3742002-12-13 20:15:29 +00005000route_vty_out_route (struct prefix *p, struct vty *vty)
5001{
5002 int len;
5003 u_int32_t destination;
5004 char buf[BUFSIZ];
5005
5006 if (p->family == AF_INET)
5007 {
5008 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5009 destination = ntohl (p->u.prefix4.s_addr);
5010
5011 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5012 || (IN_CLASSB (destination) && p->prefixlen == 16)
5013 || (IN_CLASSA (destination) && p->prefixlen == 8)
5014 || p->u.prefix4.s_addr == 0)
5015 {
5016 /* When mask is natural, mask is not displayed. */
5017 }
5018 else
5019 len += vty_out (vty, "/%d", p->prefixlen);
5020 }
5021 else
5022 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5023 p->prefixlen);
5024
5025 len = 17 - len;
5026 if (len < 1)
5027 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5028 else
5029 vty_out (vty, "%*s", len, " ");
5030}
5031
paul718e3742002-12-13 20:15:29 +00005032enum bgp_display_type
5033{
5034 normal_list,
5035};
5036
paulb40d9392005-08-22 22:34:41 +00005037/* Print the short form route status for a bgp_info */
5038static void
5039route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005040{
paulb40d9392005-08-22 22:34:41 +00005041 /* Route status display. */
5042 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5043 vty_out (vty, "R");
5044 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005045 vty_out (vty, "S");
5046 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005047 vty_out (vty, "s");
5048 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5049 vty_out (vty, "*");
5050 else
5051 vty_out (vty, " ");
5052
5053 /* Selected */
5054 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5055 vty_out (vty, "h");
5056 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5057 vty_out (vty, "d");
5058 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5059 vty_out (vty, ">");
5060 else
5061 vty_out (vty, " ");
5062
5063 /* Internal route. */
5064 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5065 vty_out (vty, "i");
5066 else
paulb40d9392005-08-22 22:34:41 +00005067 vty_out (vty, " ");
5068}
5069
5070/* called from terminal list command */
5071void
5072route_vty_out (struct vty *vty, struct prefix *p,
5073 struct bgp_info *binfo, int display, safi_t safi)
5074{
5075 struct attr *attr;
5076
5077 /* short status lead text */
5078 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005079
5080 /* print prefix and mask */
5081 if (! display)
5082 route_vty_out_route (p, vty);
5083 else
5084 vty_out (vty, "%*s", 17, " ");
5085
5086 /* Print attribute */
5087 attr = binfo->attr;
5088 if (attr)
5089 {
5090 if (p->family == AF_INET)
5091 {
5092 if (safi == SAFI_MPLS_VPN)
5093 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5094 else
5095 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5096 }
5097#ifdef HAVE_IPV6
5098 else if (p->family == AF_INET6)
5099 {
5100 int len;
5101 char buf[BUFSIZ];
5102
5103 len = vty_out (vty, "%s",
5104 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5105 len = 16 - len;
5106 if (len < 1)
5107 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5108 else
5109 vty_out (vty, "%*s", len, " ");
5110 }
5111#endif /* HAVE_IPV6 */
5112
5113 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5114 vty_out (vty, "%10d", attr->med);
5115 else
5116 vty_out (vty, " ");
5117
5118 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5119 vty_out (vty, "%7d", attr->local_pref);
5120 else
5121 vty_out (vty, " ");
5122
5123 vty_out (vty, "%7u ",attr->weight);
5124
5125 /* Print aspath */
5126 if (attr->aspath)
5127 aspath_print_vty (vty, attr->aspath);
5128
5129 /* Print origin */
5130 if (strlen (attr->aspath->str) == 0)
5131 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5132 else
5133 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5134 }
5135 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005136}
5137
5138/* called from terminal list command */
5139void
5140route_vty_out_tmp (struct vty *vty, struct prefix *p,
5141 struct attr *attr, safi_t safi)
5142{
5143 /* Route status display. */
5144 vty_out (vty, "*");
5145 vty_out (vty, ">");
5146 vty_out (vty, " ");
5147
5148 /* print prefix and mask */
5149 route_vty_out_route (p, vty);
5150
5151 /* Print attribute */
5152 if (attr)
5153 {
5154 if (p->family == AF_INET)
5155 {
5156 if (safi == SAFI_MPLS_VPN)
5157 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5158 else
5159 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5160 }
5161#ifdef HAVE_IPV6
5162 else if (p->family == AF_INET6)
5163 {
5164 int len;
5165 char buf[BUFSIZ];
5166
5167 len = vty_out (vty, "%s",
5168 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5169 len = 16 - len;
5170 if (len < 1)
5171 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5172 else
5173 vty_out (vty, "%*s", len, " ");
5174 }
5175#endif /* HAVE_IPV6 */
5176
5177 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5178 vty_out (vty, "%10d", attr->med);
5179 else
5180 vty_out (vty, " ");
5181
5182 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5183 vty_out (vty, "%7d", attr->local_pref);
5184 else
5185 vty_out (vty, " ");
5186
5187 vty_out (vty, "%7d ",attr->weight);
5188
5189 /* Print aspath */
5190 if (attr->aspath)
5191 aspath_print_vty (vty, attr->aspath);
5192
5193 /* Print origin */
5194 if (strlen (attr->aspath->str) == 0)
5195 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5196 else
5197 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5198 }
5199
5200 vty_out (vty, "%s", VTY_NEWLINE);
5201}
5202
ajs5a646652004-11-05 01:25:55 +00005203void
paul718e3742002-12-13 20:15:29 +00005204route_vty_out_tag (struct vty *vty, struct prefix *p,
5205 struct bgp_info *binfo, int display, safi_t safi)
5206{
5207 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005208 u_int32_t label = 0;
5209
paulb40d9392005-08-22 22:34:41 +00005210 /* short status lead text */
5211 route_vty_short_status_out (vty, binfo);
5212
paul718e3742002-12-13 20:15:29 +00005213 /* print prefix and mask */
5214 if (! display)
5215 route_vty_out_route (p, vty);
5216 else
5217 vty_out (vty, "%*s", 17, " ");
5218
5219 /* Print attribute */
5220 attr = binfo->attr;
5221 if (attr)
5222 {
5223 if (p->family == AF_INET)
5224 {
5225 if (safi == SAFI_MPLS_VPN)
5226 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5227 else
5228 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5229 }
5230#ifdef HAVE_IPV6
5231 else if (p->family == AF_INET6)
5232 {
5233 char buf[BUFSIZ];
5234 char buf1[BUFSIZ];
5235 if (attr->mp_nexthop_len == 16)
5236 vty_out (vty, "%s",
5237 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5238 else if (attr->mp_nexthop_len == 32)
5239 vty_out (vty, "%s(%s)",
5240 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5241 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5242
5243 }
5244#endif /* HAVE_IPV6 */
5245 }
5246
5247 label = decode_label (binfo->tag);
5248
5249 vty_out (vty, "notag/%d", label);
5250
5251 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005252}
5253
5254/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005255static void
paul718e3742002-12-13 20:15:29 +00005256damp_route_vty_out (struct vty *vty, struct prefix *p,
5257 struct bgp_info *binfo, int display, safi_t safi)
5258{
5259 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005260 int len;
5261
paulb40d9392005-08-22 22:34:41 +00005262 /* short status lead text */
5263 route_vty_short_status_out (vty, binfo);
5264
paul718e3742002-12-13 20:15:29 +00005265 /* print prefix and mask */
5266 if (! display)
5267 route_vty_out_route (p, vty);
5268 else
5269 vty_out (vty, "%*s", 17, " ");
5270
5271 len = vty_out (vty, "%s", binfo->peer->host);
5272 len = 17 - len;
5273 if (len < 1)
5274 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5275 else
5276 vty_out (vty, "%*s", len, " ");
5277
5278 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5279
5280 /* Print attribute */
5281 attr = binfo->attr;
5282 if (attr)
5283 {
5284 /* Print aspath */
5285 if (attr->aspath)
5286 aspath_print_vty (vty, attr->aspath);
5287
5288 /* Print origin */
5289 if (strlen (attr->aspath->str) == 0)
5290 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5291 else
5292 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5293 }
5294 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005295}
5296
5297#define BGP_UPTIME_LEN 25
5298
5299/* flap route */
ajs5a646652004-11-05 01:25:55 +00005300static void
paul718e3742002-12-13 20:15:29 +00005301flap_route_vty_out (struct vty *vty, struct prefix *p,
5302 struct bgp_info *binfo, int display, safi_t safi)
5303{
5304 struct attr *attr;
5305 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005306 char timebuf[BGP_UPTIME_LEN];
5307 int len;
5308
paul718e3742002-12-13 20:15:29 +00005309 bdi = binfo->damp_info;
5310
paulb40d9392005-08-22 22:34:41 +00005311 /* short status lead text */
5312 route_vty_short_status_out (vty, binfo);
5313
paul718e3742002-12-13 20:15:29 +00005314 /* print prefix and mask */
5315 if (! display)
5316 route_vty_out_route (p, vty);
5317 else
5318 vty_out (vty, "%*s", 17, " ");
5319
5320 len = vty_out (vty, "%s", binfo->peer->host);
5321 len = 16 - len;
5322 if (len < 1)
5323 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5324 else
5325 vty_out (vty, "%*s", len, " ");
5326
5327 len = vty_out (vty, "%d", bdi->flap);
5328 len = 5 - len;
5329 if (len < 1)
5330 vty_out (vty, " ");
5331 else
5332 vty_out (vty, "%*s ", len, " ");
5333
5334 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5335 timebuf, BGP_UPTIME_LEN));
5336
5337 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5338 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5339 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5340 else
5341 vty_out (vty, "%*s ", 8, " ");
5342
5343 /* Print attribute */
5344 attr = binfo->attr;
5345 if (attr)
5346 {
5347 /* Print aspath */
5348 if (attr->aspath)
5349 aspath_print_vty (vty, attr->aspath);
5350
5351 /* Print origin */
5352 if (strlen (attr->aspath->str) == 0)
5353 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5354 else
5355 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5356 }
5357 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005358}
5359
paul94f2b392005-06-28 12:44:16 +00005360static void
paul718e3742002-12-13 20:15:29 +00005361route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5362 struct bgp_info *binfo, afi_t afi, safi_t safi)
5363{
5364 char buf[INET6_ADDRSTRLEN];
5365 char buf1[BUFSIZ];
5366 struct attr *attr;
5367 int sockunion_vty_out (struct vty *, union sockunion *);
5368
5369 attr = binfo->attr;
5370
5371 if (attr)
5372 {
5373 /* Line1 display AS-path, Aggregator */
5374 if (attr->aspath)
5375 {
5376 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005377 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005378 vty_out (vty, "Local");
5379 else
5380 aspath_print_vty (vty, attr->aspath);
5381 }
5382
paulb40d9392005-08-22 22:34:41 +00005383 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5384 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005385 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5386 vty_out (vty, ", (stale)");
5387 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5388 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5389 inet_ntoa (attr->aggregator_addr));
5390 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5391 vty_out (vty, ", (Received from a RR-client)");
5392 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5393 vty_out (vty, ", (Received from a RS-client)");
5394 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5395 vty_out (vty, ", (history entry)");
5396 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5397 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005398 vty_out (vty, "%s", VTY_NEWLINE);
5399
5400 /* Line2 display Next-hop, Neighbor, Router-id */
5401 if (p->family == AF_INET)
5402 {
5403 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5404 inet_ntoa (attr->mp_nexthop_global_in) :
5405 inet_ntoa (attr->nexthop));
5406 }
5407#ifdef HAVE_IPV6
5408 else
5409 {
5410 vty_out (vty, " %s",
5411 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5412 buf, INET6_ADDRSTRLEN));
5413 }
5414#endif /* HAVE_IPV6 */
5415
5416 if (binfo->peer == bgp->peer_self)
5417 {
5418 vty_out (vty, " from %s ",
5419 p->family == AF_INET ? "0.0.0.0" : "::");
5420 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5421 }
5422 else
5423 {
5424 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5425 vty_out (vty, " (inaccessible)");
5426 else if (binfo->igpmetric)
5427 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005428 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005429 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5430 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5431 else
5432 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5433 }
5434 vty_out (vty, "%s", VTY_NEWLINE);
5435
5436#ifdef HAVE_IPV6
5437 /* display nexthop local */
5438 if (attr->mp_nexthop_len == 32)
5439 {
5440 vty_out (vty, " (%s)%s",
5441 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5442 buf, INET6_ADDRSTRLEN),
5443 VTY_NEWLINE);
5444 }
5445#endif /* HAVE_IPV6 */
5446
5447 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5448 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5449
5450 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5451 vty_out (vty, ", metric %d", attr->med);
5452
5453 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5454 vty_out (vty, ", localpref %d", attr->local_pref);
5455 else
5456 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5457
5458 if (attr->weight != 0)
5459 vty_out (vty, ", weight %d", attr->weight);
5460
5461 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5462 vty_out (vty, ", valid");
5463
5464 if (binfo->peer != bgp->peer_self)
5465 {
5466 if (binfo->peer->as == binfo->peer->local_as)
5467 vty_out (vty, ", internal");
5468 else
5469 vty_out (vty, ", %s",
5470 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5471 }
5472 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5473 vty_out (vty, ", aggregated, local");
5474 else if (binfo->type != ZEBRA_ROUTE_BGP)
5475 vty_out (vty, ", sourced");
5476 else
5477 vty_out (vty, ", sourced, local");
5478
5479 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5480 vty_out (vty, ", atomic-aggregate");
5481
5482 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5483 vty_out (vty, ", best");
5484
5485 vty_out (vty, "%s", VTY_NEWLINE);
5486
5487 /* Line 4 display Community */
5488 if (attr->community)
5489 vty_out (vty, " Community: %s%s", attr->community->str,
5490 VTY_NEWLINE);
5491
5492 /* Line 5 display Extended-community */
5493 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5494 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5495 VTY_NEWLINE);
5496
5497 /* Line 6 display Originator, Cluster-id */
5498 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5499 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5500 {
5501 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5502 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5503
5504 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5505 {
5506 int i;
5507 vty_out (vty, ", Cluster list: ");
5508 for (i = 0; i < attr->cluster->length / 4; i++)
5509 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5510 }
5511 vty_out (vty, "%s", VTY_NEWLINE);
5512 }
5513
5514 if (binfo->damp_info)
5515 bgp_damp_info_vty (vty, binfo);
5516
5517 /* Line 7 display Uptime */
5518 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5519 }
5520 vty_out (vty, "%s", VTY_NEWLINE);
5521}
5522
paulb40d9392005-08-22 22:34:41 +00005523#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 +00005524#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005525#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5526#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5527#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5528
5529enum bgp_show_type
5530{
5531 bgp_show_type_normal,
5532 bgp_show_type_regexp,
5533 bgp_show_type_prefix_list,
5534 bgp_show_type_filter_list,
5535 bgp_show_type_route_map,
5536 bgp_show_type_neighbor,
5537 bgp_show_type_cidr_only,
5538 bgp_show_type_prefix_longer,
5539 bgp_show_type_community_all,
5540 bgp_show_type_community,
5541 bgp_show_type_community_exact,
5542 bgp_show_type_community_list,
5543 bgp_show_type_community_list_exact,
5544 bgp_show_type_flap_statistics,
5545 bgp_show_type_flap_address,
5546 bgp_show_type_flap_prefix,
5547 bgp_show_type_flap_cidr_only,
5548 bgp_show_type_flap_regexp,
5549 bgp_show_type_flap_filter_list,
5550 bgp_show_type_flap_prefix_list,
5551 bgp_show_type_flap_prefix_longer,
5552 bgp_show_type_flap_route_map,
5553 bgp_show_type_flap_neighbor,
5554 bgp_show_type_dampend_paths,
5555 bgp_show_type_damp_neighbor
5556};
5557
ajs5a646652004-11-05 01:25:55 +00005558static int
paulfee0f4c2004-09-13 05:12:46 +00005559bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005560 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005561{
paul718e3742002-12-13 20:15:29 +00005562 struct bgp_info *ri;
5563 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005564 int header = 1;
paul718e3742002-12-13 20:15:29 +00005565 int display;
ajs5a646652004-11-05 01:25:55 +00005566 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005567
5568 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005569 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005570
paul718e3742002-12-13 20:15:29 +00005571 /* Start processing of routes. */
5572 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5573 if (rn->info != NULL)
5574 {
5575 display = 0;
5576
5577 for (ri = rn->info; ri; ri = ri->next)
5578 {
ajs5a646652004-11-05 01:25:55 +00005579 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005580 || type == bgp_show_type_flap_address
5581 || type == bgp_show_type_flap_prefix
5582 || type == bgp_show_type_flap_cidr_only
5583 || type == bgp_show_type_flap_regexp
5584 || type == bgp_show_type_flap_filter_list
5585 || type == bgp_show_type_flap_prefix_list
5586 || type == bgp_show_type_flap_prefix_longer
5587 || type == bgp_show_type_flap_route_map
5588 || type == bgp_show_type_flap_neighbor
5589 || type == bgp_show_type_dampend_paths
5590 || type == bgp_show_type_damp_neighbor)
5591 {
5592 if (! ri->damp_info)
5593 continue;
5594 }
5595 if (type == bgp_show_type_regexp
5596 || type == bgp_show_type_flap_regexp)
5597 {
ajs5a646652004-11-05 01:25:55 +00005598 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005599
5600 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5601 continue;
5602 }
5603 if (type == bgp_show_type_prefix_list
5604 || type == bgp_show_type_flap_prefix_list)
5605 {
ajs5a646652004-11-05 01:25:55 +00005606 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005607
5608 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5609 continue;
5610 }
5611 if (type == bgp_show_type_filter_list
5612 || type == bgp_show_type_flap_filter_list)
5613 {
ajs5a646652004-11-05 01:25:55 +00005614 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005615
5616 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5617 continue;
5618 }
5619 if (type == bgp_show_type_route_map
5620 || type == bgp_show_type_flap_route_map)
5621 {
ajs5a646652004-11-05 01:25:55 +00005622 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005623 struct bgp_info binfo;
5624 struct attr dummy_attr;
5625 int ret;
5626
5627 dummy_attr = *ri->attr;
5628 binfo.peer = ri->peer;
5629 binfo.attr = &dummy_attr;
5630
5631 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5632
5633 if (ret == RMAP_DENYMATCH)
5634 continue;
5635 }
5636 if (type == bgp_show_type_neighbor
5637 || type == bgp_show_type_flap_neighbor
5638 || type == bgp_show_type_damp_neighbor)
5639 {
ajs5a646652004-11-05 01:25:55 +00005640 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005641
5642 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5643 continue;
5644 }
5645 if (type == bgp_show_type_cidr_only
5646 || type == bgp_show_type_flap_cidr_only)
5647 {
5648 u_int32_t destination;
5649
5650 destination = ntohl (rn->p.u.prefix4.s_addr);
5651 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5652 continue;
5653 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5654 continue;
5655 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5656 continue;
5657 }
5658 if (type == bgp_show_type_prefix_longer
5659 || type == bgp_show_type_flap_prefix_longer)
5660 {
ajs5a646652004-11-05 01:25:55 +00005661 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005662
5663 if (! prefix_match (p, &rn->p))
5664 continue;
5665 }
5666 if (type == bgp_show_type_community_all)
5667 {
5668 if (! ri->attr->community)
5669 continue;
5670 }
5671 if (type == bgp_show_type_community)
5672 {
ajs5a646652004-11-05 01:25:55 +00005673 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005674
5675 if (! ri->attr->community ||
5676 ! community_match (ri->attr->community, com))
5677 continue;
5678 }
5679 if (type == bgp_show_type_community_exact)
5680 {
ajs5a646652004-11-05 01:25:55 +00005681 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005682
5683 if (! ri->attr->community ||
5684 ! community_cmp (ri->attr->community, com))
5685 continue;
5686 }
5687 if (type == bgp_show_type_community_list)
5688 {
ajs5a646652004-11-05 01:25:55 +00005689 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005690
5691 if (! community_list_match (ri->attr->community, list))
5692 continue;
5693 }
5694 if (type == bgp_show_type_community_list_exact)
5695 {
ajs5a646652004-11-05 01:25:55 +00005696 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005697
5698 if (! community_list_exact_match (ri->attr->community, list))
5699 continue;
5700 }
5701 if (type == bgp_show_type_flap_address
5702 || type == bgp_show_type_flap_prefix)
5703 {
ajs5a646652004-11-05 01:25:55 +00005704 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005705
5706 if (! prefix_match (&rn->p, p))
5707 continue;
5708
5709 if (type == bgp_show_type_flap_prefix)
5710 if (p->prefixlen != rn->p.prefixlen)
5711 continue;
5712 }
5713 if (type == bgp_show_type_dampend_paths
5714 || type == bgp_show_type_damp_neighbor)
5715 {
5716 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5717 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5718 continue;
5719 }
5720
5721 if (header)
5722 {
hasso93406d82005-02-02 14:40:33 +00005723 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5724 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5725 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005726 if (type == bgp_show_type_dampend_paths
5727 || type == bgp_show_type_damp_neighbor)
5728 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5729 else if (type == bgp_show_type_flap_statistics
5730 || type == bgp_show_type_flap_address
5731 || type == bgp_show_type_flap_prefix
5732 || type == bgp_show_type_flap_cidr_only
5733 || type == bgp_show_type_flap_regexp
5734 || type == bgp_show_type_flap_filter_list
5735 || type == bgp_show_type_flap_prefix_list
5736 || type == bgp_show_type_flap_prefix_longer
5737 || type == bgp_show_type_flap_route_map
5738 || type == bgp_show_type_flap_neighbor)
5739 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5740 else
5741 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005742 header = 0;
5743 }
5744
5745 if (type == bgp_show_type_dampend_paths
5746 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005747 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005748 else if (type == bgp_show_type_flap_statistics
5749 || type == bgp_show_type_flap_address
5750 || type == bgp_show_type_flap_prefix
5751 || type == bgp_show_type_flap_cidr_only
5752 || type == bgp_show_type_flap_regexp
5753 || type == bgp_show_type_flap_filter_list
5754 || type == bgp_show_type_flap_prefix_list
5755 || type == bgp_show_type_flap_prefix_longer
5756 || type == bgp_show_type_flap_route_map
5757 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005758 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005759 else
ajs5a646652004-11-05 01:25:55 +00005760 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005761 display++;
5762 }
5763 if (display)
ajs5a646652004-11-05 01:25:55 +00005764 output_count++;
paul718e3742002-12-13 20:15:29 +00005765 }
5766
5767 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005768 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005769 {
5770 if (type == bgp_show_type_normal)
5771 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5772 }
5773 else
5774 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005775 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005776
5777 return CMD_SUCCESS;
5778}
5779
ajs5a646652004-11-05 01:25:55 +00005780static int
paulfee0f4c2004-09-13 05:12:46 +00005781bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005782 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005783{
5784 struct bgp_table *table;
5785
5786 if (bgp == NULL) {
5787 bgp = bgp_get_default ();
5788 }
5789
5790 if (bgp == NULL)
5791 {
5792 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5793 return CMD_WARNING;
5794 }
5795
5796
5797 table = bgp->rib[afi][safi];
5798
ajs5a646652004-11-05 01:25:55 +00005799 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005800}
5801
paul718e3742002-12-13 20:15:29 +00005802/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005803static void
paul718e3742002-12-13 20:15:29 +00005804route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5805 struct bgp_node *rn,
5806 struct prefix_rd *prd, afi_t afi, safi_t safi)
5807{
5808 struct bgp_info *ri;
5809 struct prefix *p;
5810 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005811 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005812 char buf1[INET6_ADDRSTRLEN];
5813 char buf2[INET6_ADDRSTRLEN];
5814 int count = 0;
5815 int best = 0;
5816 int suppress = 0;
5817 int no_export = 0;
5818 int no_advertise = 0;
5819 int local_as = 0;
5820 int first = 0;
5821
5822 p = &rn->p;
5823 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5824 (safi == SAFI_MPLS_VPN ?
5825 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5826 safi == SAFI_MPLS_VPN ? ":" : "",
5827 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5828 p->prefixlen, VTY_NEWLINE);
5829
5830 for (ri = rn->info; ri; ri = ri->next)
5831 {
5832 count++;
5833 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5834 {
5835 best = count;
5836 if (ri->suppress)
5837 suppress = 1;
5838 if (ri->attr->community != NULL)
5839 {
5840 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5841 no_advertise = 1;
5842 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5843 no_export = 1;
5844 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5845 local_as = 1;
5846 }
5847 }
5848 }
5849
5850 vty_out (vty, "Paths: (%d available", count);
5851 if (best)
5852 {
5853 vty_out (vty, ", best #%d", best);
5854 if (safi == SAFI_UNICAST)
5855 vty_out (vty, ", table Default-IP-Routing-Table");
5856 }
5857 else
5858 vty_out (vty, ", no best path");
5859 if (no_advertise)
5860 vty_out (vty, ", not advertised to any peer");
5861 else if (no_export)
5862 vty_out (vty, ", not advertised to EBGP peer");
5863 else if (local_as)
5864 vty_out (vty, ", not advertised outside local AS");
5865 if (suppress)
5866 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5867 vty_out (vty, ")%s", VTY_NEWLINE);
5868
5869 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005870 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005871 {
5872 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5873 {
5874 if (! first)
5875 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5876 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5877 first = 1;
5878 }
5879 }
5880 if (! first)
5881 vty_out (vty, " Not advertised to any peer");
5882 vty_out (vty, "%s", VTY_NEWLINE);
5883}
5884
5885/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005886static int
paulfee0f4c2004-09-13 05:12:46 +00005887bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005888 struct bgp_table *rib, const char *ip_str,
5889 afi_t afi, safi_t safi, struct prefix_rd *prd,
5890 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005891{
5892 int ret;
5893 int header;
5894 int display = 0;
5895 struct prefix match;
5896 struct bgp_node *rn;
5897 struct bgp_node *rm;
5898 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005899 struct bgp_table *table;
5900
paul718e3742002-12-13 20:15:29 +00005901 /* Check IP address argument. */
5902 ret = str2prefix (ip_str, &match);
5903 if (! ret)
5904 {
5905 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5906 return CMD_WARNING;
5907 }
5908
5909 match.family = afi2family (afi);
5910
5911 if (safi == SAFI_MPLS_VPN)
5912 {
paulfee0f4c2004-09-13 05:12:46 +00005913 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005914 {
5915 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5916 continue;
5917
5918 if ((table = rn->info) != NULL)
5919 {
5920 header = 1;
5921
5922 if ((rm = bgp_node_match (table, &match)) != NULL)
5923 {
5924 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5925 continue;
5926
5927 for (ri = rm->info; ri; ri = ri->next)
5928 {
5929 if (header)
5930 {
5931 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5932 AFI_IP, SAFI_MPLS_VPN);
5933
5934 header = 0;
5935 }
5936 display++;
5937 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5938 }
5939 }
5940 }
5941 }
5942 }
5943 else
5944 {
5945 header = 1;
5946
paulfee0f4c2004-09-13 05:12:46 +00005947 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005948 {
5949 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5950 {
5951 for (ri = rn->info; ri; ri = ri->next)
5952 {
5953 if (header)
5954 {
5955 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5956 header = 0;
5957 }
5958 display++;
5959 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5960 }
5961 }
5962 }
5963 }
5964
5965 if (! display)
5966 {
5967 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5968 return CMD_WARNING;
5969 }
5970
5971 return CMD_SUCCESS;
5972}
5973
paulfee0f4c2004-09-13 05:12:46 +00005974/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00005975static int
paulfd79ac92004-10-13 05:06:08 +00005976bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00005977 afi_t afi, safi_t safi, struct prefix_rd *prd,
5978 int prefix_check)
5979{
5980 struct bgp *bgp;
5981
5982 /* BGP structure lookup. */
5983 if (view_name)
5984 {
5985 bgp = bgp_lookup_by_name (view_name);
5986 if (bgp == NULL)
5987 {
5988 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
5989 return CMD_WARNING;
5990 }
5991 }
5992 else
5993 {
5994 bgp = bgp_get_default ();
5995 if (bgp == NULL)
5996 {
5997 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5998 return CMD_WARNING;
5999 }
6000 }
6001
6002 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6003 afi, safi, prd, prefix_check);
6004}
6005
paul718e3742002-12-13 20:15:29 +00006006/* BGP route print out function. */
6007DEFUN (show_ip_bgp,
6008 show_ip_bgp_cmd,
6009 "show ip bgp",
6010 SHOW_STR
6011 IP_STR
6012 BGP_STR)
6013{
ajs5a646652004-11-05 01:25:55 +00006014 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006015}
6016
6017DEFUN (show_ip_bgp_ipv4,
6018 show_ip_bgp_ipv4_cmd,
6019 "show ip bgp ipv4 (unicast|multicast)",
6020 SHOW_STR
6021 IP_STR
6022 BGP_STR
6023 "Address family\n"
6024 "Address Family modifier\n"
6025 "Address Family modifier\n")
6026{
6027 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006028 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6029 NULL);
paul718e3742002-12-13 20:15:29 +00006030
ajs5a646652004-11-05 01:25:55 +00006031 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006032}
6033
6034DEFUN (show_ip_bgp_route,
6035 show_ip_bgp_route_cmd,
6036 "show ip bgp A.B.C.D",
6037 SHOW_STR
6038 IP_STR
6039 BGP_STR
6040 "Network in the BGP routing table to display\n")
6041{
6042 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6043}
6044
6045DEFUN (show_ip_bgp_ipv4_route,
6046 show_ip_bgp_ipv4_route_cmd,
6047 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6048 SHOW_STR
6049 IP_STR
6050 BGP_STR
6051 "Address family\n"
6052 "Address Family modifier\n"
6053 "Address Family modifier\n"
6054 "Network in the BGP routing table to display\n")
6055{
6056 if (strncmp (argv[0], "m", 1) == 0)
6057 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6058
6059 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6060}
6061
6062DEFUN (show_ip_bgp_vpnv4_all_route,
6063 show_ip_bgp_vpnv4_all_route_cmd,
6064 "show ip bgp vpnv4 all A.B.C.D",
6065 SHOW_STR
6066 IP_STR
6067 BGP_STR
6068 "Display VPNv4 NLRI specific information\n"
6069 "Display information about all VPNv4 NLRIs\n"
6070 "Network in the BGP routing table to display\n")
6071{
6072 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6073}
6074
6075DEFUN (show_ip_bgp_vpnv4_rd_route,
6076 show_ip_bgp_vpnv4_rd_route_cmd,
6077 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6078 SHOW_STR
6079 IP_STR
6080 BGP_STR
6081 "Display VPNv4 NLRI specific information\n"
6082 "Display information for a route distinguisher\n"
6083 "VPN Route Distinguisher\n"
6084 "Network in the BGP routing table to display\n")
6085{
6086 int ret;
6087 struct prefix_rd prd;
6088
6089 ret = str2prefix_rd (argv[0], &prd);
6090 if (! ret)
6091 {
6092 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6093 return CMD_WARNING;
6094 }
6095 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6096}
6097
6098DEFUN (show_ip_bgp_prefix,
6099 show_ip_bgp_prefix_cmd,
6100 "show ip bgp A.B.C.D/M",
6101 SHOW_STR
6102 IP_STR
6103 BGP_STR
6104 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6105{
6106 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6107}
6108
6109DEFUN (show_ip_bgp_ipv4_prefix,
6110 show_ip_bgp_ipv4_prefix_cmd,
6111 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6112 SHOW_STR
6113 IP_STR
6114 BGP_STR
6115 "Address family\n"
6116 "Address Family modifier\n"
6117 "Address Family modifier\n"
6118 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6119{
6120 if (strncmp (argv[0], "m", 1) == 0)
6121 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6122
6123 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6124}
6125
6126DEFUN (show_ip_bgp_vpnv4_all_prefix,
6127 show_ip_bgp_vpnv4_all_prefix_cmd,
6128 "show ip bgp vpnv4 all A.B.C.D/M",
6129 SHOW_STR
6130 IP_STR
6131 BGP_STR
6132 "Display VPNv4 NLRI specific information\n"
6133 "Display information about all VPNv4 NLRIs\n"
6134 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6135{
6136 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6137}
6138
6139DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6140 show_ip_bgp_vpnv4_rd_prefix_cmd,
6141 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6142 SHOW_STR
6143 IP_STR
6144 BGP_STR
6145 "Display VPNv4 NLRI specific information\n"
6146 "Display information for a route distinguisher\n"
6147 "VPN Route Distinguisher\n"
6148 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6149{
6150 int ret;
6151 struct prefix_rd prd;
6152
6153 ret = str2prefix_rd (argv[0], &prd);
6154 if (! ret)
6155 {
6156 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6157 return CMD_WARNING;
6158 }
6159 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6160}
6161
6162DEFUN (show_ip_bgp_view,
6163 show_ip_bgp_view_cmd,
6164 "show ip bgp view WORD",
6165 SHOW_STR
6166 IP_STR
6167 BGP_STR
6168 "BGP view\n"
6169 "BGP view name\n")
6170{
paulbb46e942003-10-24 19:02:03 +00006171 struct bgp *bgp;
6172
6173 /* BGP structure lookup. */
6174 bgp = bgp_lookup_by_name (argv[0]);
6175 if (bgp == NULL)
6176 {
6177 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6178 return CMD_WARNING;
6179 }
6180
ajs5a646652004-11-05 01:25:55 +00006181 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006182}
6183
6184DEFUN (show_ip_bgp_view_route,
6185 show_ip_bgp_view_route_cmd,
6186 "show ip bgp view WORD A.B.C.D",
6187 SHOW_STR
6188 IP_STR
6189 BGP_STR
6190 "BGP view\n"
6191 "BGP view name\n"
6192 "Network in the BGP routing table to display\n")
6193{
6194 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6195}
6196
6197DEFUN (show_ip_bgp_view_prefix,
6198 show_ip_bgp_view_prefix_cmd,
6199 "show ip bgp view WORD A.B.C.D/M",
6200 SHOW_STR
6201 IP_STR
6202 BGP_STR
6203 "BGP view\n"
6204 "BGP view name\n"
6205 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6206{
6207 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6208}
6209
6210#ifdef HAVE_IPV6
6211DEFUN (show_bgp,
6212 show_bgp_cmd,
6213 "show bgp",
6214 SHOW_STR
6215 BGP_STR)
6216{
ajs5a646652004-11-05 01:25:55 +00006217 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6218 NULL);
paul718e3742002-12-13 20:15:29 +00006219}
6220
6221ALIAS (show_bgp,
6222 show_bgp_ipv6_cmd,
6223 "show bgp ipv6",
6224 SHOW_STR
6225 BGP_STR
6226 "Address family\n")
6227
6228/* old command */
6229DEFUN (show_ipv6_bgp,
6230 show_ipv6_bgp_cmd,
6231 "show ipv6 bgp",
6232 SHOW_STR
6233 IP_STR
6234 BGP_STR)
6235{
ajs5a646652004-11-05 01:25:55 +00006236 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6237 NULL);
paul718e3742002-12-13 20:15:29 +00006238}
6239
6240DEFUN (show_bgp_route,
6241 show_bgp_route_cmd,
6242 "show bgp X:X::X:X",
6243 SHOW_STR
6244 BGP_STR
6245 "Network in the BGP routing table to display\n")
6246{
6247 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6248}
6249
6250ALIAS (show_bgp_route,
6251 show_bgp_ipv6_route_cmd,
6252 "show bgp ipv6 X:X::X:X",
6253 SHOW_STR
6254 BGP_STR
6255 "Address family\n"
6256 "Network in the BGP routing table to display\n")
6257
6258/* old command */
6259DEFUN (show_ipv6_bgp_route,
6260 show_ipv6_bgp_route_cmd,
6261 "show ipv6 bgp X:X::X:X",
6262 SHOW_STR
6263 IP_STR
6264 BGP_STR
6265 "Network in the BGP routing table to display\n")
6266{
6267 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6268}
6269
6270DEFUN (show_bgp_prefix,
6271 show_bgp_prefix_cmd,
6272 "show bgp X:X::X:X/M",
6273 SHOW_STR
6274 BGP_STR
6275 "IPv6 prefix <network>/<length>\n")
6276{
6277 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6278}
6279
6280ALIAS (show_bgp_prefix,
6281 show_bgp_ipv6_prefix_cmd,
6282 "show bgp ipv6 X:X::X:X/M",
6283 SHOW_STR
6284 BGP_STR
6285 "Address family\n"
6286 "IPv6 prefix <network>/<length>\n")
6287
6288/* old command */
6289DEFUN (show_ipv6_bgp_prefix,
6290 show_ipv6_bgp_prefix_cmd,
6291 "show ipv6 bgp X:X::X:X/M",
6292 SHOW_STR
6293 IP_STR
6294 BGP_STR
6295 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6296{
6297 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6298}
6299
paulbb46e942003-10-24 19:02:03 +00006300DEFUN (show_bgp_view,
6301 show_bgp_view_cmd,
6302 "show bgp view WORD",
6303 SHOW_STR
6304 BGP_STR
6305 "BGP view\n"
6306 "View name\n")
6307{
6308 struct bgp *bgp;
6309
6310 /* BGP structure lookup. */
6311 bgp = bgp_lookup_by_name (argv[0]);
6312 if (bgp == NULL)
6313 {
6314 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6315 return CMD_WARNING;
6316 }
6317
ajs5a646652004-11-05 01:25:55 +00006318 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006319}
6320
6321ALIAS (show_bgp_view,
6322 show_bgp_view_ipv6_cmd,
6323 "show bgp view WORD ipv6",
6324 SHOW_STR
6325 BGP_STR
6326 "BGP view\n"
6327 "View name\n"
6328 "Address family\n")
6329
6330DEFUN (show_bgp_view_route,
6331 show_bgp_view_route_cmd,
6332 "show bgp view WORD X:X::X:X",
6333 SHOW_STR
6334 BGP_STR
6335 "BGP view\n"
6336 "View name\n"
6337 "Network in the BGP routing table to display\n")
6338{
6339 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6340}
6341
6342ALIAS (show_bgp_view_route,
6343 show_bgp_view_ipv6_route_cmd,
6344 "show bgp view WORD ipv6 X:X::X:X",
6345 SHOW_STR
6346 BGP_STR
6347 "BGP view\n"
6348 "View name\n"
6349 "Address family\n"
6350 "Network in the BGP routing table to display\n")
6351
6352DEFUN (show_bgp_view_prefix,
6353 show_bgp_view_prefix_cmd,
6354 "show bgp view WORD X:X::X:X/M",
6355 SHOW_STR
6356 BGP_STR
6357 "BGP view\n"
6358 "View name\n"
6359 "IPv6 prefix <network>/<length>\n")
6360{
6361 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6362}
6363
6364ALIAS (show_bgp_view_prefix,
6365 show_bgp_view_ipv6_prefix_cmd,
6366 "show bgp view WORD ipv6 X:X::X:X/M",
6367 SHOW_STR
6368 BGP_STR
6369 "BGP view\n"
6370 "View name\n"
6371 "Address family\n"
6372 "IPv6 prefix <network>/<length>\n")
6373
paul718e3742002-12-13 20:15:29 +00006374/* old command */
6375DEFUN (show_ipv6_mbgp,
6376 show_ipv6_mbgp_cmd,
6377 "show ipv6 mbgp",
6378 SHOW_STR
6379 IP_STR
6380 MBGP_STR)
6381{
ajs5a646652004-11-05 01:25:55 +00006382 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6383 NULL);
paul718e3742002-12-13 20:15:29 +00006384}
6385
6386/* old command */
6387DEFUN (show_ipv6_mbgp_route,
6388 show_ipv6_mbgp_route_cmd,
6389 "show ipv6 mbgp X:X::X:X",
6390 SHOW_STR
6391 IP_STR
6392 MBGP_STR
6393 "Network in the MBGP routing table to display\n")
6394{
6395 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6396}
6397
6398/* old command */
6399DEFUN (show_ipv6_mbgp_prefix,
6400 show_ipv6_mbgp_prefix_cmd,
6401 "show ipv6 mbgp X:X::X:X/M",
6402 SHOW_STR
6403 IP_STR
6404 MBGP_STR
6405 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6406{
6407 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6408}
6409#endif
6410
paul718e3742002-12-13 20:15:29 +00006411
paul94f2b392005-06-28 12:44:16 +00006412static int
paulfd79ac92004-10-13 05:06:08 +00006413bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006414 safi_t safi, enum bgp_show_type type)
6415{
6416 int i;
6417 struct buffer *b;
6418 char *regstr;
6419 int first;
6420 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006421 int rc;
paul718e3742002-12-13 20:15:29 +00006422
6423 first = 0;
6424 b = buffer_new (1024);
6425 for (i = 0; i < argc; i++)
6426 {
6427 if (first)
6428 buffer_putc (b, ' ');
6429 else
6430 {
6431 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6432 continue;
6433 first = 1;
6434 }
6435
6436 buffer_putstr (b, argv[i]);
6437 }
6438 buffer_putc (b, '\0');
6439
6440 regstr = buffer_getstr (b);
6441 buffer_free (b);
6442
6443 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006444 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006445 if (! regex)
6446 {
6447 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6448 VTY_NEWLINE);
6449 return CMD_WARNING;
6450 }
6451
ajs5a646652004-11-05 01:25:55 +00006452 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6453 bgp_regex_free (regex);
6454 return rc;
paul718e3742002-12-13 20:15:29 +00006455}
6456
6457DEFUN (show_ip_bgp_regexp,
6458 show_ip_bgp_regexp_cmd,
6459 "show ip bgp regexp .LINE",
6460 SHOW_STR
6461 IP_STR
6462 BGP_STR
6463 "Display routes matching the AS path regular expression\n"
6464 "A regular-expression to match the BGP AS paths\n")
6465{
6466 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6467 bgp_show_type_regexp);
6468}
6469
6470DEFUN (show_ip_bgp_flap_regexp,
6471 show_ip_bgp_flap_regexp_cmd,
6472 "show ip bgp flap-statistics regexp .LINE",
6473 SHOW_STR
6474 IP_STR
6475 BGP_STR
6476 "Display flap statistics of routes\n"
6477 "Display routes matching the AS path regular expression\n"
6478 "A regular-expression to match the BGP AS paths\n")
6479{
6480 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6481 bgp_show_type_flap_regexp);
6482}
6483
6484DEFUN (show_ip_bgp_ipv4_regexp,
6485 show_ip_bgp_ipv4_regexp_cmd,
6486 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6487 SHOW_STR
6488 IP_STR
6489 BGP_STR
6490 "Address family\n"
6491 "Address Family modifier\n"
6492 "Address Family modifier\n"
6493 "Display routes matching the AS path regular expression\n"
6494 "A regular-expression to match the BGP AS paths\n")
6495{
6496 if (strncmp (argv[0], "m", 1) == 0)
6497 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6498 bgp_show_type_regexp);
6499
6500 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6501 bgp_show_type_regexp);
6502}
6503
6504#ifdef HAVE_IPV6
6505DEFUN (show_bgp_regexp,
6506 show_bgp_regexp_cmd,
6507 "show bgp regexp .LINE",
6508 SHOW_STR
6509 BGP_STR
6510 "Display routes matching the AS path regular expression\n"
6511 "A regular-expression to match the BGP AS paths\n")
6512{
6513 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6514 bgp_show_type_regexp);
6515}
6516
6517ALIAS (show_bgp_regexp,
6518 show_bgp_ipv6_regexp_cmd,
6519 "show bgp ipv6 regexp .LINE",
6520 SHOW_STR
6521 BGP_STR
6522 "Address family\n"
6523 "Display routes matching the AS path regular expression\n"
6524 "A regular-expression to match the BGP AS paths\n")
6525
6526/* old command */
6527DEFUN (show_ipv6_bgp_regexp,
6528 show_ipv6_bgp_regexp_cmd,
6529 "show ipv6 bgp regexp .LINE",
6530 SHOW_STR
6531 IP_STR
6532 BGP_STR
6533 "Display routes matching the AS path regular expression\n"
6534 "A regular-expression to match the BGP AS paths\n")
6535{
6536 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6537 bgp_show_type_regexp);
6538}
6539
6540/* old command */
6541DEFUN (show_ipv6_mbgp_regexp,
6542 show_ipv6_mbgp_regexp_cmd,
6543 "show ipv6 mbgp regexp .LINE",
6544 SHOW_STR
6545 IP_STR
6546 BGP_STR
6547 "Display routes matching the AS path regular expression\n"
6548 "A regular-expression to match the MBGP AS paths\n")
6549{
6550 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6551 bgp_show_type_regexp);
6552}
6553#endif /* HAVE_IPV6 */
6554
paul94f2b392005-06-28 12:44:16 +00006555static int
paulfd79ac92004-10-13 05:06:08 +00006556bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006557 safi_t safi, enum bgp_show_type type)
6558{
6559 struct prefix_list *plist;
6560
6561 plist = prefix_list_lookup (afi, prefix_list_str);
6562 if (plist == NULL)
6563 {
6564 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6565 prefix_list_str, VTY_NEWLINE);
6566 return CMD_WARNING;
6567 }
6568
ajs5a646652004-11-05 01:25:55 +00006569 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006570}
6571
6572DEFUN (show_ip_bgp_prefix_list,
6573 show_ip_bgp_prefix_list_cmd,
6574 "show ip bgp prefix-list WORD",
6575 SHOW_STR
6576 IP_STR
6577 BGP_STR
6578 "Display routes conforming to the prefix-list\n"
6579 "IP prefix-list name\n")
6580{
6581 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6582 bgp_show_type_prefix_list);
6583}
6584
6585DEFUN (show_ip_bgp_flap_prefix_list,
6586 show_ip_bgp_flap_prefix_list_cmd,
6587 "show ip bgp flap-statistics prefix-list WORD",
6588 SHOW_STR
6589 IP_STR
6590 BGP_STR
6591 "Display flap statistics of routes\n"
6592 "Display routes conforming to the prefix-list\n"
6593 "IP prefix-list name\n")
6594{
6595 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6596 bgp_show_type_flap_prefix_list);
6597}
6598
6599DEFUN (show_ip_bgp_ipv4_prefix_list,
6600 show_ip_bgp_ipv4_prefix_list_cmd,
6601 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6602 SHOW_STR
6603 IP_STR
6604 BGP_STR
6605 "Address family\n"
6606 "Address Family modifier\n"
6607 "Address Family modifier\n"
6608 "Display routes conforming to the prefix-list\n"
6609 "IP prefix-list name\n")
6610{
6611 if (strncmp (argv[0], "m", 1) == 0)
6612 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6613 bgp_show_type_prefix_list);
6614
6615 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6616 bgp_show_type_prefix_list);
6617}
6618
6619#ifdef HAVE_IPV6
6620DEFUN (show_bgp_prefix_list,
6621 show_bgp_prefix_list_cmd,
6622 "show bgp prefix-list WORD",
6623 SHOW_STR
6624 BGP_STR
6625 "Display routes conforming to the prefix-list\n"
6626 "IPv6 prefix-list name\n")
6627{
6628 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6629 bgp_show_type_prefix_list);
6630}
6631
6632ALIAS (show_bgp_prefix_list,
6633 show_bgp_ipv6_prefix_list_cmd,
6634 "show bgp ipv6 prefix-list WORD",
6635 SHOW_STR
6636 BGP_STR
6637 "Address family\n"
6638 "Display routes conforming to the prefix-list\n"
6639 "IPv6 prefix-list name\n")
6640
6641/* old command */
6642DEFUN (show_ipv6_bgp_prefix_list,
6643 show_ipv6_bgp_prefix_list_cmd,
6644 "show ipv6 bgp prefix-list WORD",
6645 SHOW_STR
6646 IPV6_STR
6647 BGP_STR
6648 "Display routes matching the prefix-list\n"
6649 "IPv6 prefix-list name\n")
6650{
6651 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6652 bgp_show_type_prefix_list);
6653}
6654
6655/* old command */
6656DEFUN (show_ipv6_mbgp_prefix_list,
6657 show_ipv6_mbgp_prefix_list_cmd,
6658 "show ipv6 mbgp prefix-list WORD",
6659 SHOW_STR
6660 IPV6_STR
6661 MBGP_STR
6662 "Display routes matching the prefix-list\n"
6663 "IPv6 prefix-list name\n")
6664{
6665 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6666 bgp_show_type_prefix_list);
6667}
6668#endif /* HAVE_IPV6 */
6669
paul94f2b392005-06-28 12:44:16 +00006670static int
paulfd79ac92004-10-13 05:06:08 +00006671bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006672 safi_t safi, enum bgp_show_type type)
6673{
6674 struct as_list *as_list;
6675
6676 as_list = as_list_lookup (filter);
6677 if (as_list == NULL)
6678 {
6679 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6680 return CMD_WARNING;
6681 }
6682
ajs5a646652004-11-05 01:25:55 +00006683 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006684}
6685
6686DEFUN (show_ip_bgp_filter_list,
6687 show_ip_bgp_filter_list_cmd,
6688 "show ip bgp filter-list WORD",
6689 SHOW_STR
6690 IP_STR
6691 BGP_STR
6692 "Display routes conforming to the filter-list\n"
6693 "Regular expression access list name\n")
6694{
6695 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6696 bgp_show_type_filter_list);
6697}
6698
6699DEFUN (show_ip_bgp_flap_filter_list,
6700 show_ip_bgp_flap_filter_list_cmd,
6701 "show ip bgp flap-statistics filter-list WORD",
6702 SHOW_STR
6703 IP_STR
6704 BGP_STR
6705 "Display flap statistics of routes\n"
6706 "Display routes conforming to the filter-list\n"
6707 "Regular expression access list name\n")
6708{
6709 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6710 bgp_show_type_flap_filter_list);
6711}
6712
6713DEFUN (show_ip_bgp_ipv4_filter_list,
6714 show_ip_bgp_ipv4_filter_list_cmd,
6715 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6716 SHOW_STR
6717 IP_STR
6718 BGP_STR
6719 "Address family\n"
6720 "Address Family modifier\n"
6721 "Address Family modifier\n"
6722 "Display routes conforming to the filter-list\n"
6723 "Regular expression access list name\n")
6724{
6725 if (strncmp (argv[0], "m", 1) == 0)
6726 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6727 bgp_show_type_filter_list);
6728
6729 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6730 bgp_show_type_filter_list);
6731}
6732
6733#ifdef HAVE_IPV6
6734DEFUN (show_bgp_filter_list,
6735 show_bgp_filter_list_cmd,
6736 "show bgp filter-list WORD",
6737 SHOW_STR
6738 BGP_STR
6739 "Display routes conforming to the filter-list\n"
6740 "Regular expression access list name\n")
6741{
6742 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6743 bgp_show_type_filter_list);
6744}
6745
6746ALIAS (show_bgp_filter_list,
6747 show_bgp_ipv6_filter_list_cmd,
6748 "show bgp ipv6 filter-list WORD",
6749 SHOW_STR
6750 BGP_STR
6751 "Address family\n"
6752 "Display routes conforming to the filter-list\n"
6753 "Regular expression access list name\n")
6754
6755/* old command */
6756DEFUN (show_ipv6_bgp_filter_list,
6757 show_ipv6_bgp_filter_list_cmd,
6758 "show ipv6 bgp filter-list WORD",
6759 SHOW_STR
6760 IPV6_STR
6761 BGP_STR
6762 "Display routes conforming to the filter-list\n"
6763 "Regular expression access list name\n")
6764{
6765 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6766 bgp_show_type_filter_list);
6767}
6768
6769/* old command */
6770DEFUN (show_ipv6_mbgp_filter_list,
6771 show_ipv6_mbgp_filter_list_cmd,
6772 "show ipv6 mbgp filter-list WORD",
6773 SHOW_STR
6774 IPV6_STR
6775 MBGP_STR
6776 "Display routes conforming to the filter-list\n"
6777 "Regular expression access list name\n")
6778{
6779 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6780 bgp_show_type_filter_list);
6781}
6782#endif /* HAVE_IPV6 */
6783
paul94f2b392005-06-28 12:44:16 +00006784static int
paulfd79ac92004-10-13 05:06:08 +00006785bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006786 safi_t safi, enum bgp_show_type type)
6787{
6788 struct route_map *rmap;
6789
6790 rmap = route_map_lookup_by_name (rmap_str);
6791 if (! rmap)
6792 {
6793 vty_out (vty, "%% %s is not a valid route-map name%s",
6794 rmap_str, VTY_NEWLINE);
6795 return CMD_WARNING;
6796 }
6797
ajs5a646652004-11-05 01:25:55 +00006798 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006799}
6800
6801DEFUN (show_ip_bgp_route_map,
6802 show_ip_bgp_route_map_cmd,
6803 "show ip bgp route-map WORD",
6804 SHOW_STR
6805 IP_STR
6806 BGP_STR
6807 "Display routes matching the route-map\n"
6808 "A route-map to match on\n")
6809{
6810 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6811 bgp_show_type_route_map);
6812}
6813
6814DEFUN (show_ip_bgp_flap_route_map,
6815 show_ip_bgp_flap_route_map_cmd,
6816 "show ip bgp flap-statistics route-map WORD",
6817 SHOW_STR
6818 IP_STR
6819 BGP_STR
6820 "Display flap statistics of routes\n"
6821 "Display routes matching the route-map\n"
6822 "A route-map to match on\n")
6823{
6824 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6825 bgp_show_type_flap_route_map);
6826}
6827
6828DEFUN (show_ip_bgp_ipv4_route_map,
6829 show_ip_bgp_ipv4_route_map_cmd,
6830 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6831 SHOW_STR
6832 IP_STR
6833 BGP_STR
6834 "Address family\n"
6835 "Address Family modifier\n"
6836 "Address Family modifier\n"
6837 "Display routes matching the route-map\n"
6838 "A route-map to match on\n")
6839{
6840 if (strncmp (argv[0], "m", 1) == 0)
6841 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6842 bgp_show_type_route_map);
6843
6844 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6845 bgp_show_type_route_map);
6846}
6847
6848DEFUN (show_bgp_route_map,
6849 show_bgp_route_map_cmd,
6850 "show bgp route-map WORD",
6851 SHOW_STR
6852 BGP_STR
6853 "Display routes matching the route-map\n"
6854 "A route-map to match on\n")
6855{
6856 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6857 bgp_show_type_route_map);
6858}
6859
6860ALIAS (show_bgp_route_map,
6861 show_bgp_ipv6_route_map_cmd,
6862 "show bgp ipv6 route-map WORD",
6863 SHOW_STR
6864 BGP_STR
6865 "Address family\n"
6866 "Display routes matching the route-map\n"
6867 "A route-map to match on\n")
6868
6869DEFUN (show_ip_bgp_cidr_only,
6870 show_ip_bgp_cidr_only_cmd,
6871 "show ip bgp cidr-only",
6872 SHOW_STR
6873 IP_STR
6874 BGP_STR
6875 "Display only routes with non-natural netmasks\n")
6876{
6877 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006878 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006879}
6880
6881DEFUN (show_ip_bgp_flap_cidr_only,
6882 show_ip_bgp_flap_cidr_only_cmd,
6883 "show ip bgp flap-statistics cidr-only",
6884 SHOW_STR
6885 IP_STR
6886 BGP_STR
6887 "Display flap statistics of routes\n"
6888 "Display only routes with non-natural netmasks\n")
6889{
6890 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006891 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006892}
6893
6894DEFUN (show_ip_bgp_ipv4_cidr_only,
6895 show_ip_bgp_ipv4_cidr_only_cmd,
6896 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6897 SHOW_STR
6898 IP_STR
6899 BGP_STR
6900 "Address family\n"
6901 "Address Family modifier\n"
6902 "Address Family modifier\n"
6903 "Display only routes with non-natural netmasks\n")
6904{
6905 if (strncmp (argv[0], "m", 1) == 0)
6906 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006907 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006908
6909 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006910 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006911}
6912
6913DEFUN (show_ip_bgp_community_all,
6914 show_ip_bgp_community_all_cmd,
6915 "show ip bgp community",
6916 SHOW_STR
6917 IP_STR
6918 BGP_STR
6919 "Display routes matching the communities\n")
6920{
6921 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006922 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006923}
6924
6925DEFUN (show_ip_bgp_ipv4_community_all,
6926 show_ip_bgp_ipv4_community_all_cmd,
6927 "show ip bgp ipv4 (unicast|multicast) community",
6928 SHOW_STR
6929 IP_STR
6930 BGP_STR
6931 "Address family\n"
6932 "Address Family modifier\n"
6933 "Address Family modifier\n"
6934 "Display routes matching the communities\n")
6935{
6936 if (strncmp (argv[0], "m", 1) == 0)
6937 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006938 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006939
6940 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006941 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006942}
6943
6944#ifdef HAVE_IPV6
6945DEFUN (show_bgp_community_all,
6946 show_bgp_community_all_cmd,
6947 "show bgp community",
6948 SHOW_STR
6949 BGP_STR
6950 "Display routes matching the communities\n")
6951{
6952 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006953 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006954}
6955
6956ALIAS (show_bgp_community_all,
6957 show_bgp_ipv6_community_all_cmd,
6958 "show bgp ipv6 community",
6959 SHOW_STR
6960 BGP_STR
6961 "Address family\n"
6962 "Display routes matching the communities\n")
6963
6964/* old command */
6965DEFUN (show_ipv6_bgp_community_all,
6966 show_ipv6_bgp_community_all_cmd,
6967 "show ipv6 bgp community",
6968 SHOW_STR
6969 IPV6_STR
6970 BGP_STR
6971 "Display routes matching the communities\n")
6972{
6973 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006974 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006975}
6976
6977/* old command */
6978DEFUN (show_ipv6_mbgp_community_all,
6979 show_ipv6_mbgp_community_all_cmd,
6980 "show ipv6 mbgp community",
6981 SHOW_STR
6982 IPV6_STR
6983 MBGP_STR
6984 "Display routes matching the communities\n")
6985{
6986 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006987 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006988}
6989#endif /* HAVE_IPV6 */
6990
paul94f2b392005-06-28 12:44:16 +00006991static int
paulfd79ac92004-10-13 05:06:08 +00006992bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
6993 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00006994{
6995 struct community *com;
6996 struct buffer *b;
6997 int i;
6998 char *str;
6999 int first = 0;
7000
7001 b = buffer_new (1024);
7002 for (i = 0; i < argc; i++)
7003 {
7004 if (first)
7005 buffer_putc (b, ' ');
7006 else
7007 {
7008 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7009 continue;
7010 first = 1;
7011 }
7012
7013 buffer_putstr (b, argv[i]);
7014 }
7015 buffer_putc (b, '\0');
7016
7017 str = buffer_getstr (b);
7018 buffer_free (b);
7019
7020 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007021 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007022 if (! com)
7023 {
7024 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7025 return CMD_WARNING;
7026 }
7027
ajs5a646652004-11-05 01:25:55 +00007028 return bgp_show (vty, NULL, afi, safi,
7029 (exact ? bgp_show_type_community_exact :
7030 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007031}
7032
7033DEFUN (show_ip_bgp_community,
7034 show_ip_bgp_community_cmd,
7035 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7036 SHOW_STR
7037 IP_STR
7038 BGP_STR
7039 "Display routes matching the communities\n"
7040 "community number\n"
7041 "Do not send outside local AS (well-known community)\n"
7042 "Do not advertise to any peer (well-known community)\n"
7043 "Do not export to next AS (well-known community)\n")
7044{
7045 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7046}
7047
7048ALIAS (show_ip_bgp_community,
7049 show_ip_bgp_community2_cmd,
7050 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7051 SHOW_STR
7052 IP_STR
7053 BGP_STR
7054 "Display routes matching the communities\n"
7055 "community number\n"
7056 "Do not send outside local AS (well-known community)\n"
7057 "Do not advertise to any peer (well-known community)\n"
7058 "Do not export to next AS (well-known community)\n"
7059 "community number\n"
7060 "Do not send outside local AS (well-known community)\n"
7061 "Do not advertise to any peer (well-known community)\n"
7062 "Do not export to next AS (well-known community)\n")
7063
7064ALIAS (show_ip_bgp_community,
7065 show_ip_bgp_community3_cmd,
7066 "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)",
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 "community number\n"
7080 "Do not send outside local AS (well-known community)\n"
7081 "Do not advertise to any peer (well-known community)\n"
7082 "Do not export to next AS (well-known community)\n")
7083
7084ALIAS (show_ip_bgp_community,
7085 show_ip_bgp_community4_cmd,
7086 "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)",
7087 SHOW_STR
7088 IP_STR
7089 BGP_STR
7090 "Display routes matching the communities\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 "community number\n"
7100 "Do not send outside local AS (well-known community)\n"
7101 "Do not advertise to any peer (well-known community)\n"
7102 "Do not export to next AS (well-known community)\n"
7103 "community number\n"
7104 "Do not send outside local AS (well-known community)\n"
7105 "Do not advertise to any peer (well-known community)\n"
7106 "Do not export to next AS (well-known community)\n")
7107
7108DEFUN (show_ip_bgp_ipv4_community,
7109 show_ip_bgp_ipv4_community_cmd,
7110 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7111 SHOW_STR
7112 IP_STR
7113 BGP_STR
7114 "Address family\n"
7115 "Address Family modifier\n"
7116 "Address Family modifier\n"
7117 "Display routes matching the communities\n"
7118 "community number\n"
7119 "Do not send outside local AS (well-known community)\n"
7120 "Do not advertise to any peer (well-known community)\n"
7121 "Do not export to next AS (well-known community)\n")
7122{
7123 if (strncmp (argv[0], "m", 1) == 0)
7124 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7125
7126 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7127}
7128
7129ALIAS (show_ip_bgp_ipv4_community,
7130 show_ip_bgp_ipv4_community2_cmd,
7131 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7132 SHOW_STR
7133 IP_STR
7134 BGP_STR
7135 "Address family\n"
7136 "Address Family modifier\n"
7137 "Address Family modifier\n"
7138 "Display routes matching the communities\n"
7139 "community number\n"
7140 "Do not send outside local AS (well-known community)\n"
7141 "Do not advertise to any peer (well-known community)\n"
7142 "Do not export to next AS (well-known community)\n"
7143 "community number\n"
7144 "Do not send outside local AS (well-known community)\n"
7145 "Do not advertise to any peer (well-known community)\n"
7146 "Do not export to next AS (well-known community)\n")
7147
7148ALIAS (show_ip_bgp_ipv4_community,
7149 show_ip_bgp_ipv4_community3_cmd,
7150 "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)",
7151 SHOW_STR
7152 IP_STR
7153 BGP_STR
7154 "Address family\n"
7155 "Address Family modifier\n"
7156 "Address Family modifier\n"
7157 "Display routes matching the communities\n"
7158 "community number\n"
7159 "Do not send outside local AS (well-known community)\n"
7160 "Do not advertise to any peer (well-known community)\n"
7161 "Do not export to next AS (well-known community)\n"
7162 "community number\n"
7163 "Do not send outside local AS (well-known community)\n"
7164 "Do not advertise to any peer (well-known community)\n"
7165 "Do not export to next AS (well-known community)\n"
7166 "community number\n"
7167 "Do not send outside local AS (well-known community)\n"
7168 "Do not advertise to any peer (well-known community)\n"
7169 "Do not export to next AS (well-known community)\n")
7170
7171ALIAS (show_ip_bgp_ipv4_community,
7172 show_ip_bgp_ipv4_community4_cmd,
7173 "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)",
7174 SHOW_STR
7175 IP_STR
7176 BGP_STR
7177 "Address family\n"
7178 "Address Family modifier\n"
7179 "Address Family modifier\n"
7180 "Display routes matching the communities\n"
7181 "community number\n"
7182 "Do not send outside local AS (well-known community)\n"
7183 "Do not advertise to any peer (well-known community)\n"
7184 "Do not export to next AS (well-known community)\n"
7185 "community number\n"
7186 "Do not send outside local AS (well-known community)\n"
7187 "Do not advertise to any peer (well-known community)\n"
7188 "Do not export to next AS (well-known community)\n"
7189 "community number\n"
7190 "Do not send outside local AS (well-known community)\n"
7191 "Do not advertise to any peer (well-known community)\n"
7192 "Do not export to next AS (well-known community)\n"
7193 "community number\n"
7194 "Do not send outside local AS (well-known community)\n"
7195 "Do not advertise to any peer (well-known community)\n"
7196 "Do not export to next AS (well-known community)\n")
7197
7198DEFUN (show_ip_bgp_community_exact,
7199 show_ip_bgp_community_exact_cmd,
7200 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7201 SHOW_STR
7202 IP_STR
7203 BGP_STR
7204 "Display routes matching the communities\n"
7205 "community number\n"
7206 "Do not send outside local AS (well-known community)\n"
7207 "Do not advertise to any peer (well-known community)\n"
7208 "Do not export to next AS (well-known community)\n"
7209 "Exact match of the communities")
7210{
7211 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7212}
7213
7214ALIAS (show_ip_bgp_community_exact,
7215 show_ip_bgp_community2_exact_cmd,
7216 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (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 "community number\n"
7226 "Do not send outside local AS (well-known community)\n"
7227 "Do not advertise to any peer (well-known community)\n"
7228 "Do not export to next AS (well-known community)\n"
7229 "Exact match of the communities")
7230
7231ALIAS (show_ip_bgp_community_exact,
7232 show_ip_bgp_community3_exact_cmd,
7233 "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",
7234 SHOW_STR
7235 IP_STR
7236 BGP_STR
7237 "Display routes matching the communities\n"
7238 "community number\n"
7239 "Do not send outside local AS (well-known community)\n"
7240 "Do not advertise to any peer (well-known community)\n"
7241 "Do not export to next AS (well-known community)\n"
7242 "community number\n"
7243 "Do not send outside local AS (well-known community)\n"
7244 "Do not advertise to any peer (well-known community)\n"
7245 "Do not export to next AS (well-known community)\n"
7246 "community number\n"
7247 "Do not send outside local AS (well-known community)\n"
7248 "Do not advertise to any peer (well-known community)\n"
7249 "Do not export to next AS (well-known community)\n"
7250 "Exact match of the communities")
7251
7252ALIAS (show_ip_bgp_community_exact,
7253 show_ip_bgp_community4_exact_cmd,
7254 "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",
7255 SHOW_STR
7256 IP_STR
7257 BGP_STR
7258 "Display routes matching the communities\n"
7259 "community number\n"
7260 "Do not send outside local AS (well-known community)\n"
7261 "Do not advertise to any peer (well-known community)\n"
7262 "Do not export to next AS (well-known community)\n"
7263 "community number\n"
7264 "Do not send outside local AS (well-known community)\n"
7265 "Do not advertise to any peer (well-known community)\n"
7266 "Do not export to next AS (well-known community)\n"
7267 "community number\n"
7268 "Do not send outside local AS (well-known community)\n"
7269 "Do not advertise to any peer (well-known community)\n"
7270 "Do not export to next AS (well-known community)\n"
7271 "community number\n"
7272 "Do not send outside local AS (well-known community)\n"
7273 "Do not advertise to any peer (well-known community)\n"
7274 "Do not export to next AS (well-known community)\n"
7275 "Exact match of the communities")
7276
7277DEFUN (show_ip_bgp_ipv4_community_exact,
7278 show_ip_bgp_ipv4_community_exact_cmd,
7279 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7280 SHOW_STR
7281 IP_STR
7282 BGP_STR
7283 "Address family\n"
7284 "Address Family modifier\n"
7285 "Address Family modifier\n"
7286 "Display routes matching the communities\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{
7293 if (strncmp (argv[0], "m", 1) == 0)
7294 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7295
7296 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7297}
7298
7299ALIAS (show_ip_bgp_ipv4_community_exact,
7300 show_ip_bgp_ipv4_community2_exact_cmd,
7301 "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",
7302 SHOW_STR
7303 IP_STR
7304 BGP_STR
7305 "Address family\n"
7306 "Address Family modifier\n"
7307 "Address Family modifier\n"
7308 "Display routes matching the communities\n"
7309 "community number\n"
7310 "Do not send outside local AS (well-known community)\n"
7311 "Do not advertise to any peer (well-known community)\n"
7312 "Do not export to next AS (well-known community)\n"
7313 "community number\n"
7314 "Do not send outside local AS (well-known community)\n"
7315 "Do not advertise to any peer (well-known community)\n"
7316 "Do not export to next AS (well-known community)\n"
7317 "Exact match of the communities")
7318
7319ALIAS (show_ip_bgp_ipv4_community_exact,
7320 show_ip_bgp_ipv4_community3_exact_cmd,
7321 "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",
7322 SHOW_STR
7323 IP_STR
7324 BGP_STR
7325 "Address family\n"
7326 "Address Family modifier\n"
7327 "Address Family modifier\n"
7328 "Display routes matching the communities\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 "community number\n"
7334 "Do not send outside local AS (well-known community)\n"
7335 "Do not advertise to any peer (well-known community)\n"
7336 "Do not export to next AS (well-known community)\n"
7337 "community number\n"
7338 "Do not send outside local AS (well-known community)\n"
7339 "Do not advertise to any peer (well-known community)\n"
7340 "Do not export to next AS (well-known community)\n"
7341 "Exact match of the communities")
7342
7343ALIAS (show_ip_bgp_ipv4_community_exact,
7344 show_ip_bgp_ipv4_community4_exact_cmd,
7345 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7346 SHOW_STR
7347 IP_STR
7348 BGP_STR
7349 "Address family\n"
7350 "Address Family modifier\n"
7351 "Address Family modifier\n"
7352 "Display routes matching the communities\n"
7353 "community number\n"
7354 "Do not send outside local AS (well-known community)\n"
7355 "Do not advertise to any peer (well-known community)\n"
7356 "Do not export to next AS (well-known community)\n"
7357 "community number\n"
7358 "Do not send outside local AS (well-known community)\n"
7359 "Do not advertise to any peer (well-known community)\n"
7360 "Do not export to next AS (well-known community)\n"
7361 "community number\n"
7362 "Do not send outside local AS (well-known community)\n"
7363 "Do not advertise to any peer (well-known community)\n"
7364 "Do not export to next AS (well-known community)\n"
7365 "community number\n"
7366 "Do not send outside local AS (well-known community)\n"
7367 "Do not advertise to any peer (well-known community)\n"
7368 "Do not export to next AS (well-known community)\n"
7369 "Exact match of the communities")
7370
7371#ifdef HAVE_IPV6
7372DEFUN (show_bgp_community,
7373 show_bgp_community_cmd,
7374 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7375 SHOW_STR
7376 BGP_STR
7377 "Display routes matching the communities\n"
7378 "community number\n"
7379 "Do not send outside local AS (well-known community)\n"
7380 "Do not advertise to any peer (well-known community)\n"
7381 "Do not export to next AS (well-known community)\n")
7382{
7383 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7384}
7385
7386ALIAS (show_bgp_community,
7387 show_bgp_ipv6_community_cmd,
7388 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7389 SHOW_STR
7390 BGP_STR
7391 "Address family\n"
7392 "Display routes matching the communities\n"
7393 "community number\n"
7394 "Do not send outside local AS (well-known community)\n"
7395 "Do not advertise to any peer (well-known community)\n"
7396 "Do not export to next AS (well-known community)\n")
7397
7398ALIAS (show_bgp_community,
7399 show_bgp_community2_cmd,
7400 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7401 SHOW_STR
7402 BGP_STR
7403 "Display routes matching the communities\n"
7404 "community number\n"
7405 "Do not send outside local AS (well-known community)\n"
7406 "Do not advertise to any peer (well-known community)\n"
7407 "Do not export to next AS (well-known community)\n"
7408 "community number\n"
7409 "Do not send outside local AS (well-known community)\n"
7410 "Do not advertise to any peer (well-known community)\n"
7411 "Do not export to next AS (well-known community)\n")
7412
7413ALIAS (show_bgp_community,
7414 show_bgp_ipv6_community2_cmd,
7415 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7416 SHOW_STR
7417 BGP_STR
7418 "Address family\n"
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_community3_cmd,
7431 "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)",
7432 SHOW_STR
7433 BGP_STR
7434 "Display routes matching the communities\n"
7435 "community number\n"
7436 "Do not send outside local AS (well-known community)\n"
7437 "Do not advertise to any peer (well-known community)\n"
7438 "Do not export to next AS (well-known community)\n"
7439 "community number\n"
7440 "Do not send outside local AS (well-known community)\n"
7441 "Do not advertise to any peer (well-known community)\n"
7442 "Do not export to next AS (well-known community)\n"
7443 "community number\n"
7444 "Do not send outside local AS (well-known community)\n"
7445 "Do not advertise to any peer (well-known community)\n"
7446 "Do not export to next AS (well-known community)\n")
7447
7448ALIAS (show_bgp_community,
7449 show_bgp_ipv6_community3_cmd,
7450 "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)",
7451 SHOW_STR
7452 BGP_STR
7453 "Address family\n"
7454 "Display routes matching the communities\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 "community number\n"
7464 "Do not send outside local AS (well-known community)\n"
7465 "Do not advertise to any peer (well-known community)\n"
7466 "Do not export to next AS (well-known community)\n")
7467
7468ALIAS (show_bgp_community,
7469 show_bgp_community4_cmd,
7470 "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)",
7471 SHOW_STR
7472 BGP_STR
7473 "Display routes matching the communities\n"
7474 "community number\n"
7475 "Do not send outside local AS (well-known community)\n"
7476 "Do not advertise to any peer (well-known community)\n"
7477 "Do not export to next AS (well-known community)\n"
7478 "community number\n"
7479 "Do not send outside local AS (well-known community)\n"
7480 "Do not advertise to any peer (well-known community)\n"
7481 "Do not export to next AS (well-known community)\n"
7482 "community number\n"
7483 "Do not send outside local AS (well-known community)\n"
7484 "Do not advertise to any peer (well-known community)\n"
7485 "Do not export to next AS (well-known community)\n"
7486 "community number\n"
7487 "Do not send outside local AS (well-known community)\n"
7488 "Do not advertise to any peer (well-known community)\n"
7489 "Do not export to next AS (well-known community)\n")
7490
7491ALIAS (show_bgp_community,
7492 show_bgp_ipv6_community4_cmd,
7493 "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)",
7494 SHOW_STR
7495 BGP_STR
7496 "Address family\n"
7497 "Display routes matching the communities\n"
7498 "community number\n"
7499 "Do not send outside local AS (well-known community)\n"
7500 "Do not advertise to any peer (well-known community)\n"
7501 "Do not export to next AS (well-known community)\n"
7502 "community number\n"
7503 "Do not send outside local AS (well-known community)\n"
7504 "Do not advertise to any peer (well-known community)\n"
7505 "Do not export to next AS (well-known community)\n"
7506 "community number\n"
7507 "Do not send outside local AS (well-known community)\n"
7508 "Do not advertise to any peer (well-known community)\n"
7509 "Do not export to next AS (well-known community)\n"
7510 "community number\n"
7511 "Do not send outside local AS (well-known community)\n"
7512 "Do not advertise to any peer (well-known community)\n"
7513 "Do not export to next AS (well-known community)\n")
7514
7515/* old command */
7516DEFUN (show_ipv6_bgp_community,
7517 show_ipv6_bgp_community_cmd,
7518 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7519 SHOW_STR
7520 IPV6_STR
7521 BGP_STR
7522 "Display routes matching the communities\n"
7523 "community number\n"
7524 "Do not send outside local AS (well-known community)\n"
7525 "Do not advertise to any peer (well-known community)\n"
7526 "Do not export to next AS (well-known community)\n")
7527{
7528 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7529}
7530
7531/* old command */
7532ALIAS (show_ipv6_bgp_community,
7533 show_ipv6_bgp_community2_cmd,
7534 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (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 "community number\n"
7544 "Do not send outside local AS (well-known community)\n"
7545 "Do not advertise to any peer (well-known community)\n"
7546 "Do not export to next AS (well-known community)\n")
7547
7548/* old command */
7549ALIAS (show_ipv6_bgp_community,
7550 show_ipv6_bgp_community3_cmd,
7551 "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)",
7552 SHOW_STR
7553 IPV6_STR
7554 BGP_STR
7555 "Display routes matching the communities\n"
7556 "community number\n"
7557 "Do not send outside local AS (well-known community)\n"
7558 "Do not advertise to any peer (well-known community)\n"
7559 "Do not export to next AS (well-known community)\n"
7560 "community number\n"
7561 "Do not send outside local AS (well-known community)\n"
7562 "Do not advertise to any peer (well-known community)\n"
7563 "Do not export to next AS (well-known community)\n"
7564 "community number\n"
7565 "Do not send outside local AS (well-known community)\n"
7566 "Do not advertise to any peer (well-known community)\n"
7567 "Do not export to next AS (well-known community)\n")
7568
7569/* old command */
7570ALIAS (show_ipv6_bgp_community,
7571 show_ipv6_bgp_community4_cmd,
7572 "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)",
7573 SHOW_STR
7574 IPV6_STR
7575 BGP_STR
7576 "Display routes matching the communities\n"
7577 "community number\n"
7578 "Do not send outside local AS (well-known community)\n"
7579 "Do not advertise to any peer (well-known community)\n"
7580 "Do not export to next AS (well-known community)\n"
7581 "community number\n"
7582 "Do not send outside local AS (well-known community)\n"
7583 "Do not advertise to any peer (well-known community)\n"
7584 "Do not export to next AS (well-known community)\n"
7585 "community number\n"
7586 "Do not send outside local AS (well-known community)\n"
7587 "Do not advertise to any peer (well-known community)\n"
7588 "Do not export to next AS (well-known community)\n"
7589 "community number\n"
7590 "Do not send outside local AS (well-known community)\n"
7591 "Do not advertise to any peer (well-known community)\n"
7592 "Do not export to next AS (well-known community)\n")
7593
7594DEFUN (show_bgp_community_exact,
7595 show_bgp_community_exact_cmd,
7596 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7597 SHOW_STR
7598 BGP_STR
7599 "Display routes matching the communities\n"
7600 "community number\n"
7601 "Do not send outside local AS (well-known community)\n"
7602 "Do not advertise to any peer (well-known community)\n"
7603 "Do not export to next AS (well-known community)\n"
7604 "Exact match of the communities")
7605{
7606 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7607}
7608
7609ALIAS (show_bgp_community_exact,
7610 show_bgp_ipv6_community_exact_cmd,
7611 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7612 SHOW_STR
7613 BGP_STR
7614 "Address family\n"
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
7622ALIAS (show_bgp_community_exact,
7623 show_bgp_community2_exact_cmd,
7624 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7625 SHOW_STR
7626 BGP_STR
7627 "Display routes matching the communities\n"
7628 "community number\n"
7629 "Do not send outside local AS (well-known community)\n"
7630 "Do not advertise to any peer (well-known community)\n"
7631 "Do not export to next AS (well-known community)\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_ipv6_community2_exact_cmd,
7640 "show bgp ipv6 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 "Address family\n"
7644 "Display routes matching the communities\n"
7645 "community number\n"
7646 "Do not send outside local AS (well-known community)\n"
7647 "Do not advertise to any peer (well-known community)\n"
7648 "Do not export to next AS (well-known community)\n"
7649 "community number\n"
7650 "Do not send outside local AS (well-known community)\n"
7651 "Do not advertise to any peer (well-known community)\n"
7652 "Do not export to next AS (well-known community)\n"
7653 "Exact match of the communities")
7654
7655ALIAS (show_bgp_community_exact,
7656 show_bgp_community3_exact_cmd,
7657 "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",
7658 SHOW_STR
7659 BGP_STR
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 "community number\n"
7670 "Do not send outside local AS (well-known community)\n"
7671 "Do not advertise to any peer (well-known community)\n"
7672 "Do not export to next AS (well-known community)\n"
7673 "Exact match of the communities")
7674
7675ALIAS (show_bgp_community_exact,
7676 show_bgp_ipv6_community3_exact_cmd,
7677 "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",
7678 SHOW_STR
7679 BGP_STR
7680 "Address family\n"
7681 "Display routes matching the communities\n"
7682 "community number\n"
7683 "Do not send outside local AS (well-known community)\n"
7684 "Do not advertise to any peer (well-known community)\n"
7685 "Do not export to next AS (well-known community)\n"
7686 "community number\n"
7687 "Do not send outside local AS (well-known community)\n"
7688 "Do not advertise to any peer (well-known community)\n"
7689 "Do not export to next AS (well-known community)\n"
7690 "community number\n"
7691 "Do not send outside local AS (well-known community)\n"
7692 "Do not advertise to any peer (well-known community)\n"
7693 "Do not export to next AS (well-known community)\n"
7694 "Exact match of the communities")
7695
7696ALIAS (show_bgp_community_exact,
7697 show_bgp_community4_exact_cmd,
7698 "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",
7699 SHOW_STR
7700 BGP_STR
7701 "Display routes matching the communities\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 "community number\n"
7711 "Do not send outside local AS (well-known community)\n"
7712 "Do not advertise to any peer (well-known community)\n"
7713 "Do not export to next AS (well-known community)\n"
7714 "community number\n"
7715 "Do not send outside local AS (well-known community)\n"
7716 "Do not advertise to any peer (well-known community)\n"
7717 "Do not export to next AS (well-known community)\n"
7718 "Exact match of the communities")
7719
7720ALIAS (show_bgp_community_exact,
7721 show_bgp_ipv6_community4_exact_cmd,
7722 "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",
7723 SHOW_STR
7724 BGP_STR
7725 "Address family\n"
7726 "Display routes matching the communities\n"
7727 "community number\n"
7728 "Do not send outside local AS (well-known community)\n"
7729 "Do not advertise to any peer (well-known community)\n"
7730 "Do not export to next AS (well-known community)\n"
7731 "community number\n"
7732 "Do not send outside local AS (well-known community)\n"
7733 "Do not advertise to any peer (well-known community)\n"
7734 "Do not export to next AS (well-known community)\n"
7735 "community number\n"
7736 "Do not send outside local AS (well-known community)\n"
7737 "Do not advertise to any peer (well-known community)\n"
7738 "Do not export to next AS (well-known community)\n"
7739 "community number\n"
7740 "Do not send outside local AS (well-known community)\n"
7741 "Do not advertise to any peer (well-known community)\n"
7742 "Do not export to next AS (well-known community)\n"
7743 "Exact match of the communities")
7744
7745/* old command */
7746DEFUN (show_ipv6_bgp_community_exact,
7747 show_ipv6_bgp_community_exact_cmd,
7748 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7749 SHOW_STR
7750 IPV6_STR
7751 BGP_STR
7752 "Display routes matching the communities\n"
7753 "community number\n"
7754 "Do not send outside local AS (well-known community)\n"
7755 "Do not advertise to any peer (well-known community)\n"
7756 "Do not export to next AS (well-known community)\n"
7757 "Exact match of the communities")
7758{
7759 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7760}
7761
7762/* old command */
7763ALIAS (show_ipv6_bgp_community_exact,
7764 show_ipv6_bgp_community2_exact_cmd,
7765 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7766 SHOW_STR
7767 IPV6_STR
7768 BGP_STR
7769 "Display routes matching the communities\n"
7770 "community number\n"
7771 "Do not send outside local AS (well-known community)\n"
7772 "Do not advertise to any peer (well-known community)\n"
7773 "Do not export to next AS (well-known community)\n"
7774 "community number\n"
7775 "Do not send outside local AS (well-known community)\n"
7776 "Do not advertise to any peer (well-known community)\n"
7777 "Do not export to next AS (well-known community)\n"
7778 "Exact match of the communities")
7779
7780/* old command */
7781ALIAS (show_ipv6_bgp_community_exact,
7782 show_ipv6_bgp_community3_exact_cmd,
7783 "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",
7784 SHOW_STR
7785 IPV6_STR
7786 BGP_STR
7787 "Display routes matching the communities\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n"
7800 "Exact match of the communities")
7801
7802/* old command */
7803ALIAS (show_ipv6_bgp_community_exact,
7804 show_ipv6_bgp_community4_exact_cmd,
7805 "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",
7806 SHOW_STR
7807 IPV6_STR
7808 BGP_STR
7809 "Display routes matching the communities\n"
7810 "community number\n"
7811 "Do not send outside local AS (well-known community)\n"
7812 "Do not advertise to any peer (well-known community)\n"
7813 "Do not export to next AS (well-known community)\n"
7814 "community number\n"
7815 "Do not send outside local AS (well-known community)\n"
7816 "Do not advertise to any peer (well-known community)\n"
7817 "Do not export to next AS (well-known community)\n"
7818 "community number\n"
7819 "Do not send outside local AS (well-known community)\n"
7820 "Do not advertise to any peer (well-known community)\n"
7821 "Do not export to next AS (well-known community)\n"
7822 "community number\n"
7823 "Do not send outside local AS (well-known community)\n"
7824 "Do not advertise to any peer (well-known community)\n"
7825 "Do not export to next AS (well-known community)\n"
7826 "Exact match of the communities")
7827
7828/* old command */
7829DEFUN (show_ipv6_mbgp_community,
7830 show_ipv6_mbgp_community_cmd,
7831 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7832 SHOW_STR
7833 IPV6_STR
7834 MBGP_STR
7835 "Display routes matching the communities\n"
7836 "community number\n"
7837 "Do not send outside local AS (well-known community)\n"
7838 "Do not advertise to any peer (well-known community)\n"
7839 "Do not export to next AS (well-known community)\n")
7840{
7841 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7842}
7843
7844/* old command */
7845ALIAS (show_ipv6_mbgp_community,
7846 show_ipv6_mbgp_community2_cmd,
7847 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (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 "community number\n"
7857 "Do not send outside local AS (well-known community)\n"
7858 "Do not advertise to any peer (well-known community)\n"
7859 "Do not export to next AS (well-known community)\n")
7860
7861/* old command */
7862ALIAS (show_ipv6_mbgp_community,
7863 show_ipv6_mbgp_community3_cmd,
7864 "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)",
7865 SHOW_STR
7866 IPV6_STR
7867 MBGP_STR
7868 "Display routes matching the communities\n"
7869 "community number\n"
7870 "Do not send outside local AS (well-known community)\n"
7871 "Do not advertise to any peer (well-known community)\n"
7872 "Do not export to next AS (well-known community)\n"
7873 "community number\n"
7874 "Do not send outside local AS (well-known community)\n"
7875 "Do not advertise to any peer (well-known community)\n"
7876 "Do not export to next AS (well-known community)\n"
7877 "community number\n"
7878 "Do not send outside local AS (well-known community)\n"
7879 "Do not advertise to any peer (well-known community)\n"
7880 "Do not export to next AS (well-known community)\n")
7881
7882/* old command */
7883ALIAS (show_ipv6_mbgp_community,
7884 show_ipv6_mbgp_community4_cmd,
7885 "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)",
7886 SHOW_STR
7887 IPV6_STR
7888 MBGP_STR
7889 "Display routes matching the communities\n"
7890 "community number\n"
7891 "Do not send outside local AS (well-known community)\n"
7892 "Do not advertise to any peer (well-known community)\n"
7893 "Do not export to next AS (well-known community)\n"
7894 "community number\n"
7895 "Do not send outside local AS (well-known community)\n"
7896 "Do not advertise to any peer (well-known community)\n"
7897 "Do not export to next AS (well-known community)\n"
7898 "community number\n"
7899 "Do not send outside local AS (well-known community)\n"
7900 "Do not advertise to any peer (well-known community)\n"
7901 "Do not export to next AS (well-known community)\n"
7902 "community number\n"
7903 "Do not send outside local AS (well-known community)\n"
7904 "Do not advertise to any peer (well-known community)\n"
7905 "Do not export to next AS (well-known community)\n")
7906
7907/* old command */
7908DEFUN (show_ipv6_mbgp_community_exact,
7909 show_ipv6_mbgp_community_exact_cmd,
7910 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7911 SHOW_STR
7912 IPV6_STR
7913 MBGP_STR
7914 "Display routes matching the communities\n"
7915 "community number\n"
7916 "Do not send outside local AS (well-known community)\n"
7917 "Do not advertise to any peer (well-known community)\n"
7918 "Do not export to next AS (well-known community)\n"
7919 "Exact match of the communities")
7920{
7921 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7922}
7923
7924/* old command */
7925ALIAS (show_ipv6_mbgp_community_exact,
7926 show_ipv6_mbgp_community2_exact_cmd,
7927 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7928 SHOW_STR
7929 IPV6_STR
7930 MBGP_STR
7931 "Display routes matching the communities\n"
7932 "community number\n"
7933 "Do not send outside local AS (well-known community)\n"
7934 "Do not advertise to any peer (well-known community)\n"
7935 "Do not export to next AS (well-known community)\n"
7936 "community number\n"
7937 "Do not send outside local AS (well-known community)\n"
7938 "Do not advertise to any peer (well-known community)\n"
7939 "Do not export to next AS (well-known community)\n"
7940 "Exact match of the communities")
7941
7942/* old command */
7943ALIAS (show_ipv6_mbgp_community_exact,
7944 show_ipv6_mbgp_community3_exact_cmd,
7945 "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",
7946 SHOW_STR
7947 IPV6_STR
7948 MBGP_STR
7949 "Display routes matching the communities\n"
7950 "community number\n"
7951 "Do not send outside local AS (well-known community)\n"
7952 "Do not advertise to any peer (well-known community)\n"
7953 "Do not export to next AS (well-known community)\n"
7954 "community number\n"
7955 "Do not send outside local AS (well-known community)\n"
7956 "Do not advertise to any peer (well-known community)\n"
7957 "Do not export to next AS (well-known community)\n"
7958 "community number\n"
7959 "Do not send outside local AS (well-known community)\n"
7960 "Do not advertise to any peer (well-known community)\n"
7961 "Do not export to next AS (well-known community)\n"
7962 "Exact match of the communities")
7963
7964/* old command */
7965ALIAS (show_ipv6_mbgp_community_exact,
7966 show_ipv6_mbgp_community4_exact_cmd,
7967 "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",
7968 SHOW_STR
7969 IPV6_STR
7970 MBGP_STR
7971 "Display routes matching the communities\n"
7972 "community number\n"
7973 "Do not send outside local AS (well-known community)\n"
7974 "Do not advertise to any peer (well-known community)\n"
7975 "Do not export to next AS (well-known community)\n"
7976 "community number\n"
7977 "Do not send outside local AS (well-known community)\n"
7978 "Do not advertise to any peer (well-known community)\n"
7979 "Do not export to next AS (well-known community)\n"
7980 "community number\n"
7981 "Do not send outside local AS (well-known community)\n"
7982 "Do not advertise to any peer (well-known community)\n"
7983 "Do not export to next AS (well-known community)\n"
7984 "community number\n"
7985 "Do not send outside local AS (well-known community)\n"
7986 "Do not advertise to any peer (well-known community)\n"
7987 "Do not export to next AS (well-known community)\n"
7988 "Exact match of the communities")
7989#endif /* HAVE_IPV6 */
7990
paul94f2b392005-06-28 12:44:16 +00007991static int
paulfd79ac92004-10-13 05:06:08 +00007992bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00007993 u_int16_t afi, u_char safi)
7994{
7995 struct community_list *list;
7996
hassofee6e4e2005-02-02 16:29:31 +00007997 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00007998 if (list == NULL)
7999 {
8000 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8001 VTY_NEWLINE);
8002 return CMD_WARNING;
8003 }
8004
ajs5a646652004-11-05 01:25:55 +00008005 return bgp_show (vty, NULL, afi, safi,
8006 (exact ? bgp_show_type_community_list_exact :
8007 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008008}
8009
8010DEFUN (show_ip_bgp_community_list,
8011 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008012 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008013 SHOW_STR
8014 IP_STR
8015 BGP_STR
8016 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008017 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008018 "community-list name\n")
8019{
8020 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8021}
8022
8023DEFUN (show_ip_bgp_ipv4_community_list,
8024 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008025 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008026 SHOW_STR
8027 IP_STR
8028 BGP_STR
8029 "Address family\n"
8030 "Address Family modifier\n"
8031 "Address Family modifier\n"
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 if (strncmp (argv[0], "m", 1) == 0)
8037 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8038
8039 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8040}
8041
8042DEFUN (show_ip_bgp_community_list_exact,
8043 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008044 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008045 SHOW_STR
8046 IP_STR
8047 BGP_STR
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 "Exact match of the communities\n")
8052{
8053 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8054}
8055
8056DEFUN (show_ip_bgp_ipv4_community_list_exact,
8057 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008058 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008059 SHOW_STR
8060 IP_STR
8061 BGP_STR
8062 "Address family\n"
8063 "Address Family modifier\n"
8064 "Address Family modifier\n"
8065 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008066 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008067 "community-list name\n"
8068 "Exact match of the communities\n")
8069{
8070 if (strncmp (argv[0], "m", 1) == 0)
8071 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8072
8073 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8074}
8075
8076#ifdef HAVE_IPV6
8077DEFUN (show_bgp_community_list,
8078 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008079 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008080 SHOW_STR
8081 BGP_STR
8082 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008083 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008084 "community-list name\n")
8085{
8086 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8087}
8088
8089ALIAS (show_bgp_community_list,
8090 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008091 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008092 SHOW_STR
8093 BGP_STR
8094 "Address family\n"
8095 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008096 "community-list number\n"
8097 "community-list name\n");
paul718e3742002-12-13 20:15:29 +00008098
8099/* old command */
8100DEFUN (show_ipv6_bgp_community_list,
8101 show_ipv6_bgp_community_list_cmd,
8102 "show ipv6 bgp community-list WORD",
8103 SHOW_STR
8104 IPV6_STR
8105 BGP_STR
8106 "Display routes matching the community-list\n"
8107 "community-list name\n")
8108{
8109 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8110}
8111
8112/* old command */
8113DEFUN (show_ipv6_mbgp_community_list,
8114 show_ipv6_mbgp_community_list_cmd,
8115 "show ipv6 mbgp community-list WORD",
8116 SHOW_STR
8117 IPV6_STR
8118 MBGP_STR
8119 "Display routes matching the community-list\n"
8120 "community-list name\n")
8121{
8122 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8123}
8124
8125DEFUN (show_bgp_community_list_exact,
8126 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008127 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008128 SHOW_STR
8129 BGP_STR
8130 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008131 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008132 "community-list name\n"
8133 "Exact match of the communities\n")
8134{
8135 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8136}
8137
8138ALIAS (show_bgp_community_list_exact,
8139 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008140 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008141 SHOW_STR
8142 BGP_STR
8143 "Address family\n"
8144 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008145 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008146 "community-list name\n"
8147 "Exact match of the communities\n")
8148
8149/* old command */
8150DEFUN (show_ipv6_bgp_community_list_exact,
8151 show_ipv6_bgp_community_list_exact_cmd,
8152 "show ipv6 bgp community-list WORD exact-match",
8153 SHOW_STR
8154 IPV6_STR
8155 BGP_STR
8156 "Display routes matching the community-list\n"
8157 "community-list name\n"
8158 "Exact match of the communities\n")
8159{
8160 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8161}
8162
8163/* old command */
8164DEFUN (show_ipv6_mbgp_community_list_exact,
8165 show_ipv6_mbgp_community_list_exact_cmd,
8166 "show ipv6 mbgp community-list WORD exact-match",
8167 SHOW_STR
8168 IPV6_STR
8169 MBGP_STR
8170 "Display routes matching the community-list\n"
8171 "community-list name\n"
8172 "Exact match of the communities\n")
8173{
8174 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8175}
8176#endif /* HAVE_IPV6 */
8177
paul94f2b392005-06-28 12:44:16 +00008178static int
paulfd79ac92004-10-13 05:06:08 +00008179bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008180 safi_t safi, enum bgp_show_type type)
8181{
8182 int ret;
8183 struct prefix *p;
8184
8185 p = prefix_new();
8186
8187 ret = str2prefix (prefix, p);
8188 if (! ret)
8189 {
8190 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8191 return CMD_WARNING;
8192 }
8193
ajs5a646652004-11-05 01:25:55 +00008194 ret = bgp_show (vty, NULL, afi, safi, type, p);
8195 prefix_free(p);
8196 return ret;
paul718e3742002-12-13 20:15:29 +00008197}
8198
8199DEFUN (show_ip_bgp_prefix_longer,
8200 show_ip_bgp_prefix_longer_cmd,
8201 "show ip bgp A.B.C.D/M longer-prefixes",
8202 SHOW_STR
8203 IP_STR
8204 BGP_STR
8205 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8206 "Display route and more specific routes\n")
8207{
8208 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8209 bgp_show_type_prefix_longer);
8210}
8211
8212DEFUN (show_ip_bgp_flap_prefix_longer,
8213 show_ip_bgp_flap_prefix_longer_cmd,
8214 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8215 SHOW_STR
8216 IP_STR
8217 BGP_STR
8218 "Display flap statistics of routes\n"
8219 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8220 "Display route and more specific routes\n")
8221{
8222 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8223 bgp_show_type_flap_prefix_longer);
8224}
8225
8226DEFUN (show_ip_bgp_ipv4_prefix_longer,
8227 show_ip_bgp_ipv4_prefix_longer_cmd,
8228 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8229 SHOW_STR
8230 IP_STR
8231 BGP_STR
8232 "Address family\n"
8233 "Address Family modifier\n"
8234 "Address Family modifier\n"
8235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8236 "Display route and more specific routes\n")
8237{
8238 if (strncmp (argv[0], "m", 1) == 0)
8239 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8240 bgp_show_type_prefix_longer);
8241
8242 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8243 bgp_show_type_prefix_longer);
8244}
8245
8246DEFUN (show_ip_bgp_flap_address,
8247 show_ip_bgp_flap_address_cmd,
8248 "show ip bgp flap-statistics A.B.C.D",
8249 SHOW_STR
8250 IP_STR
8251 BGP_STR
8252 "Display flap statistics of routes\n"
8253 "Network in the BGP routing table to display\n")
8254{
8255 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8256 bgp_show_type_flap_address);
8257}
8258
8259DEFUN (show_ip_bgp_flap_prefix,
8260 show_ip_bgp_flap_prefix_cmd,
8261 "show ip bgp flap-statistics A.B.C.D/M",
8262 SHOW_STR
8263 IP_STR
8264 BGP_STR
8265 "Display flap statistics of routes\n"
8266 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8267{
8268 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8269 bgp_show_type_flap_prefix);
8270}
8271#ifdef HAVE_IPV6
8272DEFUN (show_bgp_prefix_longer,
8273 show_bgp_prefix_longer_cmd,
8274 "show bgp X:X::X:X/M longer-prefixes",
8275 SHOW_STR
8276 BGP_STR
8277 "IPv6 prefix <network>/<length>\n"
8278 "Display route and more specific routes\n")
8279{
8280 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8281 bgp_show_type_prefix_longer);
8282}
8283
8284ALIAS (show_bgp_prefix_longer,
8285 show_bgp_ipv6_prefix_longer_cmd,
8286 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8287 SHOW_STR
8288 BGP_STR
8289 "Address family\n"
8290 "IPv6 prefix <network>/<length>\n"
8291 "Display route and more specific routes\n")
8292
8293/* old command */
8294DEFUN (show_ipv6_bgp_prefix_longer,
8295 show_ipv6_bgp_prefix_longer_cmd,
8296 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8297 SHOW_STR
8298 IPV6_STR
8299 BGP_STR
8300 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8301 "Display route and more specific routes\n")
8302{
8303 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8304 bgp_show_type_prefix_longer);
8305}
8306
8307/* old command */
8308DEFUN (show_ipv6_mbgp_prefix_longer,
8309 show_ipv6_mbgp_prefix_longer_cmd,
8310 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8311 SHOW_STR
8312 IPV6_STR
8313 MBGP_STR
8314 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8315 "Display route and more specific routes\n")
8316{
8317 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8318 bgp_show_type_prefix_longer);
8319}
8320#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008321
paul94f2b392005-06-28 12:44:16 +00008322static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008323peer_lookup_in_view (struct vty *vty, const char *view_name,
8324 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008325{
8326 int ret;
8327 struct bgp *bgp;
8328 struct peer *peer;
8329 union sockunion su;
8330
8331 /* BGP structure lookup. */
8332 if (view_name)
8333 {
8334 bgp = bgp_lookup_by_name (view_name);
8335 if (! bgp)
8336 {
8337 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8338 return NULL;
8339 }
8340 }
paul5228ad22004-06-04 17:58:18 +00008341 else
paulbb46e942003-10-24 19:02:03 +00008342 {
8343 bgp = bgp_get_default ();
8344 if (! bgp)
8345 {
8346 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8347 return NULL;
8348 }
8349 }
8350
8351 /* Get peer sockunion. */
8352 ret = str2sockunion (ip_str, &su);
8353 if (ret < 0)
8354 {
8355 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8356 return NULL;
8357 }
8358
8359 /* Peer structure lookup. */
8360 peer = peer_lookup (bgp, &su);
8361 if (! peer)
8362 {
8363 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8364 return NULL;
8365 }
8366
8367 return peer;
8368}
8369
paul94f2b392005-06-28 12:44:16 +00008370static void
paul718e3742002-12-13 20:15:29 +00008371show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8372 int in)
8373{
8374 struct bgp_table *table;
8375 struct bgp_adj_in *ain;
8376 struct bgp_adj_out *adj;
8377 unsigned long output_count;
8378 struct bgp_node *rn;
8379 int header1 = 1;
8380 struct bgp *bgp;
8381 int header2 = 1;
8382
paulbb46e942003-10-24 19:02:03 +00008383 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008384
8385 if (! bgp)
8386 return;
8387
8388 table = bgp->rib[afi][safi];
8389
8390 output_count = 0;
8391
8392 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8393 PEER_STATUS_DEFAULT_ORIGINATE))
8394 {
8395 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 +00008396 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8397 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008398
8399 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8400 VTY_NEWLINE, VTY_NEWLINE);
8401 header1 = 0;
8402 }
8403
8404 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8405 if (in)
8406 {
8407 for (ain = rn->adj_in; ain; ain = ain->next)
8408 if (ain->peer == peer)
8409 {
8410 if (header1)
8411 {
8412 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 +00008413 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8414 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008415 header1 = 0;
8416 }
8417 if (header2)
8418 {
8419 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8420 header2 = 0;
8421 }
8422 if (ain->attr)
8423 {
8424 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8425 output_count++;
8426 }
8427 }
8428 }
8429 else
8430 {
8431 for (adj = rn->adj_out; adj; adj = adj->next)
8432 if (adj->peer == peer)
8433 {
8434 if (header1)
8435 {
8436 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 +00008437 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8438 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008439 header1 = 0;
8440 }
8441 if (header2)
8442 {
8443 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8444 header2 = 0;
8445 }
8446 if (adj->attr)
8447 {
8448 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8449 output_count++;
8450 }
8451 }
8452 }
8453
8454 if (output_count != 0)
8455 vty_out (vty, "%sTotal number of prefixes %ld%s",
8456 VTY_NEWLINE, output_count, VTY_NEWLINE);
8457}
8458
paul94f2b392005-06-28 12:44:16 +00008459static int
paulbb46e942003-10-24 19:02:03 +00008460peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8461{
paul718e3742002-12-13 20:15:29 +00008462 if (! peer || ! peer->afc[afi][safi])
8463 {
8464 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8465 return CMD_WARNING;
8466 }
8467
8468 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8469 {
8470 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8471 VTY_NEWLINE);
8472 return CMD_WARNING;
8473 }
8474
8475 show_adj_route (vty, peer, afi, safi, in);
8476
8477 return CMD_SUCCESS;
8478}
8479
8480DEFUN (show_ip_bgp_neighbor_advertised_route,
8481 show_ip_bgp_neighbor_advertised_route_cmd,
8482 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8483 SHOW_STR
8484 IP_STR
8485 BGP_STR
8486 "Detailed information on TCP and BGP neighbor connections\n"
8487 "Neighbor to display information about\n"
8488 "Neighbor to display information about\n"
8489 "Display the routes advertised to a BGP neighbor\n")
8490{
paulbb46e942003-10-24 19:02:03 +00008491 struct peer *peer;
8492
8493 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8494 if (! peer)
8495 return CMD_WARNING;
8496
8497 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008498}
8499
8500DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8501 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8502 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8503 SHOW_STR
8504 IP_STR
8505 BGP_STR
8506 "Address family\n"
8507 "Address Family modifier\n"
8508 "Address Family modifier\n"
8509 "Detailed information on TCP and BGP neighbor connections\n"
8510 "Neighbor to display information about\n"
8511 "Neighbor to display information about\n"
8512 "Display the routes advertised to a BGP neighbor\n")
8513{
paulbb46e942003-10-24 19:02:03 +00008514 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008515
paulbb46e942003-10-24 19:02:03 +00008516 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8517 if (! peer)
8518 return CMD_WARNING;
8519
8520 if (strncmp (argv[0], "m", 1) == 0)
8521 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8522
8523 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008524}
8525
8526#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008527DEFUN (show_bgp_view_neighbor_advertised_route,
8528 show_bgp_view_neighbor_advertised_route_cmd,
8529 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8530 SHOW_STR
8531 BGP_STR
8532 "BGP view\n"
8533 "View name\n"
8534 "Detailed information on TCP and BGP neighbor connections\n"
8535 "Neighbor to display information about\n"
8536 "Neighbor to display information about\n"
8537 "Display the routes advertised to a BGP neighbor\n")
8538{
8539 struct peer *peer;
8540
8541 if (argc == 2)
8542 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8543 else
8544 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8545
8546 if (! peer)
8547 return CMD_WARNING;
8548
8549 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8550}
8551
8552ALIAS (show_bgp_view_neighbor_advertised_route,
8553 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8554 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8555 SHOW_STR
8556 BGP_STR
8557 "BGP view\n"
8558 "View name\n"
8559 "Address family\n"
8560 "Detailed information on TCP and BGP neighbor connections\n"
8561 "Neighbor to display information about\n"
8562 "Neighbor to display information about\n"
8563 "Display the routes advertised to a BGP neighbor\n")
8564
8565DEFUN (show_bgp_view_neighbor_received_routes,
8566 show_bgp_view_neighbor_received_routes_cmd,
8567 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8568 SHOW_STR
8569 BGP_STR
8570 "BGP view\n"
8571 "View name\n"
8572 "Detailed information on TCP and BGP neighbor connections\n"
8573 "Neighbor to display information about\n"
8574 "Neighbor to display information about\n"
8575 "Display the received routes from neighbor\n")
8576{
8577 struct peer *peer;
8578
8579 if (argc == 2)
8580 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8581 else
8582 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8583
8584 if (! peer)
8585 return CMD_WARNING;
8586
8587 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8588}
8589
8590ALIAS (show_bgp_view_neighbor_received_routes,
8591 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8592 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8593 SHOW_STR
8594 BGP_STR
8595 "BGP view\n"
8596 "View name\n"
8597 "Address family\n"
8598 "Detailed information on TCP and BGP neighbor connections\n"
8599 "Neighbor to display information about\n"
8600 "Neighbor to display information about\n"
8601 "Display the received routes from neighbor\n")
8602
8603ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008604 show_bgp_neighbor_advertised_route_cmd,
8605 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8606 SHOW_STR
8607 BGP_STR
8608 "Detailed information on TCP and BGP neighbor connections\n"
8609 "Neighbor to display information about\n"
8610 "Neighbor to display information about\n"
8611 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008612
8613ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008614 show_bgp_ipv6_neighbor_advertised_route_cmd,
8615 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8616 SHOW_STR
8617 BGP_STR
8618 "Address family\n"
8619 "Detailed information on TCP and BGP neighbor connections\n"
8620 "Neighbor to display information about\n"
8621 "Neighbor to display information about\n"
8622 "Display the routes advertised to a BGP neighbor\n")
8623
8624/* old command */
paulbb46e942003-10-24 19:02:03 +00008625ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008626 ipv6_bgp_neighbor_advertised_route_cmd,
8627 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8628 SHOW_STR
8629 IPV6_STR
8630 BGP_STR
8631 "Detailed information on TCP and BGP neighbor connections\n"
8632 "Neighbor to display information about\n"
8633 "Neighbor to display information about\n"
8634 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008635
paul718e3742002-12-13 20:15:29 +00008636/* old command */
8637DEFUN (ipv6_mbgp_neighbor_advertised_route,
8638 ipv6_mbgp_neighbor_advertised_route_cmd,
8639 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8640 SHOW_STR
8641 IPV6_STR
8642 MBGP_STR
8643 "Detailed information on TCP and BGP neighbor connections\n"
8644 "Neighbor to display information about\n"
8645 "Neighbor to display information about\n"
8646 "Display the routes advertised to a BGP neighbor\n")
8647{
paulbb46e942003-10-24 19:02:03 +00008648 struct peer *peer;
8649
8650 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8651 if (! peer)
8652 return CMD_WARNING;
8653
8654 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008655}
8656#endif /* HAVE_IPV6 */
8657
8658DEFUN (show_ip_bgp_neighbor_received_routes,
8659 show_ip_bgp_neighbor_received_routes_cmd,
8660 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8661 SHOW_STR
8662 IP_STR
8663 BGP_STR
8664 "Detailed information on TCP and BGP neighbor connections\n"
8665 "Neighbor to display information about\n"
8666 "Neighbor to display information about\n"
8667 "Display the received routes from neighbor\n")
8668{
paulbb46e942003-10-24 19:02:03 +00008669 struct peer *peer;
8670
8671 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8672 if (! peer)
8673 return CMD_WARNING;
8674
8675 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008676}
8677
8678DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8679 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8680 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8681 SHOW_STR
8682 IP_STR
8683 BGP_STR
8684 "Address family\n"
8685 "Address Family modifier\n"
8686 "Address Family modifier\n"
8687 "Detailed information on TCP and BGP neighbor connections\n"
8688 "Neighbor to display information about\n"
8689 "Neighbor to display information about\n"
8690 "Display the received routes from neighbor\n")
8691{
paulbb46e942003-10-24 19:02:03 +00008692 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008693
paulbb46e942003-10-24 19:02:03 +00008694 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8695 if (! peer)
8696 return CMD_WARNING;
8697
8698 if (strncmp (argv[0], "m", 1) == 0)
8699 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8700
8701 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008702}
8703
8704DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8705 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8706 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8707 SHOW_STR
8708 IP_STR
8709 BGP_STR
8710 "Detailed information on TCP and BGP neighbor connections\n"
8711 "Neighbor to display information about\n"
8712 "Neighbor to display information about\n"
8713 "Display information received from a BGP neighbor\n"
8714 "Display the prefixlist filter\n")
8715{
8716 char name[BUFSIZ];
8717 union sockunion *su;
8718 struct peer *peer;
8719 int count;
8720
8721 su = sockunion_str2su (argv[0]);
8722 if (su == NULL)
8723 return CMD_WARNING;
8724
8725 peer = peer_lookup (NULL, su);
8726 if (! peer)
8727 return CMD_WARNING;
8728
8729 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8730 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8731 if (count)
8732 {
8733 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8734 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8735 }
8736
8737 return CMD_SUCCESS;
8738}
8739
8740DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8741 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8742 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8743 SHOW_STR
8744 IP_STR
8745 BGP_STR
8746 "Address family\n"
8747 "Address Family modifier\n"
8748 "Address Family modifier\n"
8749 "Detailed information on TCP and BGP neighbor connections\n"
8750 "Neighbor to display information about\n"
8751 "Neighbor to display information about\n"
8752 "Display information received from a BGP neighbor\n"
8753 "Display the prefixlist filter\n")
8754{
8755 char name[BUFSIZ];
8756 union sockunion *su;
8757 struct peer *peer;
8758 int count;
8759
8760 su = sockunion_str2su (argv[1]);
8761 if (su == NULL)
8762 return CMD_WARNING;
8763
8764 peer = peer_lookup (NULL, su);
8765 if (! peer)
8766 return CMD_WARNING;
8767
8768 if (strncmp (argv[0], "m", 1) == 0)
8769 {
8770 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8771 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8772 if (count)
8773 {
8774 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8775 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8776 }
8777 }
8778 else
8779 {
8780 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8781 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8782 if (count)
8783 {
8784 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8785 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8786 }
8787 }
8788
8789 return CMD_SUCCESS;
8790}
8791
8792
8793#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008794ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008795 show_bgp_neighbor_received_routes_cmd,
8796 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8797 SHOW_STR
8798 BGP_STR
8799 "Detailed information on TCP and BGP neighbor connections\n"
8800 "Neighbor to display information about\n"
8801 "Neighbor to display information about\n"
8802 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008803
paulbb46e942003-10-24 19:02:03 +00008804ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008805 show_bgp_ipv6_neighbor_received_routes_cmd,
8806 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8807 SHOW_STR
8808 BGP_STR
8809 "Address family\n"
8810 "Detailed information on TCP and BGP neighbor connections\n"
8811 "Neighbor to display information about\n"
8812 "Neighbor to display information about\n"
8813 "Display the received routes from neighbor\n")
8814
8815DEFUN (show_bgp_neighbor_received_prefix_filter,
8816 show_bgp_neighbor_received_prefix_filter_cmd,
8817 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8818 SHOW_STR
8819 BGP_STR
8820 "Detailed information on TCP and BGP neighbor connections\n"
8821 "Neighbor to display information about\n"
8822 "Neighbor to display information about\n"
8823 "Display information received from a BGP neighbor\n"
8824 "Display the prefixlist filter\n")
8825{
8826 char name[BUFSIZ];
8827 union sockunion *su;
8828 struct peer *peer;
8829 int count;
8830
8831 su = sockunion_str2su (argv[0]);
8832 if (su == NULL)
8833 return CMD_WARNING;
8834
8835 peer = peer_lookup (NULL, su);
8836 if (! peer)
8837 return CMD_WARNING;
8838
8839 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8840 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8841 if (count)
8842 {
8843 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8844 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8845 }
8846
8847 return CMD_SUCCESS;
8848}
8849
8850ALIAS (show_bgp_neighbor_received_prefix_filter,
8851 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8852 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8853 SHOW_STR
8854 BGP_STR
8855 "Address family\n"
8856 "Detailed information on TCP and BGP neighbor connections\n"
8857 "Neighbor to display information about\n"
8858 "Neighbor to display information about\n"
8859 "Display information received from a BGP neighbor\n"
8860 "Display the prefixlist filter\n")
8861
8862/* old command */
paulbb46e942003-10-24 19:02:03 +00008863ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008864 ipv6_bgp_neighbor_received_routes_cmd,
8865 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8866 SHOW_STR
8867 IPV6_STR
8868 BGP_STR
8869 "Detailed information on TCP and BGP neighbor connections\n"
8870 "Neighbor to display information about\n"
8871 "Neighbor to display information about\n"
8872 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008873
8874/* old command */
8875DEFUN (ipv6_mbgp_neighbor_received_routes,
8876 ipv6_mbgp_neighbor_received_routes_cmd,
8877 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8878 SHOW_STR
8879 IPV6_STR
8880 MBGP_STR
8881 "Detailed information on TCP and BGP neighbor connections\n"
8882 "Neighbor to display information about\n"
8883 "Neighbor to display information about\n"
8884 "Display the received routes from neighbor\n")
8885{
paulbb46e942003-10-24 19:02:03 +00008886 struct peer *peer;
8887
8888 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8889 if (! peer)
8890 return CMD_WARNING;
8891
8892 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00008893}
paulbb46e942003-10-24 19:02:03 +00008894
8895DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8896 show_bgp_view_neighbor_received_prefix_filter_cmd,
8897 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8898 SHOW_STR
8899 BGP_STR
8900 "BGP view\n"
8901 "View name\n"
8902 "Detailed information on TCP and BGP neighbor connections\n"
8903 "Neighbor to display information about\n"
8904 "Neighbor to display information about\n"
8905 "Display information received from a BGP neighbor\n"
8906 "Display the prefixlist filter\n")
8907{
8908 char name[BUFSIZ];
8909 union sockunion *su;
8910 struct peer *peer;
8911 struct bgp *bgp;
8912 int count;
8913
8914 /* BGP structure lookup. */
8915 bgp = bgp_lookup_by_name (argv[0]);
8916 if (bgp == NULL)
8917 {
8918 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8919 return CMD_WARNING;
8920 }
8921
8922 su = sockunion_str2su (argv[1]);
8923 if (su == NULL)
8924 return CMD_WARNING;
8925
8926 peer = peer_lookup (bgp, su);
8927 if (! peer)
8928 return CMD_WARNING;
8929
8930 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8931 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8932 if (count)
8933 {
8934 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8935 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8936 }
8937
8938 return CMD_SUCCESS;
8939}
8940
8941ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8942 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8943 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8944 SHOW_STR
8945 BGP_STR
8946 "BGP view\n"
8947 "View name\n"
8948 "Address family\n"
8949 "Detailed information on TCP and BGP neighbor connections\n"
8950 "Neighbor to display information about\n"
8951 "Neighbor to display information about\n"
8952 "Display information received from a BGP neighbor\n"
8953 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008954#endif /* HAVE_IPV6 */
8955
paul94f2b392005-06-28 12:44:16 +00008956static int
paulbb46e942003-10-24 19:02:03 +00008957bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008958 safi_t safi, enum bgp_show_type type)
8959{
paul718e3742002-12-13 20:15:29 +00008960 if (! peer || ! peer->afc[afi][safi])
8961 {
8962 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008963 return CMD_WARNING;
8964 }
8965
ajs5a646652004-11-05 01:25:55 +00008966 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00008967}
8968
8969DEFUN (show_ip_bgp_neighbor_routes,
8970 show_ip_bgp_neighbor_routes_cmd,
8971 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8972 SHOW_STR
8973 IP_STR
8974 BGP_STR
8975 "Detailed information on TCP and BGP neighbor connections\n"
8976 "Neighbor to display information about\n"
8977 "Neighbor to display information about\n"
8978 "Display routes learned from neighbor\n")
8979{
paulbb46e942003-10-24 19:02:03 +00008980 struct peer *peer;
8981
8982 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8983 if (! peer)
8984 return CMD_WARNING;
8985
8986 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008987 bgp_show_type_neighbor);
8988}
8989
8990DEFUN (show_ip_bgp_neighbor_flap,
8991 show_ip_bgp_neighbor_flap_cmd,
8992 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8993 SHOW_STR
8994 IP_STR
8995 BGP_STR
8996 "Detailed information on TCP and BGP neighbor connections\n"
8997 "Neighbor to display information about\n"
8998 "Neighbor to display information about\n"
8999 "Display flap statistics of the routes learned from neighbor\n")
9000{
paulbb46e942003-10-24 19:02:03 +00009001 struct peer *peer;
9002
9003 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9004 if (! peer)
9005 return CMD_WARNING;
9006
9007 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009008 bgp_show_type_flap_neighbor);
9009}
9010
9011DEFUN (show_ip_bgp_neighbor_damp,
9012 show_ip_bgp_neighbor_damp_cmd,
9013 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9014 SHOW_STR
9015 IP_STR
9016 BGP_STR
9017 "Detailed information on TCP and BGP neighbor connections\n"
9018 "Neighbor to display information about\n"
9019 "Neighbor to display information about\n"
9020 "Display the dampened routes received from neighbor\n")
9021{
paulbb46e942003-10-24 19:02:03 +00009022 struct peer *peer;
9023
9024 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9025 if (! peer)
9026 return CMD_WARNING;
9027
9028 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009029 bgp_show_type_damp_neighbor);
9030}
9031
9032DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9033 show_ip_bgp_ipv4_neighbor_routes_cmd,
9034 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9035 SHOW_STR
9036 IP_STR
9037 BGP_STR
9038 "Address family\n"
9039 "Address Family modifier\n"
9040 "Address Family modifier\n"
9041 "Detailed information on TCP and BGP neighbor connections\n"
9042 "Neighbor to display information about\n"
9043 "Neighbor to display information about\n"
9044 "Display routes learned from neighbor\n")
9045{
paulbb46e942003-10-24 19:02:03 +00009046 struct peer *peer;
9047
9048 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9049 if (! peer)
9050 return CMD_WARNING;
9051
paul718e3742002-12-13 20:15:29 +00009052 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009053 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009054 bgp_show_type_neighbor);
9055
paulbb46e942003-10-24 19:02:03 +00009056 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009057 bgp_show_type_neighbor);
9058}
paulbb46e942003-10-24 19:02:03 +00009059
paulfee0f4c2004-09-13 05:12:46 +00009060DEFUN (show_ip_bgp_view_rsclient,
9061 show_ip_bgp_view_rsclient_cmd,
9062 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9063 SHOW_STR
9064 IP_STR
9065 BGP_STR
9066 "BGP view\n"
9067 "BGP view name\n"
9068 "Information about Route Server Client\n"
9069 NEIGHBOR_ADDR_STR)
9070{
9071 struct bgp_table *table;
9072 struct peer *peer;
9073
9074 if (argc == 2)
9075 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9076 else
9077 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9078
9079 if (! peer)
9080 return CMD_WARNING;
9081
9082 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9083 {
9084 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9085 VTY_NEWLINE);
9086 return CMD_WARNING;
9087 }
9088
9089 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9090 PEER_FLAG_RSERVER_CLIENT))
9091 {
9092 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9093 VTY_NEWLINE);
9094 return CMD_WARNING;
9095 }
9096
9097 table = peer->rib[AFI_IP][SAFI_UNICAST];
9098
ajs5a646652004-11-05 01:25:55 +00009099 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009100}
9101
9102ALIAS (show_ip_bgp_view_rsclient,
9103 show_ip_bgp_rsclient_cmd,
9104 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9105 SHOW_STR
9106 IP_STR
9107 BGP_STR
9108 "Information about Route Server Client\n"
9109 NEIGHBOR_ADDR_STR)
9110
9111DEFUN (show_ip_bgp_view_rsclient_route,
9112 show_ip_bgp_view_rsclient_route_cmd,
9113 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9114 SHOW_STR
9115 IP_STR
9116 BGP_STR
9117 "BGP view\n"
9118 "BGP view name\n"
9119 "Information about Route Server Client\n"
9120 NEIGHBOR_ADDR_STR
9121 "Network in the BGP routing table to display\n")
9122{
9123 struct bgp *bgp;
9124 struct peer *peer;
9125
9126 /* BGP structure lookup. */
9127 if (argc == 3)
9128 {
9129 bgp = bgp_lookup_by_name (argv[0]);
9130 if (bgp == NULL)
9131 {
9132 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9133 return CMD_WARNING;
9134 }
9135 }
9136 else
9137 {
9138 bgp = bgp_get_default ();
9139 if (bgp == NULL)
9140 {
9141 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9142 return CMD_WARNING;
9143 }
9144 }
9145
9146 if (argc == 3)
9147 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9148 else
9149 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9150
9151 if (! peer)
9152 return CMD_WARNING;
9153
9154 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9155 {
9156 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9157 VTY_NEWLINE);
9158 return CMD_WARNING;
9159}
9160
9161 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9162 PEER_FLAG_RSERVER_CLIENT))
9163 {
9164 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9165 VTY_NEWLINE);
9166 return CMD_WARNING;
9167 }
9168
9169 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9170 (argc == 3) ? argv[2] : argv[1],
9171 AFI_IP, SAFI_UNICAST, NULL, 0);
9172}
9173
9174ALIAS (show_ip_bgp_view_rsclient_route,
9175 show_ip_bgp_rsclient_route_cmd,
9176 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9177 SHOW_STR
9178 IP_STR
9179 BGP_STR
9180 "Information about Route Server Client\n"
9181 NEIGHBOR_ADDR_STR
9182 "Network in the BGP routing table to display\n")
9183
9184DEFUN (show_ip_bgp_view_rsclient_prefix,
9185 show_ip_bgp_view_rsclient_prefix_cmd,
9186 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9187 SHOW_STR
9188 IP_STR
9189 BGP_STR
9190 "BGP view\n"
9191 "BGP view name\n"
9192 "Information about Route Server Client\n"
9193 NEIGHBOR_ADDR_STR
9194 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9195{
9196 struct bgp *bgp;
9197 struct peer *peer;
9198
9199 /* BGP structure lookup. */
9200 if (argc == 3)
9201 {
9202 bgp = bgp_lookup_by_name (argv[0]);
9203 if (bgp == NULL)
9204 {
9205 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9206 return CMD_WARNING;
9207 }
9208 }
9209 else
9210 {
9211 bgp = bgp_get_default ();
9212 if (bgp == NULL)
9213 {
9214 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9215 return CMD_WARNING;
9216 }
9217 }
9218
9219 if (argc == 3)
9220 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9221 else
9222 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9223
9224 if (! peer)
9225 return CMD_WARNING;
9226
9227 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9228 {
9229 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9230 VTY_NEWLINE);
9231 return CMD_WARNING;
9232}
9233
9234 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9235 PEER_FLAG_RSERVER_CLIENT))
9236{
9237 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9238 VTY_NEWLINE);
9239 return CMD_WARNING;
9240 }
9241
9242 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9243 (argc == 3) ? argv[2] : argv[1],
9244 AFI_IP, SAFI_UNICAST, NULL, 1);
9245}
9246
9247ALIAS (show_ip_bgp_view_rsclient_prefix,
9248 show_ip_bgp_rsclient_prefix_cmd,
9249 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9250 SHOW_STR
9251 IP_STR
9252 BGP_STR
9253 "Information about Route Server Client\n"
9254 NEIGHBOR_ADDR_STR
9255 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9256
9257
paul718e3742002-12-13 20:15:29 +00009258#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009259DEFUN (show_bgp_view_neighbor_routes,
9260 show_bgp_view_neighbor_routes_cmd,
9261 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9262 SHOW_STR
9263 BGP_STR
9264 "BGP view\n"
9265 "BGP view name\n"
9266 "Detailed information on TCP and BGP neighbor connections\n"
9267 "Neighbor to display information about\n"
9268 "Neighbor to display information about\n"
9269 "Display routes learned from neighbor\n")
9270{
9271 struct peer *peer;
9272
9273 if (argc == 2)
9274 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9275 else
9276 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9277
9278 if (! peer)
9279 return CMD_WARNING;
9280
9281 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9282 bgp_show_type_neighbor);
9283}
9284
9285ALIAS (show_bgp_view_neighbor_routes,
9286 show_bgp_view_ipv6_neighbor_routes_cmd,
9287 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9288 SHOW_STR
9289 BGP_STR
9290 "BGP view\n"
9291 "BGP view name\n"
9292 "Address family\n"
9293 "Detailed information on TCP and BGP neighbor connections\n"
9294 "Neighbor to display information about\n"
9295 "Neighbor to display information about\n"
9296 "Display routes learned from neighbor\n")
9297
9298DEFUN (show_bgp_view_neighbor_damp,
9299 show_bgp_view_neighbor_damp_cmd,
9300 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9301 SHOW_STR
9302 BGP_STR
9303 "BGP view\n"
9304 "BGP view name\n"
9305 "Detailed information on TCP and BGP neighbor connections\n"
9306 "Neighbor to display information about\n"
9307 "Neighbor to display information about\n"
9308 "Display the dampened routes received from neighbor\n")
9309{
9310 struct peer *peer;
9311
9312 if (argc == 2)
9313 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9314 else
9315 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9316
9317 if (! peer)
9318 return CMD_WARNING;
9319
9320 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9321 bgp_show_type_damp_neighbor);
9322}
9323
9324ALIAS (show_bgp_view_neighbor_damp,
9325 show_bgp_view_ipv6_neighbor_damp_cmd,
9326 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9327 SHOW_STR
9328 BGP_STR
9329 "BGP view\n"
9330 "BGP view name\n"
9331 "Address family\n"
9332 "Detailed information on TCP and BGP neighbor connections\n"
9333 "Neighbor to display information about\n"
9334 "Neighbor to display information about\n"
9335 "Display the dampened routes received from neighbor\n")
9336
9337DEFUN (show_bgp_view_neighbor_flap,
9338 show_bgp_view_neighbor_flap_cmd,
9339 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9340 SHOW_STR
9341 BGP_STR
9342 "BGP view\n"
9343 "BGP view name\n"
9344 "Detailed information on TCP and BGP neighbor connections\n"
9345 "Neighbor to display information about\n"
9346 "Neighbor to display information about\n"
9347 "Display flap statistics of the routes learned from neighbor\n")
9348{
9349 struct peer *peer;
9350
9351 if (argc == 2)
9352 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9353 else
9354 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9355
9356 if (! peer)
9357 return CMD_WARNING;
9358
9359 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9360 bgp_show_type_flap_neighbor);
9361}
9362
9363ALIAS (show_bgp_view_neighbor_flap,
9364 show_bgp_view_ipv6_neighbor_flap_cmd,
9365 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9366 SHOW_STR
9367 BGP_STR
9368 "BGP view\n"
9369 "BGP view name\n"
9370 "Address family\n"
9371 "Detailed information on TCP and BGP neighbor connections\n"
9372 "Neighbor to display information about\n"
9373 "Neighbor to display information about\n"
9374 "Display flap statistics of the routes learned from neighbor\n")
9375
9376ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009377 show_bgp_neighbor_routes_cmd,
9378 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9379 SHOW_STR
9380 BGP_STR
9381 "Detailed information on TCP and BGP neighbor connections\n"
9382 "Neighbor to display information about\n"
9383 "Neighbor to display information about\n"
9384 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009385
paulbb46e942003-10-24 19:02:03 +00009386
9387ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009388 show_bgp_ipv6_neighbor_routes_cmd,
9389 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9390 SHOW_STR
9391 BGP_STR
9392 "Address family\n"
9393 "Detailed information on TCP and BGP neighbor connections\n"
9394 "Neighbor to display information about\n"
9395 "Neighbor to display information about\n"
9396 "Display routes learned from neighbor\n")
9397
9398/* old command */
paulbb46e942003-10-24 19:02:03 +00009399ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009400 ipv6_bgp_neighbor_routes_cmd,
9401 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9402 SHOW_STR
9403 IPV6_STR
9404 BGP_STR
9405 "Detailed information on TCP and BGP neighbor connections\n"
9406 "Neighbor to display information about\n"
9407 "Neighbor to display information about\n"
9408 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009409
9410/* old command */
9411DEFUN (ipv6_mbgp_neighbor_routes,
9412 ipv6_mbgp_neighbor_routes_cmd,
9413 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9414 SHOW_STR
9415 IPV6_STR
9416 MBGP_STR
9417 "Detailed information on TCP and BGP neighbor connections\n"
9418 "Neighbor to display information about\n"
9419 "Neighbor to display information about\n"
9420 "Display routes learned from neighbor\n")
9421{
paulbb46e942003-10-24 19:02:03 +00009422 struct peer *peer;
9423
9424 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9425 if (! peer)
9426 return CMD_WARNING;
9427
9428 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009429 bgp_show_type_neighbor);
9430}
paulbb46e942003-10-24 19:02:03 +00009431
9432ALIAS (show_bgp_view_neighbor_flap,
9433 show_bgp_neighbor_flap_cmd,
9434 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9435 SHOW_STR
9436 BGP_STR
9437 "Detailed information on TCP and BGP neighbor connections\n"
9438 "Neighbor to display information about\n"
9439 "Neighbor to display information about\n"
9440 "Display flap statistics of the routes learned from neighbor\n")
9441
9442ALIAS (show_bgp_view_neighbor_flap,
9443 show_bgp_ipv6_neighbor_flap_cmd,
9444 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9445 SHOW_STR
9446 BGP_STR
9447 "Address family\n"
9448 "Detailed information on TCP and BGP neighbor connections\n"
9449 "Neighbor to display information about\n"
9450 "Neighbor to display information about\n"
9451 "Display flap statistics of the routes learned from neighbor\n")
9452
9453ALIAS (show_bgp_view_neighbor_damp,
9454 show_bgp_neighbor_damp_cmd,
9455 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9456 SHOW_STR
9457 BGP_STR
9458 "Detailed information on TCP and BGP neighbor connections\n"
9459 "Neighbor to display information about\n"
9460 "Neighbor to display information about\n"
9461 "Display the dampened routes received from neighbor\n")
9462
9463ALIAS (show_bgp_view_neighbor_damp,
9464 show_bgp_ipv6_neighbor_damp_cmd,
9465 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9466 SHOW_STR
9467 BGP_STR
9468 "Address family\n"
9469 "Detailed information on TCP and BGP neighbor connections\n"
9470 "Neighbor to display information about\n"
9471 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009472 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009473
9474DEFUN (show_bgp_view_rsclient,
9475 show_bgp_view_rsclient_cmd,
9476 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9477 SHOW_STR
9478 BGP_STR
9479 "BGP view\n"
9480 "BGP view name\n"
9481 "Information about Route Server Client\n"
9482 NEIGHBOR_ADDR_STR)
9483{
9484 struct bgp_table *table;
9485 struct peer *peer;
9486
9487 if (argc == 2)
9488 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9489 else
9490 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9491
9492 if (! peer)
9493 return CMD_WARNING;
9494
9495 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9496 {
9497 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9498 VTY_NEWLINE);
9499 return CMD_WARNING;
9500 }
9501
9502 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9503 PEER_FLAG_RSERVER_CLIENT))
9504 {
9505 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9506 VTY_NEWLINE);
9507 return CMD_WARNING;
9508 }
9509
9510 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9511
ajs5a646652004-11-05 01:25:55 +00009512 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009513}
9514
9515ALIAS (show_bgp_view_rsclient,
9516 show_bgp_rsclient_cmd,
9517 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9518 SHOW_STR
9519 BGP_STR
9520 "Information about Route Server Client\n"
9521 NEIGHBOR_ADDR_STR)
9522
9523DEFUN (show_bgp_view_rsclient_route,
9524 show_bgp_view_rsclient_route_cmd,
9525 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9526 SHOW_STR
9527 BGP_STR
9528 "BGP view\n"
9529 "BGP view name\n"
9530 "Information about Route Server Client\n"
9531 NEIGHBOR_ADDR_STR
9532 "Network in the BGP routing table to display\n")
9533{
9534 struct bgp *bgp;
9535 struct peer *peer;
9536
9537 /* BGP structure lookup. */
9538 if (argc == 3)
9539 {
9540 bgp = bgp_lookup_by_name (argv[0]);
9541 if (bgp == NULL)
9542 {
9543 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9544 return CMD_WARNING;
9545 }
9546 }
9547 else
9548 {
9549 bgp = bgp_get_default ();
9550 if (bgp == NULL)
9551 {
9552 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9553 return CMD_WARNING;
9554 }
9555 }
9556
9557 if (argc == 3)
9558 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9559 else
9560 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9561
9562 if (! peer)
9563 return CMD_WARNING;
9564
9565 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9566 {
9567 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9568 VTY_NEWLINE);
9569 return CMD_WARNING;
9570 }
9571
9572 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9573 PEER_FLAG_RSERVER_CLIENT))
9574 {
9575 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9576 VTY_NEWLINE);
9577 return CMD_WARNING;
9578 }
9579
9580 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9581 (argc == 3) ? argv[2] : argv[1],
9582 AFI_IP6, SAFI_UNICAST, NULL, 0);
9583}
9584
9585ALIAS (show_bgp_view_rsclient_route,
9586 show_bgp_rsclient_route_cmd,
9587 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9588 SHOW_STR
9589 BGP_STR
9590 "Information about Route Server Client\n"
9591 NEIGHBOR_ADDR_STR
9592 "Network in the BGP routing table to display\n")
9593
9594DEFUN (show_bgp_view_rsclient_prefix,
9595 show_bgp_view_rsclient_prefix_cmd,
9596 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9597 SHOW_STR
9598 BGP_STR
9599 "BGP view\n"
9600 "BGP view name\n"
9601 "Information about Route Server Client\n"
9602 NEIGHBOR_ADDR_STR
9603 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9604{
9605 struct bgp *bgp;
9606 struct peer *peer;
9607
9608 /* BGP structure lookup. */
9609 if (argc == 3)
9610 {
9611 bgp = bgp_lookup_by_name (argv[0]);
9612 if (bgp == NULL)
9613 {
9614 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9615 return CMD_WARNING;
9616 }
9617 }
9618 else
9619 {
9620 bgp = bgp_get_default ();
9621 if (bgp == NULL)
9622 {
9623 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9624 return CMD_WARNING;
9625 }
9626 }
9627
9628 if (argc == 3)
9629 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9630 else
9631 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9632
9633 if (! peer)
9634 return CMD_WARNING;
9635
9636 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9637 {
9638 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9639 VTY_NEWLINE);
9640 return CMD_WARNING;
9641 }
9642
9643 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9644 PEER_FLAG_RSERVER_CLIENT))
9645 {
9646 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9647 VTY_NEWLINE);
9648 return CMD_WARNING;
9649 }
9650
9651 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9652 (argc == 3) ? argv[2] : argv[1],
9653 AFI_IP6, SAFI_UNICAST, NULL, 1);
9654}
9655
9656ALIAS (show_bgp_view_rsclient_prefix,
9657 show_bgp_rsclient_prefix_cmd,
9658 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9659 SHOW_STR
9660 BGP_STR
9661 "Information about Route Server Client\n"
9662 NEIGHBOR_ADDR_STR
9663 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9664
paul718e3742002-12-13 20:15:29 +00009665#endif /* HAVE_IPV6 */
9666
9667struct bgp_table *bgp_distance_table;
9668
9669struct bgp_distance
9670{
9671 /* Distance value for the IP source prefix. */
9672 u_char distance;
9673
9674 /* Name of the access-list to be matched. */
9675 char *access_list;
9676};
9677
paul94f2b392005-06-28 12:44:16 +00009678static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +00009679bgp_distance_new ()
9680{
9681 struct bgp_distance *new;
9682 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9683 memset (new, 0, sizeof (struct bgp_distance));
9684 return new;
9685}
9686
paul94f2b392005-06-28 12:44:16 +00009687static void
paul718e3742002-12-13 20:15:29 +00009688bgp_distance_free (struct bgp_distance *bdistance)
9689{
9690 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9691}
9692
paul94f2b392005-06-28 12:44:16 +00009693static int
paulfd79ac92004-10-13 05:06:08 +00009694bgp_distance_set (struct vty *vty, const char *distance_str,
9695 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009696{
9697 int ret;
9698 struct prefix_ipv4 p;
9699 u_char distance;
9700 struct bgp_node *rn;
9701 struct bgp_distance *bdistance;
9702
9703 ret = str2prefix_ipv4 (ip_str, &p);
9704 if (ret == 0)
9705 {
9706 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9707 return CMD_WARNING;
9708 }
9709
9710 distance = atoi (distance_str);
9711
9712 /* Get BGP distance node. */
9713 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9714 if (rn->info)
9715 {
9716 bdistance = rn->info;
9717 bgp_unlock_node (rn);
9718 }
9719 else
9720 {
9721 bdistance = bgp_distance_new ();
9722 rn->info = bdistance;
9723 }
9724
9725 /* Set distance value. */
9726 bdistance->distance = distance;
9727
9728 /* Reset access-list configuration. */
9729 if (bdistance->access_list)
9730 {
9731 free (bdistance->access_list);
9732 bdistance->access_list = NULL;
9733 }
9734 if (access_list_str)
9735 bdistance->access_list = strdup (access_list_str);
9736
9737 return CMD_SUCCESS;
9738}
9739
paul94f2b392005-06-28 12:44:16 +00009740static int
paulfd79ac92004-10-13 05:06:08 +00009741bgp_distance_unset (struct vty *vty, const char *distance_str,
9742 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009743{
9744 int ret;
9745 struct prefix_ipv4 p;
9746 u_char distance;
9747 struct bgp_node *rn;
9748 struct bgp_distance *bdistance;
9749
9750 ret = str2prefix_ipv4 (ip_str, &p);
9751 if (ret == 0)
9752 {
9753 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9754 return CMD_WARNING;
9755 }
9756
9757 distance = atoi (distance_str);
9758
9759 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9760 if (! rn)
9761 {
9762 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9763 return CMD_WARNING;
9764 }
9765
9766 bdistance = rn->info;
9767
9768 if (bdistance->access_list)
9769 free (bdistance->access_list);
9770 bgp_distance_free (bdistance);
9771
9772 rn->info = NULL;
9773 bgp_unlock_node (rn);
9774 bgp_unlock_node (rn);
9775
9776 return CMD_SUCCESS;
9777}
9778
paul94f2b392005-06-28 12:44:16 +00009779static void
paul718e3742002-12-13 20:15:29 +00009780bgp_distance_reset ()
9781{
9782 struct bgp_node *rn;
9783 struct bgp_distance *bdistance;
9784
9785 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9786 if ((bdistance = rn->info) != NULL)
9787 {
9788 if (bdistance->access_list)
9789 free (bdistance->access_list);
9790 bgp_distance_free (bdistance);
9791 rn->info = NULL;
9792 bgp_unlock_node (rn);
9793 }
9794}
9795
9796/* Apply BGP information to distance method. */
9797u_char
9798bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9799{
9800 struct bgp_node *rn;
9801 struct prefix_ipv4 q;
9802 struct peer *peer;
9803 struct bgp_distance *bdistance;
9804 struct access_list *alist;
9805 struct bgp_static *bgp_static;
9806
9807 if (! bgp)
9808 return 0;
9809
9810 if (p->family != AF_INET)
9811 return 0;
9812
9813 peer = rinfo->peer;
9814
9815 if (peer->su.sa.sa_family != AF_INET)
9816 return 0;
9817
9818 memset (&q, 0, sizeof (struct prefix_ipv4));
9819 q.family = AF_INET;
9820 q.prefix = peer->su.sin.sin_addr;
9821 q.prefixlen = IPV4_MAX_BITLEN;
9822
9823 /* Check source address. */
9824 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9825 if (rn)
9826 {
9827 bdistance = rn->info;
9828 bgp_unlock_node (rn);
9829
9830 if (bdistance->access_list)
9831 {
9832 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9833 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9834 return bdistance->distance;
9835 }
9836 else
9837 return bdistance->distance;
9838 }
9839
9840 /* Backdoor check. */
9841 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9842 if (rn)
9843 {
9844 bgp_static = rn->info;
9845 bgp_unlock_node (rn);
9846
9847 if (bgp_static->backdoor)
9848 {
9849 if (bgp->distance_local)
9850 return bgp->distance_local;
9851 else
9852 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9853 }
9854 }
9855
9856 if (peer_sort (peer) == BGP_PEER_EBGP)
9857 {
9858 if (bgp->distance_ebgp)
9859 return bgp->distance_ebgp;
9860 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9861 }
9862 else
9863 {
9864 if (bgp->distance_ibgp)
9865 return bgp->distance_ibgp;
9866 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9867 }
9868}
9869
9870DEFUN (bgp_distance,
9871 bgp_distance_cmd,
9872 "distance bgp <1-255> <1-255> <1-255>",
9873 "Define an administrative distance\n"
9874 "BGP distance\n"
9875 "Distance for routes external to the AS\n"
9876 "Distance for routes internal to the AS\n"
9877 "Distance for local routes\n")
9878{
9879 struct bgp *bgp;
9880
9881 bgp = vty->index;
9882
9883 bgp->distance_ebgp = atoi (argv[0]);
9884 bgp->distance_ibgp = atoi (argv[1]);
9885 bgp->distance_local = atoi (argv[2]);
9886 return CMD_SUCCESS;
9887}
9888
9889DEFUN (no_bgp_distance,
9890 no_bgp_distance_cmd,
9891 "no distance bgp <1-255> <1-255> <1-255>",
9892 NO_STR
9893 "Define an administrative distance\n"
9894 "BGP distance\n"
9895 "Distance for routes external to the AS\n"
9896 "Distance for routes internal to the AS\n"
9897 "Distance for local routes\n")
9898{
9899 struct bgp *bgp;
9900
9901 bgp = vty->index;
9902
9903 bgp->distance_ebgp= 0;
9904 bgp->distance_ibgp = 0;
9905 bgp->distance_local = 0;
9906 return CMD_SUCCESS;
9907}
9908
9909ALIAS (no_bgp_distance,
9910 no_bgp_distance2_cmd,
9911 "no distance bgp",
9912 NO_STR
9913 "Define an administrative distance\n"
9914 "BGP distance\n")
9915
9916DEFUN (bgp_distance_source,
9917 bgp_distance_source_cmd,
9918 "distance <1-255> A.B.C.D/M",
9919 "Define an administrative distance\n"
9920 "Administrative distance\n"
9921 "IP source prefix\n")
9922{
9923 bgp_distance_set (vty, argv[0], argv[1], NULL);
9924 return CMD_SUCCESS;
9925}
9926
9927DEFUN (no_bgp_distance_source,
9928 no_bgp_distance_source_cmd,
9929 "no distance <1-255> A.B.C.D/M",
9930 NO_STR
9931 "Define an administrative distance\n"
9932 "Administrative distance\n"
9933 "IP source prefix\n")
9934{
9935 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9936 return CMD_SUCCESS;
9937}
9938
9939DEFUN (bgp_distance_source_access_list,
9940 bgp_distance_source_access_list_cmd,
9941 "distance <1-255> A.B.C.D/M WORD",
9942 "Define an administrative distance\n"
9943 "Administrative distance\n"
9944 "IP source prefix\n"
9945 "Access list name\n")
9946{
9947 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9948 return CMD_SUCCESS;
9949}
9950
9951DEFUN (no_bgp_distance_source_access_list,
9952 no_bgp_distance_source_access_list_cmd,
9953 "no distance <1-255> A.B.C.D/M WORD",
9954 NO_STR
9955 "Define an administrative distance\n"
9956 "Administrative distance\n"
9957 "IP source prefix\n"
9958 "Access list name\n")
9959{
9960 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9961 return CMD_SUCCESS;
9962}
9963
9964DEFUN (bgp_damp_set,
9965 bgp_damp_set_cmd,
9966 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9967 "BGP Specific commands\n"
9968 "Enable route-flap dampening\n"
9969 "Half-life time for the penalty\n"
9970 "Value to start reusing a route\n"
9971 "Value to start suppressing a route\n"
9972 "Maximum duration to suppress a stable route\n")
9973{
9974 struct bgp *bgp;
9975 int half = DEFAULT_HALF_LIFE * 60;
9976 int reuse = DEFAULT_REUSE;
9977 int suppress = DEFAULT_SUPPRESS;
9978 int max = 4 * half;
9979
9980 if (argc == 4)
9981 {
9982 half = atoi (argv[0]) * 60;
9983 reuse = atoi (argv[1]);
9984 suppress = atoi (argv[2]);
9985 max = atoi (argv[3]) * 60;
9986 }
9987 else if (argc == 1)
9988 {
9989 half = atoi (argv[0]) * 60;
9990 max = 4 * half;
9991 }
9992
9993 bgp = vty->index;
9994 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
9995 half, reuse, suppress, max);
9996}
9997
9998ALIAS (bgp_damp_set,
9999 bgp_damp_set2_cmd,
10000 "bgp dampening <1-45>",
10001 "BGP Specific commands\n"
10002 "Enable route-flap dampening\n"
10003 "Half-life time for the penalty\n")
10004
10005ALIAS (bgp_damp_set,
10006 bgp_damp_set3_cmd,
10007 "bgp dampening",
10008 "BGP Specific commands\n"
10009 "Enable route-flap dampening\n")
10010
10011DEFUN (bgp_damp_unset,
10012 bgp_damp_unset_cmd,
10013 "no bgp dampening",
10014 NO_STR
10015 "BGP Specific commands\n"
10016 "Enable route-flap dampening\n")
10017{
10018 struct bgp *bgp;
10019
10020 bgp = vty->index;
10021 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10022}
10023
10024ALIAS (bgp_damp_unset,
10025 bgp_damp_unset2_cmd,
10026 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10027 NO_STR
10028 "BGP Specific commands\n"
10029 "Enable route-flap dampening\n"
10030 "Half-life time for the penalty\n"
10031 "Value to start reusing a route\n"
10032 "Value to start suppressing a route\n"
10033 "Maximum duration to suppress a stable route\n")
10034
10035DEFUN (show_ip_bgp_dampened_paths,
10036 show_ip_bgp_dampened_paths_cmd,
10037 "show ip bgp dampened-paths",
10038 SHOW_STR
10039 IP_STR
10040 BGP_STR
10041 "Display paths suppressed due to dampening\n")
10042{
ajs5a646652004-11-05 01:25:55 +000010043 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10044 NULL);
paul718e3742002-12-13 20:15:29 +000010045}
10046
10047DEFUN (show_ip_bgp_flap_statistics,
10048 show_ip_bgp_flap_statistics_cmd,
10049 "show ip bgp flap-statistics",
10050 SHOW_STR
10051 IP_STR
10052 BGP_STR
10053 "Display flap statistics of routes\n")
10054{
ajs5a646652004-11-05 01:25:55 +000010055 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10056 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010057}
10058
10059/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010060static int
paulfd79ac92004-10-13 05:06:08 +000010061bgp_clear_damp_route (struct vty *vty, const char *view_name,
10062 const char *ip_str, afi_t afi, safi_t safi,
10063 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010064{
10065 int ret;
10066 struct prefix match;
10067 struct bgp_node *rn;
10068 struct bgp_node *rm;
10069 struct bgp_info *ri;
10070 struct bgp_info *ri_temp;
10071 struct bgp *bgp;
10072 struct bgp_table *table;
10073
10074 /* BGP structure lookup. */
10075 if (view_name)
10076 {
10077 bgp = bgp_lookup_by_name (view_name);
10078 if (bgp == NULL)
10079 {
10080 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10081 return CMD_WARNING;
10082 }
10083 }
10084 else
10085 {
10086 bgp = bgp_get_default ();
10087 if (bgp == NULL)
10088 {
10089 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10090 return CMD_WARNING;
10091 }
10092 }
10093
10094 /* Check IP address argument. */
10095 ret = str2prefix (ip_str, &match);
10096 if (! ret)
10097 {
10098 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10099 return CMD_WARNING;
10100 }
10101
10102 match.family = afi2family (afi);
10103
10104 if (safi == SAFI_MPLS_VPN)
10105 {
10106 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10107 {
10108 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10109 continue;
10110
10111 if ((table = rn->info) != NULL)
10112 if ((rm = bgp_node_match (table, &match)) != NULL)
10113 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10114 {
10115 ri = rm->info;
10116 while (ri)
10117 {
10118 if (ri->damp_info)
10119 {
10120 ri_temp = ri->next;
10121 bgp_damp_info_free (ri->damp_info, 1);
10122 ri = ri_temp;
10123 }
10124 else
10125 ri = ri->next;
10126 }
10127 }
10128 }
10129 }
10130 else
10131 {
10132 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10133 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10134 {
10135 ri = rn->info;
10136 while (ri)
10137 {
10138 if (ri->damp_info)
10139 {
10140 ri_temp = ri->next;
10141 bgp_damp_info_free (ri->damp_info, 1);
10142 ri = ri_temp;
10143 }
10144 else
10145 ri = ri->next;
10146 }
10147 }
10148 }
10149
10150 return CMD_SUCCESS;
10151}
10152
10153DEFUN (clear_ip_bgp_dampening,
10154 clear_ip_bgp_dampening_cmd,
10155 "clear ip bgp dampening",
10156 CLEAR_STR
10157 IP_STR
10158 BGP_STR
10159 "Clear route flap dampening information\n")
10160{
10161 bgp_damp_info_clean ();
10162 return CMD_SUCCESS;
10163}
10164
10165DEFUN (clear_ip_bgp_dampening_prefix,
10166 clear_ip_bgp_dampening_prefix_cmd,
10167 "clear ip bgp dampening A.B.C.D/M",
10168 CLEAR_STR
10169 IP_STR
10170 BGP_STR
10171 "Clear route flap dampening information\n"
10172 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10173{
10174 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10175 SAFI_UNICAST, NULL, 1);
10176}
10177
10178DEFUN (clear_ip_bgp_dampening_address,
10179 clear_ip_bgp_dampening_address_cmd,
10180 "clear ip bgp dampening A.B.C.D",
10181 CLEAR_STR
10182 IP_STR
10183 BGP_STR
10184 "Clear route flap dampening information\n"
10185 "Network to clear damping information\n")
10186{
10187 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10188 SAFI_UNICAST, NULL, 0);
10189}
10190
10191DEFUN (clear_ip_bgp_dampening_address_mask,
10192 clear_ip_bgp_dampening_address_mask_cmd,
10193 "clear ip bgp dampening A.B.C.D A.B.C.D",
10194 CLEAR_STR
10195 IP_STR
10196 BGP_STR
10197 "Clear route flap dampening information\n"
10198 "Network to clear damping information\n"
10199 "Network mask\n")
10200{
10201 int ret;
10202 char prefix_str[BUFSIZ];
10203
10204 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10205 if (! ret)
10206 {
10207 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10208 return CMD_WARNING;
10209 }
10210
10211 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10212 SAFI_UNICAST, NULL, 0);
10213}
10214
paul94f2b392005-06-28 12:44:16 +000010215static int
paul718e3742002-12-13 20:15:29 +000010216bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10217 afi_t afi, safi_t safi, int *write)
10218{
10219 struct bgp_node *prn;
10220 struct bgp_node *rn;
10221 struct bgp_table *table;
10222 struct prefix *p;
10223 struct prefix_rd *prd;
10224 struct bgp_static *bgp_static;
10225 u_int32_t label;
10226 char buf[SU_ADDRSTRLEN];
10227 char rdbuf[RD_ADDRSTRLEN];
10228
10229 /* Network configuration. */
10230 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10231 if ((table = prn->info) != NULL)
10232 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10233 if ((bgp_static = rn->info) != NULL)
10234 {
10235 p = &rn->p;
10236 prd = (struct prefix_rd *) &prn->p;
10237
10238 /* "address-family" display. */
10239 bgp_config_write_family_header (vty, afi, safi, write);
10240
10241 /* "network" configuration display. */
10242 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10243 label = decode_label (bgp_static->tag);
10244
10245 vty_out (vty, " network %s/%d rd %s tag %d",
10246 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10247 p->prefixlen,
10248 rdbuf, label);
10249 vty_out (vty, "%s", VTY_NEWLINE);
10250 }
10251 return 0;
10252}
10253
10254/* Configuration of static route announcement and aggregate
10255 information. */
10256int
10257bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10258 afi_t afi, safi_t safi, int *write)
10259{
10260 struct bgp_node *rn;
10261 struct prefix *p;
10262 struct bgp_static *bgp_static;
10263 struct bgp_aggregate *bgp_aggregate;
10264 char buf[SU_ADDRSTRLEN];
10265
10266 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10267 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10268
10269 /* Network configuration. */
10270 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10271 if ((bgp_static = rn->info) != NULL)
10272 {
10273 p = &rn->p;
10274
10275 /* "address-family" display. */
10276 bgp_config_write_family_header (vty, afi, safi, write);
10277
10278 /* "network" configuration display. */
10279 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10280 {
10281 u_int32_t destination;
10282 struct in_addr netmask;
10283
10284 destination = ntohl (p->u.prefix4.s_addr);
10285 masklen2ip (p->prefixlen, &netmask);
10286 vty_out (vty, " network %s",
10287 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10288
10289 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10290 || (IN_CLASSB (destination) && p->prefixlen == 16)
10291 || (IN_CLASSA (destination) && p->prefixlen == 8)
10292 || p->u.prefix4.s_addr == 0)
10293 {
10294 /* Natural mask is not display. */
10295 }
10296 else
10297 vty_out (vty, " mask %s", inet_ntoa (netmask));
10298 }
10299 else
10300 {
10301 vty_out (vty, " network %s/%d",
10302 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10303 p->prefixlen);
10304 }
10305
10306 if (bgp_static->rmap.name)
10307 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10308 else if (bgp_static->backdoor)
10309 vty_out (vty, " backdoor");
10310
10311 vty_out (vty, "%s", VTY_NEWLINE);
10312 }
10313
10314 /* Aggregate-address configuration. */
10315 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10316 if ((bgp_aggregate = rn->info) != NULL)
10317 {
10318 p = &rn->p;
10319
10320 /* "address-family" display. */
10321 bgp_config_write_family_header (vty, afi, safi, write);
10322
10323 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10324 {
10325 struct in_addr netmask;
10326
10327 masklen2ip (p->prefixlen, &netmask);
10328 vty_out (vty, " aggregate-address %s %s",
10329 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10330 inet_ntoa (netmask));
10331 }
10332 else
10333 {
10334 vty_out (vty, " aggregate-address %s/%d",
10335 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10336 p->prefixlen);
10337 }
10338
10339 if (bgp_aggregate->as_set)
10340 vty_out (vty, " as-set");
10341
10342 if (bgp_aggregate->summary_only)
10343 vty_out (vty, " summary-only");
10344
10345 vty_out (vty, "%s", VTY_NEWLINE);
10346 }
10347
10348 return 0;
10349}
10350
10351int
10352bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10353{
10354 struct bgp_node *rn;
10355 struct bgp_distance *bdistance;
10356
10357 /* Distance configuration. */
10358 if (bgp->distance_ebgp
10359 && bgp->distance_ibgp
10360 && bgp->distance_local
10361 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10362 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10363 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10364 vty_out (vty, " distance bgp %d %d %d%s",
10365 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10366 VTY_NEWLINE);
10367
10368 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10369 if ((bdistance = rn->info) != NULL)
10370 {
10371 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10372 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10373 bdistance->access_list ? bdistance->access_list : "",
10374 VTY_NEWLINE);
10375 }
10376
10377 return 0;
10378}
10379
10380/* Allocate routing table structure and install commands. */
10381void
10382bgp_route_init ()
10383{
10384 /* Init BGP distance table. */
10385 bgp_distance_table = bgp_table_init ();
10386
10387 /* IPv4 BGP commands. */
10388 install_element (BGP_NODE, &bgp_network_cmd);
10389 install_element (BGP_NODE, &bgp_network_mask_cmd);
10390 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10391 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10392 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10393 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10394 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10395 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10396 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10397 install_element (BGP_NODE, &no_bgp_network_cmd);
10398 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10399 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10400 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10401 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10402 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10403 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10404 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10405 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10406
10407 install_element (BGP_NODE, &aggregate_address_cmd);
10408 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10409 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10410 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10411 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10412 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10413 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10414 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10415 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10416 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10417 install_element (BGP_NODE, &no_aggregate_address_cmd);
10418 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10419 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10420 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10421 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10422 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10423 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10424 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10425 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10426 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10427
10428 /* IPv4 unicast configuration. */
10429 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10430 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10431 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10432 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10433 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10434 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10435 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10436 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10437 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10438 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10439 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10440 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10441 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10442 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10443 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10444 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10445 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10446 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10447 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10448 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10449 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10450 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10451 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10452 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10453 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10454 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10455 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10456 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10457 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10458 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10459 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10460 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10461
10462 /* IPv4 multicast configuration. */
10463 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10464 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10465 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10466 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10467 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10468 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10469 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10470 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10471 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10472 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10473 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10474 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10475 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10476 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10477 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10478 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10479 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10480 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10481 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10482 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10483 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10484 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10485 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10486 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10487 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10488 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10489 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10495
10496 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10497 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10498 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10499 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10500 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10501 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10502 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10504 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10505 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10506 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10507 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10508 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10509 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10511 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10512 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10513 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10514 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10515 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10516 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10517 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10519 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10520 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10521 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10522 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10523 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10524 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10526 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10529 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10530 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10531 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10532 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10533 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10535 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10536 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10537 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10539 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10540 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10541 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10543 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10545 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10546 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10547 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10548 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10549 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10550 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10551 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10552 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10553 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10554 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10555 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10556 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10557 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10558 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10559 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10560 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10561 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10562 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010563 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10564 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10565 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10566 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10567 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10568 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010569
10570 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10571 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10572 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10573 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10574 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10575 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10576 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10577 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10578 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10579 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10580 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10581 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10582 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10583 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10584 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10585 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10586 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10587 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10588 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10589 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10590 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10591 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10592 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10593 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10594 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10595 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10596 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10597 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10598 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10601 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10602 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10603 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10604 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10605 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10606 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10608 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10609 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10611 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10613 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10615 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10616 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10617 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10618 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10619 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10620 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10621 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10622 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10623 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10624 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10625 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10626 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10627 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10628 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10629 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10630 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10631 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10632 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10633 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10634 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10635 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10636 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010637 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10638 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10639 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10640 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10641 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10642 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010643
10644 /* BGP dampening clear commands */
10645 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10646 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10647 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10648 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10649
10650#ifdef HAVE_IPV6
10651 /* New config IPv6 BGP commands. */
10652 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10653 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10654 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10655 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10656
10657 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10658 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10659 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10660 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10661
10662 /* Old config IPv6 BGP commands. */
10663 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10664 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10665
10666 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10667 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10668 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10669 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10670
10671 install_element (VIEW_NODE, &show_bgp_cmd);
10672 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10673 install_element (VIEW_NODE, &show_bgp_route_cmd);
10674 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10675 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10676 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10677 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10678 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10679 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10680 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10681 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10682 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10683 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10684 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10685 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10686 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10687 install_element (VIEW_NODE, &show_bgp_community_cmd);
10688 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10689 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10690 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10691 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10692 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10693 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10694 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10695 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10696 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10697 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10698 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10699 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10700 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10701 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10702 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10703 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10704 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10705 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10706 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10707 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10708 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10709 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10710 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10711 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10712 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10713 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10714 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10715 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10716 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010717 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10718 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10719 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10720 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010721 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10722 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10723 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010724 install_element (VIEW_NODE, &show_bgp_view_cmd);
10725 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10726 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10727 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10728 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10729 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10730 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10731 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10732 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10733 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10734 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10735 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10736 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10737 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10738 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10739 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10740 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10741 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010742 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10743 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10744 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010745
10746 install_element (ENABLE_NODE, &show_bgp_cmd);
10747 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10748 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10749 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10750 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10751 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10752 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10753 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10754 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10755 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10756 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10757 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10758 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10759 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10760 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10761 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10762 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10763 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10764 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10765 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10766 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10767 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10768 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10769 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10770 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10771 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10772 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10773 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10774 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10775 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10776 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10777 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10778 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10779 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10780 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10781 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10782 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10783 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10784 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10785 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10786 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10787 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10788 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10789 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10790 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10791 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010792 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10793 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10794 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10795 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010796 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10797 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10798 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010799 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10800 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10801 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10802 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10803 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10804 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10805 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10806 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10807 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10808 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10809 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10810 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10811 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10812 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10813 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10814 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10815 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10816 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010817 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10818 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10819 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010820
10821 /* old command */
10822 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10823 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10824 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10825 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10826 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10827 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10828 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10829 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10830 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10831 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10832 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10833 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10834 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10835 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10836 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10837 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10838 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10839 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10840 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10841 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10842 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10843 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10844 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10845 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10846 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10847 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10848 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10849 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10850 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10851 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10852 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10853 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10854 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10855 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10856 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10857 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000010858
paul718e3742002-12-13 20:15:29 +000010859 /* old command */
10860 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10861 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10862 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10863 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10864 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10865 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10866 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10867 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10868 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10869 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10870 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10871 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10872 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10873 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10874 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10875 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10876 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10877 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10878 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10879 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10880 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10881 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10882 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10883 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10884 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10885 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10886 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10887 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10888 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10889 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10890 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10891 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10892 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10893 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10894 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10895 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10896
10897 /* old command */
10898 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10899 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10900 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10901 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10902
10903 /* old command */
10904 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10905 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10906 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10907 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10908
10909 /* old command */
10910 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10911 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10912 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10913 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10914#endif /* HAVE_IPV6 */
10915
10916 install_element (BGP_NODE, &bgp_distance_cmd);
10917 install_element (BGP_NODE, &no_bgp_distance_cmd);
10918 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10919 install_element (BGP_NODE, &bgp_distance_source_cmd);
10920 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10921 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10922 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10923
10924 install_element (BGP_NODE, &bgp_damp_set_cmd);
10925 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10926 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10927 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10928 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10929 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10930 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10931 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10932 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10933 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
10934}