blob: 6c21e3f395adb442d88b1cb9edc2c279f1901b00 [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;
paul718e3742002-12-13 20:15:29 +0000608 struct peer *from;
609 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000610 int transparent;
611 int reflect;
612
613 from = ri->peer;
614 filter = &peer->filter[afi][safi];
615 bgp = peer->bgp;
616
617#ifdef DISABLE_BGP_ANNOUNCE
618 return 0;
619#endif
620
paulfee0f4c2004-09-13 05:12:46 +0000621 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
622 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
623 return 0;
624
paul718e3742002-12-13 20:15:29 +0000625 /* Do not send back route to sender. */
626 if (from == peer)
627 return 0;
628
paul35be31b2004-05-01 18:17:04 +0000629 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
630 if (p->family == AF_INET
631 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
632 return 0;
633#ifdef HAVE_IPV6
634 if (p->family == AF_INET6
635 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
636 return 0;
637#endif
638
paul718e3742002-12-13 20:15:29 +0000639 /* Aggregate-address suppress check. */
640 if (ri->suppress)
641 if (! UNSUPPRESS_MAP_NAME (filter))
642 return 0;
643
644 /* Default route check. */
645 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
646 {
647 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
648 return 0;
649#ifdef HAVE_IPV6
650 else if (p->family == AF_INET6 && p->prefixlen == 0)
651 return 0;
652#endif /* HAVE_IPV6 */
653 }
654
paul286e1e72003-08-08 00:24:31 +0000655 /* Transparency check. */
656 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
657 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
658 transparent = 1;
659 else
660 transparent = 0;
661
paul718e3742002-12-13 20:15:29 +0000662 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000663 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000664 return 0;
665
666 /* If the attribute has originator-id and it is same as remote
667 peer's id. */
668 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
669 {
670 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
671 {
672 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000673 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000674 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
675 peer->host,
676 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
677 p->prefixlen);
678 return 0;
679 }
680 }
681
682 /* ORF prefix-list filter check */
683 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
684 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
685 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
686 if (peer->orf_plist[afi][safi])
687 {
688 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
689 return 0;
690 }
691
692 /* Output filter check. */
693 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
694 {
695 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000696 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000697 "%s [Update:SEND] %s/%d is filtered",
698 peer->host,
699 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
700 p->prefixlen);
701 return 0;
702 }
703
704#ifdef BGP_SEND_ASPATH_CHECK
705 /* AS path loop check. */
706 if (aspath_loop_check (ri->attr->aspath, peer->as))
707 {
708 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000709 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000710 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
711 peer->host, peer->as);
712 return 0;
713 }
714#endif /* BGP_SEND_ASPATH_CHECK */
715
716 /* If we're a CONFED we need to loop check the CONFED ID too */
717 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
718 {
719 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
720 {
721 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000722 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000723 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
724 peer->host,
725 bgp->confed_id);
726 return 0;
727 }
728 }
729
730 /* Route-Reflect check. */
731 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
732 reflect = 1;
733 else
734 reflect = 0;
735
736 /* IBGP reflection check. */
737 if (reflect)
738 {
739 /* A route from a Client peer. */
740 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
741 {
742 /* Reflect to all the Non-Client peers and also to the
743 Client peers other than the originator. Originator check
744 is already done. So there is noting to do. */
745 /* no bgp client-to-client reflection check. */
746 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
747 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
748 return 0;
749 }
750 else
751 {
752 /* A route from a Non-client peer. Reflect to all other
753 clients. */
754 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
755 return 0;
756 }
757 }
758
759 /* For modify attribute, copy it to temporary structure. */
760 *attr = *ri->attr;
761
762 /* If local-preference is not set. */
763 if ((peer_sort (peer) == BGP_PEER_IBGP
764 || peer_sort (peer) == BGP_PEER_CONFED)
765 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
766 {
767 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
768 attr->local_pref = bgp->default_local_pref;
769 }
770
paul718e3742002-12-13 20:15:29 +0000771 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
772 if (peer_sort (peer) == BGP_PEER_EBGP
773 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
774 {
775 if (ri->peer != bgp->peer_self && ! transparent
776 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
777 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
778 }
779
780 /* next-hop-set */
781 if (transparent || reflect
782 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
783 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000784#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000785 || (p->family == AF_INET6 &&
786 ! IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000787#endif /* HAVE_IPV6 */
788 )))
paul718e3742002-12-13 20:15:29 +0000789 {
790 /* NEXT-HOP Unchanged. */
791 }
792 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
793 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
794#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000795 || (p->family == AF_INET6 &&
796 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000797#endif /* HAVE_IPV6 */
798 || (peer_sort (peer) == BGP_PEER_EBGP
799 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
800 {
801 /* Set IPv4 nexthop. */
802 if (p->family == AF_INET)
803 {
804 if (safi == SAFI_MPLS_VPN)
805 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
806 else
807 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
808 }
809#ifdef HAVE_IPV6
810 /* Set IPv6 nexthop. */
811 if (p->family == AF_INET6)
812 {
813 /* IPv6 global nexthop must be included. */
814 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
815 IPV6_MAX_BYTELEN);
816 attr->mp_nexthop_len = 16;
817 }
818#endif /* HAVE_IPV6 */
819 }
820
821#ifdef HAVE_IPV6
822 if (p->family == AF_INET6)
823 {
paulfee0f4c2004-09-13 05:12:46 +0000824 /* Left nexthop_local unchanged if so configured. */
825 if ( CHECK_FLAG (peer->af_flags[afi][safi],
826 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
827 {
828 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
829 attr->mp_nexthop_len=32;
830 else
831 attr->mp_nexthop_len=16;
832 }
833
834 /* Default nexthop_local treatment for non-RS-Clients */
835 else
836 {
paul718e3742002-12-13 20:15:29 +0000837 /* Link-local address should not be transit to different peer. */
838 attr->mp_nexthop_len = 16;
839
840 /* Set link-local address for shared network peer. */
841 if (peer->shared_network
842 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
843 {
844 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
845 IPV6_MAX_BYTELEN);
846 attr->mp_nexthop_len = 32;
847 }
848
849 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
850 address.*/
851 if (reflect)
852 attr->mp_nexthop_len = 16;
853
854 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
855 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
856 attr->mp_nexthop_len = 16;
857 }
paulfee0f4c2004-09-13 05:12:46 +0000858
859 }
paul718e3742002-12-13 20:15:29 +0000860#endif /* HAVE_IPV6 */
861
862 /* If this is EBGP peer and remove-private-AS is set. */
863 if (peer_sort (peer) == BGP_PEER_EBGP
864 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
865 && aspath_private_as_check (attr->aspath))
866 attr->aspath = aspath_empty_get ();
867
868 /* Route map & unsuppress-map apply. */
869 if (ROUTE_MAP_OUT_NAME (filter)
870 || ri->suppress)
871 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +0000872 struct bgp_info info;
873 struct attr dummy_attr;
874
paul718e3742002-12-13 20:15:29 +0000875 info.peer = peer;
876 info.attr = attr;
877
878 /* The route reflector is not allowed to modify the attributes
879 of the reflected IBGP routes. */
880 if (peer_sort (from) == BGP_PEER_IBGP
881 && peer_sort (peer) == BGP_PEER_IBGP)
882 {
883 dummy_attr = *attr;
884 info.attr = &dummy_attr;
885 }
paulac41b2a2003-08-12 05:32:27 +0000886
887 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
888
paul718e3742002-12-13 20:15:29 +0000889 if (ri->suppress)
890 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
891 else
892 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
893
paulac41b2a2003-08-12 05:32:27 +0000894 peer->rmap_type = 0;
895
paul718e3742002-12-13 20:15:29 +0000896 if (ret == RMAP_DENYMATCH)
897 {
898 bgp_attr_flush (attr);
899 return 0;
900 }
901 }
902 return 1;
903}
904
paul94f2b392005-06-28 12:44:16 +0000905static int
paulfee0f4c2004-09-13 05:12:46 +0000906bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
907 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000908{
paulfee0f4c2004-09-13 05:12:46 +0000909 int ret;
910 char buf[SU_ADDRSTRLEN];
911 struct bgp_filter *filter;
912 struct bgp_info info;
913 struct peer *from;
914 struct bgp *bgp;
915
916 from = ri->peer;
917 filter = &rsclient->filter[afi][safi];
918 bgp = rsclient->bgp;
919
920#ifdef DISABLE_BGP_ANNOUNCE
921 return 0;
922#endif
923
924 /* Do not send back route to sender. */
925 if (from == rsclient)
926 return 0;
927
928 /* Aggregate-address suppress check. */
929 if (ri->suppress)
930 if (! UNSUPPRESS_MAP_NAME (filter))
931 return 0;
932
933 /* Default route check. */
934 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
935 PEER_STATUS_DEFAULT_ORIGINATE))
936 {
937 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
938 return 0;
939#ifdef HAVE_IPV6
940 else if (p->family == AF_INET6 && p->prefixlen == 0)
941 return 0;
942#endif /* HAVE_IPV6 */
943 }
944
945 /* If the attribute has originator-id and it is same as remote
946 peer's id. */
947 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
948 {
949 if (IPV4_ADDR_SAME (&rsclient->remote_id, &ri->attr->originator_id))
950 {
951 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000952 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000953 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
954 rsclient->host,
955 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
956 p->prefixlen);
957 return 0;
958 }
959 }
960
961 /* ORF prefix-list filter check */
962 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
963 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
964 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
965 if (rsclient->orf_plist[afi][safi])
966 {
967 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
968 return 0;
969 }
970
971 /* Output filter check. */
972 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
973 {
974 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000975 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000976 "%s [Update:SEND] %s/%d is filtered",
977 rsclient->host,
978 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
979 p->prefixlen);
980 return 0;
981 }
982
983#ifdef BGP_SEND_ASPATH_CHECK
984 /* AS path loop check. */
985 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
986 {
987 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000988 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000989 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
990 rsclient->host, rsclient->as);
991 return 0;
992 }
993#endif /* BGP_SEND_ASPATH_CHECK */
994
995 /* For modify attribute, copy it to temporary structure. */
996 *attr = *ri->attr;
997
998 /* next-hop-set */
999 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1000#ifdef HAVE_IPV6
1001 || (p->family == AF_INET6 &&
1002 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
1003#endif /* HAVE_IPV6 */
1004 )
1005 {
1006 /* Set IPv4 nexthop. */
1007 if (p->family == AF_INET)
1008 {
1009 if (safi == SAFI_MPLS_VPN)
1010 memcpy (&attr->mp_nexthop_global_in, &rsclient->nexthop.v4,
1011 IPV4_MAX_BYTELEN);
1012 else
1013 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1014 }
1015#ifdef HAVE_IPV6
1016 /* Set IPv6 nexthop. */
1017 if (p->family == AF_INET6)
1018 {
1019 /* IPv6 global nexthop must be included. */
1020 memcpy (&attr->mp_nexthop_global, &rsclient->nexthop.v6_global,
1021
1022 IPV6_MAX_BYTELEN);
1023 attr->mp_nexthop_len = 16;
1024 }
1025#endif /* HAVE_IPV6 */
1026 }
1027
1028#ifdef HAVE_IPV6
1029 if (p->family == AF_INET6)
1030 {
1031 /* Left nexthop_local unchanged if so configured. */
1032 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1033 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1034 {
1035 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1036 attr->mp_nexthop_len=32;
1037 else
1038 attr->mp_nexthop_len=16;
1039 }
1040
1041 /* Default nexthop_local treatment for RS-Clients */
1042 else
1043 {
1044 /* Announcer and RS-Client are both in the same network */
1045 if (rsclient->shared_network && from->shared_network &&
1046 (rsclient->ifindex == from->ifindex))
1047 {
1048 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1049 attr->mp_nexthop_len=32;
1050 else
1051 attr->mp_nexthop_len=16;
1052 }
1053
1054 /* Set link-local address for shared network peer. */
1055 else if (rsclient->shared_network
1056 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1057 {
1058 memcpy (&attr->mp_nexthop_local, &rsclient->nexthop.v6_local,
1059 IPV6_MAX_BYTELEN);
1060 attr->mp_nexthop_len = 32;
1061 }
1062
1063 else
1064 attr->mp_nexthop_len = 16;
1065 }
1066
1067 }
1068#endif /* HAVE_IPV6 */
1069
1070
1071 /* If this is EBGP peer and remove-private-AS is set. */
1072 if (peer_sort (rsclient) == BGP_PEER_EBGP
1073 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1074 && aspath_private_as_check (attr->aspath))
1075 attr->aspath = aspath_empty_get ();
1076
1077 /* Route map & unsuppress-map apply. */
1078 if (ROUTE_MAP_OUT_NAME (filter) || ri->suppress)
1079 {
1080 info.peer = rsclient;
1081 info.attr = attr;
1082
1083 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1084
1085 if (ri->suppress)
1086 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1087 else
1088 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1089
1090 rsclient->rmap_type = 0;
1091
1092 if (ret == RMAP_DENYMATCH)
1093 {
1094 bgp_attr_flush (attr);
1095 return 0;
1096 }
1097 }
1098
1099 return 1;
1100}
1101
1102struct bgp_info_pair
1103{
1104 struct bgp_info *old;
1105 struct bgp_info *new;
1106};
1107
paul94f2b392005-06-28 12:44:16 +00001108static void
paulfee0f4c2004-09-13 05:12:46 +00001109bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1110{
paul718e3742002-12-13 20:15:29 +00001111 struct bgp_info *new_select;
1112 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001113 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001114 struct bgp_info *ri1;
1115 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001116 struct bgp_info *nextri = NULL;
1117
paul718e3742002-12-13 20:15:29 +00001118 /* bgp deterministic-med */
1119 new_select = NULL;
1120 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1121 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1122 {
1123 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1124 continue;
1125 if (BGP_INFO_HOLDDOWN (ri1))
1126 continue;
1127
1128 new_select = ri1;
1129 if (ri1->next)
1130 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1131 {
1132 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1133 continue;
1134 if (BGP_INFO_HOLDDOWN (ri2))
1135 continue;
1136
1137 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1138 || aspath_cmp_left_confed (ri1->attr->aspath,
1139 ri2->attr->aspath))
1140 {
1141 if (bgp_info_cmp (bgp, ri2, new_select))
1142 {
1143 UNSET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1144 new_select = ri2;
1145 }
1146
1147 SET_FLAG (ri2->flags, BGP_INFO_DMED_CHECK);
1148 }
1149 }
1150 SET_FLAG (new_select->flags, BGP_INFO_DMED_CHECK);
1151 SET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1152 }
1153
1154 /* Check old selected route and new selected route. */
1155 old_select = NULL;
1156 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001157 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001158 {
1159 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1160 old_select = ri;
1161
1162 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001163 {
1164 /* reap REMOVED routes, if needs be
1165 * selected route must stay for a while longer though
1166 */
1167 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1168 && (ri != old_select))
1169 bgp_info_reap (rn, ri);
1170
1171 continue;
1172 }
paul718e3742002-12-13 20:15:29 +00001173
1174 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1175 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1176 {
1177 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1178 continue;
1179 }
1180 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1181 UNSET_FLAG (ri->flags, BGP_INFO_DMED_SELECTED);
1182
1183 if (bgp_info_cmp (bgp, ri, new_select))
1184 new_select = ri;
1185 }
paulb40d9392005-08-22 22:34:41 +00001186
paulfee0f4c2004-09-13 05:12:46 +00001187 result->old = old_select;
1188 result->new = new_select;
1189
1190 return;
1191}
1192
paul94f2b392005-06-28 12:44:16 +00001193static int
paulfee0f4c2004-09-13 05:12:46 +00001194bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1195 struct bgp_node *rn, struct attr *attr, afi_t afi, safi_t safi)
1196 {
1197 struct prefix *p;
1198
1199 p = &rn->p;
1200
1201 /* Announce route to Established peer. */
1202 if (peer->status != Established)
1203 return 0;
1204
1205 /* Address family configuration check. */
1206 if (! peer->afc_nego[afi][safi])
1207 return 0;
1208
1209 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1210 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1211 PEER_STATUS_ORF_WAIT_REFRESH))
1212 return 0;
1213
1214 switch (rn->table->type)
1215 {
1216 case BGP_TABLE_MAIN:
1217 /* Announcement to peer->conf. If the route is filtered,
1218 withdraw it. */
1219 if (selected && bgp_announce_check (selected, peer, p, attr, afi, safi))
1220 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1221 else
1222 bgp_adj_out_unset (rn, peer, p, afi, safi);
1223 break;
1224 case BGP_TABLE_RSCLIENT:
1225 /* Announcement to peer->conf. If the route is filtered,
1226 withdraw it. */
1227 if (selected && bgp_announce_check_rsclient
1228 (selected, peer, p, attr, afi, safi))
1229 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1230 else
1231 bgp_adj_out_unset (rn, peer, p, afi, safi);
1232 break;
1233 }
1234 return 0;
paul200df112005-06-01 11:17:05 +00001235}
paulfee0f4c2004-09-13 05:12:46 +00001236
paul200df112005-06-01 11:17:05 +00001237struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001238{
paul200df112005-06-01 11:17:05 +00001239 struct bgp *bgp;
1240 struct bgp_node *rn;
1241 afi_t afi;
1242 safi_t safi;
1243};
1244
1245static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001246bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001247{
paul0fb58d52005-11-14 14:31:49 +00001248 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001249 struct bgp *bgp = pq->bgp;
1250 struct bgp_node *rn = pq->rn;
1251 afi_t afi = pq->afi;
1252 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001253 struct bgp_info *new_select;
1254 struct bgp_info *old_select;
1255 struct bgp_info_pair old_and_new;
1256 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001257 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001258 struct peer *rsclient = rn->table->owner;
1259
1260 /* we shouldn't run if the clear_route_node queue is still running
1261 * or scheduled to run, or we can race with session coming up
1262 * and adding routes back before we've cleared them
1263 */
1264 if (bm->clear_node_queue && bm->clear_node_queue->thread)
1265 return WQ_QUEUE_BLOCKED;
1266
paulfee0f4c2004-09-13 05:12:46 +00001267 /* Best path selection. */
1268 bgp_best_selection (bgp, rn, &old_and_new);
1269 new_select = old_and_new.new;
1270 old_select = old_and_new.old;
1271
paul200df112005-06-01 11:17:05 +00001272 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1273 {
1274 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1275 {
1276 /* Nothing to do. */
1277 if (old_select && old_select == new_select)
1278 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1279 continue;
paulfee0f4c2004-09-13 05:12:46 +00001280
paul200df112005-06-01 11:17:05 +00001281 if (old_select)
1282 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1283 if (new_select)
1284 {
1285 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1286 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1287 }
paulfee0f4c2004-09-13 05:12:46 +00001288
paul200df112005-06-01 11:17:05 +00001289 bgp_process_announce_selected (rsclient, new_select, rn, &attr,
1290 afi, safi);
1291 }
1292 }
1293 else
1294 {
hassob7395792005-08-26 12:58:38 +00001295 if (old_select)
1296 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1297 if (new_select)
1298 {
1299 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1300 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1301 }
paul200df112005-06-01 11:17:05 +00001302 bgp_process_announce_selected (rsclient, new_select, rn,
1303 &attr, afi, safi);
1304 }
paulfee0f4c2004-09-13 05:12:46 +00001305
paulb40d9392005-08-22 22:34:41 +00001306 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1307 bgp_info_reap (rn, old_select);
1308
paul200df112005-06-01 11:17:05 +00001309 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1310 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001311}
1312
paul200df112005-06-01 11:17:05 +00001313static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001314bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001315{
paul0fb58d52005-11-14 14:31:49 +00001316 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001317 struct bgp *bgp = pq->bgp;
1318 struct bgp_node *rn = pq->rn;
1319 afi_t afi = pq->afi;
1320 safi_t safi = pq->safi;
1321 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001322 struct bgp_info *new_select;
1323 struct bgp_info *old_select;
1324 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001325 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001326 struct peer *peer;
1327 struct attr attr;
paul200df112005-06-01 11:17:05 +00001328
1329 /* we shouldn't run if the clear_route_node queue is still running
1330 * or scheduled to run, or we can race with session coming up
1331 * and adding routes back before we've cleared them
1332 */
1333 if (bm->clear_node_queue && bm->clear_node_queue->thread)
1334 return WQ_QUEUE_BLOCKED;
paulfee0f4c2004-09-13 05:12:46 +00001335
1336 /* Best path selection. */
1337 bgp_best_selection (bgp, rn, &old_and_new);
1338 old_select = old_and_new.old;
1339 new_select = old_and_new.new;
1340
1341 /* Nothing to do. */
1342 if (old_select && old_select == new_select)
1343 {
1344 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001345 {
1346 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1347 bgp_zebra_announce (p, old_select, bgp);
1348
1349 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1350 return WQ_SUCCESS;
1351 }
paulfee0f4c2004-09-13 05:12:46 +00001352 }
paul718e3742002-12-13 20:15:29 +00001353
hasso338b3422005-02-23 14:27:24 +00001354 if (old_select)
1355 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1356 if (new_select)
1357 {
1358 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1359 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1360 }
1361
1362
paul718e3742002-12-13 20:15:29 +00001363 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001364 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001365 {
paulfee0f4c2004-09-13 05:12:46 +00001366 bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi);
paul718e3742002-12-13 20:15:29 +00001367 }
1368
1369 /* FIB update. */
1370 if (safi == SAFI_UNICAST && ! bgp->name &&
1371 ! bgp_option_check (BGP_OPT_NO_FIB))
1372 {
1373 if (new_select
1374 && new_select->type == ZEBRA_ROUTE_BGP
1375 && new_select->sub_type == BGP_ROUTE_NORMAL)
1376 bgp_zebra_announce (p, new_select, bgp);
1377 else
1378 {
1379 /* Withdraw the route from the kernel. */
1380 if (old_select
1381 && old_select->type == ZEBRA_ROUTE_BGP
1382 && old_select->sub_type == BGP_ROUTE_NORMAL)
1383 bgp_zebra_withdraw (p, old_select);
1384 }
1385 }
paulb40d9392005-08-22 22:34:41 +00001386
1387 /* Reap old select bgp_info, it it has been removed */
1388 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1389 bgp_info_reap (rn, old_select);
1390
paul200df112005-06-01 11:17:05 +00001391 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1392 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001393}
1394
paul200df112005-06-01 11:17:05 +00001395static void
paul0fb58d52005-11-14 14:31:49 +00001396bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001397{
paul0fb58d52005-11-14 14:31:49 +00001398 struct bgp_process_queue *pq = data;
1399
paul200df112005-06-01 11:17:05 +00001400 bgp_unlock_node (pq->rn);
1401 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1402}
1403
1404static void
1405bgp_process_queue_init (void)
1406{
1407 bm->process_main_queue
1408 = work_queue_new (bm->master, "process_main_queue");
1409 bm->process_rsclient_queue
1410 = work_queue_new (bm->master, "process_rsclient_queue");
1411
1412 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1413 {
1414 zlog_err ("%s: Failed to allocate work queue", __func__);
1415 exit (1);
1416 }
1417
1418 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1419 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1420 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1421 bm->process_rsclient_queue->spec.del_item_data
1422 = bm->process_main_queue->spec.del_item_data;
1423 bm->process_main_queue->spec.max_retries
1424 = bm->process_main_queue->spec.max_retries = 0;
1425 bm->process_rsclient_queue->spec.hold
1426 = bm->process_main_queue->spec.hold = 500;
paul200df112005-06-01 11:17:05 +00001427}
1428
1429void
paulfee0f4c2004-09-13 05:12:46 +00001430bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1431{
paul200df112005-06-01 11:17:05 +00001432 struct bgp_process_queue *pqnode;
1433
1434 /* already scheduled for processing? */
1435 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1436 return;
1437
1438 if ( (bm->process_main_queue == NULL) ||
1439 (bm->process_rsclient_queue == NULL) )
1440 bgp_process_queue_init ();
1441
1442 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1443 sizeof (struct bgp_process_queue));
1444 if (!pqnode)
1445 return;
1446
1447 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1448 pqnode->bgp = bgp;
1449 pqnode->afi = afi;
1450 pqnode->safi = safi;
1451
paulfee0f4c2004-09-13 05:12:46 +00001452 switch (rn->table->type)
1453 {
paul200df112005-06-01 11:17:05 +00001454 case BGP_TABLE_MAIN:
1455 work_queue_add (bm->process_main_queue, pqnode);
1456 break;
1457 case BGP_TABLE_RSCLIENT:
1458 work_queue_add (bm->process_rsclient_queue, pqnode);
1459 break;
paulfee0f4c2004-09-13 05:12:46 +00001460 }
paul200df112005-06-01 11:17:05 +00001461
1462 return;
paulfee0f4c2004-09-13 05:12:46 +00001463}
hasso0a486e52005-02-01 20:57:17 +00001464
paul94f2b392005-06-28 12:44:16 +00001465static int
hasso0a486e52005-02-01 20:57:17 +00001466bgp_maximum_prefix_restart_timer (struct thread *thread)
1467{
1468 struct peer *peer;
1469
1470 peer = THREAD_ARG (thread);
1471 peer->t_pmax_restart = NULL;
1472
1473 if (BGP_DEBUG (events, EVENTS))
1474 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1475 peer->host);
1476
1477 peer_clear (peer);
1478
1479 return 0;
1480}
1481
paulfee0f4c2004-09-13 05:12:46 +00001482int
paul5228ad22004-06-04 17:58:18 +00001483bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1484 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001485{
hassoe0701b72004-05-20 09:19:34 +00001486 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1487 return 0;
1488
1489 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001490 {
hassoe0701b72004-05-20 09:19:34 +00001491 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1492 && ! always)
1493 return 0;
paul718e3742002-12-13 20:15:29 +00001494
hassoe0701b72004-05-20 09:19:34 +00001495 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001496 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1497 "limit %ld", afi_safi_print (afi, safi), peer->host,
1498 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001499 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001500
hassoe0701b72004-05-20 09:19:34 +00001501 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1502 return 0;
paul718e3742002-12-13 20:15:29 +00001503
hassoe0701b72004-05-20 09:19:34 +00001504 {
paul5228ad22004-06-04 17:58:18 +00001505 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001506
1507 if (safi == SAFI_MPLS_VPN)
1508 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001509
1510 ndata[0] = (afi >> 8);
1511 ndata[1] = afi;
1512 ndata[2] = safi;
1513 ndata[3] = (peer->pmax[afi][safi] >> 24);
1514 ndata[4] = (peer->pmax[afi][safi] >> 16);
1515 ndata[5] = (peer->pmax[afi][safi] >> 8);
1516 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001517
1518 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1519 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1520 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1521 }
hasso0a486e52005-02-01 20:57:17 +00001522
1523 /* restart timer start */
1524 if (peer->pmax_restart[afi][safi])
1525 {
1526 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1527
1528 if (BGP_DEBUG (events, EVENTS))
1529 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1530 peer->host, peer->v_pmax_restart);
1531
1532 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1533 peer->v_pmax_restart);
1534 }
1535
hassoe0701b72004-05-20 09:19:34 +00001536 return 1;
paul718e3742002-12-13 20:15:29 +00001537 }
hassoe0701b72004-05-20 09:19:34 +00001538 else
1539 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1540
1541 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1542 {
1543 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1544 && ! always)
1545 return 0;
1546
1547 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001548 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1549 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1550 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001551 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1552 }
1553 else
1554 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001555 return 0;
1556}
1557
paul902212c2006-02-05 17:51:19 +00001558static void
1559bgp_pcount_increment (struct bgp_node *rn, struct bgp_info *ri,
1560 afi_t afi, safi_t safi)
1561{
1562 assert (ri && rn);
1563
1564 if (!CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)
1565 && rn->table->type == BGP_TABLE_MAIN)
1566 {
1567 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
1568 ri->peer->pcount[afi][safi]++;
1569 }
1570}
1571
1572static void
1573bgp_pcount_decrement (struct bgp_node *rn, struct bgp_info *ri,
1574 afi_t afi, safi_t safi)
1575{
1576 /* Ignore 'pcount' for RS-client tables */
1577 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)
1578 && rn->table->type == BGP_TABLE_MAIN)
1579 {
1580 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
1581
1582 /* slight hack, but more robust against errors. */
1583 if (ri->peer->pcount[afi][safi])
1584 ri->peer->pcount[afi][safi]--;
1585 else
1586 {
1587 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
1588 __func__, ri->peer->host);
1589 zlog_backtrace (LOG_WARNING);
1590 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
1591 }
1592 }
1593}
1594
paulb40d9392005-08-22 22:34:41 +00001595/* Unconditionally remove the route from the RIB, without taking
1596 * damping into consideration (eg, because the session went down)
1597 */
paul94f2b392005-06-28 12:44:16 +00001598static void
paul718e3742002-12-13 20:15:29 +00001599bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1600 afi_t afi, safi_t safi)
1601{
paul902212c2006-02-05 17:51:19 +00001602 bgp_pcount_decrement (rn, ri, afi, safi);
1603 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1604
1605 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1606 bgp_info_delete (rn, ri); /* keep historical info */
1607
paulb40d9392005-08-22 22:34:41 +00001608 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001609}
1610
paul94f2b392005-06-28 12:44:16 +00001611static void
paul718e3742002-12-13 20:15:29 +00001612bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001613 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001614{
paul718e3742002-12-13 20:15:29 +00001615 int status = BGP_DAMP_NONE;
1616
paulb40d9392005-08-22 22:34:41 +00001617 /* apply dampening, if result is suppressed, we'll be retaining
1618 * the bgp_info in the RIB for historical reference.
1619 */
1620 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1621 && peer_sort (peer) == BGP_PEER_EBGP)
1622 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1623 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001624 {
1625 bgp_pcount_decrement (rn, ri, afi, safi);
1626 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1627 return;
1628 }
1629
1630 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001631}
1632
paul94f2b392005-06-28 12:44:16 +00001633static void
paulfee0f4c2004-09-13 05:12:46 +00001634bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1635 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1636 int sub_type, struct prefix_rd *prd, u_char *tag)
1637{
1638 struct bgp_node *rn;
1639 struct bgp *bgp;
1640 struct attr new_attr;
1641 struct attr *attr_new;
1642 struct attr *attr_new2;
1643 struct bgp_info *ri;
1644 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001645 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001646 char buf[SU_ADDRSTRLEN];
1647
1648 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1649 if (peer == rsclient)
1650 return;
1651
1652 bgp = peer->bgp;
1653 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1654
1655 /* Check previously received route. */
1656 for (ri = rn->info; ri; ri = ri->next)
1657 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1658 break;
1659
1660 /* AS path loop check. */
1661 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1662 {
1663 reason = "as-path contains our own AS;";
1664 goto filtered;
1665 }
1666
1667 /* Route reflector originator ID check. */
1668 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1669 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->originator_id))
1670 {
1671 reason = "originator is us;";
1672 goto filtered;
1673 }
1674
1675 new_attr = *attr;
1676
1677 /* Apply export policy. */
1678 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1679 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1680 {
1681 reason = "export-policy;";
1682 goto filtered;
1683 }
1684
1685 attr_new2 = bgp_attr_intern (&new_attr);
1686
1687 /* Apply import policy. */
1688 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1689 {
1690 bgp_attr_unintern (attr_new2);
1691
1692 reason = "import-policy;";
1693 goto filtered;
1694 }
1695
1696 attr_new = bgp_attr_intern (&new_attr);
1697 bgp_attr_unintern (attr_new2);
1698
1699 /* IPv4 unicast next hop check. */
1700 if (afi == AFI_IP && safi == SAFI_UNICAST)
1701 {
1702 /* Next hop must not be 0.0.0.0 nor Class E address. */
1703 if (new_attr.nexthop.s_addr == 0
1704 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1705 {
1706 bgp_attr_unintern (attr_new);
1707
1708 reason = "martian next-hop;";
1709 goto filtered;
1710 }
1711 }
1712
1713 /* If the update is implicit withdraw. */
1714 if (ri)
1715 {
1716 ri->uptime = time (NULL);
1717
1718 /* Same attribute comes in. */
1719 if (attrhash_cmp (ri->attr, attr_new))
1720 {
1721
1722 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1723
1724 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001725 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001726 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1727 peer->host,
1728 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1729 p->prefixlen, rsclient->host);
1730
1731 bgp_unlock_node (rn);
1732 bgp_attr_unintern (attr_new);
1733
1734 return;
1735 }
1736
1737 /* Received Logging. */
1738 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001739 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001740 peer->host,
1741 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1742 p->prefixlen, rsclient->host);
1743
1744 /* The attribute is changed. */
1745 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1746
1747 /* Update to new attribute. */
1748 bgp_attr_unintern (ri->attr);
1749 ri->attr = attr_new;
1750
1751 /* Update MPLS tag. */
1752 if (safi == SAFI_MPLS_VPN)
1753 memcpy (ri->tag, tag, 3);
1754
1755 SET_FLAG (ri->flags, BGP_INFO_VALID);
1756
1757 /* Process change. */
1758 bgp_process (bgp, rn, afi, safi);
1759 bgp_unlock_node (rn);
1760
1761 return;
1762 }
1763
1764 /* Received Logging. */
1765 if (BGP_DEBUG (update, UPDATE_IN))
1766 {
ajsd2c1f162004-12-08 21:10:20 +00001767 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001768 peer->host,
1769 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1770 p->prefixlen, rsclient->host);
1771 }
1772
1773 /* Make new BGP info. */
1774 new = bgp_info_new ();
1775 new->type = type;
1776 new->sub_type = sub_type;
1777 new->peer = peer;
1778 new->attr = attr_new;
1779 new->uptime = time (NULL);
1780
1781 /* Update MPLS tag. */
1782 if (safi == SAFI_MPLS_VPN)
1783 memcpy (new->tag, tag, 3);
1784
1785 SET_FLAG (new->flags, BGP_INFO_VALID);
1786
1787 /* Register new BGP information. */
1788 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001789
1790 /* route_node_get lock */
1791 bgp_unlock_node (rn);
1792
paulfee0f4c2004-09-13 05:12:46 +00001793 /* Process change. */
1794 bgp_process (bgp, rn, afi, safi);
1795
1796 return;
1797
1798 filtered:
1799
1800 /* This BGP update is filtered. Log the reason then update BGP entry. */
1801 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001802 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001803 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1804 peer->host,
1805 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1806 p->prefixlen, rsclient->host, reason);
1807
1808 if (ri)
paulb40d9392005-08-22 22:34:41 +00001809 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001810
1811 bgp_unlock_node (rn);
1812
1813 return;
1814}
1815
paul94f2b392005-06-28 12:44:16 +00001816static void
paulfee0f4c2004-09-13 05:12:46 +00001817bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1818 struct peer *peer, struct prefix *p, int type, int sub_type,
1819 struct prefix_rd *prd, u_char *tag)
1820 {
1821 struct bgp_node *rn;
1822 struct bgp_info *ri;
1823 char buf[SU_ADDRSTRLEN];
1824
1825 if (rsclient == peer)
1826 return;
1827
1828 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1829
1830 /* Lookup withdrawn route. */
1831 for (ri = rn->info; ri; ri = ri->next)
1832 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1833 break;
1834
1835 /* Withdraw specified route from routing table. */
1836 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001837 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001838 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001839 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001840 "%s Can't find the route %s/%d", peer->host,
1841 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1842 p->prefixlen);
1843
1844 /* Unlock bgp_node_get() lock. */
1845 bgp_unlock_node (rn);
1846 }
1847
paul94f2b392005-06-28 12:44:16 +00001848static int
paulfee0f4c2004-09-13 05:12:46 +00001849bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001850 afi_t afi, safi_t safi, int type, int sub_type,
1851 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1852{
1853 int ret;
1854 int aspath_loop_count = 0;
1855 struct bgp_node *rn;
1856 struct bgp *bgp;
1857 struct attr new_attr;
1858 struct attr *attr_new;
1859 struct bgp_info *ri;
1860 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001861 const char *reason;
paul718e3742002-12-13 20:15:29 +00001862 char buf[SU_ADDRSTRLEN];
1863
1864 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001865 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00001866
1867 /* When peer's soft reconfiguration enabled. Record input packet in
1868 Adj-RIBs-In. */
1869 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1870 && peer != bgp->peer_self && ! soft_reconfig)
1871 bgp_adj_in_set (rn, peer, attr);
1872
1873 /* Check previously received route. */
1874 for (ri = rn->info; ri; ri = ri->next)
1875 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1876 break;
1877
1878 /* AS path local-as loop check. */
1879 if (peer->change_local_as)
1880 {
1881 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1882 aspath_loop_count = 1;
1883
1884 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1885 {
1886 reason = "as-path contains our own AS;";
1887 goto filtered;
1888 }
1889 }
1890
1891 /* AS path loop check. */
1892 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1893 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1894 && aspath_loop_check(attr->aspath, bgp->confed_id)
1895 > peer->allowas_in[afi][safi]))
1896 {
1897 reason = "as-path contains our own AS;";
1898 goto filtered;
1899 }
1900
1901 /* Route reflector originator ID check. */
1902 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1903 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1904 {
1905 reason = "originator is us;";
1906 goto filtered;
1907 }
1908
1909 /* Route reflector cluster ID check. */
1910 if (bgp_cluster_filter (peer, attr))
1911 {
1912 reason = "reflected from the same cluster;";
1913 goto filtered;
1914 }
1915
1916 /* Apply incoming filter. */
1917 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1918 {
1919 reason = "filter;";
1920 goto filtered;
1921 }
1922
1923 /* Apply incoming route-map. */
1924 new_attr = *attr;
1925
1926 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1927 {
1928 reason = "route-map;";
1929 goto filtered;
1930 }
1931
1932 /* IPv4 unicast next hop check. */
1933 if (afi == AFI_IP && safi == SAFI_UNICAST)
1934 {
1935 /* If the peer is EBGP and nexthop is not on connected route,
1936 discard it. */
1937 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1938 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00001939 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00001940 {
1941 reason = "non-connected next-hop;";
1942 goto filtered;
1943 }
1944
1945 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1946 must not be my own address. */
1947 if (bgp_nexthop_self (afi, &new_attr)
1948 || new_attr.nexthop.s_addr == 0
1949 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1950 {
1951 reason = "martian next-hop;";
1952 goto filtered;
1953 }
1954 }
1955
1956 attr_new = bgp_attr_intern (&new_attr);
1957
1958 /* If the update is implicit withdraw. */
1959 if (ri)
1960 {
1961 ri->uptime = time (NULL);
1962
1963 /* Same attribute comes in. */
1964 if (attrhash_cmp (ri->attr, attr_new))
1965 {
1966 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1967
1968 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1969 && peer_sort (peer) == BGP_PEER_EBGP
1970 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1971 {
1972 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001973 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001974 peer->host,
1975 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1976 p->prefixlen);
1977
paul902212c2006-02-05 17:51:19 +00001978 bgp_pcount_increment (rn, ri, afi, safi);
1979
1980 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
1981 {
1982 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1983 bgp_process (bgp, rn, afi, safi);
1984 }
paul718e3742002-12-13 20:15:29 +00001985 }
1986 else
1987 {
1988 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001989 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00001990 "%s rcvd %s/%d...duplicate ignored",
1991 peer->host,
1992 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1993 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00001994
1995 /* graceful restart STALE flag unset. */
1996 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1997 {
1998 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00001999 bgp_pcount_increment (rn, ri, afi, safi);
2000 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002001 }
paul718e3742002-12-13 20:15:29 +00002002 }
2003
2004 bgp_unlock_node (rn);
2005 bgp_attr_unintern (attr_new);
2006 return 0;
2007 }
2008
2009 /* Received Logging. */
2010 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002011 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002012 peer->host,
2013 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2014 p->prefixlen);
2015
hasso93406d82005-02-02 14:40:33 +00002016 /* graceful restart STALE flag unset. */
2017 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
paul902212c2006-02-05 17:51:19 +00002018 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002019
paul718e3742002-12-13 20:15:29 +00002020 /* The attribute is changed. */
2021 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002022
2023 /* implicit withdraw, decrement aggregate and pcount here.
2024 * only if update is accepted, they'll increment below.
2025 */
2026 bgp_pcount_decrement (rn, ri, afi, safi);
2027 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2028
paul718e3742002-12-13 20:15:29 +00002029 /* Update bgp route dampening information. */
2030 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2031 && peer_sort (peer) == BGP_PEER_EBGP)
2032 {
2033 /* This is implicit withdraw so we should update dampening
2034 information. */
2035 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2036 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002037 }
2038
paul718e3742002-12-13 20:15:29 +00002039 /* Update to new attribute. */
2040 bgp_attr_unintern (ri->attr);
2041 ri->attr = attr_new;
2042
2043 /* Update MPLS tag. */
2044 if (safi == SAFI_MPLS_VPN)
2045 memcpy (ri->tag, tag, 3);
2046
2047 /* Update bgp route dampening information. */
2048 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2049 && peer_sort (peer) == BGP_PEER_EBGP)
2050 {
2051 /* Now we do normal update dampening. */
2052 ret = bgp_damp_update (ri, rn, afi, safi);
2053 if (ret == BGP_DAMP_SUPPRESSED)
2054 {
2055 bgp_unlock_node (rn);
2056 return 0;
2057 }
2058 }
2059
2060 /* Nexthop reachability check. */
2061 if ((afi == AFI_IP || afi == AFI_IP6)
2062 && safi == SAFI_UNICAST
2063 && (peer_sort (peer) == BGP_PEER_IBGP
2064 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002065 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002066 {
2067 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
2068 SET_FLAG (ri->flags, BGP_INFO_VALID);
2069 else
2070 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2071 }
2072 else
2073 SET_FLAG (ri->flags, BGP_INFO_VALID);
2074
2075 /* Process change. */
paul902212c2006-02-05 17:51:19 +00002076 bgp_pcount_increment (rn, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00002077 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2078
2079 bgp_process (bgp, rn, afi, safi);
2080 bgp_unlock_node (rn);
2081 return 0;
2082 }
2083
2084 /* Received Logging. */
2085 if (BGP_DEBUG (update, UPDATE_IN))
2086 {
ajsd2c1f162004-12-08 21:10:20 +00002087 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002088 peer->host,
2089 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2090 p->prefixlen);
2091 }
2092
paul718e3742002-12-13 20:15:29 +00002093 /* Make new BGP info. */
2094 new = bgp_info_new ();
2095 new->type = type;
2096 new->sub_type = sub_type;
2097 new->peer = peer;
2098 new->attr = attr_new;
2099 new->uptime = time (NULL);
2100
2101 /* Update MPLS tag. */
2102 if (safi == SAFI_MPLS_VPN)
2103 memcpy (new->tag, tag, 3);
2104
2105 /* Nexthop reachability check. */
2106 if ((afi == AFI_IP || afi == AFI_IP6)
2107 && safi == SAFI_UNICAST
2108 && (peer_sort (peer) == BGP_PEER_IBGP
2109 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002110 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002111 {
2112 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
2113 SET_FLAG (new->flags, BGP_INFO_VALID);
2114 else
2115 UNSET_FLAG (new->flags, BGP_INFO_VALID);
2116 }
2117 else
2118 SET_FLAG (new->flags, BGP_INFO_VALID);
2119
paul902212c2006-02-05 17:51:19 +00002120 /* Increment prefix */
2121 bgp_pcount_increment (rn, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00002122 bgp_aggregate_increment (bgp, p, new, afi, safi);
2123
2124 /* Register new BGP information. */
2125 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002126
2127 /* route_node_get lock */
2128 bgp_unlock_node (rn);
2129
paul718e3742002-12-13 20:15:29 +00002130 /* If maximum prefix count is configured and current prefix
2131 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002132 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2133 return -1;
paul718e3742002-12-13 20:15:29 +00002134
2135 /* Process change. */
2136 bgp_process (bgp, rn, afi, safi);
2137
2138 return 0;
2139
2140 /* This BGP update is filtered. Log the reason then update BGP
2141 entry. */
2142 filtered:
2143 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002144 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002145 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2146 peer->host,
2147 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2148 p->prefixlen, reason);
2149
2150 if (ri)
paulb40d9392005-08-22 22:34:41 +00002151 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002152
2153 bgp_unlock_node (rn);
2154
2155 return 0;
2156}
2157
2158int
paulfee0f4c2004-09-13 05:12:46 +00002159bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2160 afi_t afi, safi_t safi, int type, int sub_type,
2161 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2162{
2163 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002164 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002165 struct bgp *bgp;
2166 int ret;
2167
2168 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2169 soft_reconfig);
2170
2171 bgp = peer->bgp;
2172
2173 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002174 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002175 {
2176 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2177 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2178 sub_type, prd, tag);
2179 }
2180
2181 return ret;
2182}
2183
2184int
paul718e3742002-12-13 20:15:29 +00002185bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002186 afi_t afi, safi_t safi, int type, int sub_type,
2187 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002188{
2189 struct bgp *bgp;
2190 char buf[SU_ADDRSTRLEN];
2191 struct bgp_node *rn;
2192 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002193 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002194 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002195
2196 bgp = peer->bgp;
2197
paulfee0f4c2004-09-13 05:12:46 +00002198 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002199 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002200 {
2201 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2202 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2203 }
2204
paul718e3742002-12-13 20:15:29 +00002205 /* Logging. */
2206 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002207 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002208 peer->host,
2209 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2210 p->prefixlen);
2211
2212 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002213 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002214
2215 /* If peer is soft reconfiguration enabled. Record input packet for
2216 further calculation. */
2217 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2218 && peer != bgp->peer_self)
2219 bgp_adj_in_unset (rn, peer);
2220
2221 /* Lookup withdrawn route. */
2222 for (ri = rn->info; ri; ri = ri->next)
2223 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2224 break;
2225
2226 /* Withdraw specified route from routing table. */
2227 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002228 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002229 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002230 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002231 "%s Can't find the route %s/%d", peer->host,
2232 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2233 p->prefixlen);
2234
2235 /* Unlock bgp_node_get() lock. */
2236 bgp_unlock_node (rn);
2237
2238 return 0;
2239}
2240
2241void
2242bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2243{
2244 struct bgp *bgp;
2245 struct attr attr;
2246 struct aspath *aspath;
2247 struct prefix p;
2248 struct bgp_info binfo;
2249 struct peer *from;
2250 int ret = RMAP_DENYMATCH;
2251
2252 bgp = peer->bgp;
2253 from = bgp->peer_self;
2254
2255 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2256 aspath = attr.aspath;
2257 attr.local_pref = bgp->default_local_pref;
2258 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2259
2260 if (afi == AFI_IP)
2261 str2prefix ("0.0.0.0/0", &p);
2262#ifdef HAVE_IPV6
2263 else if (afi == AFI_IP6)
2264 {
2265 str2prefix ("::/0", &p);
2266
2267 /* IPv6 global nexthop must be included. */
2268 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2269 IPV6_MAX_BYTELEN);
2270 attr.mp_nexthop_len = 16;
2271
2272 /* If the peer is on shared nextwork and we have link-local
2273 nexthop set it. */
2274 if (peer->shared_network
2275 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2276 {
2277 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2278 IPV6_MAX_BYTELEN);
2279 attr.mp_nexthop_len = 32;
2280 }
2281 }
2282#endif /* HAVE_IPV6 */
2283 else
2284 return;
2285
2286 if (peer->default_rmap[afi][safi].name)
2287 {
2288 binfo.peer = bgp->peer_self;
2289 binfo.attr = &attr;
2290
paulfee0f4c2004-09-13 05:12:46 +00002291 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2292
paul718e3742002-12-13 20:15:29 +00002293 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2294 RMAP_BGP, &binfo);
2295
paulfee0f4c2004-09-13 05:12:46 +00002296 bgp->peer_self->rmap_type = 0;
2297
paul718e3742002-12-13 20:15:29 +00002298 if (ret == RMAP_DENYMATCH)
2299 {
2300 bgp_attr_flush (&attr);
2301 withdraw = 1;
2302 }
2303 }
2304
2305 if (withdraw)
2306 {
2307 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2308 bgp_default_withdraw_send (peer, afi, safi);
2309 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2310 }
2311 else
2312 {
2313 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2314 bgp_default_update_send (peer, &attr, afi, safi, from);
2315 }
2316
2317 aspath_unintern (aspath);
2318}
2319
2320static void
2321bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002322 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002323{
2324 struct bgp_node *rn;
2325 struct bgp_info *ri;
2326 struct attr attr;
2327
2328 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002329 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002330
2331 if (safi != SAFI_MPLS_VPN
2332 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2333 bgp_default_originate (peer, afi, safi, 0);
2334
2335 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2336 for (ri = rn->info; ri; ri = ri->next)
2337 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2338 {
paulfee0f4c2004-09-13 05:12:46 +00002339 if ( (rsclient) ?
2340 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2341 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002342 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2343 else
2344 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2345 }
2346}
2347
2348void
2349bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2350{
2351 struct bgp_node *rn;
2352 struct bgp_table *table;
2353
2354 if (peer->status != Established)
2355 return;
2356
2357 if (! peer->afc_nego[afi][safi])
2358 return;
2359
2360 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2361 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2362 return;
2363
2364 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002365 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002366 else
2367 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2368 rn = bgp_route_next(rn))
2369 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002370 bgp_announce_table (peer, afi, safi, table, 0);
2371
2372 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2373 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002374}
2375
2376void
2377bgp_announce_route_all (struct peer *peer)
2378{
2379 afi_t afi;
2380 safi_t safi;
2381
2382 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2383 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2384 bgp_announce_route (peer, afi, safi);
2385}
2386
2387static void
paulfee0f4c2004-09-13 05:12:46 +00002388bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2389 safi_t safi, struct bgp_table *table)
2390{
2391 struct bgp_node *rn;
2392 struct bgp_adj_in *ain;
2393
2394 if (! table)
2395 table = rsclient->bgp->rib[afi][safi];
2396
2397 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2398 for (ain = rn->adj_in; ain; ain = ain->next)
2399 {
2400 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2401 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2402 }
2403}
2404
2405void
2406bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2407{
2408 struct bgp_table *table;
2409 struct bgp_node *rn;
2410
2411 if (safi != SAFI_MPLS_VPN)
2412 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2413
2414 else
2415 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2416 rn = bgp_route_next (rn))
2417 if ((table = rn->info) != NULL)
2418 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2419}
2420
2421static void
paul718e3742002-12-13 20:15:29 +00002422bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2423 struct bgp_table *table)
2424{
2425 int ret;
2426 struct bgp_node *rn;
2427 struct bgp_adj_in *ain;
2428
2429 if (! table)
2430 table = peer->bgp->rib[afi][safi];
2431
2432 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2433 for (ain = rn->adj_in; ain; ain = ain->next)
2434 {
2435 if (ain->peer == peer)
2436 {
2437 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2438 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2439 NULL, NULL, 1);
2440 if (ret < 0)
2441 {
2442 bgp_unlock_node (rn);
2443 return;
2444 }
2445 continue;
2446 }
2447 }
2448}
2449
2450void
2451bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2452{
2453 struct bgp_node *rn;
2454 struct bgp_table *table;
2455
2456 if (peer->status != Established)
2457 return;
2458
2459 if (safi != SAFI_MPLS_VPN)
2460 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2461 else
2462 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2463 rn = bgp_route_next (rn))
2464 if ((table = rn->info) != NULL)
2465 bgp_soft_reconfig_table (peer, afi, safi, table);
2466}
2467
paul200df112005-06-01 11:17:05 +00002468struct bgp_clear_node_queue
2469{
2470 struct bgp_node *rn;
2471 struct peer *peer;
2472 afi_t afi;
2473 safi_t safi;
2474};
2475
2476static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002477bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002478{
paul0fb58d52005-11-14 14:31:49 +00002479 struct bgp_clear_node_queue *cq = data;
paul200df112005-06-01 11:17:05 +00002480 struct bgp_adj_in *ain;
2481 struct bgp_adj_out *aout;
2482 struct bgp_info *ri;
2483
2484 assert (cq->rn && cq->peer);
2485
2486 for (ri = cq->rn->info; ri; ri = ri->next)
2487 if (ri->peer == cq->peer)
2488 {
2489 /* graceful restart STALE flag set. */
2490 if (CHECK_FLAG (cq->peer->sflags, PEER_STATUS_NSF_WAIT)
2491 && cq->peer->nsf[cq->afi][cq->safi]
2492 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2493 && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
paul902212c2006-02-05 17:51:19 +00002494 && ! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
2495 && ! CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
paul200df112005-06-01 11:17:05 +00002496 {
paul902212c2006-02-05 17:51:19 +00002497 bgp_pcount_decrement (cq->rn, ri, cq->afi, cq->safi);
paul200df112005-06-01 11:17:05 +00002498 SET_FLAG (ri->flags, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002499 }
2500 else
2501 bgp_rib_remove (cq->rn, ri, cq->peer, cq->afi, cq->safi);
2502 break;
2503 }
2504 for (ain = cq->rn->adj_in; ain; ain = ain->next)
2505 if (ain->peer == cq->peer)
2506 {
2507 bgp_adj_in_remove (cq->rn, ain);
2508 bgp_unlock_node (cq->rn);
2509 break;
2510 }
2511 for (aout = cq->rn->adj_out; aout; aout = aout->next)
2512 if (aout->peer == cq->peer)
2513 {
2514 bgp_adj_out_remove (cq->rn, aout, cq->peer, cq->afi, cq->safi);
2515 bgp_unlock_node (cq->rn);
2516 break;
2517 }
2518 return WQ_SUCCESS;
2519}
2520
2521static void
paul0fb58d52005-11-14 14:31:49 +00002522bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002523{
paul0fb58d52005-11-14 14:31:49 +00002524 struct bgp_clear_node_queue *cq = data;
paul200df112005-06-01 11:17:05 +00002525 bgp_unlock_node (cq->rn);
2526 peer_unlock (cq->peer); /* bgp_clear_node_queue_del */
2527 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cq);
2528}
2529
2530static void
paul94f2b392005-06-28 12:44:16 +00002531bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002532{
2533 /* unplug the 2 processing queues */
2534 if (bm->process_main_queue)
2535 work_queue_unplug (bm->process_main_queue);
2536 if (bm->process_rsclient_queue)
2537 work_queue_unplug (bm->process_rsclient_queue);
2538}
2539
2540static void
2541bgp_clear_node_queue_init (void)
2542{
2543 if ( (bm->clear_node_queue
2544 = work_queue_new (bm->master, "clear_route_node")) == NULL)
2545 {
2546 zlog_err ("%s: Failed to allocate work queue", __func__);
2547 exit (1);
2548 }
2549 bm->clear_node_queue->spec.hold = 10;
paul200df112005-06-01 11:17:05 +00002550 bm->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2551 bm->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2552 bm->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2553 bm->clear_node_queue->spec.max_retries = 0;
2554}
2555
paul718e3742002-12-13 20:15:29 +00002556static void
2557bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002558 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002559{
paul200df112005-06-01 11:17:05 +00002560 struct bgp_clear_node_queue *cqnode;
paul718e3742002-12-13 20:15:29 +00002561 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002562
paul718e3742002-12-13 20:15:29 +00002563 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002564 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002565
hasso6cf159b2005-03-21 10:28:14 +00002566 /* If still no table => afi/safi isn't configured at all or smth. */
2567 if (! table)
2568 return;
2569
paul200df112005-06-01 11:17:05 +00002570 if (bm->clear_node_queue == NULL)
2571 bgp_clear_node_queue_init ();
2572
2573 /* plug the two bgp_process queues to avoid any chance of racing
2574 * with a session coming back up and adding routes before we've
2575 * cleared them all. We'll unplug them with completion callback.
2576 */
2577 if (bm->process_main_queue)
2578 work_queue_plug (bm->process_main_queue);
2579 if (bm->process_rsclient_queue)
2580 work_queue_plug (bm->process_rsclient_queue);
2581
paul718e3742002-12-13 20:15:29 +00002582 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2583 {
paul200df112005-06-01 11:17:05 +00002584 if (rn->info == NULL)
2585 continue;
2586
2587 if ( (cqnode = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2588 sizeof (struct bgp_clear_node_queue))) == NULL)
2589 continue;
2590
2591 cqnode->rn = bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2592 cqnode->afi = afi;
2593 cqnode->safi = safi;
2594 cqnode->peer = peer_lock (peer); /* bgp_clear_node_queue_del */
2595 work_queue_add (bm->clear_node_queue, cqnode);
paul718e3742002-12-13 20:15:29 +00002596 }
paul200df112005-06-01 11:17:05 +00002597 return;
paul718e3742002-12-13 20:15:29 +00002598}
2599
2600void
2601bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2602{
2603 struct bgp_node *rn;
2604 struct bgp_table *table;
paulfee0f4c2004-09-13 05:12:46 +00002605 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002606 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002607
paul718e3742002-12-13 20:15:29 +00002608 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002609 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002610 else
2611 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2612 rn = bgp_route_next (rn))
2613 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002614 bgp_clear_route_table (peer, afi, safi, table, NULL);
2615
paul1eb8ef22005-04-07 07:30:20 +00002616 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002617 {
2618 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2619 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2620 }
paul718e3742002-12-13 20:15:29 +00002621}
2622
2623void
2624bgp_clear_route_all (struct peer *peer)
2625{
2626 afi_t afi;
2627 safi_t safi;
2628
2629 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2630 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2631 bgp_clear_route (peer, afi, safi);
2632}
2633
2634void
2635bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2636{
2637 struct bgp_table *table;
2638 struct bgp_node *rn;
2639 struct bgp_adj_in *ain;
2640
2641 table = peer->bgp->rib[afi][safi];
2642
2643 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2644 for (ain = rn->adj_in; ain ; ain = ain->next)
2645 if (ain->peer == peer)
2646 {
2647 bgp_adj_in_remove (rn, ain);
2648 bgp_unlock_node (rn);
2649 break;
2650 }
2651}
hasso93406d82005-02-02 14:40:33 +00002652
2653void
2654bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2655{
2656 struct bgp_node *rn;
2657 struct bgp_info *ri;
2658 struct bgp_table *table;
2659
2660 table = peer->bgp->rib[afi][safi];
2661
2662 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2663 {
2664 for (ri = rn->info; ri; ri = ri->next)
2665 if (ri->peer == peer)
2666 {
2667 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2668 bgp_rib_remove (rn, ri, peer, afi, safi);
2669 break;
2670 }
2671 }
2672}
paul718e3742002-12-13 20:15:29 +00002673
2674/* Delete all kernel routes. */
2675void
paul545acaf2004-04-20 15:13:15 +00002676bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002677{
2678 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002679 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002680 struct bgp_node *rn;
2681 struct bgp_table *table;
2682 struct bgp_info *ri;
2683
paul1eb8ef22005-04-07 07:30:20 +00002684 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002685 {
2686 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2687
2688 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2689 for (ri = rn->info; ri; ri = ri->next)
2690 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2691 && ri->type == ZEBRA_ROUTE_BGP
2692 && ri->sub_type == BGP_ROUTE_NORMAL)
2693 bgp_zebra_withdraw (&rn->p, ri);
2694
2695 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2696
2697 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2698 for (ri = rn->info; ri; ri = ri->next)
2699 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2700 && ri->type == ZEBRA_ROUTE_BGP
2701 && ri->sub_type == BGP_ROUTE_NORMAL)
2702 bgp_zebra_withdraw (&rn->p, ri);
2703 }
2704}
2705
2706void
2707bgp_reset ()
2708{
2709 vty_reset ();
2710 bgp_zclient_reset ();
2711 access_list_reset ();
2712 prefix_list_reset ();
2713}
2714
2715/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2716 value. */
2717int
2718bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2719{
2720 u_char *pnt;
2721 u_char *lim;
2722 struct prefix p;
2723 int psize;
2724 int ret;
2725
2726 /* Check peer status. */
2727 if (peer->status != Established)
2728 return 0;
2729
2730 pnt = packet->nlri;
2731 lim = pnt + packet->length;
2732
2733 for (; pnt < lim; pnt += psize)
2734 {
2735 /* Clear prefix structure. */
2736 memset (&p, 0, sizeof (struct prefix));
2737
2738 /* Fetch prefix length. */
2739 p.prefixlen = *pnt++;
2740 p.family = afi2family (packet->afi);
2741
2742 /* Already checked in nlri_sanity_check(). We do double check
2743 here. */
2744 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2745 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2746 return -1;
2747
2748 /* Packet size overflow check. */
2749 psize = PSIZE (p.prefixlen);
2750
2751 /* When packet overflow occur return immediately. */
2752 if (pnt + psize > lim)
2753 return -1;
2754
2755 /* Fetch prefix from NLRI packet. */
2756 memcpy (&p.u.prefix, pnt, psize);
2757
2758 /* Check address. */
2759 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2760 {
2761 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2762 {
paulf5ba3872004-07-09 12:11:31 +00002763 /*
2764 * From draft-ietf-idr-bgp4-22, Section 6.3:
2765 * If a BGP router receives an UPDATE message with a
2766 * semantically incorrect NLRI field, in which a prefix is
2767 * semantically incorrect (eg. an unexpected multicast IP
2768 * address), it should ignore the prefix.
2769 */
paul718e3742002-12-13 20:15:29 +00002770 zlog (peer->log, LOG_ERR,
2771 "IPv4 unicast NLRI is multicast address %s",
2772 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002773
paul718e3742002-12-13 20:15:29 +00002774 return -1;
2775 }
2776 }
2777
2778#ifdef HAVE_IPV6
2779 /* Check address. */
2780 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2781 {
2782 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2783 {
2784 char buf[BUFSIZ];
2785
2786 zlog (peer->log, LOG_WARNING,
2787 "IPv6 link-local NLRI received %s ignore this NLRI",
2788 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2789
2790 continue;
2791 }
2792 }
2793#endif /* HAVE_IPV6 */
2794
2795 /* Normal process. */
2796 if (attr)
2797 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2798 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2799 else
2800 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2801 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2802
2803 /* Address family configuration mismatch or maximum-prefix count
2804 overflow. */
2805 if (ret < 0)
2806 return -1;
2807 }
2808
2809 /* Packet length consistency check. */
2810 if (pnt != lim)
2811 return -1;
2812
2813 return 0;
2814}
2815
2816/* NLRI encode syntax check routine. */
2817int
2818bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2819 bgp_size_t length)
2820{
2821 u_char *end;
2822 u_char prefixlen;
2823 int psize;
2824
2825 end = pnt + length;
2826
2827 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2828 syntactic validity. If the field is syntactically incorrect,
2829 then the Error Subcode is set to Invalid Network Field. */
2830
2831 while (pnt < end)
2832 {
2833 prefixlen = *pnt++;
2834
2835 /* Prefix length check. */
2836 if ((afi == AFI_IP && prefixlen > 32)
2837 || (afi == AFI_IP6 && prefixlen > 128))
2838 {
2839 plog_err (peer->log,
2840 "%s [Error] Update packet error (wrong prefix length %d)",
2841 peer->host, prefixlen);
2842 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2843 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2844 return -1;
2845 }
2846
2847 /* Packet size overflow check. */
2848 psize = PSIZE (prefixlen);
2849
2850 if (pnt + psize > end)
2851 {
2852 plog_err (peer->log,
2853 "%s [Error] Update packet error"
2854 " (prefix data overflow prefix size is %d)",
2855 peer->host, psize);
2856 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2857 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2858 return -1;
2859 }
2860
2861 pnt += psize;
2862 }
2863
2864 /* Packet length consistency check. */
2865 if (pnt != end)
2866 {
2867 plog_err (peer->log,
2868 "%s [Error] Update packet error"
2869 " (prefix length mismatch with total length)",
2870 peer->host);
2871 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2872 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2873 return -1;
2874 }
2875 return 0;
2876}
2877
paul94f2b392005-06-28 12:44:16 +00002878static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002879bgp_static_new ()
2880{
2881 struct bgp_static *new;
2882 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2883 memset (new, 0, sizeof (struct bgp_static));
2884 return new;
2885}
2886
paul94f2b392005-06-28 12:44:16 +00002887static void
paul718e3742002-12-13 20:15:29 +00002888bgp_static_free (struct bgp_static *bgp_static)
2889{
2890 if (bgp_static->rmap.name)
2891 free (bgp_static->rmap.name);
2892 XFREE (MTYPE_BGP_STATIC, bgp_static);
2893}
2894
paul94f2b392005-06-28 12:44:16 +00002895static void
paulfee0f4c2004-09-13 05:12:46 +00002896bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2897 struct prefix *p, afi_t afi, safi_t safi)
2898{
2899 struct bgp_node *rn;
2900 struct bgp_info *ri;
2901
2902 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2903
2904 /* Check selected route and self inserted route. */
2905 for (ri = rn->info; ri; ri = ri->next)
2906 if (ri->peer == bgp->peer_self
2907 && ri->type == ZEBRA_ROUTE_BGP
2908 && ri->sub_type == BGP_ROUTE_STATIC)
2909 break;
2910
2911 /* Withdraw static BGP route from routing table. */
2912 if (ri)
2913 {
2914 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2915 bgp_process (bgp, rn, afi, safi);
2916 bgp_info_delete (rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00002917 }
2918
2919 /* Unlock bgp_node_lookup. */
2920 bgp_unlock_node (rn);
2921}
2922
paul94f2b392005-06-28 12:44:16 +00002923static void
paulfee0f4c2004-09-13 05:12:46 +00002924bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2925 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2926{
2927 struct bgp_node *rn;
2928 struct bgp_info *ri;
2929 struct bgp_info *new;
2930 struct bgp_info info;
2931 struct attr new_attr;
2932 struct attr *attr_new;
2933 struct attr attr;
2934 struct bgp *bgp;
2935 int ret;
2936 char buf[SU_ADDRSTRLEN];
2937
2938 bgp = rsclient->bgp;
2939
2940 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2941
2942 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2943 if (bgp_static)
2944 {
2945 attr.nexthop = bgp_static->igpnexthop;
2946 attr.med = bgp_static->igpmetric;
2947 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
2948 }
2949
2950 new_attr = attr;
2951
2952 /* Apply network route-map for export to this rsclient. */
2953 if (bgp_static->rmap.name)
2954 {
2955 info.peer = rsclient;
2956 info.attr = &new_attr;
2957
2958 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2959 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2960
2961 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2962
2963 rsclient->rmap_type = 0;
2964
2965 if (ret == RMAP_DENYMATCH)
2966 {
2967 /* Free uninterned attribute. */
2968 bgp_attr_flush (&new_attr);
2969
2970 /* Unintern original. */
2971 aspath_unintern (attr.aspath);
2972 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2973
2974 return;
2975 }
2976 attr_new = bgp_attr_intern (&new_attr);
2977 }
2978 else
2979 attr_new = bgp_attr_intern (&attr);
2980
2981 new_attr = *attr_new;
2982
2983 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2984
2985 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2986{
2987 /* This BGP update is filtered. Log the reason then update BGP entry. */
2988 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002989 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002990 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
2991 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2992 p->prefixlen, rsclient->host);
2993
2994 bgp->peer_self->rmap_type = 0;
2995
2996 bgp_attr_unintern (attr_new);
2997 aspath_unintern (attr.aspath);
2998
2999 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3000
3001 return;
3002 }
3003
3004 bgp->peer_self->rmap_type = 0;
3005
3006 bgp_attr_unintern (attr_new);
3007 attr_new = bgp_attr_intern (&new_attr);
3008
3009 for (ri = rn->info; ri; ri = ri->next)
3010 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3011 && ri->sub_type == BGP_ROUTE_STATIC)
3012 break;
3013
3014 if (ri)
3015 {
3016 if (attrhash_cmp (ri->attr, attr_new))
3017 {
3018 bgp_unlock_node (rn);
3019 bgp_attr_unintern (attr_new);
3020 aspath_unintern (attr.aspath);
3021 return;
3022 }
3023 else
3024 {
3025 /* The attribute is changed. */
3026 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3027
3028 /* Rewrite BGP route information. */
3029 bgp_attr_unintern (ri->attr);
3030 ri->attr = attr_new;
3031 ri->uptime = time (NULL);
3032
3033 /* Process change. */
3034 bgp_process (bgp, rn, afi, safi);
3035 bgp_unlock_node (rn);
3036 aspath_unintern (attr.aspath);
3037 return;
3038 }
3039}
3040
3041 /* Make new BGP info. */
3042 new = bgp_info_new ();
3043 new->type = ZEBRA_ROUTE_BGP;
3044 new->sub_type = BGP_ROUTE_STATIC;
3045 new->peer = bgp->peer_self;
3046 SET_FLAG (new->flags, BGP_INFO_VALID);
3047 new->attr = attr_new;
3048 new->uptime = time (NULL);
3049
3050 /* Register new BGP information. */
3051 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003052
3053 /* route_node_get lock */
3054 bgp_unlock_node (rn);
3055
paulfee0f4c2004-09-13 05:12:46 +00003056 /* Process change. */
3057 bgp_process (bgp, rn, afi, safi);
3058
3059 /* Unintern original. */
3060 aspath_unintern (attr.aspath);
3061}
3062
paul94f2b392005-06-28 12:44:16 +00003063static void
paulfee0f4c2004-09-13 05:12:46 +00003064bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003065 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3066{
3067 struct bgp_node *rn;
3068 struct bgp_info *ri;
3069 struct bgp_info *new;
3070 struct bgp_info info;
3071 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003072 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003073 struct attr *attr_new;
3074 int ret;
3075
paulfee0f4c2004-09-13 05:12:46 +00003076 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003077
3078 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3079 if (bgp_static)
3080 {
3081 attr.nexthop = bgp_static->igpnexthop;
3082 attr.med = bgp_static->igpmetric;
3083 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3084 }
3085
3086 /* Apply route-map. */
3087 if (bgp_static->rmap.name)
3088 {
paul286e1e72003-08-08 00:24:31 +00003089 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003090 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003091 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003092
paulfee0f4c2004-09-13 05:12:46 +00003093 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3094
paul718e3742002-12-13 20:15:29 +00003095 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003096
paulfee0f4c2004-09-13 05:12:46 +00003097 bgp->peer_self->rmap_type = 0;
3098
paul718e3742002-12-13 20:15:29 +00003099 if (ret == RMAP_DENYMATCH)
3100 {
3101 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003102 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003103
3104 /* Unintern original. */
3105 aspath_unintern (attr.aspath);
3106 bgp_static_withdraw (bgp, p, afi, safi);
3107 return;
3108 }
paul286e1e72003-08-08 00:24:31 +00003109 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003110 }
paul286e1e72003-08-08 00:24:31 +00003111 else
3112 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003113
3114 for (ri = rn->info; ri; ri = ri->next)
3115 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3116 && ri->sub_type == BGP_ROUTE_STATIC)
3117 break;
3118
3119 if (ri)
3120 {
3121 if (attrhash_cmp (ri->attr, attr_new))
3122 {
3123 bgp_unlock_node (rn);
3124 bgp_attr_unintern (attr_new);
3125 aspath_unintern (attr.aspath);
3126 return;
3127 }
3128 else
3129 {
3130 /* The attribute is changed. */
3131 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3132
3133 /* Rewrite BGP route information. */
3134 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3135 bgp_attr_unintern (ri->attr);
3136 ri->attr = attr_new;
3137 ri->uptime = time (NULL);
3138
3139 /* Process change. */
3140 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3141 bgp_process (bgp, rn, afi, safi);
3142 bgp_unlock_node (rn);
3143 aspath_unintern (attr.aspath);
3144 return;
3145 }
3146 }
3147
3148 /* Make new BGP info. */
3149 new = bgp_info_new ();
3150 new->type = ZEBRA_ROUTE_BGP;
3151 new->sub_type = BGP_ROUTE_STATIC;
3152 new->peer = bgp->peer_self;
3153 SET_FLAG (new->flags, BGP_INFO_VALID);
3154 new->attr = attr_new;
3155 new->uptime = time (NULL);
3156
3157 /* Aggregate address increment. */
3158 bgp_aggregate_increment (bgp, p, new, afi, safi);
3159
3160 /* Register new BGP information. */
3161 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003162
3163 /* route_node_get lock */
3164 bgp_unlock_node (rn);
3165
paul718e3742002-12-13 20:15:29 +00003166 /* Process change. */
3167 bgp_process (bgp, rn, afi, safi);
3168
3169 /* Unintern original. */
3170 aspath_unintern (attr.aspath);
3171}
3172
3173void
paulfee0f4c2004-09-13 05:12:46 +00003174bgp_static_update (struct bgp *bgp, struct prefix *p,
3175 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3176{
3177 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003178 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003179
3180 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3181
paul1eb8ef22005-04-07 07:30:20 +00003182 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003183 {
3184 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3185 }
3186}
3187
paul94f2b392005-06-28 12:44:16 +00003188static void
paul718e3742002-12-13 20:15:29 +00003189bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3190 u_char safi, struct prefix_rd *prd, u_char *tag)
3191{
3192 struct bgp_node *rn;
3193 struct bgp_info *new;
3194
paulfee0f4c2004-09-13 05:12:46 +00003195 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003196
3197 /* Make new BGP info. */
3198 new = bgp_info_new ();
3199 new->type = ZEBRA_ROUTE_BGP;
3200 new->sub_type = BGP_ROUTE_STATIC;
3201 new->peer = bgp->peer_self;
3202 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3203 SET_FLAG (new->flags, BGP_INFO_VALID);
3204 new->uptime = time (NULL);
3205 memcpy (new->tag, tag, 3);
3206
3207 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003208 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003209
3210 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003211 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003212
paul200df112005-06-01 11:17:05 +00003213 /* route_node_get lock */
3214 bgp_unlock_node (rn);
3215
paul718e3742002-12-13 20:15:29 +00003216 /* Process change. */
3217 bgp_process (bgp, rn, afi, safi);
3218}
3219
3220void
3221bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3222 safi_t safi)
3223{
3224 struct bgp_node *rn;
3225 struct bgp_info *ri;
3226
paulfee0f4c2004-09-13 05:12:46 +00003227 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003228
3229 /* Check selected route and self inserted route. */
3230 for (ri = rn->info; ri; ri = ri->next)
3231 if (ri->peer == bgp->peer_self
3232 && ri->type == ZEBRA_ROUTE_BGP
3233 && ri->sub_type == BGP_ROUTE_STATIC)
3234 break;
3235
3236 /* Withdraw static BGP route from routing table. */
3237 if (ri)
3238 {
3239 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3240 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3241 bgp_process (bgp, rn, afi, safi);
3242 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003243 }
3244
3245 /* Unlock bgp_node_lookup. */
3246 bgp_unlock_node (rn);
3247}
3248
3249void
paulfee0f4c2004-09-13 05:12:46 +00003250bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3251{
3252 struct bgp_static *bgp_static;
3253 struct bgp *bgp;
3254 struct bgp_node *rn;
3255 struct prefix *p;
3256
3257 bgp = rsclient->bgp;
3258
3259 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3260 if ((bgp_static = rn->info) != NULL)
3261 {
3262 p = &rn->p;
3263
3264 bgp_static_update_rsclient (rsclient, p, bgp_static,
3265 afi, safi);
3266 }
3267}
3268
paul94f2b392005-06-28 12:44:16 +00003269static void
paul718e3742002-12-13 20:15:29 +00003270bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3271 u_char safi, struct prefix_rd *prd, u_char *tag)
3272{
3273 struct bgp_node *rn;
3274 struct bgp_info *ri;
3275
paulfee0f4c2004-09-13 05:12:46 +00003276 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003277
3278 /* Check selected route and self inserted route. */
3279 for (ri = rn->info; ri; ri = ri->next)
3280 if (ri->peer == bgp->peer_self
3281 && ri->type == ZEBRA_ROUTE_BGP
3282 && ri->sub_type == BGP_ROUTE_STATIC)
3283 break;
3284
3285 /* Withdraw static BGP route from routing table. */
3286 if (ri)
3287 {
3288 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3289 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3290 bgp_process (bgp, rn, afi, safi);
3291 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003292 }
3293
3294 /* Unlock bgp_node_lookup. */
3295 bgp_unlock_node (rn);
3296}
3297
3298/* Configure static BGP network. When user don't run zebra, static
3299 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003300static int
paulfd79ac92004-10-13 05:06:08 +00003301bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3302 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003303{
3304 int ret;
3305 struct prefix p;
3306 struct bgp_static *bgp_static;
3307 struct bgp_node *rn;
3308 int need_update = 0;
3309
3310 /* Convert IP prefix string to struct prefix. */
3311 ret = str2prefix (ip_str, &p);
3312 if (! ret)
3313 {
3314 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3315 return CMD_WARNING;
3316 }
3317#ifdef HAVE_IPV6
3318 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3319 {
3320 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3321 VTY_NEWLINE);
3322 return CMD_WARNING;
3323 }
3324#endif /* HAVE_IPV6 */
3325
3326 apply_mask (&p);
3327
3328 /* Set BGP static route configuration. */
3329 rn = bgp_node_get (bgp->route[afi][safi], &p);
3330
3331 if (rn->info)
3332 {
3333 /* Configuration change. */
3334 bgp_static = rn->info;
3335
3336 /* Check previous routes are installed into BGP. */
3337 if (! bgp_static->backdoor && bgp_static->valid)
3338 need_update = 1;
3339
3340 bgp_static->backdoor = backdoor;
3341 if (rmap)
3342 {
3343 if (bgp_static->rmap.name)
3344 free (bgp_static->rmap.name);
3345 bgp_static->rmap.name = strdup (rmap);
3346 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3347 }
3348 else
3349 {
3350 if (bgp_static->rmap.name)
3351 free (bgp_static->rmap.name);
3352 bgp_static->rmap.name = NULL;
3353 bgp_static->rmap.map = NULL;
3354 bgp_static->valid = 0;
3355 }
3356 bgp_unlock_node (rn);
3357 }
3358 else
3359 {
3360 /* New configuration. */
3361 bgp_static = bgp_static_new ();
3362 bgp_static->backdoor = backdoor;
3363 bgp_static->valid = 0;
3364 bgp_static->igpmetric = 0;
3365 bgp_static->igpnexthop.s_addr = 0;
3366 if (rmap)
3367 {
3368 if (bgp_static->rmap.name)
3369 free (bgp_static->rmap.name);
3370 bgp_static->rmap.name = strdup (rmap);
3371 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3372 }
3373 rn->info = bgp_static;
3374 }
3375
3376 /* If BGP scan is not enabled, we should install this route here. */
3377 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3378 {
3379 bgp_static->valid = 1;
3380
3381 if (need_update)
3382 bgp_static_withdraw (bgp, &p, afi, safi);
3383
3384 if (! bgp_static->backdoor)
3385 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3386 }
3387
3388 return CMD_SUCCESS;
3389}
3390
3391/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003392static int
paulfd79ac92004-10-13 05:06:08 +00003393bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003394 u_int16_t afi, u_char safi)
3395{
3396 int ret;
3397 struct prefix p;
3398 struct bgp_static *bgp_static;
3399 struct bgp_node *rn;
3400
3401 /* Convert IP prefix string to struct prefix. */
3402 ret = str2prefix (ip_str, &p);
3403 if (! ret)
3404 {
3405 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3406 return CMD_WARNING;
3407 }
3408#ifdef HAVE_IPV6
3409 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3410 {
3411 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3412 VTY_NEWLINE);
3413 return CMD_WARNING;
3414 }
3415#endif /* HAVE_IPV6 */
3416
3417 apply_mask (&p);
3418
3419 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3420 if (! rn)
3421 {
3422 vty_out (vty, "%% Can't find specified static route configuration.%s",
3423 VTY_NEWLINE);
3424 return CMD_WARNING;
3425 }
3426
3427 bgp_static = rn->info;
3428
3429 /* Update BGP RIB. */
3430 if (! bgp_static->backdoor)
3431 bgp_static_withdraw (bgp, &p, afi, safi);
3432
3433 /* Clear configuration. */
3434 bgp_static_free (bgp_static);
3435 rn->info = NULL;
3436 bgp_unlock_node (rn);
3437 bgp_unlock_node (rn);
3438
3439 return CMD_SUCCESS;
3440}
3441
3442/* Called from bgp_delete(). Delete all static routes from the BGP
3443 instance. */
3444void
3445bgp_static_delete (struct bgp *bgp)
3446{
3447 afi_t afi;
3448 safi_t safi;
3449 struct bgp_node *rn;
3450 struct bgp_node *rm;
3451 struct bgp_table *table;
3452 struct bgp_static *bgp_static;
3453
3454 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3455 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3456 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3457 if (rn->info != NULL)
3458 {
3459 if (safi == SAFI_MPLS_VPN)
3460 {
3461 table = rn->info;
3462
3463 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3464 {
3465 bgp_static = rn->info;
3466 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3467 AFI_IP, SAFI_MPLS_VPN,
3468 (struct prefix_rd *)&rn->p,
3469 bgp_static->tag);
3470 bgp_static_free (bgp_static);
3471 rn->info = NULL;
3472 bgp_unlock_node (rn);
3473 }
3474 }
3475 else
3476 {
3477 bgp_static = rn->info;
3478 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3479 bgp_static_free (bgp_static);
3480 rn->info = NULL;
3481 bgp_unlock_node (rn);
3482 }
3483 }
3484}
3485
3486int
paulfd79ac92004-10-13 05:06:08 +00003487bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3488 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003489{
3490 int ret;
3491 struct prefix p;
3492 struct prefix_rd prd;
3493 struct bgp *bgp;
3494 struct bgp_node *prn;
3495 struct bgp_node *rn;
3496 struct bgp_table *table;
3497 struct bgp_static *bgp_static;
3498 u_char tag[3];
3499
3500 bgp = vty->index;
3501
3502 ret = str2prefix (ip_str, &p);
3503 if (! ret)
3504 {
3505 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3506 return CMD_WARNING;
3507 }
3508 apply_mask (&p);
3509
3510 ret = str2prefix_rd (rd_str, &prd);
3511 if (! ret)
3512 {
3513 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3514 return CMD_WARNING;
3515 }
3516
3517 ret = str2tag (tag_str, tag);
3518 if (! ret)
3519 {
3520 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3521 return CMD_WARNING;
3522 }
3523
3524 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3525 (struct prefix *)&prd);
3526 if (prn->info == NULL)
3527 prn->info = bgp_table_init ();
3528 else
3529 bgp_unlock_node (prn);
3530 table = prn->info;
3531
3532 rn = bgp_node_get (table, &p);
3533
3534 if (rn->info)
3535 {
3536 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3537 bgp_unlock_node (rn);
3538 }
3539 else
3540 {
3541 /* New configuration. */
3542 bgp_static = bgp_static_new ();
3543 bgp_static->valid = 1;
3544 memcpy (bgp_static->tag, tag, 3);
3545 rn->info = bgp_static;
3546
3547 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3548 }
3549
3550 return CMD_SUCCESS;
3551}
3552
3553/* Configure static BGP network. */
3554int
paulfd79ac92004-10-13 05:06:08 +00003555bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3556 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003557{
3558 int ret;
3559 struct bgp *bgp;
3560 struct prefix p;
3561 struct prefix_rd prd;
3562 struct bgp_node *prn;
3563 struct bgp_node *rn;
3564 struct bgp_table *table;
3565 struct bgp_static *bgp_static;
3566 u_char tag[3];
3567
3568 bgp = vty->index;
3569
3570 /* Convert IP prefix string to struct prefix. */
3571 ret = str2prefix (ip_str, &p);
3572 if (! ret)
3573 {
3574 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3575 return CMD_WARNING;
3576 }
3577 apply_mask (&p);
3578
3579 ret = str2prefix_rd (rd_str, &prd);
3580 if (! ret)
3581 {
3582 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3583 return CMD_WARNING;
3584 }
3585
3586 ret = str2tag (tag_str, tag);
3587 if (! ret)
3588 {
3589 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3590 return CMD_WARNING;
3591 }
3592
3593 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3594 (struct prefix *)&prd);
3595 if (prn->info == NULL)
3596 prn->info = bgp_table_init ();
3597 else
3598 bgp_unlock_node (prn);
3599 table = prn->info;
3600
3601 rn = bgp_node_lookup (table, &p);
3602
3603 if (rn)
3604 {
3605 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3606
3607 bgp_static = rn->info;
3608 bgp_static_free (bgp_static);
3609 rn->info = NULL;
3610 bgp_unlock_node (rn);
3611 bgp_unlock_node (rn);
3612 }
3613 else
3614 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3615
3616 return CMD_SUCCESS;
3617}
3618
3619DEFUN (bgp_network,
3620 bgp_network_cmd,
3621 "network A.B.C.D/M",
3622 "Specify a network to announce via BGP\n"
3623 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3624{
3625 return bgp_static_set (vty, vty->index, argv[0],
3626 AFI_IP, bgp_node_safi (vty), NULL, 0);
3627}
3628
3629DEFUN (bgp_network_route_map,
3630 bgp_network_route_map_cmd,
3631 "network A.B.C.D/M route-map WORD",
3632 "Specify a network to announce via BGP\n"
3633 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3634 "Route-map to modify the attributes\n"
3635 "Name of the route map\n")
3636{
3637 return bgp_static_set (vty, vty->index, argv[0],
3638 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3639}
3640
3641DEFUN (bgp_network_backdoor,
3642 bgp_network_backdoor_cmd,
3643 "network A.B.C.D/M backdoor",
3644 "Specify a network to announce via BGP\n"
3645 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3646 "Specify a BGP backdoor route\n")
3647{
3648 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3649}
3650
3651DEFUN (bgp_network_mask,
3652 bgp_network_mask_cmd,
3653 "network A.B.C.D mask A.B.C.D",
3654 "Specify a network to announce via BGP\n"
3655 "Network number\n"
3656 "Network mask\n"
3657 "Network mask\n")
3658{
3659 int ret;
3660 char prefix_str[BUFSIZ];
3661
3662 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3663 if (! ret)
3664 {
3665 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3666 return CMD_WARNING;
3667 }
3668
3669 return bgp_static_set (vty, vty->index, prefix_str,
3670 AFI_IP, bgp_node_safi (vty), NULL, 0);
3671}
3672
3673DEFUN (bgp_network_mask_route_map,
3674 bgp_network_mask_route_map_cmd,
3675 "network A.B.C.D mask A.B.C.D route-map WORD",
3676 "Specify a network to announce via BGP\n"
3677 "Network number\n"
3678 "Network mask\n"
3679 "Network mask\n"
3680 "Route-map to modify the attributes\n"
3681 "Name of the route map\n")
3682{
3683 int ret;
3684 char prefix_str[BUFSIZ];
3685
3686 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3687 if (! ret)
3688 {
3689 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3690 return CMD_WARNING;
3691 }
3692
3693 return bgp_static_set (vty, vty->index, prefix_str,
3694 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3695}
3696
3697DEFUN (bgp_network_mask_backdoor,
3698 bgp_network_mask_backdoor_cmd,
3699 "network A.B.C.D mask A.B.C.D backdoor",
3700 "Specify a network to announce via BGP\n"
3701 "Network number\n"
3702 "Network mask\n"
3703 "Network mask\n"
3704 "Specify a BGP backdoor route\n")
3705{
3706 int ret;
3707 char prefix_str[BUFSIZ];
3708
3709 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3710 if (! ret)
3711 {
3712 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3713 return CMD_WARNING;
3714 }
3715
3716 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3717}
3718
3719DEFUN (bgp_network_mask_natural,
3720 bgp_network_mask_natural_cmd,
3721 "network A.B.C.D",
3722 "Specify a network to announce via BGP\n"
3723 "Network number\n")
3724{
3725 int ret;
3726 char prefix_str[BUFSIZ];
3727
3728 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3729 if (! ret)
3730 {
3731 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3732 return CMD_WARNING;
3733 }
3734
3735 return bgp_static_set (vty, vty->index, prefix_str,
3736 AFI_IP, bgp_node_safi (vty), NULL, 0);
3737}
3738
3739DEFUN (bgp_network_mask_natural_route_map,
3740 bgp_network_mask_natural_route_map_cmd,
3741 "network A.B.C.D route-map WORD",
3742 "Specify a network to announce via BGP\n"
3743 "Network number\n"
3744 "Route-map to modify the attributes\n"
3745 "Name of the route map\n")
3746{
3747 int ret;
3748 char prefix_str[BUFSIZ];
3749
3750 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3751 if (! ret)
3752 {
3753 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3754 return CMD_WARNING;
3755 }
3756
3757 return bgp_static_set (vty, vty->index, prefix_str,
3758 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3759}
3760
3761DEFUN (bgp_network_mask_natural_backdoor,
3762 bgp_network_mask_natural_backdoor_cmd,
3763 "network A.B.C.D backdoor",
3764 "Specify a network to announce via BGP\n"
3765 "Network number\n"
3766 "Specify a BGP backdoor route\n")
3767{
3768 int ret;
3769 char prefix_str[BUFSIZ];
3770
3771 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3772 if (! ret)
3773 {
3774 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3775 return CMD_WARNING;
3776 }
3777
3778 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3779}
3780
3781DEFUN (no_bgp_network,
3782 no_bgp_network_cmd,
3783 "no network A.B.C.D/M",
3784 NO_STR
3785 "Specify a network to announce via BGP\n"
3786 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3787{
3788 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3789 bgp_node_safi (vty));
3790}
3791
3792ALIAS (no_bgp_network,
3793 no_bgp_network_route_map_cmd,
3794 "no network A.B.C.D/M route-map WORD",
3795 NO_STR
3796 "Specify a network to announce via BGP\n"
3797 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3798 "Route-map to modify the attributes\n"
3799 "Name of the route map\n")
3800
3801ALIAS (no_bgp_network,
3802 no_bgp_network_backdoor_cmd,
3803 "no network A.B.C.D/M backdoor",
3804 NO_STR
3805 "Specify a network to announce via BGP\n"
3806 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3807 "Specify a BGP backdoor route\n")
3808
3809DEFUN (no_bgp_network_mask,
3810 no_bgp_network_mask_cmd,
3811 "no network A.B.C.D mask A.B.C.D",
3812 NO_STR
3813 "Specify a network to announce via BGP\n"
3814 "Network number\n"
3815 "Network mask\n"
3816 "Network mask\n")
3817{
3818 int ret;
3819 char prefix_str[BUFSIZ];
3820
3821 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3822 if (! ret)
3823 {
3824 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3825 return CMD_WARNING;
3826 }
3827
3828 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3829 bgp_node_safi (vty));
3830}
3831
3832ALIAS (no_bgp_network_mask,
3833 no_bgp_network_mask_route_map_cmd,
3834 "no network A.B.C.D mask A.B.C.D route-map WORD",
3835 NO_STR
3836 "Specify a network to announce via BGP\n"
3837 "Network number\n"
3838 "Network mask\n"
3839 "Network mask\n"
3840 "Route-map to modify the attributes\n"
3841 "Name of the route map\n")
3842
3843ALIAS (no_bgp_network_mask,
3844 no_bgp_network_mask_backdoor_cmd,
3845 "no network A.B.C.D mask A.B.C.D backdoor",
3846 NO_STR
3847 "Specify a network to announce via BGP\n"
3848 "Network number\n"
3849 "Network mask\n"
3850 "Network mask\n"
3851 "Specify a BGP backdoor route\n")
3852
3853DEFUN (no_bgp_network_mask_natural,
3854 no_bgp_network_mask_natural_cmd,
3855 "no network A.B.C.D",
3856 NO_STR
3857 "Specify a network to announce via BGP\n"
3858 "Network number\n")
3859{
3860 int ret;
3861 char prefix_str[BUFSIZ];
3862
3863 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3864 if (! ret)
3865 {
3866 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3867 return CMD_WARNING;
3868 }
3869
3870 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3871 bgp_node_safi (vty));
3872}
3873
3874ALIAS (no_bgp_network_mask_natural,
3875 no_bgp_network_mask_natural_route_map_cmd,
3876 "no network A.B.C.D route-map WORD",
3877 NO_STR
3878 "Specify a network to announce via BGP\n"
3879 "Network number\n"
3880 "Route-map to modify the attributes\n"
3881 "Name of the route map\n")
3882
3883ALIAS (no_bgp_network_mask_natural,
3884 no_bgp_network_mask_natural_backdoor_cmd,
3885 "no network A.B.C.D backdoor",
3886 NO_STR
3887 "Specify a network to announce via BGP\n"
3888 "Network number\n"
3889 "Specify a BGP backdoor route\n")
3890
3891#ifdef HAVE_IPV6
3892DEFUN (ipv6_bgp_network,
3893 ipv6_bgp_network_cmd,
3894 "network X:X::X:X/M",
3895 "Specify a network to announce via BGP\n"
3896 "IPv6 prefix <network>/<length>\n")
3897{
3898 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3899}
3900
3901DEFUN (ipv6_bgp_network_route_map,
3902 ipv6_bgp_network_route_map_cmd,
3903 "network X:X::X:X/M route-map WORD",
3904 "Specify a network to announce via BGP\n"
3905 "IPv6 prefix <network>/<length>\n"
3906 "Route-map to modify the attributes\n"
3907 "Name of the route map\n")
3908{
3909 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3910 bgp_node_safi (vty), argv[1], 0);
3911}
3912
3913DEFUN (no_ipv6_bgp_network,
3914 no_ipv6_bgp_network_cmd,
3915 "no network X:X::X:X/M",
3916 NO_STR
3917 "Specify a network to announce via BGP\n"
3918 "IPv6 prefix <network>/<length>\n")
3919{
3920 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3921}
3922
3923ALIAS (no_ipv6_bgp_network,
3924 no_ipv6_bgp_network_route_map_cmd,
3925 "no network X:X::X:X/M route-map WORD",
3926 NO_STR
3927 "Specify a network to announce via BGP\n"
3928 "IPv6 prefix <network>/<length>\n"
3929 "Route-map to modify the attributes\n"
3930 "Name of the route map\n")
3931
3932ALIAS (ipv6_bgp_network,
3933 old_ipv6_bgp_network_cmd,
3934 "ipv6 bgp network X:X::X:X/M",
3935 IPV6_STR
3936 BGP_STR
3937 "Specify a network to announce via BGP\n"
3938 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3939
3940ALIAS (no_ipv6_bgp_network,
3941 old_no_ipv6_bgp_network_cmd,
3942 "no ipv6 bgp network X:X::X:X/M",
3943 NO_STR
3944 IPV6_STR
3945 BGP_STR
3946 "Specify a network to announce via BGP\n"
3947 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3948#endif /* HAVE_IPV6 */
3949
3950/* Aggreagete address:
3951
3952 advertise-map Set condition to advertise attribute
3953 as-set Generate AS set path information
3954 attribute-map Set attributes of aggregate
3955 route-map Set parameters of aggregate
3956 summary-only Filter more specific routes from updates
3957 suppress-map Conditionally filter more specific routes from updates
3958 <cr>
3959 */
3960struct bgp_aggregate
3961{
3962 /* Summary-only flag. */
3963 u_char summary_only;
3964
3965 /* AS set generation. */
3966 u_char as_set;
3967
3968 /* Route-map for aggregated route. */
3969 struct route_map *map;
3970
3971 /* Suppress-count. */
3972 unsigned long count;
3973
3974 /* SAFI configuration. */
3975 safi_t safi;
3976};
3977
paul94f2b392005-06-28 12:44:16 +00003978static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00003979bgp_aggregate_new ()
3980{
3981 struct bgp_aggregate *new;
3982 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3983 memset (new, 0, sizeof (struct bgp_aggregate));
3984 return new;
3985}
3986
paul94f2b392005-06-28 12:44:16 +00003987static void
paul718e3742002-12-13 20:15:29 +00003988bgp_aggregate_free (struct bgp_aggregate *aggregate)
3989{
3990 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
3991}
3992
paul94f2b392005-06-28 12:44:16 +00003993static void
paul718e3742002-12-13 20:15:29 +00003994bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
3995 afi_t afi, safi_t safi, struct bgp_info *del,
3996 struct bgp_aggregate *aggregate)
3997{
3998 struct bgp_table *table;
3999 struct bgp_node *top;
4000 struct bgp_node *rn;
4001 u_char origin;
4002 struct aspath *aspath = NULL;
4003 struct aspath *asmerge = NULL;
4004 struct community *community = NULL;
4005 struct community *commerge = NULL;
4006 struct in_addr nexthop;
4007 u_int32_t med = 0;
4008 struct bgp_info *ri;
4009 struct bgp_info *new;
4010 int first = 1;
4011 unsigned long match = 0;
4012
4013 /* Record adding route's nexthop and med. */
4014 if (rinew)
4015 {
4016 nexthop = rinew->attr->nexthop;
4017 med = rinew->attr->med;
4018 }
4019
4020 /* ORIGIN attribute: If at least one route among routes that are
4021 aggregated has ORIGIN with the value INCOMPLETE, then the
4022 aggregated route must have the ORIGIN attribute with the value
4023 INCOMPLETE. Otherwise, if at least one route among routes that
4024 are aggregated has ORIGIN with the value EGP, then the aggregated
4025 route must have the origin attribute with the value EGP. In all
4026 other case the value of the ORIGIN attribute of the aggregated
4027 route is INTERNAL. */
4028 origin = BGP_ORIGIN_IGP;
4029
4030 table = bgp->rib[afi][safi];
4031
4032 top = bgp_node_get (table, p);
4033 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4034 if (rn->p.prefixlen > p->prefixlen)
4035 {
4036 match = 0;
4037
4038 for (ri = rn->info; ri; ri = ri->next)
4039 {
4040 if (BGP_INFO_HOLDDOWN (ri))
4041 continue;
4042
4043 if (del && ri == del)
4044 continue;
4045
4046 if (! rinew && first)
4047 {
4048 nexthop = ri->attr->nexthop;
4049 med = ri->attr->med;
4050 first = 0;
4051 }
4052
4053#ifdef AGGREGATE_NEXTHOP_CHECK
4054 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4055 || ri->attr->med != med)
4056 {
4057 if (aspath)
4058 aspath_free (aspath);
4059 if (community)
4060 community_free (community);
4061 bgp_unlock_node (rn);
4062 bgp_unlock_node (top);
4063 return;
4064 }
4065#endif /* AGGREGATE_NEXTHOP_CHECK */
4066
4067 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4068 {
4069 if (aggregate->summary_only)
4070 {
4071 ri->suppress++;
4072 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4073 match++;
4074 }
4075
4076 aggregate->count++;
4077
4078 if (aggregate->as_set)
4079 {
4080 if (origin < ri->attr->origin)
4081 origin = ri->attr->origin;
4082
4083 if (aspath)
4084 {
4085 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4086 aspath_free (aspath);
4087 aspath = asmerge;
4088 }
4089 else
4090 aspath = aspath_dup (ri->attr->aspath);
4091
4092 if (ri->attr->community)
4093 {
4094 if (community)
4095 {
4096 commerge = community_merge (community,
4097 ri->attr->community);
4098 community = community_uniq_sort (commerge);
4099 community_free (commerge);
4100 }
4101 else
4102 community = community_dup (ri->attr->community);
4103 }
4104 }
4105 }
4106 }
4107 if (match)
4108 bgp_process (bgp, rn, afi, safi);
4109 }
4110 bgp_unlock_node (top);
4111
4112 if (rinew)
4113 {
4114 aggregate->count++;
4115
4116 if (aggregate->summary_only)
4117 rinew->suppress++;
4118
4119 if (aggregate->as_set)
4120 {
4121 if (origin < rinew->attr->origin)
4122 origin = rinew->attr->origin;
4123
4124 if (aspath)
4125 {
4126 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4127 aspath_free (aspath);
4128 aspath = asmerge;
4129 }
4130 else
4131 aspath = aspath_dup (rinew->attr->aspath);
4132
4133 if (rinew->attr->community)
4134 {
4135 if (community)
4136 {
4137 commerge = community_merge (community,
4138 rinew->attr->community);
4139 community = community_uniq_sort (commerge);
4140 community_free (commerge);
4141 }
4142 else
4143 community = community_dup (rinew->attr->community);
4144 }
4145 }
4146 }
4147
4148 if (aggregate->count > 0)
4149 {
4150 rn = bgp_node_get (table, p);
4151 new = bgp_info_new ();
4152 new->type = ZEBRA_ROUTE_BGP;
4153 new->sub_type = BGP_ROUTE_AGGREGATE;
4154 new->peer = bgp->peer_self;
4155 SET_FLAG (new->flags, BGP_INFO_VALID);
4156 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4157 new->uptime = time (NULL);
4158
4159 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004160 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004161 bgp_process (bgp, rn, afi, safi);
4162 }
4163 else
4164 {
4165 if (aspath)
4166 aspath_free (aspath);
4167 if (community)
4168 community_free (community);
4169 }
4170}
4171
4172void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4173 struct bgp_aggregate *);
4174
4175void
4176bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4177 struct bgp_info *ri, afi_t afi, safi_t safi)
4178{
4179 struct bgp_node *child;
4180 struct bgp_node *rn;
4181 struct bgp_aggregate *aggregate;
4182
4183 /* MPLS-VPN aggregation is not yet supported. */
4184 if (safi == SAFI_MPLS_VPN)
4185 return;
4186
4187 if (p->prefixlen == 0)
4188 return;
4189
4190 if (BGP_INFO_HOLDDOWN (ri))
4191 return;
4192
4193 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4194
4195 /* Aggregate address configuration check. */
4196 for (rn = child; rn; rn = rn->parent)
4197 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4198 {
4199 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004200 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004201 }
4202 bgp_unlock_node (child);
4203}
4204
4205void
4206bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4207 struct bgp_info *del, afi_t afi, safi_t safi)
4208{
4209 struct bgp_node *child;
4210 struct bgp_node *rn;
4211 struct bgp_aggregate *aggregate;
4212
4213 /* MPLS-VPN aggregation is not yet supported. */
4214 if (safi == SAFI_MPLS_VPN)
4215 return;
4216
4217 if (p->prefixlen == 0)
4218 return;
4219
4220 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4221
4222 /* Aggregate address configuration check. */
4223 for (rn = child; rn; rn = rn->parent)
4224 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4225 {
4226 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004227 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004228 }
4229 bgp_unlock_node (child);
4230}
4231
paul94f2b392005-06-28 12:44:16 +00004232static void
paul718e3742002-12-13 20:15:29 +00004233bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4234 struct bgp_aggregate *aggregate)
4235{
4236 struct bgp_table *table;
4237 struct bgp_node *top;
4238 struct bgp_node *rn;
4239 struct bgp_info *new;
4240 struct bgp_info *ri;
4241 unsigned long match;
4242 u_char origin = BGP_ORIGIN_IGP;
4243 struct aspath *aspath = NULL;
4244 struct aspath *asmerge = NULL;
4245 struct community *community = NULL;
4246 struct community *commerge = NULL;
4247
4248 table = bgp->rib[afi][safi];
4249
4250 /* Sanity check. */
4251 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4252 return;
4253 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4254 return;
4255
4256 /* If routes exists below this node, generate aggregate routes. */
4257 top = bgp_node_get (table, p);
4258 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4259 if (rn->p.prefixlen > p->prefixlen)
4260 {
4261 match = 0;
4262
4263 for (ri = rn->info; ri; ri = ri->next)
4264 {
4265 if (BGP_INFO_HOLDDOWN (ri))
4266 continue;
4267
4268 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4269 {
4270 /* summary-only aggregate route suppress aggregated
4271 route announcement. */
4272 if (aggregate->summary_only)
4273 {
4274 ri->suppress++;
4275 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4276 match++;
4277 }
4278 /* as-set aggregate route generate origin, as path,
4279 community aggregation. */
4280 if (aggregate->as_set)
4281 {
4282 if (origin < ri->attr->origin)
4283 origin = ri->attr->origin;
4284
4285 if (aspath)
4286 {
4287 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4288 aspath_free (aspath);
4289 aspath = asmerge;
4290 }
4291 else
4292 aspath = aspath_dup (ri->attr->aspath);
4293
4294 if (ri->attr->community)
4295 {
4296 if (community)
4297 {
4298 commerge = community_merge (community,
4299 ri->attr->community);
4300 community = community_uniq_sort (commerge);
4301 community_free (commerge);
4302 }
4303 else
4304 community = community_dup (ri->attr->community);
4305 }
4306 }
4307 aggregate->count++;
4308 }
4309 }
4310
4311 /* If this node is suppressed, process the change. */
4312 if (match)
4313 bgp_process (bgp, rn, afi, safi);
4314 }
4315 bgp_unlock_node (top);
4316
4317 /* Add aggregate route to BGP table. */
4318 if (aggregate->count)
4319 {
4320 rn = bgp_node_get (table, p);
4321
4322 new = bgp_info_new ();
4323 new->type = ZEBRA_ROUTE_BGP;
4324 new->sub_type = BGP_ROUTE_AGGREGATE;
4325 new->peer = bgp->peer_self;
4326 SET_FLAG (new->flags, BGP_INFO_VALID);
4327 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4328 new->uptime = time (NULL);
4329
4330 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004331 bgp_unlock_node (rn);
4332
paul718e3742002-12-13 20:15:29 +00004333 /* Process change. */
4334 bgp_process (bgp, rn, afi, safi);
4335 }
4336}
4337
4338void
4339bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4340 safi_t safi, struct bgp_aggregate *aggregate)
4341{
4342 struct bgp_table *table;
4343 struct bgp_node *top;
4344 struct bgp_node *rn;
4345 struct bgp_info *ri;
4346 unsigned long match;
4347
4348 table = bgp->rib[afi][safi];
4349
4350 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4351 return;
4352 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4353 return;
4354
4355 /* If routes exists below this node, generate aggregate routes. */
4356 top = bgp_node_get (table, p);
4357 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4358 if (rn->p.prefixlen > p->prefixlen)
4359 {
4360 match = 0;
4361
4362 for (ri = rn->info; ri; ri = ri->next)
4363 {
4364 if (BGP_INFO_HOLDDOWN (ri))
4365 continue;
4366
4367 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4368 {
4369 if (aggregate->summary_only)
4370 {
4371 ri->suppress--;
4372
4373 if (ri->suppress == 0)
4374 {
4375 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4376 match++;
4377 }
4378 }
4379 aggregate->count--;
4380 }
4381 }
4382
4383 /* If this node is suppressed, process the change. */
4384 if (match)
4385 bgp_process (bgp, rn, afi, safi);
4386 }
4387 bgp_unlock_node (top);
4388
4389 /* Delete aggregate route from BGP table. */
4390 rn = bgp_node_get (table, p);
4391
4392 for (ri = rn->info; ri; ri = ri->next)
4393 if (ri->peer == bgp->peer_self
4394 && ri->type == ZEBRA_ROUTE_BGP
4395 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4396 break;
4397
4398 /* Withdraw static BGP route from routing table. */
4399 if (ri)
4400 {
4401 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4402 bgp_process (bgp, rn, afi, safi);
4403 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004404 }
4405
4406 /* Unlock bgp_node_lookup. */
4407 bgp_unlock_node (rn);
4408}
4409
4410/* Aggregate route attribute. */
4411#define AGGREGATE_SUMMARY_ONLY 1
4412#define AGGREGATE_AS_SET 1
4413
paul94f2b392005-06-28 12:44:16 +00004414static int
paulfd79ac92004-10-13 05:06:08 +00004415bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4416 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004417 u_char summary_only, u_char as_set)
4418{
4419 int ret;
4420 struct prefix p;
4421 struct bgp_node *rn;
4422 struct bgp *bgp;
4423 struct bgp_aggregate *aggregate;
4424
4425 /* Convert string to prefix structure. */
4426 ret = str2prefix (prefix_str, &p);
4427 if (!ret)
4428 {
4429 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4430 return CMD_WARNING;
4431 }
4432 apply_mask (&p);
4433
4434 /* Get BGP structure. */
4435 bgp = vty->index;
4436
4437 /* Old configuration check. */
4438 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4439
4440 if (rn->info)
4441 {
4442 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4443 bgp_unlock_node (rn);
4444 return CMD_WARNING;
4445 }
4446
4447 /* Make aggregate address structure. */
4448 aggregate = bgp_aggregate_new ();
4449 aggregate->summary_only = summary_only;
4450 aggregate->as_set = as_set;
4451 aggregate->safi = safi;
4452 rn->info = aggregate;
4453
4454 /* Aggregate address insert into BGP routing table. */
4455 if (safi & SAFI_UNICAST)
4456 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4457 if (safi & SAFI_MULTICAST)
4458 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4459
4460 return CMD_SUCCESS;
4461}
4462
paul94f2b392005-06-28 12:44:16 +00004463static int
paulfd79ac92004-10-13 05:06:08 +00004464bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4465 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004466{
4467 int ret;
4468 struct prefix p;
4469 struct bgp_node *rn;
4470 struct bgp *bgp;
4471 struct bgp_aggregate *aggregate;
4472
4473 /* Convert string to prefix structure. */
4474 ret = str2prefix (prefix_str, &p);
4475 if (!ret)
4476 {
4477 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4478 return CMD_WARNING;
4479 }
4480 apply_mask (&p);
4481
4482 /* Get BGP structure. */
4483 bgp = vty->index;
4484
4485 /* Old configuration check. */
4486 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4487 if (! rn)
4488 {
4489 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4490 VTY_NEWLINE);
4491 return CMD_WARNING;
4492 }
4493
4494 aggregate = rn->info;
4495 if (aggregate->safi & SAFI_UNICAST)
4496 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4497 if (aggregate->safi & SAFI_MULTICAST)
4498 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4499
4500 /* Unlock aggregate address configuration. */
4501 rn->info = NULL;
4502 bgp_aggregate_free (aggregate);
4503 bgp_unlock_node (rn);
4504 bgp_unlock_node (rn);
4505
4506 return CMD_SUCCESS;
4507}
4508
4509DEFUN (aggregate_address,
4510 aggregate_address_cmd,
4511 "aggregate-address A.B.C.D/M",
4512 "Configure BGP aggregate entries\n"
4513 "Aggregate prefix\n")
4514{
4515 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4516}
4517
4518DEFUN (aggregate_address_mask,
4519 aggregate_address_mask_cmd,
4520 "aggregate-address A.B.C.D A.B.C.D",
4521 "Configure BGP aggregate entries\n"
4522 "Aggregate address\n"
4523 "Aggregate mask\n")
4524{
4525 int ret;
4526 char prefix_str[BUFSIZ];
4527
4528 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4529
4530 if (! ret)
4531 {
4532 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4533 return CMD_WARNING;
4534 }
4535
4536 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4537 0, 0);
4538}
4539
4540DEFUN (aggregate_address_summary_only,
4541 aggregate_address_summary_only_cmd,
4542 "aggregate-address A.B.C.D/M summary-only",
4543 "Configure BGP aggregate entries\n"
4544 "Aggregate prefix\n"
4545 "Filter more specific routes from updates\n")
4546{
4547 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4548 AGGREGATE_SUMMARY_ONLY, 0);
4549}
4550
4551DEFUN (aggregate_address_mask_summary_only,
4552 aggregate_address_mask_summary_only_cmd,
4553 "aggregate-address A.B.C.D A.B.C.D summary-only",
4554 "Configure BGP aggregate entries\n"
4555 "Aggregate address\n"
4556 "Aggregate mask\n"
4557 "Filter more specific routes from updates\n")
4558{
4559 int ret;
4560 char prefix_str[BUFSIZ];
4561
4562 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4563
4564 if (! ret)
4565 {
4566 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4567 return CMD_WARNING;
4568 }
4569
4570 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4571 AGGREGATE_SUMMARY_ONLY, 0);
4572}
4573
4574DEFUN (aggregate_address_as_set,
4575 aggregate_address_as_set_cmd,
4576 "aggregate-address A.B.C.D/M as-set",
4577 "Configure BGP aggregate entries\n"
4578 "Aggregate prefix\n"
4579 "Generate AS set path information\n")
4580{
4581 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4582 0, AGGREGATE_AS_SET);
4583}
4584
4585DEFUN (aggregate_address_mask_as_set,
4586 aggregate_address_mask_as_set_cmd,
4587 "aggregate-address A.B.C.D A.B.C.D as-set",
4588 "Configure BGP aggregate entries\n"
4589 "Aggregate address\n"
4590 "Aggregate mask\n"
4591 "Generate AS set path information\n")
4592{
4593 int ret;
4594 char prefix_str[BUFSIZ];
4595
4596 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4597
4598 if (! ret)
4599 {
4600 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4601 return CMD_WARNING;
4602 }
4603
4604 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4605 0, AGGREGATE_AS_SET);
4606}
4607
4608
4609DEFUN (aggregate_address_as_set_summary,
4610 aggregate_address_as_set_summary_cmd,
4611 "aggregate-address A.B.C.D/M as-set summary-only",
4612 "Configure BGP aggregate entries\n"
4613 "Aggregate prefix\n"
4614 "Generate AS set path information\n"
4615 "Filter more specific routes from updates\n")
4616{
4617 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4618 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4619}
4620
4621ALIAS (aggregate_address_as_set_summary,
4622 aggregate_address_summary_as_set_cmd,
4623 "aggregate-address A.B.C.D/M summary-only as-set",
4624 "Configure BGP aggregate entries\n"
4625 "Aggregate prefix\n"
4626 "Filter more specific routes from updates\n"
4627 "Generate AS set path information\n")
4628
4629DEFUN (aggregate_address_mask_as_set_summary,
4630 aggregate_address_mask_as_set_summary_cmd,
4631 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4632 "Configure BGP aggregate entries\n"
4633 "Aggregate address\n"
4634 "Aggregate mask\n"
4635 "Generate AS set path information\n"
4636 "Filter more specific routes from updates\n")
4637{
4638 int ret;
4639 char prefix_str[BUFSIZ];
4640
4641 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4642
4643 if (! ret)
4644 {
4645 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4646 return CMD_WARNING;
4647 }
4648
4649 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4650 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4651}
4652
4653ALIAS (aggregate_address_mask_as_set_summary,
4654 aggregate_address_mask_summary_as_set_cmd,
4655 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4656 "Configure BGP aggregate entries\n"
4657 "Aggregate address\n"
4658 "Aggregate mask\n"
4659 "Filter more specific routes from updates\n"
4660 "Generate AS set path information\n")
4661
4662DEFUN (no_aggregate_address,
4663 no_aggregate_address_cmd,
4664 "no aggregate-address A.B.C.D/M",
4665 NO_STR
4666 "Configure BGP aggregate entries\n"
4667 "Aggregate prefix\n")
4668{
4669 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4670}
4671
4672ALIAS (no_aggregate_address,
4673 no_aggregate_address_summary_only_cmd,
4674 "no aggregate-address A.B.C.D/M summary-only",
4675 NO_STR
4676 "Configure BGP aggregate entries\n"
4677 "Aggregate prefix\n"
4678 "Filter more specific routes from updates\n")
4679
4680ALIAS (no_aggregate_address,
4681 no_aggregate_address_as_set_cmd,
4682 "no aggregate-address A.B.C.D/M as-set",
4683 NO_STR
4684 "Configure BGP aggregate entries\n"
4685 "Aggregate prefix\n"
4686 "Generate AS set path information\n")
4687
4688ALIAS (no_aggregate_address,
4689 no_aggregate_address_as_set_summary_cmd,
4690 "no aggregate-address A.B.C.D/M as-set summary-only",
4691 NO_STR
4692 "Configure BGP aggregate entries\n"
4693 "Aggregate prefix\n"
4694 "Generate AS set path information\n"
4695 "Filter more specific routes from updates\n")
4696
4697ALIAS (no_aggregate_address,
4698 no_aggregate_address_summary_as_set_cmd,
4699 "no aggregate-address A.B.C.D/M summary-only as-set",
4700 NO_STR
4701 "Configure BGP aggregate entries\n"
4702 "Aggregate prefix\n"
4703 "Filter more specific routes from updates\n"
4704 "Generate AS set path information\n")
4705
4706DEFUN (no_aggregate_address_mask,
4707 no_aggregate_address_mask_cmd,
4708 "no aggregate-address A.B.C.D A.B.C.D",
4709 NO_STR
4710 "Configure BGP aggregate entries\n"
4711 "Aggregate address\n"
4712 "Aggregate mask\n")
4713{
4714 int ret;
4715 char prefix_str[BUFSIZ];
4716
4717 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4718
4719 if (! ret)
4720 {
4721 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4722 return CMD_WARNING;
4723 }
4724
4725 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4726}
4727
4728ALIAS (no_aggregate_address_mask,
4729 no_aggregate_address_mask_summary_only_cmd,
4730 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4731 NO_STR
4732 "Configure BGP aggregate entries\n"
4733 "Aggregate address\n"
4734 "Aggregate mask\n"
4735 "Filter more specific routes from updates\n")
4736
4737ALIAS (no_aggregate_address_mask,
4738 no_aggregate_address_mask_as_set_cmd,
4739 "no aggregate-address A.B.C.D A.B.C.D as-set",
4740 NO_STR
4741 "Configure BGP aggregate entries\n"
4742 "Aggregate address\n"
4743 "Aggregate mask\n"
4744 "Generate AS set path information\n")
4745
4746ALIAS (no_aggregate_address_mask,
4747 no_aggregate_address_mask_as_set_summary_cmd,
4748 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4749 NO_STR
4750 "Configure BGP aggregate entries\n"
4751 "Aggregate address\n"
4752 "Aggregate mask\n"
4753 "Generate AS set path information\n"
4754 "Filter more specific routes from updates\n")
4755
4756ALIAS (no_aggregate_address_mask,
4757 no_aggregate_address_mask_summary_as_set_cmd,
4758 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4759 NO_STR
4760 "Configure BGP aggregate entries\n"
4761 "Aggregate address\n"
4762 "Aggregate mask\n"
4763 "Filter more specific routes from updates\n"
4764 "Generate AS set path information\n")
4765
4766#ifdef HAVE_IPV6
4767DEFUN (ipv6_aggregate_address,
4768 ipv6_aggregate_address_cmd,
4769 "aggregate-address X:X::X:X/M",
4770 "Configure BGP aggregate entries\n"
4771 "Aggregate prefix\n")
4772{
4773 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4774}
4775
4776DEFUN (ipv6_aggregate_address_summary_only,
4777 ipv6_aggregate_address_summary_only_cmd,
4778 "aggregate-address X:X::X:X/M summary-only",
4779 "Configure BGP aggregate entries\n"
4780 "Aggregate prefix\n"
4781 "Filter more specific routes from updates\n")
4782{
4783 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4784 AGGREGATE_SUMMARY_ONLY, 0);
4785}
4786
4787DEFUN (no_ipv6_aggregate_address,
4788 no_ipv6_aggregate_address_cmd,
4789 "no aggregate-address X:X::X:X/M",
4790 NO_STR
4791 "Configure BGP aggregate entries\n"
4792 "Aggregate prefix\n")
4793{
4794 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4795}
4796
4797DEFUN (no_ipv6_aggregate_address_summary_only,
4798 no_ipv6_aggregate_address_summary_only_cmd,
4799 "no aggregate-address X:X::X:X/M summary-only",
4800 NO_STR
4801 "Configure BGP aggregate entries\n"
4802 "Aggregate prefix\n"
4803 "Filter more specific routes from updates\n")
4804{
4805 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4806}
4807
4808ALIAS (ipv6_aggregate_address,
4809 old_ipv6_aggregate_address_cmd,
4810 "ipv6 bgp aggregate-address X:X::X:X/M",
4811 IPV6_STR
4812 BGP_STR
4813 "Configure BGP aggregate entries\n"
4814 "Aggregate prefix\n")
4815
4816ALIAS (ipv6_aggregate_address_summary_only,
4817 old_ipv6_aggregate_address_summary_only_cmd,
4818 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4819 IPV6_STR
4820 BGP_STR
4821 "Configure BGP aggregate entries\n"
4822 "Aggregate prefix\n"
4823 "Filter more specific routes from updates\n")
4824
4825ALIAS (no_ipv6_aggregate_address,
4826 old_no_ipv6_aggregate_address_cmd,
4827 "no ipv6 bgp aggregate-address X:X::X:X/M",
4828 NO_STR
4829 IPV6_STR
4830 BGP_STR
4831 "Configure BGP aggregate entries\n"
4832 "Aggregate prefix\n")
4833
4834ALIAS (no_ipv6_aggregate_address_summary_only,
4835 old_no_ipv6_aggregate_address_summary_only_cmd,
4836 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4837 NO_STR
4838 IPV6_STR
4839 BGP_STR
4840 "Configure BGP aggregate entries\n"
4841 "Aggregate prefix\n"
4842 "Filter more specific routes from updates\n")
4843#endif /* HAVE_IPV6 */
4844
4845/* Redistribute route treatment. */
4846void
4847bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4848 u_int32_t metric, u_char type)
4849{
4850 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004851 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004852 struct bgp_info *new;
4853 struct bgp_info *bi;
4854 struct bgp_info info;
4855 struct bgp_node *bn;
4856 struct attr attr;
4857 struct attr attr_new;
4858 struct attr *new_attr;
4859 afi_t afi;
4860 int ret;
4861
4862 /* Make default attribute. */
4863 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4864 if (nexthop)
4865 attr.nexthop = *nexthop;
4866
4867 attr.med = metric;
4868 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4869
paul1eb8ef22005-04-07 07:30:20 +00004870 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004871 {
4872 afi = family2afi (p->family);
4873
4874 if (bgp->redist[afi][type])
4875 {
4876 /* Copy attribute for modification. */
4877 attr_new = attr;
4878
4879 if (bgp->redist_metric_flag[afi][type])
4880 attr_new.med = bgp->redist_metric[afi][type];
4881
4882 /* Apply route-map. */
4883 if (bgp->rmap[afi][type].map)
4884 {
4885 info.peer = bgp->peer_self;
4886 info.attr = &attr_new;
4887
paulfee0f4c2004-09-13 05:12:46 +00004888 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4889
paul718e3742002-12-13 20:15:29 +00004890 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4891 &info);
paulfee0f4c2004-09-13 05:12:46 +00004892
4893 bgp->peer_self->rmap_type = 0;
4894
paul718e3742002-12-13 20:15:29 +00004895 if (ret == RMAP_DENYMATCH)
4896 {
4897 /* Free uninterned attribute. */
4898 bgp_attr_flush (&attr_new);
4899
4900 /* Unintern original. */
4901 aspath_unintern (attr.aspath);
4902 bgp_redistribute_delete (p, type);
4903 return;
4904 }
4905 }
4906
paulfee0f4c2004-09-13 05:12:46 +00004907 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004908 new_attr = bgp_attr_intern (&attr_new);
4909
4910 for (bi = bn->info; bi; bi = bi->next)
4911 if (bi->peer == bgp->peer_self
4912 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4913 break;
4914
4915 if (bi)
4916 {
4917 if (attrhash_cmp (bi->attr, new_attr))
4918 {
4919 bgp_attr_unintern (new_attr);
4920 aspath_unintern (attr.aspath);
4921 bgp_unlock_node (bn);
4922 return;
4923 }
4924 else
4925 {
4926 /* The attribute is changed. */
4927 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4928
4929 /* Rewrite BGP route information. */
4930 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4931 bgp_attr_unintern (bi->attr);
4932 bi->attr = new_attr;
4933 bi->uptime = time (NULL);
4934
4935 /* Process change. */
4936 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4937 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4938 bgp_unlock_node (bn);
4939 aspath_unintern (attr.aspath);
4940 return;
4941 }
4942 }
4943
4944 new = bgp_info_new ();
4945 new->type = type;
4946 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4947 new->peer = bgp->peer_self;
4948 SET_FLAG (new->flags, BGP_INFO_VALID);
4949 new->attr = new_attr;
4950 new->uptime = time (NULL);
4951
4952 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4953 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004954 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004955 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4956 }
4957 }
4958
4959 /* Unintern original. */
4960 aspath_unintern (attr.aspath);
4961}
4962
4963void
4964bgp_redistribute_delete (struct prefix *p, u_char type)
4965{
4966 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004967 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004968 afi_t afi;
4969 struct bgp_node *rn;
4970 struct bgp_info *ri;
4971
paul1eb8ef22005-04-07 07:30:20 +00004972 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004973 {
4974 afi = family2afi (p->family);
4975
4976 if (bgp->redist[afi][type])
4977 {
paulfee0f4c2004-09-13 05:12:46 +00004978 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004979
4980 for (ri = rn->info; ri; ri = ri->next)
4981 if (ri->peer == bgp->peer_self
4982 && ri->type == type)
4983 break;
4984
4985 if (ri)
4986 {
4987 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4988 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4989 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4990 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004991 }
4992 bgp_unlock_node (rn);
4993 }
4994 }
4995}
4996
4997/* Withdraw specified route type's route. */
4998void
4999bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5000{
5001 struct bgp_node *rn;
5002 struct bgp_info *ri;
5003 struct bgp_table *table;
5004
5005 table = bgp->rib[afi][SAFI_UNICAST];
5006
5007 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5008 {
5009 for (ri = rn->info; ri; ri = ri->next)
5010 if (ri->peer == bgp->peer_self
5011 && ri->type == type)
5012 break;
5013
5014 if (ri)
5015 {
5016 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5017 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
5018 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5019 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00005020 }
5021 }
5022}
5023
5024/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005025static void
paul718e3742002-12-13 20:15:29 +00005026route_vty_out_route (struct prefix *p, struct vty *vty)
5027{
5028 int len;
5029 u_int32_t destination;
5030 char buf[BUFSIZ];
5031
5032 if (p->family == AF_INET)
5033 {
5034 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5035 destination = ntohl (p->u.prefix4.s_addr);
5036
5037 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5038 || (IN_CLASSB (destination) && p->prefixlen == 16)
5039 || (IN_CLASSA (destination) && p->prefixlen == 8)
5040 || p->u.prefix4.s_addr == 0)
5041 {
5042 /* When mask is natural, mask is not displayed. */
5043 }
5044 else
5045 len += vty_out (vty, "/%d", p->prefixlen);
5046 }
5047 else
5048 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5049 p->prefixlen);
5050
5051 len = 17 - len;
5052 if (len < 1)
5053 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5054 else
5055 vty_out (vty, "%*s", len, " ");
5056}
5057
paul718e3742002-12-13 20:15:29 +00005058enum bgp_display_type
5059{
5060 normal_list,
5061};
5062
paulb40d9392005-08-22 22:34:41 +00005063/* Print the short form route status for a bgp_info */
5064static void
5065route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005066{
paulb40d9392005-08-22 22:34:41 +00005067 /* Route status display. */
5068 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5069 vty_out (vty, "R");
5070 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005071 vty_out (vty, "S");
5072 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005073 vty_out (vty, "s");
5074 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5075 vty_out (vty, "*");
5076 else
5077 vty_out (vty, " ");
5078
5079 /* Selected */
5080 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5081 vty_out (vty, "h");
5082 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5083 vty_out (vty, "d");
5084 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5085 vty_out (vty, ">");
5086 else
5087 vty_out (vty, " ");
5088
5089 /* Internal route. */
5090 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5091 vty_out (vty, "i");
5092 else
paulb40d9392005-08-22 22:34:41 +00005093 vty_out (vty, " ");
5094}
5095
5096/* called from terminal list command */
5097void
5098route_vty_out (struct vty *vty, struct prefix *p,
5099 struct bgp_info *binfo, int display, safi_t safi)
5100{
5101 struct attr *attr;
5102
5103 /* short status lead text */
5104 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005105
5106 /* print prefix and mask */
5107 if (! display)
5108 route_vty_out_route (p, vty);
5109 else
5110 vty_out (vty, "%*s", 17, " ");
5111
5112 /* Print attribute */
5113 attr = binfo->attr;
5114 if (attr)
5115 {
5116 if (p->family == AF_INET)
5117 {
5118 if (safi == SAFI_MPLS_VPN)
5119 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5120 else
5121 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5122 }
5123#ifdef HAVE_IPV6
5124 else if (p->family == AF_INET6)
5125 {
5126 int len;
5127 char buf[BUFSIZ];
5128
5129 len = vty_out (vty, "%s",
5130 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5131 len = 16 - len;
5132 if (len < 1)
5133 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5134 else
5135 vty_out (vty, "%*s", len, " ");
5136 }
5137#endif /* HAVE_IPV6 */
5138
5139 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5140 vty_out (vty, "%10d", attr->med);
5141 else
5142 vty_out (vty, " ");
5143
5144 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5145 vty_out (vty, "%7d", attr->local_pref);
5146 else
5147 vty_out (vty, " ");
5148
5149 vty_out (vty, "%7u ",attr->weight);
5150
5151 /* Print aspath */
5152 if (attr->aspath)
5153 aspath_print_vty (vty, attr->aspath);
5154
5155 /* Print origin */
5156 if (strlen (attr->aspath->str) == 0)
5157 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5158 else
5159 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5160 }
5161 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005162}
5163
5164/* called from terminal list command */
5165void
5166route_vty_out_tmp (struct vty *vty, struct prefix *p,
5167 struct attr *attr, safi_t safi)
5168{
5169 /* Route status display. */
5170 vty_out (vty, "*");
5171 vty_out (vty, ">");
5172 vty_out (vty, " ");
5173
5174 /* print prefix and mask */
5175 route_vty_out_route (p, vty);
5176
5177 /* Print attribute */
5178 if (attr)
5179 {
5180 if (p->family == AF_INET)
5181 {
5182 if (safi == SAFI_MPLS_VPN)
5183 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5184 else
5185 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5186 }
5187#ifdef HAVE_IPV6
5188 else if (p->family == AF_INET6)
5189 {
5190 int len;
5191 char buf[BUFSIZ];
5192
5193 len = vty_out (vty, "%s",
5194 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5195 len = 16 - len;
5196 if (len < 1)
5197 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5198 else
5199 vty_out (vty, "%*s", len, " ");
5200 }
5201#endif /* HAVE_IPV6 */
5202
5203 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5204 vty_out (vty, "%10d", attr->med);
5205 else
5206 vty_out (vty, " ");
5207
5208 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5209 vty_out (vty, "%7d", attr->local_pref);
5210 else
5211 vty_out (vty, " ");
5212
5213 vty_out (vty, "%7d ",attr->weight);
5214
5215 /* Print aspath */
5216 if (attr->aspath)
5217 aspath_print_vty (vty, attr->aspath);
5218
5219 /* Print origin */
5220 if (strlen (attr->aspath->str) == 0)
5221 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5222 else
5223 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5224 }
5225
5226 vty_out (vty, "%s", VTY_NEWLINE);
5227}
5228
ajs5a646652004-11-05 01:25:55 +00005229void
paul718e3742002-12-13 20:15:29 +00005230route_vty_out_tag (struct vty *vty, struct prefix *p,
5231 struct bgp_info *binfo, int display, safi_t safi)
5232{
5233 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005234 u_int32_t label = 0;
5235
paulb40d9392005-08-22 22:34:41 +00005236 /* short status lead text */
5237 route_vty_short_status_out (vty, binfo);
5238
paul718e3742002-12-13 20:15:29 +00005239 /* print prefix and mask */
5240 if (! display)
5241 route_vty_out_route (p, vty);
5242 else
5243 vty_out (vty, "%*s", 17, " ");
5244
5245 /* Print attribute */
5246 attr = binfo->attr;
5247 if (attr)
5248 {
5249 if (p->family == AF_INET)
5250 {
5251 if (safi == SAFI_MPLS_VPN)
5252 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5253 else
5254 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5255 }
5256#ifdef HAVE_IPV6
5257 else if (p->family == AF_INET6)
5258 {
5259 char buf[BUFSIZ];
5260 char buf1[BUFSIZ];
5261 if (attr->mp_nexthop_len == 16)
5262 vty_out (vty, "%s",
5263 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5264 else if (attr->mp_nexthop_len == 32)
5265 vty_out (vty, "%s(%s)",
5266 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5267 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5268
5269 }
5270#endif /* HAVE_IPV6 */
5271 }
5272
5273 label = decode_label (binfo->tag);
5274
5275 vty_out (vty, "notag/%d", label);
5276
5277 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005278}
5279
5280/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005281static void
paul718e3742002-12-13 20:15:29 +00005282damp_route_vty_out (struct vty *vty, struct prefix *p,
5283 struct bgp_info *binfo, int display, safi_t safi)
5284{
5285 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005286 int len;
5287
paulb40d9392005-08-22 22:34:41 +00005288 /* short status lead text */
5289 route_vty_short_status_out (vty, binfo);
5290
paul718e3742002-12-13 20:15:29 +00005291 /* print prefix and mask */
5292 if (! display)
5293 route_vty_out_route (p, vty);
5294 else
5295 vty_out (vty, "%*s", 17, " ");
5296
5297 len = vty_out (vty, "%s", binfo->peer->host);
5298 len = 17 - len;
5299 if (len < 1)
5300 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5301 else
5302 vty_out (vty, "%*s", len, " ");
5303
5304 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5305
5306 /* Print attribute */
5307 attr = binfo->attr;
5308 if (attr)
5309 {
5310 /* Print aspath */
5311 if (attr->aspath)
5312 aspath_print_vty (vty, attr->aspath);
5313
5314 /* Print origin */
5315 if (strlen (attr->aspath->str) == 0)
5316 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5317 else
5318 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5319 }
5320 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005321}
5322
5323#define BGP_UPTIME_LEN 25
5324
5325/* flap route */
ajs5a646652004-11-05 01:25:55 +00005326static void
paul718e3742002-12-13 20:15:29 +00005327flap_route_vty_out (struct vty *vty, struct prefix *p,
5328 struct bgp_info *binfo, int display, safi_t safi)
5329{
5330 struct attr *attr;
5331 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005332 char timebuf[BGP_UPTIME_LEN];
5333 int len;
5334
paul718e3742002-12-13 20:15:29 +00005335 bdi = binfo->damp_info;
5336
paulb40d9392005-08-22 22:34:41 +00005337 /* short status lead text */
5338 route_vty_short_status_out (vty, binfo);
5339
paul718e3742002-12-13 20:15:29 +00005340 /* print prefix and mask */
5341 if (! display)
5342 route_vty_out_route (p, vty);
5343 else
5344 vty_out (vty, "%*s", 17, " ");
5345
5346 len = vty_out (vty, "%s", binfo->peer->host);
5347 len = 16 - len;
5348 if (len < 1)
5349 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5350 else
5351 vty_out (vty, "%*s", len, " ");
5352
5353 len = vty_out (vty, "%d", bdi->flap);
5354 len = 5 - len;
5355 if (len < 1)
5356 vty_out (vty, " ");
5357 else
5358 vty_out (vty, "%*s ", len, " ");
5359
5360 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5361 timebuf, BGP_UPTIME_LEN));
5362
5363 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5364 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5365 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5366 else
5367 vty_out (vty, "%*s ", 8, " ");
5368
5369 /* Print attribute */
5370 attr = binfo->attr;
5371 if (attr)
5372 {
5373 /* Print aspath */
5374 if (attr->aspath)
5375 aspath_print_vty (vty, attr->aspath);
5376
5377 /* Print origin */
5378 if (strlen (attr->aspath->str) == 0)
5379 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5380 else
5381 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5382 }
5383 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005384}
5385
paul94f2b392005-06-28 12:44:16 +00005386static void
paul718e3742002-12-13 20:15:29 +00005387route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5388 struct bgp_info *binfo, afi_t afi, safi_t safi)
5389{
5390 char buf[INET6_ADDRSTRLEN];
5391 char buf1[BUFSIZ];
5392 struct attr *attr;
5393 int sockunion_vty_out (struct vty *, union sockunion *);
5394
5395 attr = binfo->attr;
5396
5397 if (attr)
5398 {
5399 /* Line1 display AS-path, Aggregator */
5400 if (attr->aspath)
5401 {
5402 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005403 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005404 vty_out (vty, "Local");
5405 else
5406 aspath_print_vty (vty, attr->aspath);
5407 }
5408
paulb40d9392005-08-22 22:34:41 +00005409 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5410 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005411 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5412 vty_out (vty, ", (stale)");
5413 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5414 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5415 inet_ntoa (attr->aggregator_addr));
5416 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5417 vty_out (vty, ", (Received from a RR-client)");
5418 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5419 vty_out (vty, ", (Received from a RS-client)");
5420 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5421 vty_out (vty, ", (history entry)");
5422 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5423 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005424 vty_out (vty, "%s", VTY_NEWLINE);
5425
5426 /* Line2 display Next-hop, Neighbor, Router-id */
5427 if (p->family == AF_INET)
5428 {
5429 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5430 inet_ntoa (attr->mp_nexthop_global_in) :
5431 inet_ntoa (attr->nexthop));
5432 }
5433#ifdef HAVE_IPV6
5434 else
5435 {
5436 vty_out (vty, " %s",
5437 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5438 buf, INET6_ADDRSTRLEN));
5439 }
5440#endif /* HAVE_IPV6 */
5441
5442 if (binfo->peer == bgp->peer_self)
5443 {
5444 vty_out (vty, " from %s ",
5445 p->family == AF_INET ? "0.0.0.0" : "::");
5446 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5447 }
5448 else
5449 {
5450 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5451 vty_out (vty, " (inaccessible)");
5452 else if (binfo->igpmetric)
5453 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005454 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005455 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5456 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5457 else
5458 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5459 }
5460 vty_out (vty, "%s", VTY_NEWLINE);
5461
5462#ifdef HAVE_IPV6
5463 /* display nexthop local */
5464 if (attr->mp_nexthop_len == 32)
5465 {
5466 vty_out (vty, " (%s)%s",
5467 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5468 buf, INET6_ADDRSTRLEN),
5469 VTY_NEWLINE);
5470 }
5471#endif /* HAVE_IPV6 */
5472
5473 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5474 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5475
5476 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5477 vty_out (vty, ", metric %d", attr->med);
5478
5479 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5480 vty_out (vty, ", localpref %d", attr->local_pref);
5481 else
5482 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5483
5484 if (attr->weight != 0)
5485 vty_out (vty, ", weight %d", attr->weight);
5486
5487 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5488 vty_out (vty, ", valid");
5489
5490 if (binfo->peer != bgp->peer_self)
5491 {
5492 if (binfo->peer->as == binfo->peer->local_as)
5493 vty_out (vty, ", internal");
5494 else
5495 vty_out (vty, ", %s",
5496 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5497 }
5498 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5499 vty_out (vty, ", aggregated, local");
5500 else if (binfo->type != ZEBRA_ROUTE_BGP)
5501 vty_out (vty, ", sourced");
5502 else
5503 vty_out (vty, ", sourced, local");
5504
5505 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5506 vty_out (vty, ", atomic-aggregate");
5507
5508 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5509 vty_out (vty, ", best");
5510
5511 vty_out (vty, "%s", VTY_NEWLINE);
5512
5513 /* Line 4 display Community */
5514 if (attr->community)
5515 vty_out (vty, " Community: %s%s", attr->community->str,
5516 VTY_NEWLINE);
5517
5518 /* Line 5 display Extended-community */
5519 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5520 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5521 VTY_NEWLINE);
5522
5523 /* Line 6 display Originator, Cluster-id */
5524 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5525 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5526 {
5527 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5528 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5529
5530 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5531 {
5532 int i;
5533 vty_out (vty, ", Cluster list: ");
5534 for (i = 0; i < attr->cluster->length / 4; i++)
5535 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5536 }
5537 vty_out (vty, "%s", VTY_NEWLINE);
5538 }
5539
5540 if (binfo->damp_info)
5541 bgp_damp_info_vty (vty, binfo);
5542
5543 /* Line 7 display Uptime */
5544 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5545 }
5546 vty_out (vty, "%s", VTY_NEWLINE);
5547}
5548
paulb40d9392005-08-22 22:34:41 +00005549#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 +00005550#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005551#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5552#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5553#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5554
5555enum bgp_show_type
5556{
5557 bgp_show_type_normal,
5558 bgp_show_type_regexp,
5559 bgp_show_type_prefix_list,
5560 bgp_show_type_filter_list,
5561 bgp_show_type_route_map,
5562 bgp_show_type_neighbor,
5563 bgp_show_type_cidr_only,
5564 bgp_show_type_prefix_longer,
5565 bgp_show_type_community_all,
5566 bgp_show_type_community,
5567 bgp_show_type_community_exact,
5568 bgp_show_type_community_list,
5569 bgp_show_type_community_list_exact,
5570 bgp_show_type_flap_statistics,
5571 bgp_show_type_flap_address,
5572 bgp_show_type_flap_prefix,
5573 bgp_show_type_flap_cidr_only,
5574 bgp_show_type_flap_regexp,
5575 bgp_show_type_flap_filter_list,
5576 bgp_show_type_flap_prefix_list,
5577 bgp_show_type_flap_prefix_longer,
5578 bgp_show_type_flap_route_map,
5579 bgp_show_type_flap_neighbor,
5580 bgp_show_type_dampend_paths,
5581 bgp_show_type_damp_neighbor
5582};
5583
ajs5a646652004-11-05 01:25:55 +00005584static int
paulfee0f4c2004-09-13 05:12:46 +00005585bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005586 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005587{
paul718e3742002-12-13 20:15:29 +00005588 struct bgp_info *ri;
5589 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005590 int header = 1;
paul718e3742002-12-13 20:15:29 +00005591 int display;
ajs5a646652004-11-05 01:25:55 +00005592 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005593
5594 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005595 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005596
paul718e3742002-12-13 20:15:29 +00005597 /* Start processing of routes. */
5598 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5599 if (rn->info != NULL)
5600 {
5601 display = 0;
5602
5603 for (ri = rn->info; ri; ri = ri->next)
5604 {
ajs5a646652004-11-05 01:25:55 +00005605 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005606 || type == bgp_show_type_flap_address
5607 || type == bgp_show_type_flap_prefix
5608 || type == bgp_show_type_flap_cidr_only
5609 || type == bgp_show_type_flap_regexp
5610 || type == bgp_show_type_flap_filter_list
5611 || type == bgp_show_type_flap_prefix_list
5612 || type == bgp_show_type_flap_prefix_longer
5613 || type == bgp_show_type_flap_route_map
5614 || type == bgp_show_type_flap_neighbor
5615 || type == bgp_show_type_dampend_paths
5616 || type == bgp_show_type_damp_neighbor)
5617 {
5618 if (! ri->damp_info)
5619 continue;
5620 }
5621 if (type == bgp_show_type_regexp
5622 || type == bgp_show_type_flap_regexp)
5623 {
ajs5a646652004-11-05 01:25:55 +00005624 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005625
5626 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5627 continue;
5628 }
5629 if (type == bgp_show_type_prefix_list
5630 || type == bgp_show_type_flap_prefix_list)
5631 {
ajs5a646652004-11-05 01:25:55 +00005632 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005633
5634 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5635 continue;
5636 }
5637 if (type == bgp_show_type_filter_list
5638 || type == bgp_show_type_flap_filter_list)
5639 {
ajs5a646652004-11-05 01:25:55 +00005640 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005641
5642 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5643 continue;
5644 }
5645 if (type == bgp_show_type_route_map
5646 || type == bgp_show_type_flap_route_map)
5647 {
ajs5a646652004-11-05 01:25:55 +00005648 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005649 struct bgp_info binfo;
5650 struct attr dummy_attr;
5651 int ret;
5652
5653 dummy_attr = *ri->attr;
5654 binfo.peer = ri->peer;
5655 binfo.attr = &dummy_attr;
5656
5657 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5658
5659 if (ret == RMAP_DENYMATCH)
5660 continue;
5661 }
5662 if (type == bgp_show_type_neighbor
5663 || type == bgp_show_type_flap_neighbor
5664 || type == bgp_show_type_damp_neighbor)
5665 {
ajs5a646652004-11-05 01:25:55 +00005666 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005667
5668 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5669 continue;
5670 }
5671 if (type == bgp_show_type_cidr_only
5672 || type == bgp_show_type_flap_cidr_only)
5673 {
5674 u_int32_t destination;
5675
5676 destination = ntohl (rn->p.u.prefix4.s_addr);
5677 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5678 continue;
5679 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5680 continue;
5681 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5682 continue;
5683 }
5684 if (type == bgp_show_type_prefix_longer
5685 || type == bgp_show_type_flap_prefix_longer)
5686 {
ajs5a646652004-11-05 01:25:55 +00005687 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005688
5689 if (! prefix_match (p, &rn->p))
5690 continue;
5691 }
5692 if (type == bgp_show_type_community_all)
5693 {
5694 if (! ri->attr->community)
5695 continue;
5696 }
5697 if (type == bgp_show_type_community)
5698 {
ajs5a646652004-11-05 01:25:55 +00005699 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005700
5701 if (! ri->attr->community ||
5702 ! community_match (ri->attr->community, com))
5703 continue;
5704 }
5705 if (type == bgp_show_type_community_exact)
5706 {
ajs5a646652004-11-05 01:25:55 +00005707 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005708
5709 if (! ri->attr->community ||
5710 ! community_cmp (ri->attr->community, com))
5711 continue;
5712 }
5713 if (type == bgp_show_type_community_list)
5714 {
ajs5a646652004-11-05 01:25:55 +00005715 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005716
5717 if (! community_list_match (ri->attr->community, list))
5718 continue;
5719 }
5720 if (type == bgp_show_type_community_list_exact)
5721 {
ajs5a646652004-11-05 01:25:55 +00005722 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005723
5724 if (! community_list_exact_match (ri->attr->community, list))
5725 continue;
5726 }
5727 if (type == bgp_show_type_flap_address
5728 || type == bgp_show_type_flap_prefix)
5729 {
ajs5a646652004-11-05 01:25:55 +00005730 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005731
5732 if (! prefix_match (&rn->p, p))
5733 continue;
5734
5735 if (type == bgp_show_type_flap_prefix)
5736 if (p->prefixlen != rn->p.prefixlen)
5737 continue;
5738 }
5739 if (type == bgp_show_type_dampend_paths
5740 || type == bgp_show_type_damp_neighbor)
5741 {
5742 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5743 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5744 continue;
5745 }
5746
5747 if (header)
5748 {
hasso93406d82005-02-02 14:40:33 +00005749 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5750 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5751 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005752 if (type == bgp_show_type_dampend_paths
5753 || type == bgp_show_type_damp_neighbor)
5754 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5755 else if (type == bgp_show_type_flap_statistics
5756 || type == bgp_show_type_flap_address
5757 || type == bgp_show_type_flap_prefix
5758 || type == bgp_show_type_flap_cidr_only
5759 || type == bgp_show_type_flap_regexp
5760 || type == bgp_show_type_flap_filter_list
5761 || type == bgp_show_type_flap_prefix_list
5762 || type == bgp_show_type_flap_prefix_longer
5763 || type == bgp_show_type_flap_route_map
5764 || type == bgp_show_type_flap_neighbor)
5765 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5766 else
5767 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005768 header = 0;
5769 }
5770
5771 if (type == bgp_show_type_dampend_paths
5772 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005773 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005774 else if (type == bgp_show_type_flap_statistics
5775 || type == bgp_show_type_flap_address
5776 || type == bgp_show_type_flap_prefix
5777 || type == bgp_show_type_flap_cidr_only
5778 || type == bgp_show_type_flap_regexp
5779 || type == bgp_show_type_flap_filter_list
5780 || type == bgp_show_type_flap_prefix_list
5781 || type == bgp_show_type_flap_prefix_longer
5782 || type == bgp_show_type_flap_route_map
5783 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005784 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005785 else
ajs5a646652004-11-05 01:25:55 +00005786 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005787 display++;
5788 }
5789 if (display)
ajs5a646652004-11-05 01:25:55 +00005790 output_count++;
paul718e3742002-12-13 20:15:29 +00005791 }
5792
5793 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005794 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005795 {
5796 if (type == bgp_show_type_normal)
5797 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5798 }
5799 else
5800 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005801 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005802
5803 return CMD_SUCCESS;
5804}
5805
ajs5a646652004-11-05 01:25:55 +00005806static int
paulfee0f4c2004-09-13 05:12:46 +00005807bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005808 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005809{
5810 struct bgp_table *table;
5811
5812 if (bgp == NULL) {
5813 bgp = bgp_get_default ();
5814 }
5815
5816 if (bgp == NULL)
5817 {
5818 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5819 return CMD_WARNING;
5820 }
5821
5822
5823 table = bgp->rib[afi][safi];
5824
ajs5a646652004-11-05 01:25:55 +00005825 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005826}
5827
paul718e3742002-12-13 20:15:29 +00005828/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005829static void
paul718e3742002-12-13 20:15:29 +00005830route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5831 struct bgp_node *rn,
5832 struct prefix_rd *prd, afi_t afi, safi_t safi)
5833{
5834 struct bgp_info *ri;
5835 struct prefix *p;
5836 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005837 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005838 char buf1[INET6_ADDRSTRLEN];
5839 char buf2[INET6_ADDRSTRLEN];
5840 int count = 0;
5841 int best = 0;
5842 int suppress = 0;
5843 int no_export = 0;
5844 int no_advertise = 0;
5845 int local_as = 0;
5846 int first = 0;
5847
5848 p = &rn->p;
5849 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5850 (safi == SAFI_MPLS_VPN ?
5851 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5852 safi == SAFI_MPLS_VPN ? ":" : "",
5853 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5854 p->prefixlen, VTY_NEWLINE);
5855
5856 for (ri = rn->info; ri; ri = ri->next)
5857 {
5858 count++;
5859 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5860 {
5861 best = count;
5862 if (ri->suppress)
5863 suppress = 1;
5864 if (ri->attr->community != NULL)
5865 {
5866 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5867 no_advertise = 1;
5868 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5869 no_export = 1;
5870 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5871 local_as = 1;
5872 }
5873 }
5874 }
5875
5876 vty_out (vty, "Paths: (%d available", count);
5877 if (best)
5878 {
5879 vty_out (vty, ", best #%d", best);
5880 if (safi == SAFI_UNICAST)
5881 vty_out (vty, ", table Default-IP-Routing-Table");
5882 }
5883 else
5884 vty_out (vty, ", no best path");
5885 if (no_advertise)
5886 vty_out (vty, ", not advertised to any peer");
5887 else if (no_export)
5888 vty_out (vty, ", not advertised to EBGP peer");
5889 else if (local_as)
5890 vty_out (vty, ", not advertised outside local AS");
5891 if (suppress)
5892 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5893 vty_out (vty, ")%s", VTY_NEWLINE);
5894
5895 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005896 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005897 {
5898 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5899 {
5900 if (! first)
5901 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5902 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5903 first = 1;
5904 }
5905 }
5906 if (! first)
5907 vty_out (vty, " Not advertised to any peer");
5908 vty_out (vty, "%s", VTY_NEWLINE);
5909}
5910
5911/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005912static int
paulfee0f4c2004-09-13 05:12:46 +00005913bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005914 struct bgp_table *rib, const char *ip_str,
5915 afi_t afi, safi_t safi, struct prefix_rd *prd,
5916 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005917{
5918 int ret;
5919 int header;
5920 int display = 0;
5921 struct prefix match;
5922 struct bgp_node *rn;
5923 struct bgp_node *rm;
5924 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005925 struct bgp_table *table;
5926
paul718e3742002-12-13 20:15:29 +00005927 /* Check IP address argument. */
5928 ret = str2prefix (ip_str, &match);
5929 if (! ret)
5930 {
5931 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5932 return CMD_WARNING;
5933 }
5934
5935 match.family = afi2family (afi);
5936
5937 if (safi == SAFI_MPLS_VPN)
5938 {
paulfee0f4c2004-09-13 05:12:46 +00005939 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005940 {
5941 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5942 continue;
5943
5944 if ((table = rn->info) != NULL)
5945 {
5946 header = 1;
5947
5948 if ((rm = bgp_node_match (table, &match)) != NULL)
5949 {
5950 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5951 continue;
5952
5953 for (ri = rm->info; ri; ri = ri->next)
5954 {
5955 if (header)
5956 {
5957 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5958 AFI_IP, SAFI_MPLS_VPN);
5959
5960 header = 0;
5961 }
5962 display++;
5963 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5964 }
5965 }
5966 }
5967 }
5968 }
5969 else
5970 {
5971 header = 1;
5972
paulfee0f4c2004-09-13 05:12:46 +00005973 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005974 {
5975 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5976 {
5977 for (ri = rn->info; ri; ri = ri->next)
5978 {
5979 if (header)
5980 {
5981 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5982 header = 0;
5983 }
5984 display++;
5985 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5986 }
5987 }
5988 }
5989 }
5990
5991 if (! display)
5992 {
5993 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5994 return CMD_WARNING;
5995 }
5996
5997 return CMD_SUCCESS;
5998}
5999
paulfee0f4c2004-09-13 05:12:46 +00006000/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006001static int
paulfd79ac92004-10-13 05:06:08 +00006002bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006003 afi_t afi, safi_t safi, struct prefix_rd *prd,
6004 int prefix_check)
6005{
6006 struct bgp *bgp;
6007
6008 /* BGP structure lookup. */
6009 if (view_name)
6010 {
6011 bgp = bgp_lookup_by_name (view_name);
6012 if (bgp == NULL)
6013 {
6014 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6015 return CMD_WARNING;
6016 }
6017 }
6018 else
6019 {
6020 bgp = bgp_get_default ();
6021 if (bgp == NULL)
6022 {
6023 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6024 return CMD_WARNING;
6025 }
6026 }
6027
6028 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6029 afi, safi, prd, prefix_check);
6030}
6031
paul718e3742002-12-13 20:15:29 +00006032/* BGP route print out function. */
6033DEFUN (show_ip_bgp,
6034 show_ip_bgp_cmd,
6035 "show ip bgp",
6036 SHOW_STR
6037 IP_STR
6038 BGP_STR)
6039{
ajs5a646652004-11-05 01:25:55 +00006040 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006041}
6042
6043DEFUN (show_ip_bgp_ipv4,
6044 show_ip_bgp_ipv4_cmd,
6045 "show ip bgp ipv4 (unicast|multicast)",
6046 SHOW_STR
6047 IP_STR
6048 BGP_STR
6049 "Address family\n"
6050 "Address Family modifier\n"
6051 "Address Family modifier\n")
6052{
6053 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006054 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6055 NULL);
paul718e3742002-12-13 20:15:29 +00006056
ajs5a646652004-11-05 01:25:55 +00006057 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006058}
6059
6060DEFUN (show_ip_bgp_route,
6061 show_ip_bgp_route_cmd,
6062 "show ip bgp A.B.C.D",
6063 SHOW_STR
6064 IP_STR
6065 BGP_STR
6066 "Network in the BGP routing table to display\n")
6067{
6068 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6069}
6070
6071DEFUN (show_ip_bgp_ipv4_route,
6072 show_ip_bgp_ipv4_route_cmd,
6073 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6074 SHOW_STR
6075 IP_STR
6076 BGP_STR
6077 "Address family\n"
6078 "Address Family modifier\n"
6079 "Address Family modifier\n"
6080 "Network in the BGP routing table to display\n")
6081{
6082 if (strncmp (argv[0], "m", 1) == 0)
6083 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6084
6085 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6086}
6087
6088DEFUN (show_ip_bgp_vpnv4_all_route,
6089 show_ip_bgp_vpnv4_all_route_cmd,
6090 "show ip bgp vpnv4 all A.B.C.D",
6091 SHOW_STR
6092 IP_STR
6093 BGP_STR
6094 "Display VPNv4 NLRI specific information\n"
6095 "Display information about all VPNv4 NLRIs\n"
6096 "Network in the BGP routing table to display\n")
6097{
6098 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6099}
6100
6101DEFUN (show_ip_bgp_vpnv4_rd_route,
6102 show_ip_bgp_vpnv4_rd_route_cmd,
6103 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6104 SHOW_STR
6105 IP_STR
6106 BGP_STR
6107 "Display VPNv4 NLRI specific information\n"
6108 "Display information for a route distinguisher\n"
6109 "VPN Route Distinguisher\n"
6110 "Network in the BGP routing table to display\n")
6111{
6112 int ret;
6113 struct prefix_rd prd;
6114
6115 ret = str2prefix_rd (argv[0], &prd);
6116 if (! ret)
6117 {
6118 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6119 return CMD_WARNING;
6120 }
6121 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6122}
6123
6124DEFUN (show_ip_bgp_prefix,
6125 show_ip_bgp_prefix_cmd,
6126 "show ip bgp A.B.C.D/M",
6127 SHOW_STR
6128 IP_STR
6129 BGP_STR
6130 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6131{
6132 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6133}
6134
6135DEFUN (show_ip_bgp_ipv4_prefix,
6136 show_ip_bgp_ipv4_prefix_cmd,
6137 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6138 SHOW_STR
6139 IP_STR
6140 BGP_STR
6141 "Address family\n"
6142 "Address Family modifier\n"
6143 "Address Family modifier\n"
6144 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6145{
6146 if (strncmp (argv[0], "m", 1) == 0)
6147 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6148
6149 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6150}
6151
6152DEFUN (show_ip_bgp_vpnv4_all_prefix,
6153 show_ip_bgp_vpnv4_all_prefix_cmd,
6154 "show ip bgp vpnv4 all A.B.C.D/M",
6155 SHOW_STR
6156 IP_STR
6157 BGP_STR
6158 "Display VPNv4 NLRI specific information\n"
6159 "Display information about all VPNv4 NLRIs\n"
6160 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6161{
6162 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6163}
6164
6165DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6166 show_ip_bgp_vpnv4_rd_prefix_cmd,
6167 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6168 SHOW_STR
6169 IP_STR
6170 BGP_STR
6171 "Display VPNv4 NLRI specific information\n"
6172 "Display information for a route distinguisher\n"
6173 "VPN Route Distinguisher\n"
6174 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6175{
6176 int ret;
6177 struct prefix_rd prd;
6178
6179 ret = str2prefix_rd (argv[0], &prd);
6180 if (! ret)
6181 {
6182 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6183 return CMD_WARNING;
6184 }
6185 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6186}
6187
6188DEFUN (show_ip_bgp_view,
6189 show_ip_bgp_view_cmd,
6190 "show ip bgp view WORD",
6191 SHOW_STR
6192 IP_STR
6193 BGP_STR
6194 "BGP view\n"
6195 "BGP view name\n")
6196{
paulbb46e942003-10-24 19:02:03 +00006197 struct bgp *bgp;
6198
6199 /* BGP structure lookup. */
6200 bgp = bgp_lookup_by_name (argv[0]);
6201 if (bgp == NULL)
6202 {
6203 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6204 return CMD_WARNING;
6205 }
6206
ajs5a646652004-11-05 01:25:55 +00006207 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006208}
6209
6210DEFUN (show_ip_bgp_view_route,
6211 show_ip_bgp_view_route_cmd,
6212 "show ip bgp view WORD A.B.C.D",
6213 SHOW_STR
6214 IP_STR
6215 BGP_STR
6216 "BGP view\n"
6217 "BGP view name\n"
6218 "Network in the BGP routing table to display\n")
6219{
6220 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6221}
6222
6223DEFUN (show_ip_bgp_view_prefix,
6224 show_ip_bgp_view_prefix_cmd,
6225 "show ip bgp view WORD A.B.C.D/M",
6226 SHOW_STR
6227 IP_STR
6228 BGP_STR
6229 "BGP view\n"
6230 "BGP view name\n"
6231 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6232{
6233 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6234}
6235
6236#ifdef HAVE_IPV6
6237DEFUN (show_bgp,
6238 show_bgp_cmd,
6239 "show bgp",
6240 SHOW_STR
6241 BGP_STR)
6242{
ajs5a646652004-11-05 01:25:55 +00006243 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6244 NULL);
paul718e3742002-12-13 20:15:29 +00006245}
6246
6247ALIAS (show_bgp,
6248 show_bgp_ipv6_cmd,
6249 "show bgp ipv6",
6250 SHOW_STR
6251 BGP_STR
6252 "Address family\n")
6253
6254/* old command */
6255DEFUN (show_ipv6_bgp,
6256 show_ipv6_bgp_cmd,
6257 "show ipv6 bgp",
6258 SHOW_STR
6259 IP_STR
6260 BGP_STR)
6261{
ajs5a646652004-11-05 01:25:55 +00006262 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6263 NULL);
paul718e3742002-12-13 20:15:29 +00006264}
6265
6266DEFUN (show_bgp_route,
6267 show_bgp_route_cmd,
6268 "show bgp X:X::X:X",
6269 SHOW_STR
6270 BGP_STR
6271 "Network in the BGP routing table to display\n")
6272{
6273 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6274}
6275
6276ALIAS (show_bgp_route,
6277 show_bgp_ipv6_route_cmd,
6278 "show bgp ipv6 X:X::X:X",
6279 SHOW_STR
6280 BGP_STR
6281 "Address family\n"
6282 "Network in the BGP routing table to display\n")
6283
6284/* old command */
6285DEFUN (show_ipv6_bgp_route,
6286 show_ipv6_bgp_route_cmd,
6287 "show ipv6 bgp X:X::X:X",
6288 SHOW_STR
6289 IP_STR
6290 BGP_STR
6291 "Network in the BGP routing table to display\n")
6292{
6293 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6294}
6295
6296DEFUN (show_bgp_prefix,
6297 show_bgp_prefix_cmd,
6298 "show bgp X:X::X:X/M",
6299 SHOW_STR
6300 BGP_STR
6301 "IPv6 prefix <network>/<length>\n")
6302{
6303 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6304}
6305
6306ALIAS (show_bgp_prefix,
6307 show_bgp_ipv6_prefix_cmd,
6308 "show bgp ipv6 X:X::X:X/M",
6309 SHOW_STR
6310 BGP_STR
6311 "Address family\n"
6312 "IPv6 prefix <network>/<length>\n")
6313
6314/* old command */
6315DEFUN (show_ipv6_bgp_prefix,
6316 show_ipv6_bgp_prefix_cmd,
6317 "show ipv6 bgp X:X::X:X/M",
6318 SHOW_STR
6319 IP_STR
6320 BGP_STR
6321 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6322{
6323 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6324}
6325
paulbb46e942003-10-24 19:02:03 +00006326DEFUN (show_bgp_view,
6327 show_bgp_view_cmd,
6328 "show bgp view WORD",
6329 SHOW_STR
6330 BGP_STR
6331 "BGP view\n"
6332 "View name\n")
6333{
6334 struct bgp *bgp;
6335
6336 /* BGP structure lookup. */
6337 bgp = bgp_lookup_by_name (argv[0]);
6338 if (bgp == NULL)
6339 {
6340 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6341 return CMD_WARNING;
6342 }
6343
ajs5a646652004-11-05 01:25:55 +00006344 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006345}
6346
6347ALIAS (show_bgp_view,
6348 show_bgp_view_ipv6_cmd,
6349 "show bgp view WORD ipv6",
6350 SHOW_STR
6351 BGP_STR
6352 "BGP view\n"
6353 "View name\n"
6354 "Address family\n")
6355
6356DEFUN (show_bgp_view_route,
6357 show_bgp_view_route_cmd,
6358 "show bgp view WORD X:X::X:X",
6359 SHOW_STR
6360 BGP_STR
6361 "BGP view\n"
6362 "View name\n"
6363 "Network in the BGP routing table to display\n")
6364{
6365 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6366}
6367
6368ALIAS (show_bgp_view_route,
6369 show_bgp_view_ipv6_route_cmd,
6370 "show bgp view WORD ipv6 X:X::X:X",
6371 SHOW_STR
6372 BGP_STR
6373 "BGP view\n"
6374 "View name\n"
6375 "Address family\n"
6376 "Network in the BGP routing table to display\n")
6377
6378DEFUN (show_bgp_view_prefix,
6379 show_bgp_view_prefix_cmd,
6380 "show bgp view WORD X:X::X:X/M",
6381 SHOW_STR
6382 BGP_STR
6383 "BGP view\n"
6384 "View name\n"
6385 "IPv6 prefix <network>/<length>\n")
6386{
6387 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6388}
6389
6390ALIAS (show_bgp_view_prefix,
6391 show_bgp_view_ipv6_prefix_cmd,
6392 "show bgp view WORD ipv6 X:X::X:X/M",
6393 SHOW_STR
6394 BGP_STR
6395 "BGP view\n"
6396 "View name\n"
6397 "Address family\n"
6398 "IPv6 prefix <network>/<length>\n")
6399
paul718e3742002-12-13 20:15:29 +00006400/* old command */
6401DEFUN (show_ipv6_mbgp,
6402 show_ipv6_mbgp_cmd,
6403 "show ipv6 mbgp",
6404 SHOW_STR
6405 IP_STR
6406 MBGP_STR)
6407{
ajs5a646652004-11-05 01:25:55 +00006408 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6409 NULL);
paul718e3742002-12-13 20:15:29 +00006410}
6411
6412/* old command */
6413DEFUN (show_ipv6_mbgp_route,
6414 show_ipv6_mbgp_route_cmd,
6415 "show ipv6 mbgp X:X::X:X",
6416 SHOW_STR
6417 IP_STR
6418 MBGP_STR
6419 "Network in the MBGP routing table to display\n")
6420{
6421 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6422}
6423
6424/* old command */
6425DEFUN (show_ipv6_mbgp_prefix,
6426 show_ipv6_mbgp_prefix_cmd,
6427 "show ipv6 mbgp X:X::X:X/M",
6428 SHOW_STR
6429 IP_STR
6430 MBGP_STR
6431 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6432{
6433 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6434}
6435#endif
6436
paul718e3742002-12-13 20:15:29 +00006437
paul94f2b392005-06-28 12:44:16 +00006438static int
paulfd79ac92004-10-13 05:06:08 +00006439bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006440 safi_t safi, enum bgp_show_type type)
6441{
6442 int i;
6443 struct buffer *b;
6444 char *regstr;
6445 int first;
6446 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006447 int rc;
paul718e3742002-12-13 20:15:29 +00006448
6449 first = 0;
6450 b = buffer_new (1024);
6451 for (i = 0; i < argc; i++)
6452 {
6453 if (first)
6454 buffer_putc (b, ' ');
6455 else
6456 {
6457 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6458 continue;
6459 first = 1;
6460 }
6461
6462 buffer_putstr (b, argv[i]);
6463 }
6464 buffer_putc (b, '\0');
6465
6466 regstr = buffer_getstr (b);
6467 buffer_free (b);
6468
6469 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006470 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006471 if (! regex)
6472 {
6473 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6474 VTY_NEWLINE);
6475 return CMD_WARNING;
6476 }
6477
ajs5a646652004-11-05 01:25:55 +00006478 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6479 bgp_regex_free (regex);
6480 return rc;
paul718e3742002-12-13 20:15:29 +00006481}
6482
6483DEFUN (show_ip_bgp_regexp,
6484 show_ip_bgp_regexp_cmd,
6485 "show ip bgp regexp .LINE",
6486 SHOW_STR
6487 IP_STR
6488 BGP_STR
6489 "Display routes matching the AS path regular expression\n"
6490 "A regular-expression to match the BGP AS paths\n")
6491{
6492 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6493 bgp_show_type_regexp);
6494}
6495
6496DEFUN (show_ip_bgp_flap_regexp,
6497 show_ip_bgp_flap_regexp_cmd,
6498 "show ip bgp flap-statistics regexp .LINE",
6499 SHOW_STR
6500 IP_STR
6501 BGP_STR
6502 "Display flap statistics of routes\n"
6503 "Display routes matching the AS path regular expression\n"
6504 "A regular-expression to match the BGP AS paths\n")
6505{
6506 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6507 bgp_show_type_flap_regexp);
6508}
6509
6510DEFUN (show_ip_bgp_ipv4_regexp,
6511 show_ip_bgp_ipv4_regexp_cmd,
6512 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6513 SHOW_STR
6514 IP_STR
6515 BGP_STR
6516 "Address family\n"
6517 "Address Family modifier\n"
6518 "Address Family modifier\n"
6519 "Display routes matching the AS path regular expression\n"
6520 "A regular-expression to match the BGP AS paths\n")
6521{
6522 if (strncmp (argv[0], "m", 1) == 0)
6523 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6524 bgp_show_type_regexp);
6525
6526 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6527 bgp_show_type_regexp);
6528}
6529
6530#ifdef HAVE_IPV6
6531DEFUN (show_bgp_regexp,
6532 show_bgp_regexp_cmd,
6533 "show bgp regexp .LINE",
6534 SHOW_STR
6535 BGP_STR
6536 "Display routes matching the AS path regular expression\n"
6537 "A regular-expression to match the BGP AS paths\n")
6538{
6539 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6540 bgp_show_type_regexp);
6541}
6542
6543ALIAS (show_bgp_regexp,
6544 show_bgp_ipv6_regexp_cmd,
6545 "show bgp ipv6 regexp .LINE",
6546 SHOW_STR
6547 BGP_STR
6548 "Address family\n"
6549 "Display routes matching the AS path regular expression\n"
6550 "A regular-expression to match the BGP AS paths\n")
6551
6552/* old command */
6553DEFUN (show_ipv6_bgp_regexp,
6554 show_ipv6_bgp_regexp_cmd,
6555 "show ipv6 bgp regexp .LINE",
6556 SHOW_STR
6557 IP_STR
6558 BGP_STR
6559 "Display routes matching the AS path regular expression\n"
6560 "A regular-expression to match the BGP AS paths\n")
6561{
6562 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6563 bgp_show_type_regexp);
6564}
6565
6566/* old command */
6567DEFUN (show_ipv6_mbgp_regexp,
6568 show_ipv6_mbgp_regexp_cmd,
6569 "show ipv6 mbgp regexp .LINE",
6570 SHOW_STR
6571 IP_STR
6572 BGP_STR
6573 "Display routes matching the AS path regular expression\n"
6574 "A regular-expression to match the MBGP AS paths\n")
6575{
6576 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6577 bgp_show_type_regexp);
6578}
6579#endif /* HAVE_IPV6 */
6580
paul94f2b392005-06-28 12:44:16 +00006581static int
paulfd79ac92004-10-13 05:06:08 +00006582bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006583 safi_t safi, enum bgp_show_type type)
6584{
6585 struct prefix_list *plist;
6586
6587 plist = prefix_list_lookup (afi, prefix_list_str);
6588 if (plist == NULL)
6589 {
6590 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6591 prefix_list_str, VTY_NEWLINE);
6592 return CMD_WARNING;
6593 }
6594
ajs5a646652004-11-05 01:25:55 +00006595 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006596}
6597
6598DEFUN (show_ip_bgp_prefix_list,
6599 show_ip_bgp_prefix_list_cmd,
6600 "show ip bgp prefix-list WORD",
6601 SHOW_STR
6602 IP_STR
6603 BGP_STR
6604 "Display routes conforming to the prefix-list\n"
6605 "IP prefix-list name\n")
6606{
6607 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6608 bgp_show_type_prefix_list);
6609}
6610
6611DEFUN (show_ip_bgp_flap_prefix_list,
6612 show_ip_bgp_flap_prefix_list_cmd,
6613 "show ip bgp flap-statistics prefix-list WORD",
6614 SHOW_STR
6615 IP_STR
6616 BGP_STR
6617 "Display flap statistics of routes\n"
6618 "Display routes conforming to the prefix-list\n"
6619 "IP prefix-list name\n")
6620{
6621 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6622 bgp_show_type_flap_prefix_list);
6623}
6624
6625DEFUN (show_ip_bgp_ipv4_prefix_list,
6626 show_ip_bgp_ipv4_prefix_list_cmd,
6627 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6628 SHOW_STR
6629 IP_STR
6630 BGP_STR
6631 "Address family\n"
6632 "Address Family modifier\n"
6633 "Address Family modifier\n"
6634 "Display routes conforming to the prefix-list\n"
6635 "IP prefix-list name\n")
6636{
6637 if (strncmp (argv[0], "m", 1) == 0)
6638 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6639 bgp_show_type_prefix_list);
6640
6641 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6642 bgp_show_type_prefix_list);
6643}
6644
6645#ifdef HAVE_IPV6
6646DEFUN (show_bgp_prefix_list,
6647 show_bgp_prefix_list_cmd,
6648 "show bgp prefix-list WORD",
6649 SHOW_STR
6650 BGP_STR
6651 "Display routes conforming to the prefix-list\n"
6652 "IPv6 prefix-list name\n")
6653{
6654 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6655 bgp_show_type_prefix_list);
6656}
6657
6658ALIAS (show_bgp_prefix_list,
6659 show_bgp_ipv6_prefix_list_cmd,
6660 "show bgp ipv6 prefix-list WORD",
6661 SHOW_STR
6662 BGP_STR
6663 "Address family\n"
6664 "Display routes conforming to the prefix-list\n"
6665 "IPv6 prefix-list name\n")
6666
6667/* old command */
6668DEFUN (show_ipv6_bgp_prefix_list,
6669 show_ipv6_bgp_prefix_list_cmd,
6670 "show ipv6 bgp prefix-list WORD",
6671 SHOW_STR
6672 IPV6_STR
6673 BGP_STR
6674 "Display routes matching the prefix-list\n"
6675 "IPv6 prefix-list name\n")
6676{
6677 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6678 bgp_show_type_prefix_list);
6679}
6680
6681/* old command */
6682DEFUN (show_ipv6_mbgp_prefix_list,
6683 show_ipv6_mbgp_prefix_list_cmd,
6684 "show ipv6 mbgp prefix-list WORD",
6685 SHOW_STR
6686 IPV6_STR
6687 MBGP_STR
6688 "Display routes matching the prefix-list\n"
6689 "IPv6 prefix-list name\n")
6690{
6691 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6692 bgp_show_type_prefix_list);
6693}
6694#endif /* HAVE_IPV6 */
6695
paul94f2b392005-06-28 12:44:16 +00006696static int
paulfd79ac92004-10-13 05:06:08 +00006697bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006698 safi_t safi, enum bgp_show_type type)
6699{
6700 struct as_list *as_list;
6701
6702 as_list = as_list_lookup (filter);
6703 if (as_list == NULL)
6704 {
6705 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6706 return CMD_WARNING;
6707 }
6708
ajs5a646652004-11-05 01:25:55 +00006709 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006710}
6711
6712DEFUN (show_ip_bgp_filter_list,
6713 show_ip_bgp_filter_list_cmd,
6714 "show ip bgp filter-list WORD",
6715 SHOW_STR
6716 IP_STR
6717 BGP_STR
6718 "Display routes conforming to the filter-list\n"
6719 "Regular expression access list name\n")
6720{
6721 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6722 bgp_show_type_filter_list);
6723}
6724
6725DEFUN (show_ip_bgp_flap_filter_list,
6726 show_ip_bgp_flap_filter_list_cmd,
6727 "show ip bgp flap-statistics filter-list WORD",
6728 SHOW_STR
6729 IP_STR
6730 BGP_STR
6731 "Display flap statistics of routes\n"
6732 "Display routes conforming to the filter-list\n"
6733 "Regular expression access list name\n")
6734{
6735 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6736 bgp_show_type_flap_filter_list);
6737}
6738
6739DEFUN (show_ip_bgp_ipv4_filter_list,
6740 show_ip_bgp_ipv4_filter_list_cmd,
6741 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6742 SHOW_STR
6743 IP_STR
6744 BGP_STR
6745 "Address family\n"
6746 "Address Family modifier\n"
6747 "Address Family modifier\n"
6748 "Display routes conforming to the filter-list\n"
6749 "Regular expression access list name\n")
6750{
6751 if (strncmp (argv[0], "m", 1) == 0)
6752 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6753 bgp_show_type_filter_list);
6754
6755 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6756 bgp_show_type_filter_list);
6757}
6758
6759#ifdef HAVE_IPV6
6760DEFUN (show_bgp_filter_list,
6761 show_bgp_filter_list_cmd,
6762 "show bgp filter-list WORD",
6763 SHOW_STR
6764 BGP_STR
6765 "Display routes conforming to the filter-list\n"
6766 "Regular expression access list name\n")
6767{
6768 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6769 bgp_show_type_filter_list);
6770}
6771
6772ALIAS (show_bgp_filter_list,
6773 show_bgp_ipv6_filter_list_cmd,
6774 "show bgp ipv6 filter-list WORD",
6775 SHOW_STR
6776 BGP_STR
6777 "Address family\n"
6778 "Display routes conforming to the filter-list\n"
6779 "Regular expression access list name\n")
6780
6781/* old command */
6782DEFUN (show_ipv6_bgp_filter_list,
6783 show_ipv6_bgp_filter_list_cmd,
6784 "show ipv6 bgp filter-list WORD",
6785 SHOW_STR
6786 IPV6_STR
6787 BGP_STR
6788 "Display routes conforming to the filter-list\n"
6789 "Regular expression access list name\n")
6790{
6791 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6792 bgp_show_type_filter_list);
6793}
6794
6795/* old command */
6796DEFUN (show_ipv6_mbgp_filter_list,
6797 show_ipv6_mbgp_filter_list_cmd,
6798 "show ipv6 mbgp filter-list WORD",
6799 SHOW_STR
6800 IPV6_STR
6801 MBGP_STR
6802 "Display routes conforming to the filter-list\n"
6803 "Regular expression access list name\n")
6804{
6805 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6806 bgp_show_type_filter_list);
6807}
6808#endif /* HAVE_IPV6 */
6809
paul94f2b392005-06-28 12:44:16 +00006810static int
paulfd79ac92004-10-13 05:06:08 +00006811bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006812 safi_t safi, enum bgp_show_type type)
6813{
6814 struct route_map *rmap;
6815
6816 rmap = route_map_lookup_by_name (rmap_str);
6817 if (! rmap)
6818 {
6819 vty_out (vty, "%% %s is not a valid route-map name%s",
6820 rmap_str, VTY_NEWLINE);
6821 return CMD_WARNING;
6822 }
6823
ajs5a646652004-11-05 01:25:55 +00006824 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006825}
6826
6827DEFUN (show_ip_bgp_route_map,
6828 show_ip_bgp_route_map_cmd,
6829 "show ip bgp route-map WORD",
6830 SHOW_STR
6831 IP_STR
6832 BGP_STR
6833 "Display routes matching the route-map\n"
6834 "A route-map to match on\n")
6835{
6836 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6837 bgp_show_type_route_map);
6838}
6839
6840DEFUN (show_ip_bgp_flap_route_map,
6841 show_ip_bgp_flap_route_map_cmd,
6842 "show ip bgp flap-statistics route-map WORD",
6843 SHOW_STR
6844 IP_STR
6845 BGP_STR
6846 "Display flap statistics of routes\n"
6847 "Display routes matching the route-map\n"
6848 "A route-map to match on\n")
6849{
6850 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6851 bgp_show_type_flap_route_map);
6852}
6853
6854DEFUN (show_ip_bgp_ipv4_route_map,
6855 show_ip_bgp_ipv4_route_map_cmd,
6856 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6857 SHOW_STR
6858 IP_STR
6859 BGP_STR
6860 "Address family\n"
6861 "Address Family modifier\n"
6862 "Address Family modifier\n"
6863 "Display routes matching the route-map\n"
6864 "A route-map to match on\n")
6865{
6866 if (strncmp (argv[0], "m", 1) == 0)
6867 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6868 bgp_show_type_route_map);
6869
6870 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6871 bgp_show_type_route_map);
6872}
6873
6874DEFUN (show_bgp_route_map,
6875 show_bgp_route_map_cmd,
6876 "show bgp route-map WORD",
6877 SHOW_STR
6878 BGP_STR
6879 "Display routes matching the route-map\n"
6880 "A route-map to match on\n")
6881{
6882 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6883 bgp_show_type_route_map);
6884}
6885
6886ALIAS (show_bgp_route_map,
6887 show_bgp_ipv6_route_map_cmd,
6888 "show bgp ipv6 route-map WORD",
6889 SHOW_STR
6890 BGP_STR
6891 "Address family\n"
6892 "Display routes matching the route-map\n"
6893 "A route-map to match on\n")
6894
6895DEFUN (show_ip_bgp_cidr_only,
6896 show_ip_bgp_cidr_only_cmd,
6897 "show ip bgp cidr-only",
6898 SHOW_STR
6899 IP_STR
6900 BGP_STR
6901 "Display only routes with non-natural netmasks\n")
6902{
6903 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006904 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006905}
6906
6907DEFUN (show_ip_bgp_flap_cidr_only,
6908 show_ip_bgp_flap_cidr_only_cmd,
6909 "show ip bgp flap-statistics cidr-only",
6910 SHOW_STR
6911 IP_STR
6912 BGP_STR
6913 "Display flap statistics of routes\n"
6914 "Display only routes with non-natural netmasks\n")
6915{
6916 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006917 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006918}
6919
6920DEFUN (show_ip_bgp_ipv4_cidr_only,
6921 show_ip_bgp_ipv4_cidr_only_cmd,
6922 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6923 SHOW_STR
6924 IP_STR
6925 BGP_STR
6926 "Address family\n"
6927 "Address Family modifier\n"
6928 "Address Family modifier\n"
6929 "Display only routes with non-natural netmasks\n")
6930{
6931 if (strncmp (argv[0], "m", 1) == 0)
6932 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006933 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006934
6935 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006936 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006937}
6938
6939DEFUN (show_ip_bgp_community_all,
6940 show_ip_bgp_community_all_cmd,
6941 "show ip bgp community",
6942 SHOW_STR
6943 IP_STR
6944 BGP_STR
6945 "Display routes matching the communities\n")
6946{
6947 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006948 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006949}
6950
6951DEFUN (show_ip_bgp_ipv4_community_all,
6952 show_ip_bgp_ipv4_community_all_cmd,
6953 "show ip bgp ipv4 (unicast|multicast) community",
6954 SHOW_STR
6955 IP_STR
6956 BGP_STR
6957 "Address family\n"
6958 "Address Family modifier\n"
6959 "Address Family modifier\n"
6960 "Display routes matching the communities\n")
6961{
6962 if (strncmp (argv[0], "m", 1) == 0)
6963 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006964 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006965
6966 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006967 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006968}
6969
6970#ifdef HAVE_IPV6
6971DEFUN (show_bgp_community_all,
6972 show_bgp_community_all_cmd,
6973 "show bgp community",
6974 SHOW_STR
6975 BGP_STR
6976 "Display routes matching the communities\n")
6977{
6978 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006979 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006980}
6981
6982ALIAS (show_bgp_community_all,
6983 show_bgp_ipv6_community_all_cmd,
6984 "show bgp ipv6 community",
6985 SHOW_STR
6986 BGP_STR
6987 "Address family\n"
6988 "Display routes matching the communities\n")
6989
6990/* old command */
6991DEFUN (show_ipv6_bgp_community_all,
6992 show_ipv6_bgp_community_all_cmd,
6993 "show ipv6 bgp community",
6994 SHOW_STR
6995 IPV6_STR
6996 BGP_STR
6997 "Display routes matching the communities\n")
6998{
6999 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007000 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007001}
7002
7003/* old command */
7004DEFUN (show_ipv6_mbgp_community_all,
7005 show_ipv6_mbgp_community_all_cmd,
7006 "show ipv6 mbgp community",
7007 SHOW_STR
7008 IPV6_STR
7009 MBGP_STR
7010 "Display routes matching the communities\n")
7011{
7012 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007013 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007014}
7015#endif /* HAVE_IPV6 */
7016
paul94f2b392005-06-28 12:44:16 +00007017static int
paulfd79ac92004-10-13 05:06:08 +00007018bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7019 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007020{
7021 struct community *com;
7022 struct buffer *b;
7023 int i;
7024 char *str;
7025 int first = 0;
7026
7027 b = buffer_new (1024);
7028 for (i = 0; i < argc; i++)
7029 {
7030 if (first)
7031 buffer_putc (b, ' ');
7032 else
7033 {
7034 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7035 continue;
7036 first = 1;
7037 }
7038
7039 buffer_putstr (b, argv[i]);
7040 }
7041 buffer_putc (b, '\0');
7042
7043 str = buffer_getstr (b);
7044 buffer_free (b);
7045
7046 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007047 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007048 if (! com)
7049 {
7050 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7051 return CMD_WARNING;
7052 }
7053
ajs5a646652004-11-05 01:25:55 +00007054 return bgp_show (vty, NULL, afi, safi,
7055 (exact ? bgp_show_type_community_exact :
7056 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007057}
7058
7059DEFUN (show_ip_bgp_community,
7060 show_ip_bgp_community_cmd,
7061 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7062 SHOW_STR
7063 IP_STR
7064 BGP_STR
7065 "Display routes matching the communities\n"
7066 "community number\n"
7067 "Do not send outside local AS (well-known community)\n"
7068 "Do not advertise to any peer (well-known community)\n"
7069 "Do not export to next AS (well-known community)\n")
7070{
7071 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7072}
7073
7074ALIAS (show_ip_bgp_community,
7075 show_ip_bgp_community2_cmd,
7076 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7077 SHOW_STR
7078 IP_STR
7079 BGP_STR
7080 "Display routes matching the communities\n"
7081 "community number\n"
7082 "Do not send outside local AS (well-known community)\n"
7083 "Do not advertise to any peer (well-known community)\n"
7084 "Do not export to next AS (well-known community)\n"
7085 "community number\n"
7086 "Do not send outside local AS (well-known community)\n"
7087 "Do not advertise to any peer (well-known community)\n"
7088 "Do not export to next AS (well-known community)\n")
7089
7090ALIAS (show_ip_bgp_community,
7091 show_ip_bgp_community3_cmd,
7092 "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)",
7093 SHOW_STR
7094 IP_STR
7095 BGP_STR
7096 "Display routes matching the communities\n"
7097 "community number\n"
7098 "Do not send outside local AS (well-known community)\n"
7099 "Do not advertise to any peer (well-known community)\n"
7100 "Do not export to next AS (well-known community)\n"
7101 "community number\n"
7102 "Do not send outside local AS (well-known community)\n"
7103 "Do not advertise to any peer (well-known community)\n"
7104 "Do not export to next AS (well-known community)\n"
7105 "community number\n"
7106 "Do not send outside local AS (well-known community)\n"
7107 "Do not advertise to any peer (well-known community)\n"
7108 "Do not export to next AS (well-known community)\n")
7109
7110ALIAS (show_ip_bgp_community,
7111 show_ip_bgp_community4_cmd,
7112 "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)",
7113 SHOW_STR
7114 IP_STR
7115 BGP_STR
7116 "Display routes matching the communities\n"
7117 "community number\n"
7118 "Do not send outside local AS (well-known community)\n"
7119 "Do not advertise to any peer (well-known community)\n"
7120 "Do not export to next AS (well-known community)\n"
7121 "community number\n"
7122 "Do not send outside local AS (well-known community)\n"
7123 "Do not advertise to any peer (well-known community)\n"
7124 "Do not export to next AS (well-known community)\n"
7125 "community number\n"
7126 "Do not send outside local AS (well-known community)\n"
7127 "Do not advertise to any peer (well-known community)\n"
7128 "Do not export to next AS (well-known community)\n"
7129 "community number\n"
7130 "Do not send outside local AS (well-known community)\n"
7131 "Do not advertise to any peer (well-known community)\n"
7132 "Do not export to next AS (well-known community)\n")
7133
7134DEFUN (show_ip_bgp_ipv4_community,
7135 show_ip_bgp_ipv4_community_cmd,
7136 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7137 SHOW_STR
7138 IP_STR
7139 BGP_STR
7140 "Address family\n"
7141 "Address Family modifier\n"
7142 "Address Family modifier\n"
7143 "Display routes matching the communities\n"
7144 "community number\n"
7145 "Do not send outside local AS (well-known community)\n"
7146 "Do not advertise to any peer (well-known community)\n"
7147 "Do not export to next AS (well-known community)\n")
7148{
7149 if (strncmp (argv[0], "m", 1) == 0)
7150 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7151
7152 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7153}
7154
7155ALIAS (show_ip_bgp_ipv4_community,
7156 show_ip_bgp_ipv4_community2_cmd,
7157 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7158 SHOW_STR
7159 IP_STR
7160 BGP_STR
7161 "Address family\n"
7162 "Address Family modifier\n"
7163 "Address Family modifier\n"
7164 "Display routes matching the communities\n"
7165 "community number\n"
7166 "Do not send outside local AS (well-known community)\n"
7167 "Do not advertise to any peer (well-known community)\n"
7168 "Do not export to next AS (well-known community)\n"
7169 "community number\n"
7170 "Do not send outside local AS (well-known community)\n"
7171 "Do not advertise to any peer (well-known community)\n"
7172 "Do not export to next AS (well-known community)\n")
7173
7174ALIAS (show_ip_bgp_ipv4_community,
7175 show_ip_bgp_ipv4_community3_cmd,
7176 "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)",
7177 SHOW_STR
7178 IP_STR
7179 BGP_STR
7180 "Address family\n"
7181 "Address Family modifier\n"
7182 "Address Family modifier\n"
7183 "Display routes matching the communities\n"
7184 "community number\n"
7185 "Do not send outside local AS (well-known community)\n"
7186 "Do not advertise to any peer (well-known community)\n"
7187 "Do not export to next AS (well-known community)\n"
7188 "community number\n"
7189 "Do not send outside local AS (well-known community)\n"
7190 "Do not advertise to any peer (well-known community)\n"
7191 "Do not export to next AS (well-known community)\n"
7192 "community number\n"
7193 "Do not send outside local AS (well-known community)\n"
7194 "Do not advertise to any peer (well-known community)\n"
7195 "Do not export to next AS (well-known community)\n")
7196
7197ALIAS (show_ip_bgp_ipv4_community,
7198 show_ip_bgp_ipv4_community4_cmd,
7199 "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)",
7200 SHOW_STR
7201 IP_STR
7202 BGP_STR
7203 "Address family\n"
7204 "Address Family modifier\n"
7205 "Address Family modifier\n"
7206 "Display routes matching the communities\n"
7207 "community number\n"
7208 "Do not send outside local AS (well-known community)\n"
7209 "Do not advertise to any peer (well-known community)\n"
7210 "Do not export to next AS (well-known community)\n"
7211 "community number\n"
7212 "Do not send outside local AS (well-known community)\n"
7213 "Do not advertise to any peer (well-known community)\n"
7214 "Do not export to next AS (well-known community)\n"
7215 "community number\n"
7216 "Do not send outside local AS (well-known community)\n"
7217 "Do not advertise to any peer (well-known community)\n"
7218 "Do not export to next AS (well-known community)\n"
7219 "community number\n"
7220 "Do not send outside local AS (well-known community)\n"
7221 "Do not advertise to any peer (well-known community)\n"
7222 "Do not export to next AS (well-known community)\n")
7223
7224DEFUN (show_ip_bgp_community_exact,
7225 show_ip_bgp_community_exact_cmd,
7226 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7227 SHOW_STR
7228 IP_STR
7229 BGP_STR
7230 "Display routes matching the communities\n"
7231 "community number\n"
7232 "Do not send outside local AS (well-known community)\n"
7233 "Do not advertise to any peer (well-known community)\n"
7234 "Do not export to next AS (well-known community)\n"
7235 "Exact match of the communities")
7236{
7237 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7238}
7239
7240ALIAS (show_ip_bgp_community_exact,
7241 show_ip_bgp_community2_exact_cmd,
7242 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7243 SHOW_STR
7244 IP_STR
7245 BGP_STR
7246 "Display routes matching the communities\n"
7247 "community number\n"
7248 "Do not send outside local AS (well-known community)\n"
7249 "Do not advertise to any peer (well-known community)\n"
7250 "Do not export to next AS (well-known community)\n"
7251 "community number\n"
7252 "Do not send outside local AS (well-known community)\n"
7253 "Do not advertise to any peer (well-known community)\n"
7254 "Do not export to next AS (well-known community)\n"
7255 "Exact match of the communities")
7256
7257ALIAS (show_ip_bgp_community_exact,
7258 show_ip_bgp_community3_exact_cmd,
7259 "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",
7260 SHOW_STR
7261 IP_STR
7262 BGP_STR
7263 "Display routes matching the communities\n"
7264 "community number\n"
7265 "Do not send outside local AS (well-known community)\n"
7266 "Do not advertise to any peer (well-known community)\n"
7267 "Do not export to next AS (well-known community)\n"
7268 "community number\n"
7269 "Do not send outside local AS (well-known community)\n"
7270 "Do not advertise to any peer (well-known community)\n"
7271 "Do not export to next AS (well-known community)\n"
7272 "community number\n"
7273 "Do not send outside local AS (well-known community)\n"
7274 "Do not advertise to any peer (well-known community)\n"
7275 "Do not export to next AS (well-known community)\n"
7276 "Exact match of the communities")
7277
7278ALIAS (show_ip_bgp_community_exact,
7279 show_ip_bgp_community4_exact_cmd,
7280 "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",
7281 SHOW_STR
7282 IP_STR
7283 BGP_STR
7284 "Display routes matching the communities\n"
7285 "community number\n"
7286 "Do not send outside local AS (well-known community)\n"
7287 "Do not advertise to any peer (well-known community)\n"
7288 "Do not export to next AS (well-known community)\n"
7289 "community number\n"
7290 "Do not send outside local AS (well-known community)\n"
7291 "Do not advertise to any peer (well-known community)\n"
7292 "Do not export to next AS (well-known community)\n"
7293 "community number\n"
7294 "Do not send outside local AS (well-known community)\n"
7295 "Do not advertise to any peer (well-known community)\n"
7296 "Do not export to next AS (well-known community)\n"
7297 "community number\n"
7298 "Do not send outside local AS (well-known community)\n"
7299 "Do not advertise to any peer (well-known community)\n"
7300 "Do not export to next AS (well-known community)\n"
7301 "Exact match of the communities")
7302
7303DEFUN (show_ip_bgp_ipv4_community_exact,
7304 show_ip_bgp_ipv4_community_exact_cmd,
7305 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7306 SHOW_STR
7307 IP_STR
7308 BGP_STR
7309 "Address family\n"
7310 "Address Family modifier\n"
7311 "Address Family modifier\n"
7312 "Display routes matching the communities\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{
7319 if (strncmp (argv[0], "m", 1) == 0)
7320 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7321
7322 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7323}
7324
7325ALIAS (show_ip_bgp_ipv4_community_exact,
7326 show_ip_bgp_ipv4_community2_exact_cmd,
7327 "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",
7328 SHOW_STR
7329 IP_STR
7330 BGP_STR
7331 "Address family\n"
7332 "Address Family modifier\n"
7333 "Address Family modifier\n"
7334 "Display routes matching the communities\n"
7335 "community number\n"
7336 "Do not send outside local AS (well-known community)\n"
7337 "Do not advertise to any peer (well-known community)\n"
7338 "Do not export to next AS (well-known community)\n"
7339 "community number\n"
7340 "Do not send outside local AS (well-known community)\n"
7341 "Do not advertise to any peer (well-known community)\n"
7342 "Do not export to next AS (well-known community)\n"
7343 "Exact match of the communities")
7344
7345ALIAS (show_ip_bgp_ipv4_community_exact,
7346 show_ip_bgp_ipv4_community3_exact_cmd,
7347 "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",
7348 SHOW_STR
7349 IP_STR
7350 BGP_STR
7351 "Address family\n"
7352 "Address Family modifier\n"
7353 "Address Family modifier\n"
7354 "Display routes matching the communities\n"
7355 "community number\n"
7356 "Do not send outside local AS (well-known community)\n"
7357 "Do not advertise to any peer (well-known community)\n"
7358 "Do not export to next AS (well-known community)\n"
7359 "community number\n"
7360 "Do not send outside local AS (well-known community)\n"
7361 "Do not advertise to any peer (well-known community)\n"
7362 "Do not export to next AS (well-known community)\n"
7363 "community number\n"
7364 "Do not send outside local AS (well-known community)\n"
7365 "Do not advertise to any peer (well-known community)\n"
7366 "Do not export to next AS (well-known community)\n"
7367 "Exact match of the communities")
7368
7369ALIAS (show_ip_bgp_ipv4_community_exact,
7370 show_ip_bgp_ipv4_community4_exact_cmd,
7371 "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",
7372 SHOW_STR
7373 IP_STR
7374 BGP_STR
7375 "Address family\n"
7376 "Address Family modifier\n"
7377 "Address Family modifier\n"
7378 "Display routes matching the communities\n"
7379 "community number\n"
7380 "Do not send outside local AS (well-known community)\n"
7381 "Do not advertise to any peer (well-known community)\n"
7382 "Do not export to next AS (well-known community)\n"
7383 "community number\n"
7384 "Do not send outside local AS (well-known community)\n"
7385 "Do not advertise to any peer (well-known community)\n"
7386 "Do not export to next AS (well-known community)\n"
7387 "community number\n"
7388 "Do not send outside local AS (well-known community)\n"
7389 "Do not advertise to any peer (well-known community)\n"
7390 "Do not export to next AS (well-known community)\n"
7391 "community number\n"
7392 "Do not send outside local AS (well-known community)\n"
7393 "Do not advertise to any peer (well-known community)\n"
7394 "Do not export to next AS (well-known community)\n"
7395 "Exact match of the communities")
7396
7397#ifdef HAVE_IPV6
7398DEFUN (show_bgp_community,
7399 show_bgp_community_cmd,
7400 "show bgp community (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{
7409 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7410}
7411
7412ALIAS (show_bgp_community,
7413 show_bgp_ipv6_community_cmd,
7414 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7415 SHOW_STR
7416 BGP_STR
7417 "Address family\n"
7418 "Display routes matching the communities\n"
7419 "community number\n"
7420 "Do not send outside local AS (well-known community)\n"
7421 "Do not advertise to any peer (well-known community)\n"
7422 "Do not export to next AS (well-known community)\n")
7423
7424ALIAS (show_bgp_community,
7425 show_bgp_community2_cmd,
7426 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7427 SHOW_STR
7428 BGP_STR
7429 "Display routes matching the communities\n"
7430 "community number\n"
7431 "Do not send outside local AS (well-known community)\n"
7432 "Do not advertise to any peer (well-known community)\n"
7433 "Do not export to next AS (well-known community)\n"
7434 "community number\n"
7435 "Do not send outside local AS (well-known community)\n"
7436 "Do not advertise to any peer (well-known community)\n"
7437 "Do not export to next AS (well-known community)\n")
7438
7439ALIAS (show_bgp_community,
7440 show_bgp_ipv6_community2_cmd,
7441 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7442 SHOW_STR
7443 BGP_STR
7444 "Address family\n"
7445 "Display routes matching the communities\n"
7446 "community number\n"
7447 "Do not send outside local AS (well-known community)\n"
7448 "Do not advertise to any peer (well-known community)\n"
7449 "Do not export to next AS (well-known community)\n"
7450 "community number\n"
7451 "Do not send outside local AS (well-known community)\n"
7452 "Do not advertise to any peer (well-known community)\n"
7453 "Do not export to next AS (well-known community)\n")
7454
7455ALIAS (show_bgp_community,
7456 show_bgp_community3_cmd,
7457 "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)",
7458 SHOW_STR
7459 BGP_STR
7460 "Display routes matching the communities\n"
7461 "community number\n"
7462 "Do not send outside local AS (well-known community)\n"
7463 "Do not advertise to any peer (well-known community)\n"
7464 "Do not export to next AS (well-known community)\n"
7465 "community number\n"
7466 "Do not send outside local AS (well-known community)\n"
7467 "Do not advertise to any peer (well-known community)\n"
7468 "Do not export to next AS (well-known community)\n"
7469 "community number\n"
7470 "Do not send outside local AS (well-known community)\n"
7471 "Do not advertise to any peer (well-known community)\n"
7472 "Do not export to next AS (well-known community)\n")
7473
7474ALIAS (show_bgp_community,
7475 show_bgp_ipv6_community3_cmd,
7476 "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)",
7477 SHOW_STR
7478 BGP_STR
7479 "Address family\n"
7480 "Display routes matching the communities\n"
7481 "community number\n"
7482 "Do not send outside local AS (well-known community)\n"
7483 "Do not advertise to any peer (well-known community)\n"
7484 "Do not export to next AS (well-known community)\n"
7485 "community number\n"
7486 "Do not send outside local AS (well-known community)\n"
7487 "Do not advertise to any peer (well-known community)\n"
7488 "Do not export to next AS (well-known community)\n"
7489 "community number\n"
7490 "Do not send outside local AS (well-known community)\n"
7491 "Do not advertise to any peer (well-known community)\n"
7492 "Do not export to next AS (well-known community)\n")
7493
7494ALIAS (show_bgp_community,
7495 show_bgp_community4_cmd,
7496 "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)",
7497 SHOW_STR
7498 BGP_STR
7499 "Display routes matching the communities\n"
7500 "community number\n"
7501 "Do not send outside local AS (well-known community)\n"
7502 "Do not advertise to any peer (well-known community)\n"
7503 "Do not export to next AS (well-known community)\n"
7504 "community number\n"
7505 "Do not send outside local AS (well-known community)\n"
7506 "Do not advertise to any peer (well-known community)\n"
7507 "Do not export to next AS (well-known community)\n"
7508 "community number\n"
7509 "Do not send outside local AS (well-known community)\n"
7510 "Do not advertise to any peer (well-known community)\n"
7511 "Do not export to next AS (well-known community)\n"
7512 "community number\n"
7513 "Do not send outside local AS (well-known community)\n"
7514 "Do not advertise to any peer (well-known community)\n"
7515 "Do not export to next AS (well-known community)\n")
7516
7517ALIAS (show_bgp_community,
7518 show_bgp_ipv6_community4_cmd,
7519 "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)",
7520 SHOW_STR
7521 BGP_STR
7522 "Address family\n"
7523 "Display routes matching the communities\n"
7524 "community number\n"
7525 "Do not send outside local AS (well-known community)\n"
7526 "Do not advertise to any peer (well-known community)\n"
7527 "Do not export to next AS (well-known community)\n"
7528 "community number\n"
7529 "Do not send outside local AS (well-known community)\n"
7530 "Do not advertise to any peer (well-known community)\n"
7531 "Do not export to next AS (well-known community)\n"
7532 "community number\n"
7533 "Do not send outside local AS (well-known community)\n"
7534 "Do not advertise to any peer (well-known community)\n"
7535 "Do not export to next AS (well-known community)\n"
7536 "community number\n"
7537 "Do not send outside local AS (well-known community)\n"
7538 "Do not advertise to any peer (well-known community)\n"
7539 "Do not export to next AS (well-known community)\n")
7540
7541/* old command */
7542DEFUN (show_ipv6_bgp_community,
7543 show_ipv6_bgp_community_cmd,
7544 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7545 SHOW_STR
7546 IPV6_STR
7547 BGP_STR
7548 "Display routes matching the communities\n"
7549 "community number\n"
7550 "Do not send outside local AS (well-known community)\n"
7551 "Do not advertise to any peer (well-known community)\n"
7552 "Do not export to next AS (well-known community)\n")
7553{
7554 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7555}
7556
7557/* old command */
7558ALIAS (show_ipv6_bgp_community,
7559 show_ipv6_bgp_community2_cmd,
7560 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7561 SHOW_STR
7562 IPV6_STR
7563 BGP_STR
7564 "Display routes matching the communities\n"
7565 "community number\n"
7566 "Do not send outside local AS (well-known community)\n"
7567 "Do not advertise to any peer (well-known community)\n"
7568 "Do not export to next AS (well-known community)\n"
7569 "community number\n"
7570 "Do not send outside local AS (well-known community)\n"
7571 "Do not advertise to any peer (well-known community)\n"
7572 "Do not export to next AS (well-known community)\n")
7573
7574/* old command */
7575ALIAS (show_ipv6_bgp_community,
7576 show_ipv6_bgp_community3_cmd,
7577 "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)",
7578 SHOW_STR
7579 IPV6_STR
7580 BGP_STR
7581 "Display routes matching the communities\n"
7582 "community number\n"
7583 "Do not send outside local AS (well-known community)\n"
7584 "Do not advertise to any peer (well-known community)\n"
7585 "Do not export to next AS (well-known community)\n"
7586 "community number\n"
7587 "Do not send outside local AS (well-known community)\n"
7588 "Do not advertise to any peer (well-known community)\n"
7589 "Do not export to next AS (well-known community)\n"
7590 "community number\n"
7591 "Do not send outside local AS (well-known community)\n"
7592 "Do not advertise to any peer (well-known community)\n"
7593 "Do not export to next AS (well-known community)\n")
7594
7595/* old command */
7596ALIAS (show_ipv6_bgp_community,
7597 show_ipv6_bgp_community4_cmd,
7598 "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)",
7599 SHOW_STR
7600 IPV6_STR
7601 BGP_STR
7602 "Display routes matching the communities\n"
7603 "community number\n"
7604 "Do not send outside local AS (well-known community)\n"
7605 "Do not advertise to any peer (well-known community)\n"
7606 "Do not export to next AS (well-known community)\n"
7607 "community number\n"
7608 "Do not send outside local AS (well-known community)\n"
7609 "Do not advertise to any peer (well-known community)\n"
7610 "Do not export to next AS (well-known community)\n"
7611 "community number\n"
7612 "Do not send outside local AS (well-known community)\n"
7613 "Do not advertise to any peer (well-known community)\n"
7614 "Do not export to next AS (well-known community)\n"
7615 "community number\n"
7616 "Do not send outside local AS (well-known community)\n"
7617 "Do not advertise to any peer (well-known community)\n"
7618 "Do not export to next AS (well-known community)\n")
7619
7620DEFUN (show_bgp_community_exact,
7621 show_bgp_community_exact_cmd,
7622 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7623 SHOW_STR
7624 BGP_STR
7625 "Display routes matching the communities\n"
7626 "community number\n"
7627 "Do not send outside local AS (well-known community)\n"
7628 "Do not advertise to any peer (well-known community)\n"
7629 "Do not export to next AS (well-known community)\n"
7630 "Exact match of the communities")
7631{
7632 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7633}
7634
7635ALIAS (show_bgp_community_exact,
7636 show_bgp_ipv6_community_exact_cmd,
7637 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7638 SHOW_STR
7639 BGP_STR
7640 "Address family\n"
7641 "Display routes matching the communities\n"
7642 "community number\n"
7643 "Do not send outside local AS (well-known community)\n"
7644 "Do not advertise to any peer (well-known community)\n"
7645 "Do not export to next AS (well-known community)\n"
7646 "Exact match of the communities")
7647
7648ALIAS (show_bgp_community_exact,
7649 show_bgp_community2_exact_cmd,
7650 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7651 SHOW_STR
7652 BGP_STR
7653 "Display routes matching the communities\n"
7654 "community number\n"
7655 "Do not send outside local AS (well-known community)\n"
7656 "Do not advertise to any peer (well-known community)\n"
7657 "Do not export to next AS (well-known community)\n"
7658 "community number\n"
7659 "Do not send outside local AS (well-known community)\n"
7660 "Do not advertise to any peer (well-known community)\n"
7661 "Do not export to next AS (well-known community)\n"
7662 "Exact match of the communities")
7663
7664ALIAS (show_bgp_community_exact,
7665 show_bgp_ipv6_community2_exact_cmd,
7666 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7667 SHOW_STR
7668 BGP_STR
7669 "Address family\n"
7670 "Display routes matching the communities\n"
7671 "community number\n"
7672 "Do not send outside local AS (well-known community)\n"
7673 "Do not advertise to any peer (well-known community)\n"
7674 "Do not export to next AS (well-known community)\n"
7675 "community number\n"
7676 "Do not send outside local AS (well-known community)\n"
7677 "Do not advertise to any peer (well-known community)\n"
7678 "Do not export to next AS (well-known community)\n"
7679 "Exact match of the communities")
7680
7681ALIAS (show_bgp_community_exact,
7682 show_bgp_community3_exact_cmd,
7683 "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",
7684 SHOW_STR
7685 BGP_STR
7686 "Display routes matching the communities\n"
7687 "community number\n"
7688 "Do not send outside local AS (well-known community)\n"
7689 "Do not advertise to any peer (well-known community)\n"
7690 "Do not export to next AS (well-known community)\n"
7691 "community number\n"
7692 "Do not send outside local AS (well-known community)\n"
7693 "Do not advertise to any peer (well-known community)\n"
7694 "Do not export to next AS (well-known community)\n"
7695 "community number\n"
7696 "Do not send outside local AS (well-known community)\n"
7697 "Do not advertise to any peer (well-known community)\n"
7698 "Do not export to next AS (well-known community)\n"
7699 "Exact match of the communities")
7700
7701ALIAS (show_bgp_community_exact,
7702 show_bgp_ipv6_community3_exact_cmd,
7703 "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",
7704 SHOW_STR
7705 BGP_STR
7706 "Address family\n"
7707 "Display routes matching the communities\n"
7708 "community number\n"
7709 "Do not send outside local AS (well-known community)\n"
7710 "Do not advertise to any peer (well-known community)\n"
7711 "Do not export to next AS (well-known community)\n"
7712 "community number\n"
7713 "Do not send outside local AS (well-known community)\n"
7714 "Do not advertise to any peer (well-known community)\n"
7715 "Do not export to next AS (well-known community)\n"
7716 "community number\n"
7717 "Do not send outside local AS (well-known community)\n"
7718 "Do not advertise to any peer (well-known community)\n"
7719 "Do not export to next AS (well-known community)\n"
7720 "Exact match of the communities")
7721
7722ALIAS (show_bgp_community_exact,
7723 show_bgp_community4_exact_cmd,
7724 "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",
7725 SHOW_STR
7726 BGP_STR
7727 "Display routes matching the communities\n"
7728 "community number\n"
7729 "Do not send outside local AS (well-known community)\n"
7730 "Do not advertise to any peer (well-known community)\n"
7731 "Do not export to next AS (well-known community)\n"
7732 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\n"
7736 "community number\n"
7737 "Do not send outside local AS (well-known community)\n"
7738 "Do not advertise to any peer (well-known community)\n"
7739 "Do not export to next AS (well-known community)\n"
7740 "community number\n"
7741 "Do not send outside local AS (well-known community)\n"
7742 "Do not advertise to any peer (well-known community)\n"
7743 "Do not export to next AS (well-known community)\n"
7744 "Exact match of the communities")
7745
7746ALIAS (show_bgp_community_exact,
7747 show_bgp_ipv6_community4_exact_cmd,
7748 "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",
7749 SHOW_STR
7750 BGP_STR
7751 "Address family\n"
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 "community number\n"
7758 "Do not send outside local AS (well-known community)\n"
7759 "Do not advertise to any peer (well-known community)\n"
7760 "Do not export to next AS (well-known community)\n"
7761 "community number\n"
7762 "Do not send outside local AS (well-known community)\n"
7763 "Do not advertise to any peer (well-known community)\n"
7764 "Do not export to next AS (well-known community)\n"
7765 "community number\n"
7766 "Do not send outside local AS (well-known community)\n"
7767 "Do not advertise to any peer (well-known community)\n"
7768 "Do not export to next AS (well-known community)\n"
7769 "Exact match of the communities")
7770
7771/* old command */
7772DEFUN (show_ipv6_bgp_community_exact,
7773 show_ipv6_bgp_community_exact_cmd,
7774 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7775 SHOW_STR
7776 IPV6_STR
7777 BGP_STR
7778 "Display routes matching the communities\n"
7779 "community number\n"
7780 "Do not send outside local AS (well-known community)\n"
7781 "Do not advertise to any peer (well-known community)\n"
7782 "Do not export to next AS (well-known community)\n"
7783 "Exact match of the communities")
7784{
7785 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7786}
7787
7788/* old command */
7789ALIAS (show_ipv6_bgp_community_exact,
7790 show_ipv6_bgp_community2_exact_cmd,
7791 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7792 SHOW_STR
7793 IPV6_STR
7794 BGP_STR
7795 "Display routes matching the communities\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 "community number\n"
7801 "Do not send outside local AS (well-known community)\n"
7802 "Do not advertise to any peer (well-known community)\n"
7803 "Do not export to next AS (well-known community)\n"
7804 "Exact match of the communities")
7805
7806/* old command */
7807ALIAS (show_ipv6_bgp_community_exact,
7808 show_ipv6_bgp_community3_exact_cmd,
7809 "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",
7810 SHOW_STR
7811 IPV6_STR
7812 BGP_STR
7813 "Display routes matching the communities\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 */
7829ALIAS (show_ipv6_bgp_community_exact,
7830 show_ipv6_bgp_community4_exact_cmd,
7831 "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",
7832 SHOW_STR
7833 IPV6_STR
7834 BGP_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 "community number\n"
7841 "Do not send outside local AS (well-known community)\n"
7842 "Do not advertise to any peer (well-known community)\n"
7843 "Do not export to next AS (well-known community)\n"
7844 "community number\n"
7845 "Do not send outside local AS (well-known community)\n"
7846 "Do not advertise to any peer (well-known community)\n"
7847 "Do not export to next AS (well-known community)\n"
7848 "community number\n"
7849 "Do not send outside local AS (well-known community)\n"
7850 "Do not advertise to any peer (well-known community)\n"
7851 "Do not export to next AS (well-known community)\n"
7852 "Exact match of the communities")
7853
7854/* old command */
7855DEFUN (show_ipv6_mbgp_community,
7856 show_ipv6_mbgp_community_cmd,
7857 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7858 SHOW_STR
7859 IPV6_STR
7860 MBGP_STR
7861 "Display routes matching the communities\n"
7862 "community number\n"
7863 "Do not send outside local AS (well-known community)\n"
7864 "Do not advertise to any peer (well-known community)\n"
7865 "Do not export to next AS (well-known community)\n")
7866{
7867 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7868}
7869
7870/* old command */
7871ALIAS (show_ipv6_mbgp_community,
7872 show_ipv6_mbgp_community2_cmd,
7873 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7874 SHOW_STR
7875 IPV6_STR
7876 MBGP_STR
7877 "Display routes matching the communities\n"
7878 "community number\n"
7879 "Do not send outside local AS (well-known community)\n"
7880 "Do not advertise to any peer (well-known community)\n"
7881 "Do not export to next AS (well-known community)\n"
7882 "community number\n"
7883 "Do not send outside local AS (well-known community)\n"
7884 "Do not advertise to any peer (well-known community)\n"
7885 "Do not export to next AS (well-known community)\n")
7886
7887/* old command */
7888ALIAS (show_ipv6_mbgp_community,
7889 show_ipv6_mbgp_community3_cmd,
7890 "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)",
7891 SHOW_STR
7892 IPV6_STR
7893 MBGP_STR
7894 "Display routes matching the communities\n"
7895 "community number\n"
7896 "Do not send outside local AS (well-known community)\n"
7897 "Do not advertise to any peer (well-known community)\n"
7898 "Do not export to next AS (well-known community)\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n"
7903 "community number\n"
7904 "Do not send outside local AS (well-known community)\n"
7905 "Do not advertise to any peer (well-known community)\n"
7906 "Do not export to next AS (well-known community)\n")
7907
7908/* old command */
7909ALIAS (show_ipv6_mbgp_community,
7910 show_ipv6_mbgp_community4_cmd,
7911 "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)",
7912 SHOW_STR
7913 IPV6_STR
7914 MBGP_STR
7915 "Display routes matching the communities\n"
7916 "community number\n"
7917 "Do not send outside local AS (well-known community)\n"
7918 "Do not advertise to any peer (well-known community)\n"
7919 "Do not export to next AS (well-known community)\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n"
7928 "community number\n"
7929 "Do not send outside local AS (well-known community)\n"
7930 "Do not advertise to any peer (well-known community)\n"
7931 "Do not export to next AS (well-known community)\n")
7932
7933/* old command */
7934DEFUN (show_ipv6_mbgp_community_exact,
7935 show_ipv6_mbgp_community_exact_cmd,
7936 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7937 SHOW_STR
7938 IPV6_STR
7939 MBGP_STR
7940 "Display routes matching the communities\n"
7941 "community number\n"
7942 "Do not send outside local AS (well-known community)\n"
7943 "Do not advertise to any peer (well-known community)\n"
7944 "Do not export to next AS (well-known community)\n"
7945 "Exact match of the communities")
7946{
7947 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7948}
7949
7950/* old command */
7951ALIAS (show_ipv6_mbgp_community_exact,
7952 show_ipv6_mbgp_community2_exact_cmd,
7953 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7954 SHOW_STR
7955 IPV6_STR
7956 MBGP_STR
7957 "Display routes matching the communities\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 "community number\n"
7963 "Do not send outside local AS (well-known community)\n"
7964 "Do not advertise to any peer (well-known community)\n"
7965 "Do not export to next AS (well-known community)\n"
7966 "Exact match of the communities")
7967
7968/* old command */
7969ALIAS (show_ipv6_mbgp_community_exact,
7970 show_ipv6_mbgp_community3_exact_cmd,
7971 "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",
7972 SHOW_STR
7973 IPV6_STR
7974 MBGP_STR
7975 "Display routes matching the communities\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
7990/* old command */
7991ALIAS (show_ipv6_mbgp_community_exact,
7992 show_ipv6_mbgp_community4_exact_cmd,
7993 "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",
7994 SHOW_STR
7995 IPV6_STR
7996 MBGP_STR
7997 "Display routes matching the communities\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n"
8010 "community number\n"
8011 "Do not send outside local AS (well-known community)\n"
8012 "Do not advertise to any peer (well-known community)\n"
8013 "Do not export to next AS (well-known community)\n"
8014 "Exact match of the communities")
8015#endif /* HAVE_IPV6 */
8016
paul94f2b392005-06-28 12:44:16 +00008017static int
paulfd79ac92004-10-13 05:06:08 +00008018bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008019 u_int16_t afi, u_char safi)
8020{
8021 struct community_list *list;
8022
hassofee6e4e2005-02-02 16:29:31 +00008023 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008024 if (list == NULL)
8025 {
8026 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8027 VTY_NEWLINE);
8028 return CMD_WARNING;
8029 }
8030
ajs5a646652004-11-05 01:25:55 +00008031 return bgp_show (vty, NULL, afi, safi,
8032 (exact ? bgp_show_type_community_list_exact :
8033 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008034}
8035
8036DEFUN (show_ip_bgp_community_list,
8037 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008038 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008039 SHOW_STR
8040 IP_STR
8041 BGP_STR
8042 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008043 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008044 "community-list name\n")
8045{
8046 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8047}
8048
8049DEFUN (show_ip_bgp_ipv4_community_list,
8050 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008051 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008052 SHOW_STR
8053 IP_STR
8054 BGP_STR
8055 "Address family\n"
8056 "Address Family modifier\n"
8057 "Address Family modifier\n"
8058 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008059 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008060 "community-list name\n")
8061{
8062 if (strncmp (argv[0], "m", 1) == 0)
8063 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8064
8065 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8066}
8067
8068DEFUN (show_ip_bgp_community_list_exact,
8069 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008070 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008071 SHOW_STR
8072 IP_STR
8073 BGP_STR
8074 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008075 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008076 "community-list name\n"
8077 "Exact match of the communities\n")
8078{
8079 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8080}
8081
8082DEFUN (show_ip_bgp_ipv4_community_list_exact,
8083 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008084 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008085 SHOW_STR
8086 IP_STR
8087 BGP_STR
8088 "Address family\n"
8089 "Address Family modifier\n"
8090 "Address Family modifier\n"
8091 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008092 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008093 "community-list name\n"
8094 "Exact match of the communities\n")
8095{
8096 if (strncmp (argv[0], "m", 1) == 0)
8097 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8098
8099 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8100}
8101
8102#ifdef HAVE_IPV6
8103DEFUN (show_bgp_community_list,
8104 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008105 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008106 SHOW_STR
8107 BGP_STR
8108 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008109 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008110 "community-list name\n")
8111{
8112 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8113}
8114
8115ALIAS (show_bgp_community_list,
8116 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008117 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008118 SHOW_STR
8119 BGP_STR
8120 "Address family\n"
8121 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008122 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008123 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008124
8125/* old command */
8126DEFUN (show_ipv6_bgp_community_list,
8127 show_ipv6_bgp_community_list_cmd,
8128 "show ipv6 bgp community-list WORD",
8129 SHOW_STR
8130 IPV6_STR
8131 BGP_STR
8132 "Display routes matching the community-list\n"
8133 "community-list name\n")
8134{
8135 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8136}
8137
8138/* old command */
8139DEFUN (show_ipv6_mbgp_community_list,
8140 show_ipv6_mbgp_community_list_cmd,
8141 "show ipv6 mbgp community-list WORD",
8142 SHOW_STR
8143 IPV6_STR
8144 MBGP_STR
8145 "Display routes matching the community-list\n"
8146 "community-list name\n")
8147{
8148 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8149}
8150
8151DEFUN (show_bgp_community_list_exact,
8152 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008153 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008154 SHOW_STR
8155 BGP_STR
8156 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008157 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008158 "community-list name\n"
8159 "Exact match of the communities\n")
8160{
8161 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8162}
8163
8164ALIAS (show_bgp_community_list_exact,
8165 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008166 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008167 SHOW_STR
8168 BGP_STR
8169 "Address family\n"
8170 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008171 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008172 "community-list name\n"
8173 "Exact match of the communities\n")
8174
8175/* old command */
8176DEFUN (show_ipv6_bgp_community_list_exact,
8177 show_ipv6_bgp_community_list_exact_cmd,
8178 "show ipv6 bgp community-list WORD exact-match",
8179 SHOW_STR
8180 IPV6_STR
8181 BGP_STR
8182 "Display routes matching the community-list\n"
8183 "community-list name\n"
8184 "Exact match of the communities\n")
8185{
8186 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8187}
8188
8189/* old command */
8190DEFUN (show_ipv6_mbgp_community_list_exact,
8191 show_ipv6_mbgp_community_list_exact_cmd,
8192 "show ipv6 mbgp community-list WORD exact-match",
8193 SHOW_STR
8194 IPV6_STR
8195 MBGP_STR
8196 "Display routes matching the community-list\n"
8197 "community-list name\n"
8198 "Exact match of the communities\n")
8199{
8200 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8201}
8202#endif /* HAVE_IPV6 */
8203
paul94f2b392005-06-28 12:44:16 +00008204static int
paulfd79ac92004-10-13 05:06:08 +00008205bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008206 safi_t safi, enum bgp_show_type type)
8207{
8208 int ret;
8209 struct prefix *p;
8210
8211 p = prefix_new();
8212
8213 ret = str2prefix (prefix, p);
8214 if (! ret)
8215 {
8216 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8217 return CMD_WARNING;
8218 }
8219
ajs5a646652004-11-05 01:25:55 +00008220 ret = bgp_show (vty, NULL, afi, safi, type, p);
8221 prefix_free(p);
8222 return ret;
paul718e3742002-12-13 20:15:29 +00008223}
8224
8225DEFUN (show_ip_bgp_prefix_longer,
8226 show_ip_bgp_prefix_longer_cmd,
8227 "show ip bgp A.B.C.D/M longer-prefixes",
8228 SHOW_STR
8229 IP_STR
8230 BGP_STR
8231 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8232 "Display route and more specific routes\n")
8233{
8234 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8235 bgp_show_type_prefix_longer);
8236}
8237
8238DEFUN (show_ip_bgp_flap_prefix_longer,
8239 show_ip_bgp_flap_prefix_longer_cmd,
8240 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8241 SHOW_STR
8242 IP_STR
8243 BGP_STR
8244 "Display flap statistics of routes\n"
8245 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8246 "Display route and more specific routes\n")
8247{
8248 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8249 bgp_show_type_flap_prefix_longer);
8250}
8251
8252DEFUN (show_ip_bgp_ipv4_prefix_longer,
8253 show_ip_bgp_ipv4_prefix_longer_cmd,
8254 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8255 SHOW_STR
8256 IP_STR
8257 BGP_STR
8258 "Address family\n"
8259 "Address Family modifier\n"
8260 "Address Family modifier\n"
8261 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8262 "Display route and more specific routes\n")
8263{
8264 if (strncmp (argv[0], "m", 1) == 0)
8265 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8266 bgp_show_type_prefix_longer);
8267
8268 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8269 bgp_show_type_prefix_longer);
8270}
8271
8272DEFUN (show_ip_bgp_flap_address,
8273 show_ip_bgp_flap_address_cmd,
8274 "show ip bgp flap-statistics A.B.C.D",
8275 SHOW_STR
8276 IP_STR
8277 BGP_STR
8278 "Display flap statistics of routes\n"
8279 "Network in the BGP routing table to display\n")
8280{
8281 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8282 bgp_show_type_flap_address);
8283}
8284
8285DEFUN (show_ip_bgp_flap_prefix,
8286 show_ip_bgp_flap_prefix_cmd,
8287 "show ip bgp flap-statistics A.B.C.D/M",
8288 SHOW_STR
8289 IP_STR
8290 BGP_STR
8291 "Display flap statistics of routes\n"
8292 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8293{
8294 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8295 bgp_show_type_flap_prefix);
8296}
8297#ifdef HAVE_IPV6
8298DEFUN (show_bgp_prefix_longer,
8299 show_bgp_prefix_longer_cmd,
8300 "show bgp X:X::X:X/M longer-prefixes",
8301 SHOW_STR
8302 BGP_STR
8303 "IPv6 prefix <network>/<length>\n"
8304 "Display route and more specific routes\n")
8305{
8306 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8307 bgp_show_type_prefix_longer);
8308}
8309
8310ALIAS (show_bgp_prefix_longer,
8311 show_bgp_ipv6_prefix_longer_cmd,
8312 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8313 SHOW_STR
8314 BGP_STR
8315 "Address family\n"
8316 "IPv6 prefix <network>/<length>\n"
8317 "Display route and more specific routes\n")
8318
8319/* old command */
8320DEFUN (show_ipv6_bgp_prefix_longer,
8321 show_ipv6_bgp_prefix_longer_cmd,
8322 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8323 SHOW_STR
8324 IPV6_STR
8325 BGP_STR
8326 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8327 "Display route and more specific routes\n")
8328{
8329 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8330 bgp_show_type_prefix_longer);
8331}
8332
8333/* old command */
8334DEFUN (show_ipv6_mbgp_prefix_longer,
8335 show_ipv6_mbgp_prefix_longer_cmd,
8336 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8337 SHOW_STR
8338 IPV6_STR
8339 MBGP_STR
8340 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8341 "Display route and more specific routes\n")
8342{
8343 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8344 bgp_show_type_prefix_longer);
8345}
8346#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008347
paul94f2b392005-06-28 12:44:16 +00008348static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008349peer_lookup_in_view (struct vty *vty, const char *view_name,
8350 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008351{
8352 int ret;
8353 struct bgp *bgp;
8354 struct peer *peer;
8355 union sockunion su;
8356
8357 /* BGP structure lookup. */
8358 if (view_name)
8359 {
8360 bgp = bgp_lookup_by_name (view_name);
8361 if (! bgp)
8362 {
8363 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8364 return NULL;
8365 }
8366 }
paul5228ad22004-06-04 17:58:18 +00008367 else
paulbb46e942003-10-24 19:02:03 +00008368 {
8369 bgp = bgp_get_default ();
8370 if (! bgp)
8371 {
8372 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8373 return NULL;
8374 }
8375 }
8376
8377 /* Get peer sockunion. */
8378 ret = str2sockunion (ip_str, &su);
8379 if (ret < 0)
8380 {
8381 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8382 return NULL;
8383 }
8384
8385 /* Peer structure lookup. */
8386 peer = peer_lookup (bgp, &su);
8387 if (! peer)
8388 {
8389 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8390 return NULL;
8391 }
8392
8393 return peer;
8394}
8395
paul94f2b392005-06-28 12:44:16 +00008396static void
paul718e3742002-12-13 20:15:29 +00008397show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8398 int in)
8399{
8400 struct bgp_table *table;
8401 struct bgp_adj_in *ain;
8402 struct bgp_adj_out *adj;
8403 unsigned long output_count;
8404 struct bgp_node *rn;
8405 int header1 = 1;
8406 struct bgp *bgp;
8407 int header2 = 1;
8408
paulbb46e942003-10-24 19:02:03 +00008409 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008410
8411 if (! bgp)
8412 return;
8413
8414 table = bgp->rib[afi][safi];
8415
8416 output_count = 0;
8417
8418 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8419 PEER_STATUS_DEFAULT_ORIGINATE))
8420 {
8421 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 +00008422 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8423 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008424
8425 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8426 VTY_NEWLINE, VTY_NEWLINE);
8427 header1 = 0;
8428 }
8429
8430 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8431 if (in)
8432 {
8433 for (ain = rn->adj_in; ain; ain = ain->next)
8434 if (ain->peer == peer)
8435 {
8436 if (header1)
8437 {
8438 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 +00008439 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8440 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008441 header1 = 0;
8442 }
8443 if (header2)
8444 {
8445 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8446 header2 = 0;
8447 }
8448 if (ain->attr)
8449 {
8450 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8451 output_count++;
8452 }
8453 }
8454 }
8455 else
8456 {
8457 for (adj = rn->adj_out; adj; adj = adj->next)
8458 if (adj->peer == peer)
8459 {
8460 if (header1)
8461 {
8462 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 +00008463 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8464 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008465 header1 = 0;
8466 }
8467 if (header2)
8468 {
8469 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8470 header2 = 0;
8471 }
8472 if (adj->attr)
8473 {
8474 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8475 output_count++;
8476 }
8477 }
8478 }
8479
8480 if (output_count != 0)
8481 vty_out (vty, "%sTotal number of prefixes %ld%s",
8482 VTY_NEWLINE, output_count, VTY_NEWLINE);
8483}
8484
paul94f2b392005-06-28 12:44:16 +00008485static int
paulbb46e942003-10-24 19:02:03 +00008486peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8487{
paul718e3742002-12-13 20:15:29 +00008488 if (! peer || ! peer->afc[afi][safi])
8489 {
8490 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8491 return CMD_WARNING;
8492 }
8493
8494 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8495 {
8496 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8497 VTY_NEWLINE);
8498 return CMD_WARNING;
8499 }
8500
8501 show_adj_route (vty, peer, afi, safi, in);
8502
8503 return CMD_SUCCESS;
8504}
8505
8506DEFUN (show_ip_bgp_neighbor_advertised_route,
8507 show_ip_bgp_neighbor_advertised_route_cmd,
8508 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8509 SHOW_STR
8510 IP_STR
8511 BGP_STR
8512 "Detailed information on TCP and BGP neighbor connections\n"
8513 "Neighbor to display information about\n"
8514 "Neighbor to display information about\n"
8515 "Display the routes advertised to a BGP neighbor\n")
8516{
paulbb46e942003-10-24 19:02:03 +00008517 struct peer *peer;
8518
8519 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8520 if (! peer)
8521 return CMD_WARNING;
8522
8523 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008524}
8525
8526DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8527 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8528 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8529 SHOW_STR
8530 IP_STR
8531 BGP_STR
8532 "Address family\n"
8533 "Address Family modifier\n"
8534 "Address Family modifier\n"
8535 "Detailed information on TCP and BGP neighbor connections\n"
8536 "Neighbor to display information about\n"
8537 "Neighbor to display information about\n"
8538 "Display the routes advertised to a BGP neighbor\n")
8539{
paulbb46e942003-10-24 19:02:03 +00008540 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008541
paulbb46e942003-10-24 19:02:03 +00008542 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8543 if (! peer)
8544 return CMD_WARNING;
8545
8546 if (strncmp (argv[0], "m", 1) == 0)
8547 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8548
8549 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008550}
8551
8552#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008553DEFUN (show_bgp_view_neighbor_advertised_route,
8554 show_bgp_view_neighbor_advertised_route_cmd,
8555 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8556 SHOW_STR
8557 BGP_STR
8558 "BGP view\n"
8559 "View name\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{
8565 struct peer *peer;
8566
8567 if (argc == 2)
8568 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8569 else
8570 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8571
8572 if (! peer)
8573 return CMD_WARNING;
8574
8575 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8576}
8577
8578ALIAS (show_bgp_view_neighbor_advertised_route,
8579 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8580 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8581 SHOW_STR
8582 BGP_STR
8583 "BGP view\n"
8584 "View name\n"
8585 "Address family\n"
8586 "Detailed information on TCP and BGP neighbor connections\n"
8587 "Neighbor to display information about\n"
8588 "Neighbor to display information about\n"
8589 "Display the routes advertised to a BGP neighbor\n")
8590
8591DEFUN (show_bgp_view_neighbor_received_routes,
8592 show_bgp_view_neighbor_received_routes_cmd,
8593 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8594 SHOW_STR
8595 BGP_STR
8596 "BGP view\n"
8597 "View name\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{
8603 struct peer *peer;
8604
8605 if (argc == 2)
8606 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8607 else
8608 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8609
8610 if (! peer)
8611 return CMD_WARNING;
8612
8613 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8614}
8615
8616ALIAS (show_bgp_view_neighbor_received_routes,
8617 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8618 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8619 SHOW_STR
8620 BGP_STR
8621 "BGP view\n"
8622 "View name\n"
8623 "Address family\n"
8624 "Detailed information on TCP and BGP neighbor connections\n"
8625 "Neighbor to display information about\n"
8626 "Neighbor to display information about\n"
8627 "Display the received routes from neighbor\n")
8628
8629ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008630 show_bgp_neighbor_advertised_route_cmd,
8631 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8632 SHOW_STR
8633 BGP_STR
8634 "Detailed information on TCP and BGP neighbor connections\n"
8635 "Neighbor to display information about\n"
8636 "Neighbor to display information about\n"
8637 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008638
8639ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008640 show_bgp_ipv6_neighbor_advertised_route_cmd,
8641 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8642 SHOW_STR
8643 BGP_STR
8644 "Address family\n"
8645 "Detailed information on TCP and BGP neighbor connections\n"
8646 "Neighbor to display information about\n"
8647 "Neighbor to display information about\n"
8648 "Display the routes advertised to a BGP neighbor\n")
8649
8650/* old command */
paulbb46e942003-10-24 19:02:03 +00008651ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008652 ipv6_bgp_neighbor_advertised_route_cmd,
8653 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8654 SHOW_STR
8655 IPV6_STR
8656 BGP_STR
8657 "Detailed information on TCP and BGP neighbor connections\n"
8658 "Neighbor to display information about\n"
8659 "Neighbor to display information about\n"
8660 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008661
paul718e3742002-12-13 20:15:29 +00008662/* old command */
8663DEFUN (ipv6_mbgp_neighbor_advertised_route,
8664 ipv6_mbgp_neighbor_advertised_route_cmd,
8665 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8666 SHOW_STR
8667 IPV6_STR
8668 MBGP_STR
8669 "Detailed information on TCP and BGP neighbor connections\n"
8670 "Neighbor to display information about\n"
8671 "Neighbor to display information about\n"
8672 "Display the routes advertised to a BGP neighbor\n")
8673{
paulbb46e942003-10-24 19:02:03 +00008674 struct peer *peer;
8675
8676 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8677 if (! peer)
8678 return CMD_WARNING;
8679
8680 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008681}
8682#endif /* HAVE_IPV6 */
8683
8684DEFUN (show_ip_bgp_neighbor_received_routes,
8685 show_ip_bgp_neighbor_received_routes_cmd,
8686 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8687 SHOW_STR
8688 IP_STR
8689 BGP_STR
8690 "Detailed information on TCP and BGP neighbor connections\n"
8691 "Neighbor to display information about\n"
8692 "Neighbor to display information about\n"
8693 "Display the received routes from neighbor\n")
8694{
paulbb46e942003-10-24 19:02:03 +00008695 struct peer *peer;
8696
8697 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8698 if (! peer)
8699 return CMD_WARNING;
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_ipv4_neighbor_received_routes,
8705 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8706 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8707 SHOW_STR
8708 IP_STR
8709 BGP_STR
8710 "Address family\n"
8711 "Address Family modifier\n"
8712 "Address Family modifier\n"
8713 "Detailed information on TCP and BGP neighbor connections\n"
8714 "Neighbor to display information about\n"
8715 "Neighbor to display information about\n"
8716 "Display the received routes from neighbor\n")
8717{
paulbb46e942003-10-24 19:02:03 +00008718 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008719
paulbb46e942003-10-24 19:02:03 +00008720 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8721 if (! peer)
8722 return CMD_WARNING;
8723
8724 if (strncmp (argv[0], "m", 1) == 0)
8725 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8726
8727 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008728}
8729
8730DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8731 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8732 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8733 SHOW_STR
8734 IP_STR
8735 BGP_STR
8736 "Detailed information on TCP and BGP neighbor connections\n"
8737 "Neighbor to display information about\n"
8738 "Neighbor to display information about\n"
8739 "Display information received from a BGP neighbor\n"
8740 "Display the prefixlist filter\n")
8741{
8742 char name[BUFSIZ];
8743 union sockunion *su;
8744 struct peer *peer;
8745 int count;
8746
8747 su = sockunion_str2su (argv[0]);
8748 if (su == NULL)
8749 return CMD_WARNING;
8750
8751 peer = peer_lookup (NULL, su);
8752 if (! peer)
8753 return CMD_WARNING;
8754
8755 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8756 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8757 if (count)
8758 {
8759 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8760 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8761 }
8762
8763 return CMD_SUCCESS;
8764}
8765
8766DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8767 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8768 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8769 SHOW_STR
8770 IP_STR
8771 BGP_STR
8772 "Address family\n"
8773 "Address Family modifier\n"
8774 "Address Family modifier\n"
8775 "Detailed information on TCP and BGP neighbor connections\n"
8776 "Neighbor to display information about\n"
8777 "Neighbor to display information about\n"
8778 "Display information received from a BGP neighbor\n"
8779 "Display the prefixlist filter\n")
8780{
8781 char name[BUFSIZ];
8782 union sockunion *su;
8783 struct peer *peer;
8784 int count;
8785
8786 su = sockunion_str2su (argv[1]);
8787 if (su == NULL)
8788 return CMD_WARNING;
8789
8790 peer = peer_lookup (NULL, su);
8791 if (! peer)
8792 return CMD_WARNING;
8793
8794 if (strncmp (argv[0], "m", 1) == 0)
8795 {
8796 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8797 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8798 if (count)
8799 {
8800 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8801 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8802 }
8803 }
8804 else
8805 {
8806 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8807 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8808 if (count)
8809 {
8810 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8811 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8812 }
8813 }
8814
8815 return CMD_SUCCESS;
8816}
8817
8818
8819#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008820ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008821 show_bgp_neighbor_received_routes_cmd,
8822 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8823 SHOW_STR
8824 BGP_STR
8825 "Detailed information on TCP and BGP neighbor connections\n"
8826 "Neighbor to display information about\n"
8827 "Neighbor to display information about\n"
8828 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008829
paulbb46e942003-10-24 19:02:03 +00008830ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008831 show_bgp_ipv6_neighbor_received_routes_cmd,
8832 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8833 SHOW_STR
8834 BGP_STR
8835 "Address family\n"
8836 "Detailed information on TCP and BGP neighbor connections\n"
8837 "Neighbor to display information about\n"
8838 "Neighbor to display information about\n"
8839 "Display the received routes from neighbor\n")
8840
8841DEFUN (show_bgp_neighbor_received_prefix_filter,
8842 show_bgp_neighbor_received_prefix_filter_cmd,
8843 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8844 SHOW_STR
8845 BGP_STR
8846 "Detailed information on TCP and BGP neighbor connections\n"
8847 "Neighbor to display information about\n"
8848 "Neighbor to display information about\n"
8849 "Display information received from a BGP neighbor\n"
8850 "Display the prefixlist filter\n")
8851{
8852 char name[BUFSIZ];
8853 union sockunion *su;
8854 struct peer *peer;
8855 int count;
8856
8857 su = sockunion_str2su (argv[0]);
8858 if (su == NULL)
8859 return CMD_WARNING;
8860
8861 peer = peer_lookup (NULL, su);
8862 if (! peer)
8863 return CMD_WARNING;
8864
8865 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8866 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8867 if (count)
8868 {
8869 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8870 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8871 }
8872
8873 return CMD_SUCCESS;
8874}
8875
8876ALIAS (show_bgp_neighbor_received_prefix_filter,
8877 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8878 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8879 SHOW_STR
8880 BGP_STR
8881 "Address family\n"
8882 "Detailed information on TCP and BGP neighbor connections\n"
8883 "Neighbor to display information about\n"
8884 "Neighbor to display information about\n"
8885 "Display information received from a BGP neighbor\n"
8886 "Display the prefixlist filter\n")
8887
8888/* old command */
paulbb46e942003-10-24 19:02:03 +00008889ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008890 ipv6_bgp_neighbor_received_routes_cmd,
8891 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8892 SHOW_STR
8893 IPV6_STR
8894 BGP_STR
8895 "Detailed information on TCP and BGP neighbor connections\n"
8896 "Neighbor to display information about\n"
8897 "Neighbor to display information about\n"
8898 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008899
8900/* old command */
8901DEFUN (ipv6_mbgp_neighbor_received_routes,
8902 ipv6_mbgp_neighbor_received_routes_cmd,
8903 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8904 SHOW_STR
8905 IPV6_STR
8906 MBGP_STR
8907 "Detailed information on TCP and BGP neighbor connections\n"
8908 "Neighbor to display information about\n"
8909 "Neighbor to display information about\n"
8910 "Display the received routes from neighbor\n")
8911{
paulbb46e942003-10-24 19:02:03 +00008912 struct peer *peer;
8913
8914 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8915 if (! peer)
8916 return CMD_WARNING;
8917
8918 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00008919}
paulbb46e942003-10-24 19:02:03 +00008920
8921DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8922 show_bgp_view_neighbor_received_prefix_filter_cmd,
8923 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8924 SHOW_STR
8925 BGP_STR
8926 "BGP view\n"
8927 "View name\n"
8928 "Detailed information on TCP and BGP neighbor connections\n"
8929 "Neighbor to display information about\n"
8930 "Neighbor to display information about\n"
8931 "Display information received from a BGP neighbor\n"
8932 "Display the prefixlist filter\n")
8933{
8934 char name[BUFSIZ];
8935 union sockunion *su;
8936 struct peer *peer;
8937 struct bgp *bgp;
8938 int count;
8939
8940 /* BGP structure lookup. */
8941 bgp = bgp_lookup_by_name (argv[0]);
8942 if (bgp == NULL)
8943 {
8944 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8945 return CMD_WARNING;
8946 }
8947
8948 su = sockunion_str2su (argv[1]);
8949 if (su == NULL)
8950 return CMD_WARNING;
8951
8952 peer = peer_lookup (bgp, su);
8953 if (! peer)
8954 return CMD_WARNING;
8955
8956 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8957 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8958 if (count)
8959 {
8960 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8961 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8962 }
8963
8964 return CMD_SUCCESS;
8965}
8966
8967ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8968 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8969 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8970 SHOW_STR
8971 BGP_STR
8972 "BGP view\n"
8973 "View name\n"
8974 "Address family\n"
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 information received from a BGP neighbor\n"
8979 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008980#endif /* HAVE_IPV6 */
8981
paul94f2b392005-06-28 12:44:16 +00008982static int
paulbb46e942003-10-24 19:02:03 +00008983bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008984 safi_t safi, enum bgp_show_type type)
8985{
paul718e3742002-12-13 20:15:29 +00008986 if (! peer || ! peer->afc[afi][safi])
8987 {
8988 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008989 return CMD_WARNING;
8990 }
8991
ajs5a646652004-11-05 01:25:55 +00008992 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00008993}
8994
8995DEFUN (show_ip_bgp_neighbor_routes,
8996 show_ip_bgp_neighbor_routes_cmd,
8997 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8998 SHOW_STR
8999 IP_STR
9000 BGP_STR
9001 "Detailed information on TCP and BGP neighbor connections\n"
9002 "Neighbor to display information about\n"
9003 "Neighbor to display information about\n"
9004 "Display routes learned from neighbor\n")
9005{
paulbb46e942003-10-24 19:02:03 +00009006 struct peer *peer;
9007
9008 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9009 if (! peer)
9010 return CMD_WARNING;
9011
9012 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009013 bgp_show_type_neighbor);
9014}
9015
9016DEFUN (show_ip_bgp_neighbor_flap,
9017 show_ip_bgp_neighbor_flap_cmd,
9018 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9019 SHOW_STR
9020 IP_STR
9021 BGP_STR
9022 "Detailed information on TCP and BGP neighbor connections\n"
9023 "Neighbor to display information about\n"
9024 "Neighbor to display information about\n"
9025 "Display flap statistics of the routes learned from neighbor\n")
9026{
paulbb46e942003-10-24 19:02:03 +00009027 struct peer *peer;
9028
9029 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9030 if (! peer)
9031 return CMD_WARNING;
9032
9033 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009034 bgp_show_type_flap_neighbor);
9035}
9036
9037DEFUN (show_ip_bgp_neighbor_damp,
9038 show_ip_bgp_neighbor_damp_cmd,
9039 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9040 SHOW_STR
9041 IP_STR
9042 BGP_STR
9043 "Detailed information on TCP and BGP neighbor connections\n"
9044 "Neighbor to display information about\n"
9045 "Neighbor to display information about\n"
9046 "Display the dampened routes received from neighbor\n")
9047{
paulbb46e942003-10-24 19:02:03 +00009048 struct peer *peer;
9049
9050 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9051 if (! peer)
9052 return CMD_WARNING;
9053
9054 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009055 bgp_show_type_damp_neighbor);
9056}
9057
9058DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9059 show_ip_bgp_ipv4_neighbor_routes_cmd,
9060 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9061 SHOW_STR
9062 IP_STR
9063 BGP_STR
9064 "Address family\n"
9065 "Address Family modifier\n"
9066 "Address Family modifier\n"
9067 "Detailed information on TCP and BGP neighbor connections\n"
9068 "Neighbor to display information about\n"
9069 "Neighbor to display information about\n"
9070 "Display routes learned from neighbor\n")
9071{
paulbb46e942003-10-24 19:02:03 +00009072 struct peer *peer;
9073
9074 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9075 if (! peer)
9076 return CMD_WARNING;
9077
paul718e3742002-12-13 20:15:29 +00009078 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009079 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009080 bgp_show_type_neighbor);
9081
paulbb46e942003-10-24 19:02:03 +00009082 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009083 bgp_show_type_neighbor);
9084}
paulbb46e942003-10-24 19:02:03 +00009085
paulfee0f4c2004-09-13 05:12:46 +00009086DEFUN (show_ip_bgp_view_rsclient,
9087 show_ip_bgp_view_rsclient_cmd,
9088 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9089 SHOW_STR
9090 IP_STR
9091 BGP_STR
9092 "BGP view\n"
9093 "BGP view name\n"
9094 "Information about Route Server Client\n"
9095 NEIGHBOR_ADDR_STR)
9096{
9097 struct bgp_table *table;
9098 struct peer *peer;
9099
9100 if (argc == 2)
9101 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9102 else
9103 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9104
9105 if (! peer)
9106 return CMD_WARNING;
9107
9108 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9109 {
9110 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9111 VTY_NEWLINE);
9112 return CMD_WARNING;
9113 }
9114
9115 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9116 PEER_FLAG_RSERVER_CLIENT))
9117 {
9118 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9119 VTY_NEWLINE);
9120 return CMD_WARNING;
9121 }
9122
9123 table = peer->rib[AFI_IP][SAFI_UNICAST];
9124
ajs5a646652004-11-05 01:25:55 +00009125 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009126}
9127
9128ALIAS (show_ip_bgp_view_rsclient,
9129 show_ip_bgp_rsclient_cmd,
9130 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9131 SHOW_STR
9132 IP_STR
9133 BGP_STR
9134 "Information about Route Server Client\n"
9135 NEIGHBOR_ADDR_STR)
9136
9137DEFUN (show_ip_bgp_view_rsclient_route,
9138 show_ip_bgp_view_rsclient_route_cmd,
9139 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9140 SHOW_STR
9141 IP_STR
9142 BGP_STR
9143 "BGP view\n"
9144 "BGP view name\n"
9145 "Information about Route Server Client\n"
9146 NEIGHBOR_ADDR_STR
9147 "Network in the BGP routing table to display\n")
9148{
9149 struct bgp *bgp;
9150 struct peer *peer;
9151
9152 /* BGP structure lookup. */
9153 if (argc == 3)
9154 {
9155 bgp = bgp_lookup_by_name (argv[0]);
9156 if (bgp == NULL)
9157 {
9158 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9159 return CMD_WARNING;
9160 }
9161 }
9162 else
9163 {
9164 bgp = bgp_get_default ();
9165 if (bgp == NULL)
9166 {
9167 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9168 return CMD_WARNING;
9169 }
9170 }
9171
9172 if (argc == 3)
9173 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9174 else
9175 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9176
9177 if (! peer)
9178 return CMD_WARNING;
9179
9180 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9181 {
9182 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9183 VTY_NEWLINE);
9184 return CMD_WARNING;
9185}
9186
9187 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9188 PEER_FLAG_RSERVER_CLIENT))
9189 {
9190 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9191 VTY_NEWLINE);
9192 return CMD_WARNING;
9193 }
9194
9195 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9196 (argc == 3) ? argv[2] : argv[1],
9197 AFI_IP, SAFI_UNICAST, NULL, 0);
9198}
9199
9200ALIAS (show_ip_bgp_view_rsclient_route,
9201 show_ip_bgp_rsclient_route_cmd,
9202 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9203 SHOW_STR
9204 IP_STR
9205 BGP_STR
9206 "Information about Route Server Client\n"
9207 NEIGHBOR_ADDR_STR
9208 "Network in the BGP routing table to display\n")
9209
9210DEFUN (show_ip_bgp_view_rsclient_prefix,
9211 show_ip_bgp_view_rsclient_prefix_cmd,
9212 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9213 SHOW_STR
9214 IP_STR
9215 BGP_STR
9216 "BGP view\n"
9217 "BGP view name\n"
9218 "Information about Route Server Client\n"
9219 NEIGHBOR_ADDR_STR
9220 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9221{
9222 struct bgp *bgp;
9223 struct peer *peer;
9224
9225 /* BGP structure lookup. */
9226 if (argc == 3)
9227 {
9228 bgp = bgp_lookup_by_name (argv[0]);
9229 if (bgp == NULL)
9230 {
9231 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9232 return CMD_WARNING;
9233 }
9234 }
9235 else
9236 {
9237 bgp = bgp_get_default ();
9238 if (bgp == NULL)
9239 {
9240 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9241 return CMD_WARNING;
9242 }
9243 }
9244
9245 if (argc == 3)
9246 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9247 else
9248 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9249
9250 if (! peer)
9251 return CMD_WARNING;
9252
9253 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9254 {
9255 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9256 VTY_NEWLINE);
9257 return CMD_WARNING;
9258}
9259
9260 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9261 PEER_FLAG_RSERVER_CLIENT))
9262{
9263 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9264 VTY_NEWLINE);
9265 return CMD_WARNING;
9266 }
9267
9268 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9269 (argc == 3) ? argv[2] : argv[1],
9270 AFI_IP, SAFI_UNICAST, NULL, 1);
9271}
9272
9273ALIAS (show_ip_bgp_view_rsclient_prefix,
9274 show_ip_bgp_rsclient_prefix_cmd,
9275 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9276 SHOW_STR
9277 IP_STR
9278 BGP_STR
9279 "Information about Route Server Client\n"
9280 NEIGHBOR_ADDR_STR
9281 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9282
9283
paul718e3742002-12-13 20:15:29 +00009284#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009285DEFUN (show_bgp_view_neighbor_routes,
9286 show_bgp_view_neighbor_routes_cmd,
9287 "show bgp view WORD 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 "Detailed information on TCP and BGP neighbor connections\n"
9293 "Neighbor to display information about\n"
9294 "Neighbor to display information about\n"
9295 "Display routes learned from neighbor\n")
9296{
9297 struct peer *peer;
9298
9299 if (argc == 2)
9300 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9301 else
9302 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9303
9304 if (! peer)
9305 return CMD_WARNING;
9306
9307 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9308 bgp_show_type_neighbor);
9309}
9310
9311ALIAS (show_bgp_view_neighbor_routes,
9312 show_bgp_view_ipv6_neighbor_routes_cmd,
9313 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9314 SHOW_STR
9315 BGP_STR
9316 "BGP view\n"
9317 "BGP view name\n"
9318 "Address family\n"
9319 "Detailed information on TCP and BGP neighbor connections\n"
9320 "Neighbor to display information about\n"
9321 "Neighbor to display information about\n"
9322 "Display routes learned from neighbor\n")
9323
9324DEFUN (show_bgp_view_neighbor_damp,
9325 show_bgp_view_neighbor_damp_cmd,
9326 "show bgp view WORD 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 "Detailed information on TCP and BGP neighbor connections\n"
9332 "Neighbor to display information about\n"
9333 "Neighbor to display information about\n"
9334 "Display the dampened routes received from neighbor\n")
9335{
9336 struct peer *peer;
9337
9338 if (argc == 2)
9339 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9340 else
9341 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9342
9343 if (! peer)
9344 return CMD_WARNING;
9345
9346 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9347 bgp_show_type_damp_neighbor);
9348}
9349
9350ALIAS (show_bgp_view_neighbor_damp,
9351 show_bgp_view_ipv6_neighbor_damp_cmd,
9352 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9353 SHOW_STR
9354 BGP_STR
9355 "BGP view\n"
9356 "BGP view name\n"
9357 "Address family\n"
9358 "Detailed information on TCP and BGP neighbor connections\n"
9359 "Neighbor to display information about\n"
9360 "Neighbor to display information about\n"
9361 "Display the dampened routes received from neighbor\n")
9362
9363DEFUN (show_bgp_view_neighbor_flap,
9364 show_bgp_view_neighbor_flap_cmd,
9365 "show bgp view WORD 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 "Detailed information on TCP and BGP neighbor connections\n"
9371 "Neighbor to display information about\n"
9372 "Neighbor to display information about\n"
9373 "Display flap statistics of the routes learned from neighbor\n")
9374{
9375 struct peer *peer;
9376
9377 if (argc == 2)
9378 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9379 else
9380 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9381
9382 if (! peer)
9383 return CMD_WARNING;
9384
9385 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9386 bgp_show_type_flap_neighbor);
9387}
9388
9389ALIAS (show_bgp_view_neighbor_flap,
9390 show_bgp_view_ipv6_neighbor_flap_cmd,
9391 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9392 SHOW_STR
9393 BGP_STR
9394 "BGP view\n"
9395 "BGP view name\n"
9396 "Address family\n"
9397 "Detailed information on TCP and BGP neighbor connections\n"
9398 "Neighbor to display information about\n"
9399 "Neighbor to display information about\n"
9400 "Display flap statistics of the routes learned from neighbor\n")
9401
9402ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009403 show_bgp_neighbor_routes_cmd,
9404 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9405 SHOW_STR
9406 BGP_STR
9407 "Detailed information on TCP and BGP neighbor connections\n"
9408 "Neighbor to display information about\n"
9409 "Neighbor to display information about\n"
9410 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009411
paulbb46e942003-10-24 19:02:03 +00009412
9413ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009414 show_bgp_ipv6_neighbor_routes_cmd,
9415 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9416 SHOW_STR
9417 BGP_STR
9418 "Address family\n"
9419 "Detailed information on TCP and BGP neighbor connections\n"
9420 "Neighbor to display information about\n"
9421 "Neighbor to display information about\n"
9422 "Display routes learned from neighbor\n")
9423
9424/* old command */
paulbb46e942003-10-24 19:02:03 +00009425ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009426 ipv6_bgp_neighbor_routes_cmd,
9427 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9428 SHOW_STR
9429 IPV6_STR
9430 BGP_STR
9431 "Detailed information on TCP and BGP neighbor connections\n"
9432 "Neighbor to display information about\n"
9433 "Neighbor to display information about\n"
9434 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009435
9436/* old command */
9437DEFUN (ipv6_mbgp_neighbor_routes,
9438 ipv6_mbgp_neighbor_routes_cmd,
9439 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9440 SHOW_STR
9441 IPV6_STR
9442 MBGP_STR
9443 "Detailed information on TCP and BGP neighbor connections\n"
9444 "Neighbor to display information about\n"
9445 "Neighbor to display information about\n"
9446 "Display routes learned from neighbor\n")
9447{
paulbb46e942003-10-24 19:02:03 +00009448 struct peer *peer;
9449
9450 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9451 if (! peer)
9452 return CMD_WARNING;
9453
9454 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009455 bgp_show_type_neighbor);
9456}
paulbb46e942003-10-24 19:02:03 +00009457
9458ALIAS (show_bgp_view_neighbor_flap,
9459 show_bgp_neighbor_flap_cmd,
9460 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9461 SHOW_STR
9462 BGP_STR
9463 "Detailed information on TCP and BGP neighbor connections\n"
9464 "Neighbor to display information about\n"
9465 "Neighbor to display information about\n"
9466 "Display flap statistics of the routes learned from neighbor\n")
9467
9468ALIAS (show_bgp_view_neighbor_flap,
9469 show_bgp_ipv6_neighbor_flap_cmd,
9470 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9471 SHOW_STR
9472 BGP_STR
9473 "Address family\n"
9474 "Detailed information on TCP and BGP neighbor connections\n"
9475 "Neighbor to display information about\n"
9476 "Neighbor to display information about\n"
9477 "Display flap statistics of the routes learned from neighbor\n")
9478
9479ALIAS (show_bgp_view_neighbor_damp,
9480 show_bgp_neighbor_damp_cmd,
9481 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9482 SHOW_STR
9483 BGP_STR
9484 "Detailed information on TCP and BGP neighbor connections\n"
9485 "Neighbor to display information about\n"
9486 "Neighbor to display information about\n"
9487 "Display the dampened routes received from neighbor\n")
9488
9489ALIAS (show_bgp_view_neighbor_damp,
9490 show_bgp_ipv6_neighbor_damp_cmd,
9491 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9492 SHOW_STR
9493 BGP_STR
9494 "Address family\n"
9495 "Detailed information on TCP and BGP neighbor connections\n"
9496 "Neighbor to display information about\n"
9497 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009498 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009499
9500DEFUN (show_bgp_view_rsclient,
9501 show_bgp_view_rsclient_cmd,
9502 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9503 SHOW_STR
9504 BGP_STR
9505 "BGP view\n"
9506 "BGP view name\n"
9507 "Information about Route Server Client\n"
9508 NEIGHBOR_ADDR_STR)
9509{
9510 struct bgp_table *table;
9511 struct peer *peer;
9512
9513 if (argc == 2)
9514 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9515 else
9516 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9517
9518 if (! peer)
9519 return CMD_WARNING;
9520
9521 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9522 {
9523 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9524 VTY_NEWLINE);
9525 return CMD_WARNING;
9526 }
9527
9528 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9529 PEER_FLAG_RSERVER_CLIENT))
9530 {
9531 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9532 VTY_NEWLINE);
9533 return CMD_WARNING;
9534 }
9535
9536 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9537
ajs5a646652004-11-05 01:25:55 +00009538 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009539}
9540
9541ALIAS (show_bgp_view_rsclient,
9542 show_bgp_rsclient_cmd,
9543 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9544 SHOW_STR
9545 BGP_STR
9546 "Information about Route Server Client\n"
9547 NEIGHBOR_ADDR_STR)
9548
9549DEFUN (show_bgp_view_rsclient_route,
9550 show_bgp_view_rsclient_route_cmd,
9551 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9552 SHOW_STR
9553 BGP_STR
9554 "BGP view\n"
9555 "BGP view name\n"
9556 "Information about Route Server Client\n"
9557 NEIGHBOR_ADDR_STR
9558 "Network in the BGP routing table to display\n")
9559{
9560 struct bgp *bgp;
9561 struct peer *peer;
9562
9563 /* BGP structure lookup. */
9564 if (argc == 3)
9565 {
9566 bgp = bgp_lookup_by_name (argv[0]);
9567 if (bgp == NULL)
9568 {
9569 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9570 return CMD_WARNING;
9571 }
9572 }
9573 else
9574 {
9575 bgp = bgp_get_default ();
9576 if (bgp == NULL)
9577 {
9578 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9579 return CMD_WARNING;
9580 }
9581 }
9582
9583 if (argc == 3)
9584 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9585 else
9586 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9587
9588 if (! peer)
9589 return CMD_WARNING;
9590
9591 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9592 {
9593 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9594 VTY_NEWLINE);
9595 return CMD_WARNING;
9596 }
9597
9598 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9599 PEER_FLAG_RSERVER_CLIENT))
9600 {
9601 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9602 VTY_NEWLINE);
9603 return CMD_WARNING;
9604 }
9605
9606 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9607 (argc == 3) ? argv[2] : argv[1],
9608 AFI_IP6, SAFI_UNICAST, NULL, 0);
9609}
9610
9611ALIAS (show_bgp_view_rsclient_route,
9612 show_bgp_rsclient_route_cmd,
9613 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9614 SHOW_STR
9615 BGP_STR
9616 "Information about Route Server Client\n"
9617 NEIGHBOR_ADDR_STR
9618 "Network in the BGP routing table to display\n")
9619
9620DEFUN (show_bgp_view_rsclient_prefix,
9621 show_bgp_view_rsclient_prefix_cmd,
9622 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9623 SHOW_STR
9624 BGP_STR
9625 "BGP view\n"
9626 "BGP view name\n"
9627 "Information about Route Server Client\n"
9628 NEIGHBOR_ADDR_STR
9629 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9630{
9631 struct bgp *bgp;
9632 struct peer *peer;
9633
9634 /* BGP structure lookup. */
9635 if (argc == 3)
9636 {
9637 bgp = bgp_lookup_by_name (argv[0]);
9638 if (bgp == NULL)
9639 {
9640 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9641 return CMD_WARNING;
9642 }
9643 }
9644 else
9645 {
9646 bgp = bgp_get_default ();
9647 if (bgp == NULL)
9648 {
9649 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9650 return CMD_WARNING;
9651 }
9652 }
9653
9654 if (argc == 3)
9655 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9656 else
9657 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9658
9659 if (! peer)
9660 return CMD_WARNING;
9661
9662 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9663 {
9664 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9665 VTY_NEWLINE);
9666 return CMD_WARNING;
9667 }
9668
9669 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9670 PEER_FLAG_RSERVER_CLIENT))
9671 {
9672 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9673 VTY_NEWLINE);
9674 return CMD_WARNING;
9675 }
9676
9677 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9678 (argc == 3) ? argv[2] : argv[1],
9679 AFI_IP6, SAFI_UNICAST, NULL, 1);
9680}
9681
9682ALIAS (show_bgp_view_rsclient_prefix,
9683 show_bgp_rsclient_prefix_cmd,
9684 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9685 SHOW_STR
9686 BGP_STR
9687 "Information about Route Server Client\n"
9688 NEIGHBOR_ADDR_STR
9689 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9690
paul718e3742002-12-13 20:15:29 +00009691#endif /* HAVE_IPV6 */
9692
9693struct bgp_table *bgp_distance_table;
9694
9695struct bgp_distance
9696{
9697 /* Distance value for the IP source prefix. */
9698 u_char distance;
9699
9700 /* Name of the access-list to be matched. */
9701 char *access_list;
9702};
9703
paul94f2b392005-06-28 12:44:16 +00009704static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +00009705bgp_distance_new ()
9706{
9707 struct bgp_distance *new;
9708 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9709 memset (new, 0, sizeof (struct bgp_distance));
9710 return new;
9711}
9712
paul94f2b392005-06-28 12:44:16 +00009713static void
paul718e3742002-12-13 20:15:29 +00009714bgp_distance_free (struct bgp_distance *bdistance)
9715{
9716 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9717}
9718
paul94f2b392005-06-28 12:44:16 +00009719static int
paulfd79ac92004-10-13 05:06:08 +00009720bgp_distance_set (struct vty *vty, const char *distance_str,
9721 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009722{
9723 int ret;
9724 struct prefix_ipv4 p;
9725 u_char distance;
9726 struct bgp_node *rn;
9727 struct bgp_distance *bdistance;
9728
9729 ret = str2prefix_ipv4 (ip_str, &p);
9730 if (ret == 0)
9731 {
9732 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9733 return CMD_WARNING;
9734 }
9735
9736 distance = atoi (distance_str);
9737
9738 /* Get BGP distance node. */
9739 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9740 if (rn->info)
9741 {
9742 bdistance = rn->info;
9743 bgp_unlock_node (rn);
9744 }
9745 else
9746 {
9747 bdistance = bgp_distance_new ();
9748 rn->info = bdistance;
9749 }
9750
9751 /* Set distance value. */
9752 bdistance->distance = distance;
9753
9754 /* Reset access-list configuration. */
9755 if (bdistance->access_list)
9756 {
9757 free (bdistance->access_list);
9758 bdistance->access_list = NULL;
9759 }
9760 if (access_list_str)
9761 bdistance->access_list = strdup (access_list_str);
9762
9763 return CMD_SUCCESS;
9764}
9765
paul94f2b392005-06-28 12:44:16 +00009766static int
paulfd79ac92004-10-13 05:06:08 +00009767bgp_distance_unset (struct vty *vty, const char *distance_str,
9768 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009769{
9770 int ret;
9771 struct prefix_ipv4 p;
9772 u_char distance;
9773 struct bgp_node *rn;
9774 struct bgp_distance *bdistance;
9775
9776 ret = str2prefix_ipv4 (ip_str, &p);
9777 if (ret == 0)
9778 {
9779 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9780 return CMD_WARNING;
9781 }
9782
9783 distance = atoi (distance_str);
9784
9785 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9786 if (! rn)
9787 {
9788 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9789 return CMD_WARNING;
9790 }
9791
9792 bdistance = rn->info;
9793
9794 if (bdistance->access_list)
9795 free (bdistance->access_list);
9796 bgp_distance_free (bdistance);
9797
9798 rn->info = NULL;
9799 bgp_unlock_node (rn);
9800 bgp_unlock_node (rn);
9801
9802 return CMD_SUCCESS;
9803}
9804
paul94f2b392005-06-28 12:44:16 +00009805static void
paul718e3742002-12-13 20:15:29 +00009806bgp_distance_reset ()
9807{
9808 struct bgp_node *rn;
9809 struct bgp_distance *bdistance;
9810
9811 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9812 if ((bdistance = rn->info) != NULL)
9813 {
9814 if (bdistance->access_list)
9815 free (bdistance->access_list);
9816 bgp_distance_free (bdistance);
9817 rn->info = NULL;
9818 bgp_unlock_node (rn);
9819 }
9820}
9821
9822/* Apply BGP information to distance method. */
9823u_char
9824bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9825{
9826 struct bgp_node *rn;
9827 struct prefix_ipv4 q;
9828 struct peer *peer;
9829 struct bgp_distance *bdistance;
9830 struct access_list *alist;
9831 struct bgp_static *bgp_static;
9832
9833 if (! bgp)
9834 return 0;
9835
9836 if (p->family != AF_INET)
9837 return 0;
9838
9839 peer = rinfo->peer;
9840
9841 if (peer->su.sa.sa_family != AF_INET)
9842 return 0;
9843
9844 memset (&q, 0, sizeof (struct prefix_ipv4));
9845 q.family = AF_INET;
9846 q.prefix = peer->su.sin.sin_addr;
9847 q.prefixlen = IPV4_MAX_BITLEN;
9848
9849 /* Check source address. */
9850 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9851 if (rn)
9852 {
9853 bdistance = rn->info;
9854 bgp_unlock_node (rn);
9855
9856 if (bdistance->access_list)
9857 {
9858 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9859 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9860 return bdistance->distance;
9861 }
9862 else
9863 return bdistance->distance;
9864 }
9865
9866 /* Backdoor check. */
9867 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9868 if (rn)
9869 {
9870 bgp_static = rn->info;
9871 bgp_unlock_node (rn);
9872
9873 if (bgp_static->backdoor)
9874 {
9875 if (bgp->distance_local)
9876 return bgp->distance_local;
9877 else
9878 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9879 }
9880 }
9881
9882 if (peer_sort (peer) == BGP_PEER_EBGP)
9883 {
9884 if (bgp->distance_ebgp)
9885 return bgp->distance_ebgp;
9886 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9887 }
9888 else
9889 {
9890 if (bgp->distance_ibgp)
9891 return bgp->distance_ibgp;
9892 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9893 }
9894}
9895
9896DEFUN (bgp_distance,
9897 bgp_distance_cmd,
9898 "distance bgp <1-255> <1-255> <1-255>",
9899 "Define an administrative distance\n"
9900 "BGP distance\n"
9901 "Distance for routes external to the AS\n"
9902 "Distance for routes internal to the AS\n"
9903 "Distance for local routes\n")
9904{
9905 struct bgp *bgp;
9906
9907 bgp = vty->index;
9908
9909 bgp->distance_ebgp = atoi (argv[0]);
9910 bgp->distance_ibgp = atoi (argv[1]);
9911 bgp->distance_local = atoi (argv[2]);
9912 return CMD_SUCCESS;
9913}
9914
9915DEFUN (no_bgp_distance,
9916 no_bgp_distance_cmd,
9917 "no distance bgp <1-255> <1-255> <1-255>",
9918 NO_STR
9919 "Define an administrative distance\n"
9920 "BGP distance\n"
9921 "Distance for routes external to the AS\n"
9922 "Distance for routes internal to the AS\n"
9923 "Distance for local routes\n")
9924{
9925 struct bgp *bgp;
9926
9927 bgp = vty->index;
9928
9929 bgp->distance_ebgp= 0;
9930 bgp->distance_ibgp = 0;
9931 bgp->distance_local = 0;
9932 return CMD_SUCCESS;
9933}
9934
9935ALIAS (no_bgp_distance,
9936 no_bgp_distance2_cmd,
9937 "no distance bgp",
9938 NO_STR
9939 "Define an administrative distance\n"
9940 "BGP distance\n")
9941
9942DEFUN (bgp_distance_source,
9943 bgp_distance_source_cmd,
9944 "distance <1-255> A.B.C.D/M",
9945 "Define an administrative distance\n"
9946 "Administrative distance\n"
9947 "IP source prefix\n")
9948{
9949 bgp_distance_set (vty, argv[0], argv[1], NULL);
9950 return CMD_SUCCESS;
9951}
9952
9953DEFUN (no_bgp_distance_source,
9954 no_bgp_distance_source_cmd,
9955 "no distance <1-255> A.B.C.D/M",
9956 NO_STR
9957 "Define an administrative distance\n"
9958 "Administrative distance\n"
9959 "IP source prefix\n")
9960{
9961 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9962 return CMD_SUCCESS;
9963}
9964
9965DEFUN (bgp_distance_source_access_list,
9966 bgp_distance_source_access_list_cmd,
9967 "distance <1-255> A.B.C.D/M WORD",
9968 "Define an administrative distance\n"
9969 "Administrative distance\n"
9970 "IP source prefix\n"
9971 "Access list name\n")
9972{
9973 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9974 return CMD_SUCCESS;
9975}
9976
9977DEFUN (no_bgp_distance_source_access_list,
9978 no_bgp_distance_source_access_list_cmd,
9979 "no distance <1-255> A.B.C.D/M WORD",
9980 NO_STR
9981 "Define an administrative distance\n"
9982 "Administrative distance\n"
9983 "IP source prefix\n"
9984 "Access list name\n")
9985{
9986 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9987 return CMD_SUCCESS;
9988}
9989
9990DEFUN (bgp_damp_set,
9991 bgp_damp_set_cmd,
9992 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9993 "BGP Specific commands\n"
9994 "Enable route-flap dampening\n"
9995 "Half-life time for the penalty\n"
9996 "Value to start reusing a route\n"
9997 "Value to start suppressing a route\n"
9998 "Maximum duration to suppress a stable route\n")
9999{
10000 struct bgp *bgp;
10001 int half = DEFAULT_HALF_LIFE * 60;
10002 int reuse = DEFAULT_REUSE;
10003 int suppress = DEFAULT_SUPPRESS;
10004 int max = 4 * half;
10005
10006 if (argc == 4)
10007 {
10008 half = atoi (argv[0]) * 60;
10009 reuse = atoi (argv[1]);
10010 suppress = atoi (argv[2]);
10011 max = atoi (argv[3]) * 60;
10012 }
10013 else if (argc == 1)
10014 {
10015 half = atoi (argv[0]) * 60;
10016 max = 4 * half;
10017 }
10018
10019 bgp = vty->index;
10020 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10021 half, reuse, suppress, max);
10022}
10023
10024ALIAS (bgp_damp_set,
10025 bgp_damp_set2_cmd,
10026 "bgp dampening <1-45>",
10027 "BGP Specific commands\n"
10028 "Enable route-flap dampening\n"
10029 "Half-life time for the penalty\n")
10030
10031ALIAS (bgp_damp_set,
10032 bgp_damp_set3_cmd,
10033 "bgp dampening",
10034 "BGP Specific commands\n"
10035 "Enable route-flap dampening\n")
10036
10037DEFUN (bgp_damp_unset,
10038 bgp_damp_unset_cmd,
10039 "no bgp dampening",
10040 NO_STR
10041 "BGP Specific commands\n"
10042 "Enable route-flap dampening\n")
10043{
10044 struct bgp *bgp;
10045
10046 bgp = vty->index;
10047 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10048}
10049
10050ALIAS (bgp_damp_unset,
10051 bgp_damp_unset2_cmd,
10052 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10053 NO_STR
10054 "BGP Specific commands\n"
10055 "Enable route-flap dampening\n"
10056 "Half-life time for the penalty\n"
10057 "Value to start reusing a route\n"
10058 "Value to start suppressing a route\n"
10059 "Maximum duration to suppress a stable route\n")
10060
10061DEFUN (show_ip_bgp_dampened_paths,
10062 show_ip_bgp_dampened_paths_cmd,
10063 "show ip bgp dampened-paths",
10064 SHOW_STR
10065 IP_STR
10066 BGP_STR
10067 "Display paths suppressed due to dampening\n")
10068{
ajs5a646652004-11-05 01:25:55 +000010069 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10070 NULL);
paul718e3742002-12-13 20:15:29 +000010071}
10072
10073DEFUN (show_ip_bgp_flap_statistics,
10074 show_ip_bgp_flap_statistics_cmd,
10075 "show ip bgp flap-statistics",
10076 SHOW_STR
10077 IP_STR
10078 BGP_STR
10079 "Display flap statistics of routes\n")
10080{
ajs5a646652004-11-05 01:25:55 +000010081 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10082 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010083}
10084
10085/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010086static int
paulfd79ac92004-10-13 05:06:08 +000010087bgp_clear_damp_route (struct vty *vty, const char *view_name,
10088 const char *ip_str, afi_t afi, safi_t safi,
10089 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010090{
10091 int ret;
10092 struct prefix match;
10093 struct bgp_node *rn;
10094 struct bgp_node *rm;
10095 struct bgp_info *ri;
10096 struct bgp_info *ri_temp;
10097 struct bgp *bgp;
10098 struct bgp_table *table;
10099
10100 /* BGP structure lookup. */
10101 if (view_name)
10102 {
10103 bgp = bgp_lookup_by_name (view_name);
10104 if (bgp == NULL)
10105 {
10106 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10107 return CMD_WARNING;
10108 }
10109 }
10110 else
10111 {
10112 bgp = bgp_get_default ();
10113 if (bgp == NULL)
10114 {
10115 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10116 return CMD_WARNING;
10117 }
10118 }
10119
10120 /* Check IP address argument. */
10121 ret = str2prefix (ip_str, &match);
10122 if (! ret)
10123 {
10124 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10125 return CMD_WARNING;
10126 }
10127
10128 match.family = afi2family (afi);
10129
10130 if (safi == SAFI_MPLS_VPN)
10131 {
10132 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10133 {
10134 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10135 continue;
10136
10137 if ((table = rn->info) != NULL)
10138 if ((rm = bgp_node_match (table, &match)) != NULL)
10139 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10140 {
10141 ri = rm->info;
10142 while (ri)
10143 {
10144 if (ri->damp_info)
10145 {
10146 ri_temp = ri->next;
10147 bgp_damp_info_free (ri->damp_info, 1);
10148 ri = ri_temp;
10149 }
10150 else
10151 ri = ri->next;
10152 }
10153 }
10154 }
10155 }
10156 else
10157 {
10158 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10159 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10160 {
10161 ri = rn->info;
10162 while (ri)
10163 {
10164 if (ri->damp_info)
10165 {
10166 ri_temp = ri->next;
10167 bgp_damp_info_free (ri->damp_info, 1);
10168 ri = ri_temp;
10169 }
10170 else
10171 ri = ri->next;
10172 }
10173 }
10174 }
10175
10176 return CMD_SUCCESS;
10177}
10178
10179DEFUN (clear_ip_bgp_dampening,
10180 clear_ip_bgp_dampening_cmd,
10181 "clear ip bgp dampening",
10182 CLEAR_STR
10183 IP_STR
10184 BGP_STR
10185 "Clear route flap dampening information\n")
10186{
10187 bgp_damp_info_clean ();
10188 return CMD_SUCCESS;
10189}
10190
10191DEFUN (clear_ip_bgp_dampening_prefix,
10192 clear_ip_bgp_dampening_prefix_cmd,
10193 "clear ip bgp dampening A.B.C.D/M",
10194 CLEAR_STR
10195 IP_STR
10196 BGP_STR
10197 "Clear route flap dampening information\n"
10198 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10199{
10200 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10201 SAFI_UNICAST, NULL, 1);
10202}
10203
10204DEFUN (clear_ip_bgp_dampening_address,
10205 clear_ip_bgp_dampening_address_cmd,
10206 "clear ip bgp dampening A.B.C.D",
10207 CLEAR_STR
10208 IP_STR
10209 BGP_STR
10210 "Clear route flap dampening information\n"
10211 "Network to clear damping information\n")
10212{
10213 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10214 SAFI_UNICAST, NULL, 0);
10215}
10216
10217DEFUN (clear_ip_bgp_dampening_address_mask,
10218 clear_ip_bgp_dampening_address_mask_cmd,
10219 "clear ip bgp dampening A.B.C.D A.B.C.D",
10220 CLEAR_STR
10221 IP_STR
10222 BGP_STR
10223 "Clear route flap dampening information\n"
10224 "Network to clear damping information\n"
10225 "Network mask\n")
10226{
10227 int ret;
10228 char prefix_str[BUFSIZ];
10229
10230 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10231 if (! ret)
10232 {
10233 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10234 return CMD_WARNING;
10235 }
10236
10237 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10238 SAFI_UNICAST, NULL, 0);
10239}
10240
paul94f2b392005-06-28 12:44:16 +000010241static int
paul718e3742002-12-13 20:15:29 +000010242bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10243 afi_t afi, safi_t safi, int *write)
10244{
10245 struct bgp_node *prn;
10246 struct bgp_node *rn;
10247 struct bgp_table *table;
10248 struct prefix *p;
10249 struct prefix_rd *prd;
10250 struct bgp_static *bgp_static;
10251 u_int32_t label;
10252 char buf[SU_ADDRSTRLEN];
10253 char rdbuf[RD_ADDRSTRLEN];
10254
10255 /* Network configuration. */
10256 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10257 if ((table = prn->info) != NULL)
10258 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10259 if ((bgp_static = rn->info) != NULL)
10260 {
10261 p = &rn->p;
10262 prd = (struct prefix_rd *) &prn->p;
10263
10264 /* "address-family" display. */
10265 bgp_config_write_family_header (vty, afi, safi, write);
10266
10267 /* "network" configuration display. */
10268 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10269 label = decode_label (bgp_static->tag);
10270
10271 vty_out (vty, " network %s/%d rd %s tag %d",
10272 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10273 p->prefixlen,
10274 rdbuf, label);
10275 vty_out (vty, "%s", VTY_NEWLINE);
10276 }
10277 return 0;
10278}
10279
10280/* Configuration of static route announcement and aggregate
10281 information. */
10282int
10283bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10284 afi_t afi, safi_t safi, int *write)
10285{
10286 struct bgp_node *rn;
10287 struct prefix *p;
10288 struct bgp_static *bgp_static;
10289 struct bgp_aggregate *bgp_aggregate;
10290 char buf[SU_ADDRSTRLEN];
10291
10292 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10293 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10294
10295 /* Network configuration. */
10296 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10297 if ((bgp_static = rn->info) != NULL)
10298 {
10299 p = &rn->p;
10300
10301 /* "address-family" display. */
10302 bgp_config_write_family_header (vty, afi, safi, write);
10303
10304 /* "network" configuration display. */
10305 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10306 {
10307 u_int32_t destination;
10308 struct in_addr netmask;
10309
10310 destination = ntohl (p->u.prefix4.s_addr);
10311 masklen2ip (p->prefixlen, &netmask);
10312 vty_out (vty, " network %s",
10313 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10314
10315 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10316 || (IN_CLASSB (destination) && p->prefixlen == 16)
10317 || (IN_CLASSA (destination) && p->prefixlen == 8)
10318 || p->u.prefix4.s_addr == 0)
10319 {
10320 /* Natural mask is not display. */
10321 }
10322 else
10323 vty_out (vty, " mask %s", inet_ntoa (netmask));
10324 }
10325 else
10326 {
10327 vty_out (vty, " network %s/%d",
10328 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10329 p->prefixlen);
10330 }
10331
10332 if (bgp_static->rmap.name)
10333 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10334 else if (bgp_static->backdoor)
10335 vty_out (vty, " backdoor");
10336
10337 vty_out (vty, "%s", VTY_NEWLINE);
10338 }
10339
10340 /* Aggregate-address configuration. */
10341 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10342 if ((bgp_aggregate = rn->info) != NULL)
10343 {
10344 p = &rn->p;
10345
10346 /* "address-family" display. */
10347 bgp_config_write_family_header (vty, afi, safi, write);
10348
10349 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10350 {
10351 struct in_addr netmask;
10352
10353 masklen2ip (p->prefixlen, &netmask);
10354 vty_out (vty, " aggregate-address %s %s",
10355 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10356 inet_ntoa (netmask));
10357 }
10358 else
10359 {
10360 vty_out (vty, " aggregate-address %s/%d",
10361 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10362 p->prefixlen);
10363 }
10364
10365 if (bgp_aggregate->as_set)
10366 vty_out (vty, " as-set");
10367
10368 if (bgp_aggregate->summary_only)
10369 vty_out (vty, " summary-only");
10370
10371 vty_out (vty, "%s", VTY_NEWLINE);
10372 }
10373
10374 return 0;
10375}
10376
10377int
10378bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10379{
10380 struct bgp_node *rn;
10381 struct bgp_distance *bdistance;
10382
10383 /* Distance configuration. */
10384 if (bgp->distance_ebgp
10385 && bgp->distance_ibgp
10386 && bgp->distance_local
10387 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10388 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10389 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10390 vty_out (vty, " distance bgp %d %d %d%s",
10391 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10392 VTY_NEWLINE);
10393
10394 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10395 if ((bdistance = rn->info) != NULL)
10396 {
10397 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10398 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10399 bdistance->access_list ? bdistance->access_list : "",
10400 VTY_NEWLINE);
10401 }
10402
10403 return 0;
10404}
10405
10406/* Allocate routing table structure and install commands. */
10407void
10408bgp_route_init ()
10409{
10410 /* Init BGP distance table. */
10411 bgp_distance_table = bgp_table_init ();
10412
10413 /* IPv4 BGP commands. */
10414 install_element (BGP_NODE, &bgp_network_cmd);
10415 install_element (BGP_NODE, &bgp_network_mask_cmd);
10416 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10417 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10418 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10419 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10420 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10421 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10422 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10423 install_element (BGP_NODE, &no_bgp_network_cmd);
10424 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10425 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10426 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10427 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10428 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10429 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10430 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10431 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10432
10433 install_element (BGP_NODE, &aggregate_address_cmd);
10434 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10435 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10436 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10437 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10438 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10439 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10440 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10441 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10442 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10443 install_element (BGP_NODE, &no_aggregate_address_cmd);
10444 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10445 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10446 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10447 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10448 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10449 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10450 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10451 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10452 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10453
10454 /* IPv4 unicast configuration. */
10455 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10456 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10457 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10458 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10459 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10460 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10461 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10462 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10463 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10464 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10465 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10466 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10467 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10468 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10469 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10470 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10471 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10472 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10473 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10474 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10475 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10476 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10477 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10478 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10479 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10480 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10481 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10482 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10483 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10484 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10485 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10486 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10487
10488 /* IPv4 multicast configuration. */
10489 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10490 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10491 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10492 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10493 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10494 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10495 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10496 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10497 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10498 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10499 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10500 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10501 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10502 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10503 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10504 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10505 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10506 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10507 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10508 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10509 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10510 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10511 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10512 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10513 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10514 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10515 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10516 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10517 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10518 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10519 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10520 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10521
10522 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10524 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10526 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10527 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10528 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10530 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10531 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10532 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10533 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10534 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10535 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10536 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10537 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10539 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10540 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10541 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10543 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10545 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10546 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10547 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10548 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10549 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10550 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10551 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10553 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10554 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10555 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10556 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10557 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10558 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10559 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10560 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10561 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10562 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10563 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10564 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10565 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10566 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10567 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10568 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10569 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10570 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10571 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10572 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10573 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10574 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10575 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10576 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10577 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10578 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10579 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10580 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10581 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10582 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10583 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10584 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10585 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10586 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10587 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10588 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010589 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10590 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10591 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10592 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10593 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10594 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010595
10596 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10597 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10598 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10600 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10601 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10602 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10603 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10604 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10605 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10606 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10607 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10608 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10609 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10611 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10613 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10615 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10616 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10617 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10618 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10619 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10620 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10621 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10622 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10623 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10624 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10626 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10629 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10630 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10631 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10632 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10637 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10639 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10640 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10641 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10642 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10643 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10645 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10646 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10647 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10649 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10651 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10652 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10653 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10654 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10655 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10656 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10657 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10658 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10659 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10660 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10661 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10662 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010663 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10664 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10665 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10666 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10667 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10668 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010669
10670 /* BGP dampening clear commands */
10671 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10672 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10673 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10674 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10675
10676#ifdef HAVE_IPV6
10677 /* New config IPv6 BGP commands. */
10678 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10679 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10680 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10681 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10682
10683 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10684 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10685 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10686 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10687
10688 /* Old config IPv6 BGP commands. */
10689 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10690 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10691
10692 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10693 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10694 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10695 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10696
10697 install_element (VIEW_NODE, &show_bgp_cmd);
10698 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10699 install_element (VIEW_NODE, &show_bgp_route_cmd);
10700 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10701 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10702 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10703 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10704 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10705 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10706 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10707 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10708 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10709 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10710 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10711 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10712 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10713 install_element (VIEW_NODE, &show_bgp_community_cmd);
10714 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10715 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10716 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10717 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10718 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10719 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10720 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10721 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10722 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10723 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10724 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10725 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10726 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10727 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10728 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10729 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10730 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10731 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10732 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10733 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10734 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10735 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10736 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10737 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10738 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10739 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10740 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10741 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10742 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010743 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10744 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10745 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10746 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010747 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10748 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10749 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010750 install_element (VIEW_NODE, &show_bgp_view_cmd);
10751 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10752 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10753 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10754 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10755 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10756 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10757 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10758 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10759 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10760 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10761 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10762 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10763 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10764 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10765 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10766 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10767 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010768 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10769 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10770 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010771
10772 install_element (ENABLE_NODE, &show_bgp_cmd);
10773 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10774 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10775 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10776 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10777 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10778 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10779 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10780 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10781 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10782 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10783 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10784 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10785 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10786 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10787 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10788 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10789 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10790 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10791 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10792 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10793 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10794 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10795 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10796 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10797 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10798 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10799 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10800 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10801 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10802 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10803 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10804 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10805 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10806 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10807 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10808 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10809 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10810 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10811 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10812 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10813 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10814 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10815 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10816 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10817 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010818 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10819 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10820 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10821 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010822 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10823 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10824 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010825 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10826 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10827 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10828 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10829 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10830 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10831 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10832 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10833 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10834 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10835 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10836 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10837 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10838 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10839 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10840 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10841 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10842 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010843 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10844 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10845 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010846
10847 /* old command */
10848 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10849 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10850 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10851 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10852 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10853 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10854 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10855 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10856 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10857 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10858 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10859 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10860 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10861 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10862 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10863 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10864 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10865 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10866 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10867 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10868 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10869 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10870 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10871 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10872 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10873 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10874 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10875 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10876 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10877 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10878 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10879 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10880 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10881 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10882 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10883 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000010884
paul718e3742002-12-13 20:15:29 +000010885 /* old command */
10886 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10887 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10888 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10889 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10890 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10891 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10892 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10893 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10894 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10895 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10896 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10897 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10898 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10899 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10900 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10901 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10902 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10903 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10904 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10905 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10906 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10907 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10908 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10909 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10910 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10911 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10912 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10913 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10914 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10915 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10916 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10917 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10918 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10919 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10920 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10921 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10922
10923 /* old command */
10924 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10925 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10926 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10927 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10928
10929 /* old command */
10930 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10931 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10932 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10933 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10934
10935 /* old command */
10936 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10937 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10938 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10939 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10940#endif /* HAVE_IPV6 */
10941
10942 install_element (BGP_NODE, &bgp_distance_cmd);
10943 install_element (BGP_NODE, &no_bgp_distance_cmd);
10944 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10945 install_element (BGP_NODE, &bgp_distance_source_cmd);
10946 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10947 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10948 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10949
10950 install_element (BGP_NODE, &bgp_damp_set_cmd);
10951 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10952 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10953 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10954 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10955 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10956 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10957 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10958 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10959 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
10960}