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