blob: 3d9856b9910818c8ba710d5cdbdf222c7ff7879b [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
paulb40d9392005-08-22 22:34:41 +00001557/* Unconditionally remove the route from the RIB, without taking
1558 * damping into consideration (eg, because the session went down)
1559 */
paul94f2b392005-06-28 12:44:16 +00001560static void
paul718e3742002-12-13 20:15:29 +00001561bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1562 afi_t afi, safi_t safi)
1563{
paulb40d9392005-08-22 22:34:41 +00001564 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
1565 && rn->table->type == BGP_TABLE_MAIN)
paul718e3742002-12-13 20:15:29 +00001566 {
paulfee0f4c2004-09-13 05:12:46 +00001567 /* Ignore 'pcount' for RS-client tables */
1568 if ( rn->table->type == BGP_TABLE_MAIN)
1569 {
paulb40d9392005-08-22 22:34:41 +00001570 peer->pcount[afi][safi]--;
1571 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001572 }
paul718e3742002-12-13 20:15:29 +00001573 }
paulb40d9392005-08-22 22:34:41 +00001574 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001575 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00001576}
1577
paul94f2b392005-06-28 12:44:16 +00001578static void
paul718e3742002-12-13 20:15:29 +00001579bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001580 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001581{
paul718e3742002-12-13 20:15:29 +00001582 int status = BGP_DAMP_NONE;
1583
paulb40d9392005-08-22 22:34:41 +00001584 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
1585 && rn->table->type == BGP_TABLE_MAIN)
paul718e3742002-12-13 20:15:29 +00001586 {
paulb40d9392005-08-22 22:34:41 +00001587 /* Ignore 'pcount' for RS-client tables */
1588 if ( rn->table->type == BGP_TABLE_MAIN)
1589 {
1590 peer->pcount[afi][safi]--;
1591 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1592 }
paul718e3742002-12-13 20:15:29 +00001593 }
paulb40d9392005-08-22 22:34:41 +00001594
1595 /* apply dampening, if result is suppressed, we'll be retaining
1596 * the bgp_info in the RIB for historical reference.
1597 */
1598 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1599 && peer_sort (peer) == BGP_PEER_EBGP)
1600 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1601 == BGP_DAMP_SUPPRESSED)
1602 return;
paul718e3742002-12-13 20:15:29 +00001603
paul718e3742002-12-13 20:15:29 +00001604 bgp_process (peer->bgp, rn, afi, safi);
1605
paul718e3742002-12-13 20:15:29 +00001606 if (status != BGP_DAMP_USED)
paul200df112005-06-01 11:17:05 +00001607 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00001608}
1609
paul94f2b392005-06-28 12:44:16 +00001610static void
paulfee0f4c2004-09-13 05:12:46 +00001611bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1612 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1613 int sub_type, struct prefix_rd *prd, u_char *tag)
1614{
1615 struct bgp_node *rn;
1616 struct bgp *bgp;
1617 struct attr new_attr;
1618 struct attr *attr_new;
1619 struct attr *attr_new2;
1620 struct bgp_info *ri;
1621 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001622 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001623 char buf[SU_ADDRSTRLEN];
1624
1625 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1626 if (peer == rsclient)
1627 return;
1628
1629 bgp = peer->bgp;
1630 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1631
1632 /* Check previously received route. */
1633 for (ri = rn->info; ri; ri = ri->next)
1634 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1635 break;
1636
1637 /* AS path loop check. */
1638 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1639 {
1640 reason = "as-path contains our own AS;";
1641 goto filtered;
1642 }
1643
1644 /* Route reflector originator ID check. */
1645 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1646 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->originator_id))
1647 {
1648 reason = "originator is us;";
1649 goto filtered;
1650 }
1651
1652 new_attr = *attr;
1653
1654 /* Apply export policy. */
1655 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1656 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1657 {
1658 reason = "export-policy;";
1659 goto filtered;
1660 }
1661
1662 attr_new2 = bgp_attr_intern (&new_attr);
1663
1664 /* Apply import policy. */
1665 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1666 {
1667 bgp_attr_unintern (attr_new2);
1668
1669 reason = "import-policy;";
1670 goto filtered;
1671 }
1672
1673 attr_new = bgp_attr_intern (&new_attr);
1674 bgp_attr_unintern (attr_new2);
1675
1676 /* IPv4 unicast next hop check. */
1677 if (afi == AFI_IP && safi == SAFI_UNICAST)
1678 {
1679 /* Next hop must not be 0.0.0.0 nor Class E address. */
1680 if (new_attr.nexthop.s_addr == 0
1681 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1682 {
1683 bgp_attr_unintern (attr_new);
1684
1685 reason = "martian next-hop;";
1686 goto filtered;
1687 }
1688 }
1689
1690 /* If the update is implicit withdraw. */
1691 if (ri)
1692 {
1693 ri->uptime = time (NULL);
1694
1695 /* Same attribute comes in. */
1696 if (attrhash_cmp (ri->attr, attr_new))
1697 {
1698
1699 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1700
1701 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001702 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001703 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1704 peer->host,
1705 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1706 p->prefixlen, rsclient->host);
1707
1708 bgp_unlock_node (rn);
1709 bgp_attr_unintern (attr_new);
1710
1711 return;
1712 }
1713
1714 /* Received Logging. */
1715 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001716 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001717 peer->host,
1718 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1719 p->prefixlen, rsclient->host);
1720
1721 /* The attribute is changed. */
1722 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1723
1724 /* Update to new attribute. */
1725 bgp_attr_unintern (ri->attr);
1726 ri->attr = attr_new;
1727
1728 /* Update MPLS tag. */
1729 if (safi == SAFI_MPLS_VPN)
1730 memcpy (ri->tag, tag, 3);
1731
1732 SET_FLAG (ri->flags, BGP_INFO_VALID);
1733
1734 /* Process change. */
1735 bgp_process (bgp, rn, afi, safi);
1736 bgp_unlock_node (rn);
1737
1738 return;
1739 }
1740
1741 /* Received Logging. */
1742 if (BGP_DEBUG (update, UPDATE_IN))
1743 {
ajsd2c1f162004-12-08 21:10:20 +00001744 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001745 peer->host,
1746 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1747 p->prefixlen, rsclient->host);
1748 }
1749
1750 /* Make new BGP info. */
1751 new = bgp_info_new ();
1752 new->type = type;
1753 new->sub_type = sub_type;
1754 new->peer = peer;
1755 new->attr = attr_new;
1756 new->uptime = time (NULL);
1757
1758 /* Update MPLS tag. */
1759 if (safi == SAFI_MPLS_VPN)
1760 memcpy (new->tag, tag, 3);
1761
1762 SET_FLAG (new->flags, BGP_INFO_VALID);
1763
1764 /* Register new BGP information. */
1765 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001766
1767 /* route_node_get lock */
1768 bgp_unlock_node (rn);
1769
paulfee0f4c2004-09-13 05:12:46 +00001770 /* Process change. */
1771 bgp_process (bgp, rn, afi, safi);
1772
1773 return;
1774
1775 filtered:
1776
1777 /* This BGP update is filtered. Log the reason then update BGP entry. */
1778 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001779 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001780 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1781 peer->host,
1782 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1783 p->prefixlen, rsclient->host, reason);
1784
1785 if (ri)
paulb40d9392005-08-22 22:34:41 +00001786 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001787
1788 bgp_unlock_node (rn);
1789
1790 return;
1791}
1792
paul94f2b392005-06-28 12:44:16 +00001793static void
paulfee0f4c2004-09-13 05:12:46 +00001794bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1795 struct peer *peer, struct prefix *p, int type, int sub_type,
1796 struct prefix_rd *prd, u_char *tag)
1797 {
1798 struct bgp_node *rn;
1799 struct bgp_info *ri;
1800 char buf[SU_ADDRSTRLEN];
1801
1802 if (rsclient == peer)
1803 return;
1804
1805 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1806
1807 /* Lookup withdrawn route. */
1808 for (ri = rn->info; ri; ri = ri->next)
1809 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1810 break;
1811
1812 /* Withdraw specified route from routing table. */
1813 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001814 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001815 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001816 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001817 "%s Can't find the route %s/%d", peer->host,
1818 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1819 p->prefixlen);
1820
1821 /* Unlock bgp_node_get() lock. */
1822 bgp_unlock_node (rn);
1823 }
1824
paul94f2b392005-06-28 12:44:16 +00001825static int
paulfee0f4c2004-09-13 05:12:46 +00001826bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001827 afi_t afi, safi_t safi, int type, int sub_type,
1828 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1829{
1830 int ret;
1831 int aspath_loop_count = 0;
1832 struct bgp_node *rn;
1833 struct bgp *bgp;
1834 struct attr new_attr;
1835 struct attr *attr_new;
1836 struct bgp_info *ri;
1837 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001838 const char *reason;
paul718e3742002-12-13 20:15:29 +00001839 char buf[SU_ADDRSTRLEN];
1840
1841 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001842 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00001843
1844 /* When peer's soft reconfiguration enabled. Record input packet in
1845 Adj-RIBs-In. */
1846 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1847 && peer != bgp->peer_self && ! soft_reconfig)
1848 bgp_adj_in_set (rn, peer, attr);
1849
1850 /* Check previously received route. */
1851 for (ri = rn->info; ri; ri = ri->next)
1852 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1853 break;
1854
1855 /* AS path local-as loop check. */
1856 if (peer->change_local_as)
1857 {
1858 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1859 aspath_loop_count = 1;
1860
1861 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1862 {
1863 reason = "as-path contains our own AS;";
1864 goto filtered;
1865 }
1866 }
1867
1868 /* AS path loop check. */
1869 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1870 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1871 && aspath_loop_check(attr->aspath, bgp->confed_id)
1872 > peer->allowas_in[afi][safi]))
1873 {
1874 reason = "as-path contains our own AS;";
1875 goto filtered;
1876 }
1877
1878 /* Route reflector originator ID check. */
1879 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1880 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1881 {
1882 reason = "originator is us;";
1883 goto filtered;
1884 }
1885
1886 /* Route reflector cluster ID check. */
1887 if (bgp_cluster_filter (peer, attr))
1888 {
1889 reason = "reflected from the same cluster;";
1890 goto filtered;
1891 }
1892
1893 /* Apply incoming filter. */
1894 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1895 {
1896 reason = "filter;";
1897 goto filtered;
1898 }
1899
1900 /* Apply incoming route-map. */
1901 new_attr = *attr;
1902
1903 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1904 {
1905 reason = "route-map;";
1906 goto filtered;
1907 }
1908
1909 /* IPv4 unicast next hop check. */
1910 if (afi == AFI_IP && safi == SAFI_UNICAST)
1911 {
1912 /* If the peer is EBGP and nexthop is not on connected route,
1913 discard it. */
1914 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1915 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00001916 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00001917 {
1918 reason = "non-connected next-hop;";
1919 goto filtered;
1920 }
1921
1922 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1923 must not be my own address. */
1924 if (bgp_nexthop_self (afi, &new_attr)
1925 || new_attr.nexthop.s_addr == 0
1926 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1927 {
1928 reason = "martian next-hop;";
1929 goto filtered;
1930 }
1931 }
1932
1933 attr_new = bgp_attr_intern (&new_attr);
1934
1935 /* If the update is implicit withdraw. */
1936 if (ri)
1937 {
1938 ri->uptime = time (NULL);
1939
1940 /* Same attribute comes in. */
1941 if (attrhash_cmp (ri->attr, attr_new))
1942 {
1943 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1944
1945 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1946 && peer_sort (peer) == BGP_PEER_EBGP
1947 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1948 {
1949 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001950 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001951 peer->host,
1952 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1953 p->prefixlen);
1954
1955 peer->pcount[afi][safi]++;
1956 ret = bgp_damp_update (ri, rn, afi, safi);
1957 if (ret != BGP_DAMP_SUPPRESSED)
1958 {
1959 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1960 bgp_process (bgp, rn, afi, safi);
1961 }
1962 }
1963 else
1964 {
1965 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001966 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00001967 "%s rcvd %s/%d...duplicate ignored",
1968 peer->host,
1969 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1970 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00001971
1972 /* graceful restart STALE flag unset. */
1973 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1974 {
1975 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1976 peer->pcount[afi][safi]++;
1977 }
paul718e3742002-12-13 20:15:29 +00001978 }
1979
1980 bgp_unlock_node (rn);
1981 bgp_attr_unintern (attr_new);
1982 return 0;
1983 }
1984
1985 /* Received Logging. */
1986 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001987 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001988 peer->host,
1989 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1990 p->prefixlen);
1991
hasso93406d82005-02-02 14:40:33 +00001992 /* graceful restart STALE flag unset. */
1993 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1994 {
1995 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1996 peer->pcount[afi][safi]++;
1997 }
1998
paul718e3742002-12-13 20:15:29 +00001999 /* The attribute is changed. */
2000 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2001
2002 /* Update bgp route dampening information. */
2003 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2004 && peer_sort (peer) == BGP_PEER_EBGP)
2005 {
2006 /* This is implicit withdraw so we should update dampening
2007 information. */
2008 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2009 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2010 else
2011 peer->pcount[afi][safi]++;
2012 }
2013
2014 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2015
2016 /* Update to new attribute. */
2017 bgp_attr_unintern (ri->attr);
2018 ri->attr = attr_new;
2019
2020 /* Update MPLS tag. */
2021 if (safi == SAFI_MPLS_VPN)
2022 memcpy (ri->tag, tag, 3);
2023
2024 /* Update bgp route dampening information. */
2025 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2026 && peer_sort (peer) == BGP_PEER_EBGP)
2027 {
2028 /* Now we do normal update dampening. */
2029 ret = bgp_damp_update (ri, rn, afi, safi);
2030 if (ret == BGP_DAMP_SUPPRESSED)
2031 {
2032 bgp_unlock_node (rn);
2033 return 0;
2034 }
2035 }
2036
2037 /* Nexthop reachability check. */
2038 if ((afi == AFI_IP || afi == AFI_IP6)
2039 && safi == SAFI_UNICAST
2040 && (peer_sort (peer) == BGP_PEER_IBGP
2041 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002042 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002043 {
2044 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
2045 SET_FLAG (ri->flags, BGP_INFO_VALID);
2046 else
2047 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2048 }
2049 else
2050 SET_FLAG (ri->flags, BGP_INFO_VALID);
2051
2052 /* Process change. */
2053 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2054
2055 bgp_process (bgp, rn, afi, safi);
2056 bgp_unlock_node (rn);
2057 return 0;
2058 }
2059
2060 /* Received Logging. */
2061 if (BGP_DEBUG (update, UPDATE_IN))
2062 {
ajsd2c1f162004-12-08 21:10:20 +00002063 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002064 peer->host,
2065 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2066 p->prefixlen);
2067 }
2068
2069 /* Increment prefix counter */
2070 peer->pcount[afi][safi]++;
2071
2072 /* Make new BGP info. */
2073 new = bgp_info_new ();
2074 new->type = type;
2075 new->sub_type = sub_type;
2076 new->peer = peer;
2077 new->attr = attr_new;
2078 new->uptime = time (NULL);
2079
2080 /* Update MPLS tag. */
2081 if (safi == SAFI_MPLS_VPN)
2082 memcpy (new->tag, tag, 3);
2083
2084 /* Nexthop reachability check. */
2085 if ((afi == AFI_IP || afi == AFI_IP6)
2086 && safi == SAFI_UNICAST
2087 && (peer_sort (peer) == BGP_PEER_IBGP
2088 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002089 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002090 {
2091 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
2092 SET_FLAG (new->flags, BGP_INFO_VALID);
2093 else
2094 UNSET_FLAG (new->flags, BGP_INFO_VALID);
2095 }
2096 else
2097 SET_FLAG (new->flags, BGP_INFO_VALID);
2098
2099 /* Aggregate address increment. */
2100 bgp_aggregate_increment (bgp, p, new, afi, safi);
2101
2102 /* Register new BGP information. */
2103 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002104
2105 /* route_node_get lock */
2106 bgp_unlock_node (rn);
2107
paul718e3742002-12-13 20:15:29 +00002108 /* If maximum prefix count is configured and current prefix
2109 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002110 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2111 return -1;
paul718e3742002-12-13 20:15:29 +00002112
2113 /* Process change. */
2114 bgp_process (bgp, rn, afi, safi);
2115
2116 return 0;
2117
2118 /* This BGP update is filtered. Log the reason then update BGP
2119 entry. */
2120 filtered:
2121 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002122 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002123 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2124 peer->host,
2125 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2126 p->prefixlen, reason);
2127
2128 if (ri)
paulb40d9392005-08-22 22:34:41 +00002129 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002130
2131 bgp_unlock_node (rn);
2132
2133 return 0;
2134}
2135
2136int
paulfee0f4c2004-09-13 05:12:46 +00002137bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2138 afi_t afi, safi_t safi, int type, int sub_type,
2139 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2140{
2141 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002142 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002143 struct bgp *bgp;
2144 int ret;
2145
2146 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2147 soft_reconfig);
2148
2149 bgp = peer->bgp;
2150
2151 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002152 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002153 {
2154 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2155 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2156 sub_type, prd, tag);
2157 }
2158
2159 return ret;
2160}
2161
2162int
paul718e3742002-12-13 20:15:29 +00002163bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002164 afi_t afi, safi_t safi, int type, int sub_type,
2165 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002166{
2167 struct bgp *bgp;
2168 char buf[SU_ADDRSTRLEN];
2169 struct bgp_node *rn;
2170 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002171 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002172 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002173
2174 bgp = peer->bgp;
2175
paulfee0f4c2004-09-13 05:12:46 +00002176 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002177 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002178 {
2179 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2180 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2181 }
2182
paul718e3742002-12-13 20:15:29 +00002183 /* Logging. */
2184 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002185 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002186 peer->host,
2187 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2188 p->prefixlen);
2189
2190 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002191 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002192
2193 /* If peer is soft reconfiguration enabled. Record input packet for
2194 further calculation. */
2195 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2196 && peer != bgp->peer_self)
2197 bgp_adj_in_unset (rn, peer);
2198
2199 /* Lookup withdrawn route. */
2200 for (ri = rn->info; ri; ri = ri->next)
2201 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2202 break;
2203
2204 /* Withdraw specified route from routing table. */
2205 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002206 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002207 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002208 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002209 "%s Can't find the route %s/%d", peer->host,
2210 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2211 p->prefixlen);
2212
2213 /* Unlock bgp_node_get() lock. */
2214 bgp_unlock_node (rn);
2215
2216 return 0;
2217}
2218
2219void
2220bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2221{
2222 struct bgp *bgp;
2223 struct attr attr;
2224 struct aspath *aspath;
2225 struct prefix p;
2226 struct bgp_info binfo;
2227 struct peer *from;
2228 int ret = RMAP_DENYMATCH;
2229
2230 bgp = peer->bgp;
2231 from = bgp->peer_self;
2232
2233 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2234 aspath = attr.aspath;
2235 attr.local_pref = bgp->default_local_pref;
2236 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2237
2238 if (afi == AFI_IP)
2239 str2prefix ("0.0.0.0/0", &p);
2240#ifdef HAVE_IPV6
2241 else if (afi == AFI_IP6)
2242 {
2243 str2prefix ("::/0", &p);
2244
2245 /* IPv6 global nexthop must be included. */
2246 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2247 IPV6_MAX_BYTELEN);
2248 attr.mp_nexthop_len = 16;
2249
2250 /* If the peer is on shared nextwork and we have link-local
2251 nexthop set it. */
2252 if (peer->shared_network
2253 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2254 {
2255 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2256 IPV6_MAX_BYTELEN);
2257 attr.mp_nexthop_len = 32;
2258 }
2259 }
2260#endif /* HAVE_IPV6 */
2261 else
2262 return;
2263
2264 if (peer->default_rmap[afi][safi].name)
2265 {
2266 binfo.peer = bgp->peer_self;
2267 binfo.attr = &attr;
2268
paulfee0f4c2004-09-13 05:12:46 +00002269 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2270
paul718e3742002-12-13 20:15:29 +00002271 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2272 RMAP_BGP, &binfo);
2273
paulfee0f4c2004-09-13 05:12:46 +00002274 bgp->peer_self->rmap_type = 0;
2275
paul718e3742002-12-13 20:15:29 +00002276 if (ret == RMAP_DENYMATCH)
2277 {
2278 bgp_attr_flush (&attr);
2279 withdraw = 1;
2280 }
2281 }
2282
2283 if (withdraw)
2284 {
2285 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2286 bgp_default_withdraw_send (peer, afi, safi);
2287 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2288 }
2289 else
2290 {
2291 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2292 bgp_default_update_send (peer, &attr, afi, safi, from);
2293 }
2294
2295 aspath_unintern (aspath);
2296}
2297
2298static void
2299bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002300 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002301{
2302 struct bgp_node *rn;
2303 struct bgp_info *ri;
2304 struct attr attr;
2305
2306 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002307 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002308
2309 if (safi != SAFI_MPLS_VPN
2310 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2311 bgp_default_originate (peer, afi, safi, 0);
2312
2313 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2314 for (ri = rn->info; ri; ri = ri->next)
2315 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2316 {
paulfee0f4c2004-09-13 05:12:46 +00002317 if ( (rsclient) ?
2318 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2319 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002320 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2321 else
2322 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2323 }
2324}
2325
2326void
2327bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2328{
2329 struct bgp_node *rn;
2330 struct bgp_table *table;
2331
2332 if (peer->status != Established)
2333 return;
2334
2335 if (! peer->afc_nego[afi][safi])
2336 return;
2337
2338 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2339 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2340 return;
2341
2342 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002343 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002344 else
2345 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2346 rn = bgp_route_next(rn))
2347 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002348 bgp_announce_table (peer, afi, safi, table, 0);
2349
2350 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2351 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002352}
2353
2354void
2355bgp_announce_route_all (struct peer *peer)
2356{
2357 afi_t afi;
2358 safi_t safi;
2359
2360 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2361 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2362 bgp_announce_route (peer, afi, safi);
2363}
2364
2365static void
paulfee0f4c2004-09-13 05:12:46 +00002366bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2367 safi_t safi, struct bgp_table *table)
2368{
2369 struct bgp_node *rn;
2370 struct bgp_adj_in *ain;
2371
2372 if (! table)
2373 table = rsclient->bgp->rib[afi][safi];
2374
2375 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2376 for (ain = rn->adj_in; ain; ain = ain->next)
2377 {
2378 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2379 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2380 }
2381}
2382
2383void
2384bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2385{
2386 struct bgp_table *table;
2387 struct bgp_node *rn;
2388
2389 if (safi != SAFI_MPLS_VPN)
2390 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2391
2392 else
2393 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2394 rn = bgp_route_next (rn))
2395 if ((table = rn->info) != NULL)
2396 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2397}
2398
2399static void
paul718e3742002-12-13 20:15:29 +00002400bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2401 struct bgp_table *table)
2402{
2403 int ret;
2404 struct bgp_node *rn;
2405 struct bgp_adj_in *ain;
2406
2407 if (! table)
2408 table = peer->bgp->rib[afi][safi];
2409
2410 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2411 for (ain = rn->adj_in; ain; ain = ain->next)
2412 {
2413 if (ain->peer == peer)
2414 {
2415 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2416 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2417 NULL, NULL, 1);
2418 if (ret < 0)
2419 {
2420 bgp_unlock_node (rn);
2421 return;
2422 }
2423 continue;
2424 }
2425 }
2426}
2427
2428void
2429bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2430{
2431 struct bgp_node *rn;
2432 struct bgp_table *table;
2433
2434 if (peer->status != Established)
2435 return;
2436
2437 if (safi != SAFI_MPLS_VPN)
2438 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2439 else
2440 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2441 rn = bgp_route_next (rn))
2442 if ((table = rn->info) != NULL)
2443 bgp_soft_reconfig_table (peer, afi, safi, table);
2444}
2445
paul200df112005-06-01 11:17:05 +00002446struct bgp_clear_node_queue
2447{
2448 struct bgp_node *rn;
2449 struct peer *peer;
2450 afi_t afi;
2451 safi_t safi;
2452};
2453
2454static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002455bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002456{
paul0fb58d52005-11-14 14:31:49 +00002457 struct bgp_clear_node_queue *cq = data;
paul200df112005-06-01 11:17:05 +00002458 struct bgp_adj_in *ain;
2459 struct bgp_adj_out *aout;
2460 struct bgp_info *ri;
2461
2462 assert (cq->rn && cq->peer);
2463
2464 for (ri = cq->rn->info; ri; ri = ri->next)
2465 if (ri->peer == cq->peer)
2466 {
2467 /* graceful restart STALE flag set. */
2468 if (CHECK_FLAG (cq->peer->sflags, PEER_STATUS_NSF_WAIT)
2469 && cq->peer->nsf[cq->afi][cq->safi]
2470 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2471 && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
2472 && ! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2473 {
2474 SET_FLAG (ri->flags, BGP_INFO_STALE);
2475 cq->peer->pcount[cq->afi][cq->safi]--;
2476 }
2477 else
2478 bgp_rib_remove (cq->rn, ri, cq->peer, cq->afi, cq->safi);
2479 break;
2480 }
2481 for (ain = cq->rn->adj_in; ain; ain = ain->next)
2482 if (ain->peer == cq->peer)
2483 {
2484 bgp_adj_in_remove (cq->rn, ain);
2485 bgp_unlock_node (cq->rn);
2486 break;
2487 }
2488 for (aout = cq->rn->adj_out; aout; aout = aout->next)
2489 if (aout->peer == cq->peer)
2490 {
2491 bgp_adj_out_remove (cq->rn, aout, cq->peer, cq->afi, cq->safi);
2492 bgp_unlock_node (cq->rn);
2493 break;
2494 }
2495 return WQ_SUCCESS;
2496}
2497
2498static void
paul0fb58d52005-11-14 14:31:49 +00002499bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002500{
paul0fb58d52005-11-14 14:31:49 +00002501 struct bgp_clear_node_queue *cq = data;
paul200df112005-06-01 11:17:05 +00002502 bgp_unlock_node (cq->rn);
2503 peer_unlock (cq->peer); /* bgp_clear_node_queue_del */
2504 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cq);
2505}
2506
2507static void
paul94f2b392005-06-28 12:44:16 +00002508bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002509{
2510 /* unplug the 2 processing queues */
2511 if (bm->process_main_queue)
2512 work_queue_unplug (bm->process_main_queue);
2513 if (bm->process_rsclient_queue)
2514 work_queue_unplug (bm->process_rsclient_queue);
2515}
2516
2517static void
2518bgp_clear_node_queue_init (void)
2519{
2520 if ( (bm->clear_node_queue
2521 = work_queue_new (bm->master, "clear_route_node")) == NULL)
2522 {
2523 zlog_err ("%s: Failed to allocate work queue", __func__);
2524 exit (1);
2525 }
2526 bm->clear_node_queue->spec.hold = 10;
paul200df112005-06-01 11:17:05 +00002527 bm->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2528 bm->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2529 bm->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2530 bm->clear_node_queue->spec.max_retries = 0;
2531}
2532
paul718e3742002-12-13 20:15:29 +00002533static void
2534bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002535 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002536{
paul200df112005-06-01 11:17:05 +00002537 struct bgp_clear_node_queue *cqnode;
paul718e3742002-12-13 20:15:29 +00002538 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002539
paul718e3742002-12-13 20:15:29 +00002540 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002541 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002542
hasso6cf159b2005-03-21 10:28:14 +00002543 /* If still no table => afi/safi isn't configured at all or smth. */
2544 if (! table)
2545 return;
2546
paul200df112005-06-01 11:17:05 +00002547 if (bm->clear_node_queue == NULL)
2548 bgp_clear_node_queue_init ();
2549
2550 /* plug the two bgp_process queues to avoid any chance of racing
2551 * with a session coming back up and adding routes before we've
2552 * cleared them all. We'll unplug them with completion callback.
2553 */
2554 if (bm->process_main_queue)
2555 work_queue_plug (bm->process_main_queue);
2556 if (bm->process_rsclient_queue)
2557 work_queue_plug (bm->process_rsclient_queue);
2558
paul718e3742002-12-13 20:15:29 +00002559 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2560 {
paul200df112005-06-01 11:17:05 +00002561 if (rn->info == NULL)
2562 continue;
2563
2564 if ( (cqnode = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2565 sizeof (struct bgp_clear_node_queue))) == NULL)
2566 continue;
2567
2568 cqnode->rn = bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2569 cqnode->afi = afi;
2570 cqnode->safi = safi;
2571 cqnode->peer = peer_lock (peer); /* bgp_clear_node_queue_del */
2572 work_queue_add (bm->clear_node_queue, cqnode);
paul718e3742002-12-13 20:15:29 +00002573 }
paul200df112005-06-01 11:17:05 +00002574 return;
paul718e3742002-12-13 20:15:29 +00002575}
2576
2577void
2578bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2579{
2580 struct bgp_node *rn;
2581 struct bgp_table *table;
paulfee0f4c2004-09-13 05:12:46 +00002582 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002583 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002584
paul718e3742002-12-13 20:15:29 +00002585 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002586 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002587 else
2588 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2589 rn = bgp_route_next (rn))
2590 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002591 bgp_clear_route_table (peer, afi, safi, table, NULL);
2592
paul1eb8ef22005-04-07 07:30:20 +00002593 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002594 {
2595 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2596 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2597 }
paul718e3742002-12-13 20:15:29 +00002598}
2599
2600void
2601bgp_clear_route_all (struct peer *peer)
2602{
2603 afi_t afi;
2604 safi_t safi;
2605
2606 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2607 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2608 bgp_clear_route (peer, afi, safi);
2609}
2610
2611void
2612bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2613{
2614 struct bgp_table *table;
2615 struct bgp_node *rn;
2616 struct bgp_adj_in *ain;
2617
2618 table = peer->bgp->rib[afi][safi];
2619
2620 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2621 for (ain = rn->adj_in; ain ; ain = ain->next)
2622 if (ain->peer == peer)
2623 {
2624 bgp_adj_in_remove (rn, ain);
2625 bgp_unlock_node (rn);
2626 break;
2627 }
2628}
hasso93406d82005-02-02 14:40:33 +00002629
2630void
2631bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2632{
2633 struct bgp_node *rn;
2634 struct bgp_info *ri;
2635 struct bgp_table *table;
2636
2637 table = peer->bgp->rib[afi][safi];
2638
2639 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2640 {
2641 for (ri = rn->info; ri; ri = ri->next)
2642 if (ri->peer == peer)
2643 {
2644 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2645 bgp_rib_remove (rn, ri, peer, afi, safi);
2646 break;
2647 }
2648 }
2649}
paul718e3742002-12-13 20:15:29 +00002650
2651/* Delete all kernel routes. */
2652void
paul545acaf2004-04-20 15:13:15 +00002653bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002654{
2655 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002656 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002657 struct bgp_node *rn;
2658 struct bgp_table *table;
2659 struct bgp_info *ri;
2660
paul1eb8ef22005-04-07 07:30:20 +00002661 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002662 {
2663 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2664
2665 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2666 for (ri = rn->info; ri; ri = ri->next)
2667 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2668 && ri->type == ZEBRA_ROUTE_BGP
2669 && ri->sub_type == BGP_ROUTE_NORMAL)
2670 bgp_zebra_withdraw (&rn->p, ri);
2671
2672 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2673
2674 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2675 for (ri = rn->info; ri; ri = ri->next)
2676 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2677 && ri->type == ZEBRA_ROUTE_BGP
2678 && ri->sub_type == BGP_ROUTE_NORMAL)
2679 bgp_zebra_withdraw (&rn->p, ri);
2680 }
2681}
2682
2683void
2684bgp_reset ()
2685{
2686 vty_reset ();
2687 bgp_zclient_reset ();
2688 access_list_reset ();
2689 prefix_list_reset ();
2690}
2691
2692/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2693 value. */
2694int
2695bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2696{
2697 u_char *pnt;
2698 u_char *lim;
2699 struct prefix p;
2700 int psize;
2701 int ret;
2702
2703 /* Check peer status. */
2704 if (peer->status != Established)
2705 return 0;
2706
2707 pnt = packet->nlri;
2708 lim = pnt + packet->length;
2709
2710 for (; pnt < lim; pnt += psize)
2711 {
2712 /* Clear prefix structure. */
2713 memset (&p, 0, sizeof (struct prefix));
2714
2715 /* Fetch prefix length. */
2716 p.prefixlen = *pnt++;
2717 p.family = afi2family (packet->afi);
2718
2719 /* Already checked in nlri_sanity_check(). We do double check
2720 here. */
2721 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2722 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2723 return -1;
2724
2725 /* Packet size overflow check. */
2726 psize = PSIZE (p.prefixlen);
2727
2728 /* When packet overflow occur return immediately. */
2729 if (pnt + psize > lim)
2730 return -1;
2731
2732 /* Fetch prefix from NLRI packet. */
2733 memcpy (&p.u.prefix, pnt, psize);
2734
2735 /* Check address. */
2736 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2737 {
2738 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2739 {
paulf5ba3872004-07-09 12:11:31 +00002740 /*
2741 * From draft-ietf-idr-bgp4-22, Section 6.3:
2742 * If a BGP router receives an UPDATE message with a
2743 * semantically incorrect NLRI field, in which a prefix is
2744 * semantically incorrect (eg. an unexpected multicast IP
2745 * address), it should ignore the prefix.
2746 */
paul718e3742002-12-13 20:15:29 +00002747 zlog (peer->log, LOG_ERR,
2748 "IPv4 unicast NLRI is multicast address %s",
2749 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002750
paul718e3742002-12-13 20:15:29 +00002751 return -1;
2752 }
2753 }
2754
2755#ifdef HAVE_IPV6
2756 /* Check address. */
2757 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2758 {
2759 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2760 {
2761 char buf[BUFSIZ];
2762
2763 zlog (peer->log, LOG_WARNING,
2764 "IPv6 link-local NLRI received %s ignore this NLRI",
2765 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2766
2767 continue;
2768 }
2769 }
2770#endif /* HAVE_IPV6 */
2771
2772 /* Normal process. */
2773 if (attr)
2774 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2775 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2776 else
2777 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2778 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2779
2780 /* Address family configuration mismatch or maximum-prefix count
2781 overflow. */
2782 if (ret < 0)
2783 return -1;
2784 }
2785
2786 /* Packet length consistency check. */
2787 if (pnt != lim)
2788 return -1;
2789
2790 return 0;
2791}
2792
2793/* NLRI encode syntax check routine. */
2794int
2795bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2796 bgp_size_t length)
2797{
2798 u_char *end;
2799 u_char prefixlen;
2800 int psize;
2801
2802 end = pnt + length;
2803
2804 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2805 syntactic validity. If the field is syntactically incorrect,
2806 then the Error Subcode is set to Invalid Network Field. */
2807
2808 while (pnt < end)
2809 {
2810 prefixlen = *pnt++;
2811
2812 /* Prefix length check. */
2813 if ((afi == AFI_IP && prefixlen > 32)
2814 || (afi == AFI_IP6 && prefixlen > 128))
2815 {
2816 plog_err (peer->log,
2817 "%s [Error] Update packet error (wrong prefix length %d)",
2818 peer->host, prefixlen);
2819 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2820 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2821 return -1;
2822 }
2823
2824 /* Packet size overflow check. */
2825 psize = PSIZE (prefixlen);
2826
2827 if (pnt + psize > end)
2828 {
2829 plog_err (peer->log,
2830 "%s [Error] Update packet error"
2831 " (prefix data overflow prefix size is %d)",
2832 peer->host, psize);
2833 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2834 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2835 return -1;
2836 }
2837
2838 pnt += psize;
2839 }
2840
2841 /* Packet length consistency check. */
2842 if (pnt != end)
2843 {
2844 plog_err (peer->log,
2845 "%s [Error] Update packet error"
2846 " (prefix length mismatch with total length)",
2847 peer->host);
2848 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2849 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2850 return -1;
2851 }
2852 return 0;
2853}
2854
paul94f2b392005-06-28 12:44:16 +00002855static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002856bgp_static_new ()
2857{
2858 struct bgp_static *new;
2859 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2860 memset (new, 0, sizeof (struct bgp_static));
2861 return new;
2862}
2863
paul94f2b392005-06-28 12:44:16 +00002864static void
paul718e3742002-12-13 20:15:29 +00002865bgp_static_free (struct bgp_static *bgp_static)
2866{
2867 if (bgp_static->rmap.name)
2868 free (bgp_static->rmap.name);
2869 XFREE (MTYPE_BGP_STATIC, bgp_static);
2870}
2871
paul94f2b392005-06-28 12:44:16 +00002872static void
paulfee0f4c2004-09-13 05:12:46 +00002873bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2874 struct prefix *p, afi_t afi, safi_t safi)
2875{
2876 struct bgp_node *rn;
2877 struct bgp_info *ri;
2878
2879 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2880
2881 /* Check selected route and self inserted route. */
2882 for (ri = rn->info; ri; ri = ri->next)
2883 if (ri->peer == bgp->peer_self
2884 && ri->type == ZEBRA_ROUTE_BGP
2885 && ri->sub_type == BGP_ROUTE_STATIC)
2886 break;
2887
2888 /* Withdraw static BGP route from routing table. */
2889 if (ri)
2890 {
2891 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2892 bgp_process (bgp, rn, afi, safi);
2893 bgp_info_delete (rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00002894 }
2895
2896 /* Unlock bgp_node_lookup. */
2897 bgp_unlock_node (rn);
2898}
2899
paul94f2b392005-06-28 12:44:16 +00002900static void
paulfee0f4c2004-09-13 05:12:46 +00002901bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2902 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2903{
2904 struct bgp_node *rn;
2905 struct bgp_info *ri;
2906 struct bgp_info *new;
2907 struct bgp_info info;
2908 struct attr new_attr;
2909 struct attr *attr_new;
2910 struct attr attr;
2911 struct bgp *bgp;
2912 int ret;
2913 char buf[SU_ADDRSTRLEN];
2914
2915 bgp = rsclient->bgp;
2916
2917 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2918
2919 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2920 if (bgp_static)
2921 {
2922 attr.nexthop = bgp_static->igpnexthop;
2923 attr.med = bgp_static->igpmetric;
2924 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
2925 }
2926
2927 new_attr = attr;
2928
2929 /* Apply network route-map for export to this rsclient. */
2930 if (bgp_static->rmap.name)
2931 {
2932 info.peer = rsclient;
2933 info.attr = &new_attr;
2934
2935 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2936 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2937
2938 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2939
2940 rsclient->rmap_type = 0;
2941
2942 if (ret == RMAP_DENYMATCH)
2943 {
2944 /* Free uninterned attribute. */
2945 bgp_attr_flush (&new_attr);
2946
2947 /* Unintern original. */
2948 aspath_unintern (attr.aspath);
2949 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2950
2951 return;
2952 }
2953 attr_new = bgp_attr_intern (&new_attr);
2954 }
2955 else
2956 attr_new = bgp_attr_intern (&attr);
2957
2958 new_attr = *attr_new;
2959
2960 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2961
2962 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2963{
2964 /* This BGP update is filtered. Log the reason then update BGP entry. */
2965 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002966 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002967 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
2968 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2969 p->prefixlen, rsclient->host);
2970
2971 bgp->peer_self->rmap_type = 0;
2972
2973 bgp_attr_unintern (attr_new);
2974 aspath_unintern (attr.aspath);
2975
2976 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2977
2978 return;
2979 }
2980
2981 bgp->peer_self->rmap_type = 0;
2982
2983 bgp_attr_unintern (attr_new);
2984 attr_new = bgp_attr_intern (&new_attr);
2985
2986 for (ri = rn->info; ri; ri = ri->next)
2987 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
2988 && ri->sub_type == BGP_ROUTE_STATIC)
2989 break;
2990
2991 if (ri)
2992 {
2993 if (attrhash_cmp (ri->attr, attr_new))
2994 {
2995 bgp_unlock_node (rn);
2996 bgp_attr_unintern (attr_new);
2997 aspath_unintern (attr.aspath);
2998 return;
2999 }
3000 else
3001 {
3002 /* The attribute is changed. */
3003 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3004
3005 /* Rewrite BGP route information. */
3006 bgp_attr_unintern (ri->attr);
3007 ri->attr = attr_new;
3008 ri->uptime = time (NULL);
3009
3010 /* Process change. */
3011 bgp_process (bgp, rn, afi, safi);
3012 bgp_unlock_node (rn);
3013 aspath_unintern (attr.aspath);
3014 return;
3015 }
3016}
3017
3018 /* Make new BGP info. */
3019 new = bgp_info_new ();
3020 new->type = ZEBRA_ROUTE_BGP;
3021 new->sub_type = BGP_ROUTE_STATIC;
3022 new->peer = bgp->peer_self;
3023 SET_FLAG (new->flags, BGP_INFO_VALID);
3024 new->attr = attr_new;
3025 new->uptime = time (NULL);
3026
3027 /* Register new BGP information. */
3028 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003029
3030 /* route_node_get lock */
3031 bgp_unlock_node (rn);
3032
paulfee0f4c2004-09-13 05:12:46 +00003033 /* Process change. */
3034 bgp_process (bgp, rn, afi, safi);
3035
3036 /* Unintern original. */
3037 aspath_unintern (attr.aspath);
3038}
3039
paul94f2b392005-06-28 12:44:16 +00003040static void
paulfee0f4c2004-09-13 05:12:46 +00003041bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003042 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3043{
3044 struct bgp_node *rn;
3045 struct bgp_info *ri;
3046 struct bgp_info *new;
3047 struct bgp_info info;
3048 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003049 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003050 struct attr *attr_new;
3051 int ret;
3052
paulfee0f4c2004-09-13 05:12:46 +00003053 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003054
3055 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3056 if (bgp_static)
3057 {
3058 attr.nexthop = bgp_static->igpnexthop;
3059 attr.med = bgp_static->igpmetric;
3060 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3061 }
3062
3063 /* Apply route-map. */
3064 if (bgp_static->rmap.name)
3065 {
paul286e1e72003-08-08 00:24:31 +00003066 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003067 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003068 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003069
paulfee0f4c2004-09-13 05:12:46 +00003070 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3071
paul718e3742002-12-13 20:15:29 +00003072 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003073
paulfee0f4c2004-09-13 05:12:46 +00003074 bgp->peer_self->rmap_type = 0;
3075
paul718e3742002-12-13 20:15:29 +00003076 if (ret == RMAP_DENYMATCH)
3077 {
3078 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003079 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003080
3081 /* Unintern original. */
3082 aspath_unintern (attr.aspath);
3083 bgp_static_withdraw (bgp, p, afi, safi);
3084 return;
3085 }
paul286e1e72003-08-08 00:24:31 +00003086 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003087 }
paul286e1e72003-08-08 00:24:31 +00003088 else
3089 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003090
3091 for (ri = rn->info; ri; ri = ri->next)
3092 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3093 && ri->sub_type == BGP_ROUTE_STATIC)
3094 break;
3095
3096 if (ri)
3097 {
3098 if (attrhash_cmp (ri->attr, attr_new))
3099 {
3100 bgp_unlock_node (rn);
3101 bgp_attr_unintern (attr_new);
3102 aspath_unintern (attr.aspath);
3103 return;
3104 }
3105 else
3106 {
3107 /* The attribute is changed. */
3108 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3109
3110 /* Rewrite BGP route information. */
3111 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3112 bgp_attr_unintern (ri->attr);
3113 ri->attr = attr_new;
3114 ri->uptime = time (NULL);
3115
3116 /* Process change. */
3117 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3118 bgp_process (bgp, rn, afi, safi);
3119 bgp_unlock_node (rn);
3120 aspath_unintern (attr.aspath);
3121 return;
3122 }
3123 }
3124
3125 /* Make new BGP info. */
3126 new = bgp_info_new ();
3127 new->type = ZEBRA_ROUTE_BGP;
3128 new->sub_type = BGP_ROUTE_STATIC;
3129 new->peer = bgp->peer_self;
3130 SET_FLAG (new->flags, BGP_INFO_VALID);
3131 new->attr = attr_new;
3132 new->uptime = time (NULL);
3133
3134 /* Aggregate address increment. */
3135 bgp_aggregate_increment (bgp, p, new, afi, safi);
3136
3137 /* Register new BGP information. */
3138 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003139
3140 /* route_node_get lock */
3141 bgp_unlock_node (rn);
3142
paul718e3742002-12-13 20:15:29 +00003143 /* Process change. */
3144 bgp_process (bgp, rn, afi, safi);
3145
3146 /* Unintern original. */
3147 aspath_unintern (attr.aspath);
3148}
3149
3150void
paulfee0f4c2004-09-13 05:12:46 +00003151bgp_static_update (struct bgp *bgp, struct prefix *p,
3152 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3153{
3154 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003155 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003156
3157 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3158
paul1eb8ef22005-04-07 07:30:20 +00003159 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003160 {
3161 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3162 }
3163}
3164
paul94f2b392005-06-28 12:44:16 +00003165static void
paul718e3742002-12-13 20:15:29 +00003166bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3167 u_char safi, struct prefix_rd *prd, u_char *tag)
3168{
3169 struct bgp_node *rn;
3170 struct bgp_info *new;
3171
paulfee0f4c2004-09-13 05:12:46 +00003172 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003173
3174 /* Make new BGP info. */
3175 new = bgp_info_new ();
3176 new->type = ZEBRA_ROUTE_BGP;
3177 new->sub_type = BGP_ROUTE_STATIC;
3178 new->peer = bgp->peer_self;
3179 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3180 SET_FLAG (new->flags, BGP_INFO_VALID);
3181 new->uptime = time (NULL);
3182 memcpy (new->tag, tag, 3);
3183
3184 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003185 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003186
3187 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003188 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003189
paul200df112005-06-01 11:17:05 +00003190 /* route_node_get lock */
3191 bgp_unlock_node (rn);
3192
paul718e3742002-12-13 20:15:29 +00003193 /* Process change. */
3194 bgp_process (bgp, rn, afi, safi);
3195}
3196
3197void
3198bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3199 safi_t safi)
3200{
3201 struct bgp_node *rn;
3202 struct bgp_info *ri;
3203
paulfee0f4c2004-09-13 05:12:46 +00003204 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003205
3206 /* Check selected route and self inserted route. */
3207 for (ri = rn->info; ri; ri = ri->next)
3208 if (ri->peer == bgp->peer_self
3209 && ri->type == ZEBRA_ROUTE_BGP
3210 && ri->sub_type == BGP_ROUTE_STATIC)
3211 break;
3212
3213 /* Withdraw static BGP route from routing table. */
3214 if (ri)
3215 {
3216 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3217 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3218 bgp_process (bgp, rn, afi, safi);
3219 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003220 }
3221
3222 /* Unlock bgp_node_lookup. */
3223 bgp_unlock_node (rn);
3224}
3225
3226void
paulfee0f4c2004-09-13 05:12:46 +00003227bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3228{
3229 struct bgp_static *bgp_static;
3230 struct bgp *bgp;
3231 struct bgp_node *rn;
3232 struct prefix *p;
3233
3234 bgp = rsclient->bgp;
3235
3236 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3237 if ((bgp_static = rn->info) != NULL)
3238 {
3239 p = &rn->p;
3240
3241 bgp_static_update_rsclient (rsclient, p, bgp_static,
3242 afi, safi);
3243 }
3244}
3245
paul94f2b392005-06-28 12:44:16 +00003246static void
paul718e3742002-12-13 20:15:29 +00003247bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3248 u_char safi, struct prefix_rd *prd, u_char *tag)
3249{
3250 struct bgp_node *rn;
3251 struct bgp_info *ri;
3252
paulfee0f4c2004-09-13 05:12:46 +00003253 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003254
3255 /* Check selected route and self inserted route. */
3256 for (ri = rn->info; ri; ri = ri->next)
3257 if (ri->peer == bgp->peer_self
3258 && ri->type == ZEBRA_ROUTE_BGP
3259 && ri->sub_type == BGP_ROUTE_STATIC)
3260 break;
3261
3262 /* Withdraw static BGP route from routing table. */
3263 if (ri)
3264 {
3265 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3266 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3267 bgp_process (bgp, rn, afi, safi);
3268 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003269 }
3270
3271 /* Unlock bgp_node_lookup. */
3272 bgp_unlock_node (rn);
3273}
3274
3275/* Configure static BGP network. When user don't run zebra, static
3276 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003277static int
paulfd79ac92004-10-13 05:06:08 +00003278bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3279 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003280{
3281 int ret;
3282 struct prefix p;
3283 struct bgp_static *bgp_static;
3284 struct bgp_node *rn;
3285 int need_update = 0;
3286
3287 /* Convert IP prefix string to struct prefix. */
3288 ret = str2prefix (ip_str, &p);
3289 if (! ret)
3290 {
3291 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3292 return CMD_WARNING;
3293 }
3294#ifdef HAVE_IPV6
3295 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3296 {
3297 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3298 VTY_NEWLINE);
3299 return CMD_WARNING;
3300 }
3301#endif /* HAVE_IPV6 */
3302
3303 apply_mask (&p);
3304
3305 /* Set BGP static route configuration. */
3306 rn = bgp_node_get (bgp->route[afi][safi], &p);
3307
3308 if (rn->info)
3309 {
3310 /* Configuration change. */
3311 bgp_static = rn->info;
3312
3313 /* Check previous routes are installed into BGP. */
3314 if (! bgp_static->backdoor && bgp_static->valid)
3315 need_update = 1;
3316
3317 bgp_static->backdoor = backdoor;
3318 if (rmap)
3319 {
3320 if (bgp_static->rmap.name)
3321 free (bgp_static->rmap.name);
3322 bgp_static->rmap.name = strdup (rmap);
3323 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3324 }
3325 else
3326 {
3327 if (bgp_static->rmap.name)
3328 free (bgp_static->rmap.name);
3329 bgp_static->rmap.name = NULL;
3330 bgp_static->rmap.map = NULL;
3331 bgp_static->valid = 0;
3332 }
3333 bgp_unlock_node (rn);
3334 }
3335 else
3336 {
3337 /* New configuration. */
3338 bgp_static = bgp_static_new ();
3339 bgp_static->backdoor = backdoor;
3340 bgp_static->valid = 0;
3341 bgp_static->igpmetric = 0;
3342 bgp_static->igpnexthop.s_addr = 0;
3343 if (rmap)
3344 {
3345 if (bgp_static->rmap.name)
3346 free (bgp_static->rmap.name);
3347 bgp_static->rmap.name = strdup (rmap);
3348 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3349 }
3350 rn->info = bgp_static;
3351 }
3352
3353 /* If BGP scan is not enabled, we should install this route here. */
3354 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3355 {
3356 bgp_static->valid = 1;
3357
3358 if (need_update)
3359 bgp_static_withdraw (bgp, &p, afi, safi);
3360
3361 if (! bgp_static->backdoor)
3362 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3363 }
3364
3365 return CMD_SUCCESS;
3366}
3367
3368/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003369static int
paulfd79ac92004-10-13 05:06:08 +00003370bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003371 u_int16_t afi, u_char safi)
3372{
3373 int ret;
3374 struct prefix p;
3375 struct bgp_static *bgp_static;
3376 struct bgp_node *rn;
3377
3378 /* Convert IP prefix string to struct prefix. */
3379 ret = str2prefix (ip_str, &p);
3380 if (! ret)
3381 {
3382 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3383 return CMD_WARNING;
3384 }
3385#ifdef HAVE_IPV6
3386 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3387 {
3388 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3389 VTY_NEWLINE);
3390 return CMD_WARNING;
3391 }
3392#endif /* HAVE_IPV6 */
3393
3394 apply_mask (&p);
3395
3396 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3397 if (! rn)
3398 {
3399 vty_out (vty, "%% Can't find specified static route configuration.%s",
3400 VTY_NEWLINE);
3401 return CMD_WARNING;
3402 }
3403
3404 bgp_static = rn->info;
3405
3406 /* Update BGP RIB. */
3407 if (! bgp_static->backdoor)
3408 bgp_static_withdraw (bgp, &p, afi, safi);
3409
3410 /* Clear configuration. */
3411 bgp_static_free (bgp_static);
3412 rn->info = NULL;
3413 bgp_unlock_node (rn);
3414 bgp_unlock_node (rn);
3415
3416 return CMD_SUCCESS;
3417}
3418
3419/* Called from bgp_delete(). Delete all static routes from the BGP
3420 instance. */
3421void
3422bgp_static_delete (struct bgp *bgp)
3423{
3424 afi_t afi;
3425 safi_t safi;
3426 struct bgp_node *rn;
3427 struct bgp_node *rm;
3428 struct bgp_table *table;
3429 struct bgp_static *bgp_static;
3430
3431 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3432 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3433 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3434 if (rn->info != NULL)
3435 {
3436 if (safi == SAFI_MPLS_VPN)
3437 {
3438 table = rn->info;
3439
3440 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3441 {
3442 bgp_static = rn->info;
3443 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3444 AFI_IP, SAFI_MPLS_VPN,
3445 (struct prefix_rd *)&rn->p,
3446 bgp_static->tag);
3447 bgp_static_free (bgp_static);
3448 rn->info = NULL;
3449 bgp_unlock_node (rn);
3450 }
3451 }
3452 else
3453 {
3454 bgp_static = rn->info;
3455 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3456 bgp_static_free (bgp_static);
3457 rn->info = NULL;
3458 bgp_unlock_node (rn);
3459 }
3460 }
3461}
3462
3463int
paulfd79ac92004-10-13 05:06:08 +00003464bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3465 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003466{
3467 int ret;
3468 struct prefix p;
3469 struct prefix_rd prd;
3470 struct bgp *bgp;
3471 struct bgp_node *prn;
3472 struct bgp_node *rn;
3473 struct bgp_table *table;
3474 struct bgp_static *bgp_static;
3475 u_char tag[3];
3476
3477 bgp = vty->index;
3478
3479 ret = str2prefix (ip_str, &p);
3480 if (! ret)
3481 {
3482 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3483 return CMD_WARNING;
3484 }
3485 apply_mask (&p);
3486
3487 ret = str2prefix_rd (rd_str, &prd);
3488 if (! ret)
3489 {
3490 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3491 return CMD_WARNING;
3492 }
3493
3494 ret = str2tag (tag_str, tag);
3495 if (! ret)
3496 {
3497 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3498 return CMD_WARNING;
3499 }
3500
3501 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3502 (struct prefix *)&prd);
3503 if (prn->info == NULL)
3504 prn->info = bgp_table_init ();
3505 else
3506 bgp_unlock_node (prn);
3507 table = prn->info;
3508
3509 rn = bgp_node_get (table, &p);
3510
3511 if (rn->info)
3512 {
3513 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3514 bgp_unlock_node (rn);
3515 }
3516 else
3517 {
3518 /* New configuration. */
3519 bgp_static = bgp_static_new ();
3520 bgp_static->valid = 1;
3521 memcpy (bgp_static->tag, tag, 3);
3522 rn->info = bgp_static;
3523
3524 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3525 }
3526
3527 return CMD_SUCCESS;
3528}
3529
3530/* Configure static BGP network. */
3531int
paulfd79ac92004-10-13 05:06:08 +00003532bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3533 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003534{
3535 int ret;
3536 struct bgp *bgp;
3537 struct prefix p;
3538 struct prefix_rd prd;
3539 struct bgp_node *prn;
3540 struct bgp_node *rn;
3541 struct bgp_table *table;
3542 struct bgp_static *bgp_static;
3543 u_char tag[3];
3544
3545 bgp = vty->index;
3546
3547 /* Convert IP prefix string to struct prefix. */
3548 ret = str2prefix (ip_str, &p);
3549 if (! ret)
3550 {
3551 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3552 return CMD_WARNING;
3553 }
3554 apply_mask (&p);
3555
3556 ret = str2prefix_rd (rd_str, &prd);
3557 if (! ret)
3558 {
3559 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3560 return CMD_WARNING;
3561 }
3562
3563 ret = str2tag (tag_str, tag);
3564 if (! ret)
3565 {
3566 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3567 return CMD_WARNING;
3568 }
3569
3570 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3571 (struct prefix *)&prd);
3572 if (prn->info == NULL)
3573 prn->info = bgp_table_init ();
3574 else
3575 bgp_unlock_node (prn);
3576 table = prn->info;
3577
3578 rn = bgp_node_lookup (table, &p);
3579
3580 if (rn)
3581 {
3582 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3583
3584 bgp_static = rn->info;
3585 bgp_static_free (bgp_static);
3586 rn->info = NULL;
3587 bgp_unlock_node (rn);
3588 bgp_unlock_node (rn);
3589 }
3590 else
3591 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3592
3593 return CMD_SUCCESS;
3594}
3595
3596DEFUN (bgp_network,
3597 bgp_network_cmd,
3598 "network A.B.C.D/M",
3599 "Specify a network to announce via BGP\n"
3600 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3601{
3602 return bgp_static_set (vty, vty->index, argv[0],
3603 AFI_IP, bgp_node_safi (vty), NULL, 0);
3604}
3605
3606DEFUN (bgp_network_route_map,
3607 bgp_network_route_map_cmd,
3608 "network A.B.C.D/M route-map WORD",
3609 "Specify a network to announce via BGP\n"
3610 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3611 "Route-map to modify the attributes\n"
3612 "Name of the route map\n")
3613{
3614 return bgp_static_set (vty, vty->index, argv[0],
3615 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3616}
3617
3618DEFUN (bgp_network_backdoor,
3619 bgp_network_backdoor_cmd,
3620 "network A.B.C.D/M backdoor",
3621 "Specify a network to announce via BGP\n"
3622 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3623 "Specify a BGP backdoor route\n")
3624{
3625 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3626}
3627
3628DEFUN (bgp_network_mask,
3629 bgp_network_mask_cmd,
3630 "network A.B.C.D mask A.B.C.D",
3631 "Specify a network to announce via BGP\n"
3632 "Network number\n"
3633 "Network mask\n"
3634 "Network mask\n")
3635{
3636 int ret;
3637 char prefix_str[BUFSIZ];
3638
3639 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3640 if (! ret)
3641 {
3642 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3643 return CMD_WARNING;
3644 }
3645
3646 return bgp_static_set (vty, vty->index, prefix_str,
3647 AFI_IP, bgp_node_safi (vty), NULL, 0);
3648}
3649
3650DEFUN (bgp_network_mask_route_map,
3651 bgp_network_mask_route_map_cmd,
3652 "network A.B.C.D mask A.B.C.D route-map WORD",
3653 "Specify a network to announce via BGP\n"
3654 "Network number\n"
3655 "Network mask\n"
3656 "Network mask\n"
3657 "Route-map to modify the attributes\n"
3658 "Name of the route map\n")
3659{
3660 int ret;
3661 char prefix_str[BUFSIZ];
3662
3663 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3664 if (! ret)
3665 {
3666 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3667 return CMD_WARNING;
3668 }
3669
3670 return bgp_static_set (vty, vty->index, prefix_str,
3671 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3672}
3673
3674DEFUN (bgp_network_mask_backdoor,
3675 bgp_network_mask_backdoor_cmd,
3676 "network A.B.C.D mask A.B.C.D backdoor",
3677 "Specify a network to announce via BGP\n"
3678 "Network number\n"
3679 "Network mask\n"
3680 "Network mask\n"
3681 "Specify a BGP backdoor route\n")
3682{
3683 int ret;
3684 char prefix_str[BUFSIZ];
3685
3686 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3687 if (! ret)
3688 {
3689 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3690 return CMD_WARNING;
3691 }
3692
3693 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3694}
3695
3696DEFUN (bgp_network_mask_natural,
3697 bgp_network_mask_natural_cmd,
3698 "network A.B.C.D",
3699 "Specify a network to announce via BGP\n"
3700 "Network number\n")
3701{
3702 int ret;
3703 char prefix_str[BUFSIZ];
3704
3705 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3706 if (! ret)
3707 {
3708 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3709 return CMD_WARNING;
3710 }
3711
3712 return bgp_static_set (vty, vty->index, prefix_str,
3713 AFI_IP, bgp_node_safi (vty), NULL, 0);
3714}
3715
3716DEFUN (bgp_network_mask_natural_route_map,
3717 bgp_network_mask_natural_route_map_cmd,
3718 "network A.B.C.D route-map WORD",
3719 "Specify a network to announce via BGP\n"
3720 "Network number\n"
3721 "Route-map to modify the attributes\n"
3722 "Name of the route map\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), argv[1], 0);
3736}
3737
3738DEFUN (bgp_network_mask_natural_backdoor,
3739 bgp_network_mask_natural_backdoor_cmd,
3740 "network A.B.C.D backdoor",
3741 "Specify a network to announce via BGP\n"
3742 "Network number\n"
3743 "Specify a BGP backdoor route\n")
3744{
3745 int ret;
3746 char prefix_str[BUFSIZ];
3747
3748 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3749 if (! ret)
3750 {
3751 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3752 return CMD_WARNING;
3753 }
3754
3755 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3756}
3757
3758DEFUN (no_bgp_network,
3759 no_bgp_network_cmd,
3760 "no network A.B.C.D/M",
3761 NO_STR
3762 "Specify a network to announce via BGP\n"
3763 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3764{
3765 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3766 bgp_node_safi (vty));
3767}
3768
3769ALIAS (no_bgp_network,
3770 no_bgp_network_route_map_cmd,
3771 "no network A.B.C.D/M route-map WORD",
3772 NO_STR
3773 "Specify a network to announce via BGP\n"
3774 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3775 "Route-map to modify the attributes\n"
3776 "Name of the route map\n")
3777
3778ALIAS (no_bgp_network,
3779 no_bgp_network_backdoor_cmd,
3780 "no network A.B.C.D/M backdoor",
3781 NO_STR
3782 "Specify a network to announce via BGP\n"
3783 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3784 "Specify a BGP backdoor route\n")
3785
3786DEFUN (no_bgp_network_mask,
3787 no_bgp_network_mask_cmd,
3788 "no network A.B.C.D mask A.B.C.D",
3789 NO_STR
3790 "Specify a network to announce via BGP\n"
3791 "Network number\n"
3792 "Network mask\n"
3793 "Network mask\n")
3794{
3795 int ret;
3796 char prefix_str[BUFSIZ];
3797
3798 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3799 if (! ret)
3800 {
3801 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3802 return CMD_WARNING;
3803 }
3804
3805 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3806 bgp_node_safi (vty));
3807}
3808
3809ALIAS (no_bgp_network_mask,
3810 no_bgp_network_mask_route_map_cmd,
3811 "no network A.B.C.D mask A.B.C.D route-map WORD",
3812 NO_STR
3813 "Specify a network to announce via BGP\n"
3814 "Network number\n"
3815 "Network mask\n"
3816 "Network mask\n"
3817 "Route-map to modify the attributes\n"
3818 "Name of the route map\n")
3819
3820ALIAS (no_bgp_network_mask,
3821 no_bgp_network_mask_backdoor_cmd,
3822 "no network A.B.C.D mask A.B.C.D backdoor",
3823 NO_STR
3824 "Specify a network to announce via BGP\n"
3825 "Network number\n"
3826 "Network mask\n"
3827 "Network mask\n"
3828 "Specify a BGP backdoor route\n")
3829
3830DEFUN (no_bgp_network_mask_natural,
3831 no_bgp_network_mask_natural_cmd,
3832 "no network A.B.C.D",
3833 NO_STR
3834 "Specify a network to announce via BGP\n"
3835 "Network number\n")
3836{
3837 int ret;
3838 char prefix_str[BUFSIZ];
3839
3840 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3841 if (! ret)
3842 {
3843 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3844 return CMD_WARNING;
3845 }
3846
3847 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3848 bgp_node_safi (vty));
3849}
3850
3851ALIAS (no_bgp_network_mask_natural,
3852 no_bgp_network_mask_natural_route_map_cmd,
3853 "no network A.B.C.D route-map WORD",
3854 NO_STR
3855 "Specify a network to announce via BGP\n"
3856 "Network number\n"
3857 "Route-map to modify the attributes\n"
3858 "Name of the route map\n")
3859
3860ALIAS (no_bgp_network_mask_natural,
3861 no_bgp_network_mask_natural_backdoor_cmd,
3862 "no network A.B.C.D backdoor",
3863 NO_STR
3864 "Specify a network to announce via BGP\n"
3865 "Network number\n"
3866 "Specify a BGP backdoor route\n")
3867
3868#ifdef HAVE_IPV6
3869DEFUN (ipv6_bgp_network,
3870 ipv6_bgp_network_cmd,
3871 "network X:X::X:X/M",
3872 "Specify a network to announce via BGP\n"
3873 "IPv6 prefix <network>/<length>\n")
3874{
3875 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3876}
3877
3878DEFUN (ipv6_bgp_network_route_map,
3879 ipv6_bgp_network_route_map_cmd,
3880 "network X:X::X:X/M route-map WORD",
3881 "Specify a network to announce via BGP\n"
3882 "IPv6 prefix <network>/<length>\n"
3883 "Route-map to modify the attributes\n"
3884 "Name of the route map\n")
3885{
3886 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3887 bgp_node_safi (vty), argv[1], 0);
3888}
3889
3890DEFUN (no_ipv6_bgp_network,
3891 no_ipv6_bgp_network_cmd,
3892 "no network X:X::X:X/M",
3893 NO_STR
3894 "Specify a network to announce via BGP\n"
3895 "IPv6 prefix <network>/<length>\n")
3896{
3897 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3898}
3899
3900ALIAS (no_ipv6_bgp_network,
3901 no_ipv6_bgp_network_route_map_cmd,
3902 "no network X:X::X:X/M route-map WORD",
3903 NO_STR
3904 "Specify a network to announce via BGP\n"
3905 "IPv6 prefix <network>/<length>\n"
3906 "Route-map to modify the attributes\n"
3907 "Name of the route map\n")
3908
3909ALIAS (ipv6_bgp_network,
3910 old_ipv6_bgp_network_cmd,
3911 "ipv6 bgp network X:X::X:X/M",
3912 IPV6_STR
3913 BGP_STR
3914 "Specify a network to announce via BGP\n"
3915 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3916
3917ALIAS (no_ipv6_bgp_network,
3918 old_no_ipv6_bgp_network_cmd,
3919 "no ipv6 bgp network X:X::X:X/M",
3920 NO_STR
3921 IPV6_STR
3922 BGP_STR
3923 "Specify a network to announce via BGP\n"
3924 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3925#endif /* HAVE_IPV6 */
3926
3927/* Aggreagete address:
3928
3929 advertise-map Set condition to advertise attribute
3930 as-set Generate AS set path information
3931 attribute-map Set attributes of aggregate
3932 route-map Set parameters of aggregate
3933 summary-only Filter more specific routes from updates
3934 suppress-map Conditionally filter more specific routes from updates
3935 <cr>
3936 */
3937struct bgp_aggregate
3938{
3939 /* Summary-only flag. */
3940 u_char summary_only;
3941
3942 /* AS set generation. */
3943 u_char as_set;
3944
3945 /* Route-map for aggregated route. */
3946 struct route_map *map;
3947
3948 /* Suppress-count. */
3949 unsigned long count;
3950
3951 /* SAFI configuration. */
3952 safi_t safi;
3953};
3954
paul94f2b392005-06-28 12:44:16 +00003955static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00003956bgp_aggregate_new ()
3957{
3958 struct bgp_aggregate *new;
3959 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3960 memset (new, 0, sizeof (struct bgp_aggregate));
3961 return new;
3962}
3963
paul94f2b392005-06-28 12:44:16 +00003964static void
paul718e3742002-12-13 20:15:29 +00003965bgp_aggregate_free (struct bgp_aggregate *aggregate)
3966{
3967 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
3968}
3969
paul94f2b392005-06-28 12:44:16 +00003970static void
paul718e3742002-12-13 20:15:29 +00003971bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
3972 afi_t afi, safi_t safi, struct bgp_info *del,
3973 struct bgp_aggregate *aggregate)
3974{
3975 struct bgp_table *table;
3976 struct bgp_node *top;
3977 struct bgp_node *rn;
3978 u_char origin;
3979 struct aspath *aspath = NULL;
3980 struct aspath *asmerge = NULL;
3981 struct community *community = NULL;
3982 struct community *commerge = NULL;
3983 struct in_addr nexthop;
3984 u_int32_t med = 0;
3985 struct bgp_info *ri;
3986 struct bgp_info *new;
3987 int first = 1;
3988 unsigned long match = 0;
3989
3990 /* Record adding route's nexthop and med. */
3991 if (rinew)
3992 {
3993 nexthop = rinew->attr->nexthop;
3994 med = rinew->attr->med;
3995 }
3996
3997 /* ORIGIN attribute: If at least one route among routes that are
3998 aggregated has ORIGIN with the value INCOMPLETE, then the
3999 aggregated route must have the ORIGIN attribute with the value
4000 INCOMPLETE. Otherwise, if at least one route among routes that
4001 are aggregated has ORIGIN with the value EGP, then the aggregated
4002 route must have the origin attribute with the value EGP. In all
4003 other case the value of the ORIGIN attribute of the aggregated
4004 route is INTERNAL. */
4005 origin = BGP_ORIGIN_IGP;
4006
4007 table = bgp->rib[afi][safi];
4008
4009 top = bgp_node_get (table, p);
4010 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4011 if (rn->p.prefixlen > p->prefixlen)
4012 {
4013 match = 0;
4014
4015 for (ri = rn->info; ri; ri = ri->next)
4016 {
4017 if (BGP_INFO_HOLDDOWN (ri))
4018 continue;
4019
4020 if (del && ri == del)
4021 continue;
4022
4023 if (! rinew && first)
4024 {
4025 nexthop = ri->attr->nexthop;
4026 med = ri->attr->med;
4027 first = 0;
4028 }
4029
4030#ifdef AGGREGATE_NEXTHOP_CHECK
4031 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4032 || ri->attr->med != med)
4033 {
4034 if (aspath)
4035 aspath_free (aspath);
4036 if (community)
4037 community_free (community);
4038 bgp_unlock_node (rn);
4039 bgp_unlock_node (top);
4040 return;
4041 }
4042#endif /* AGGREGATE_NEXTHOP_CHECK */
4043
4044 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4045 {
4046 if (aggregate->summary_only)
4047 {
4048 ri->suppress++;
4049 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4050 match++;
4051 }
4052
4053 aggregate->count++;
4054
4055 if (aggregate->as_set)
4056 {
4057 if (origin < ri->attr->origin)
4058 origin = ri->attr->origin;
4059
4060 if (aspath)
4061 {
4062 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4063 aspath_free (aspath);
4064 aspath = asmerge;
4065 }
4066 else
4067 aspath = aspath_dup (ri->attr->aspath);
4068
4069 if (ri->attr->community)
4070 {
4071 if (community)
4072 {
4073 commerge = community_merge (community,
4074 ri->attr->community);
4075 community = community_uniq_sort (commerge);
4076 community_free (commerge);
4077 }
4078 else
4079 community = community_dup (ri->attr->community);
4080 }
4081 }
4082 }
4083 }
4084 if (match)
4085 bgp_process (bgp, rn, afi, safi);
4086 }
4087 bgp_unlock_node (top);
4088
4089 if (rinew)
4090 {
4091 aggregate->count++;
4092
4093 if (aggregate->summary_only)
4094 rinew->suppress++;
4095
4096 if (aggregate->as_set)
4097 {
4098 if (origin < rinew->attr->origin)
4099 origin = rinew->attr->origin;
4100
4101 if (aspath)
4102 {
4103 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4104 aspath_free (aspath);
4105 aspath = asmerge;
4106 }
4107 else
4108 aspath = aspath_dup (rinew->attr->aspath);
4109
4110 if (rinew->attr->community)
4111 {
4112 if (community)
4113 {
4114 commerge = community_merge (community,
4115 rinew->attr->community);
4116 community = community_uniq_sort (commerge);
4117 community_free (commerge);
4118 }
4119 else
4120 community = community_dup (rinew->attr->community);
4121 }
4122 }
4123 }
4124
4125 if (aggregate->count > 0)
4126 {
4127 rn = bgp_node_get (table, p);
4128 new = bgp_info_new ();
4129 new->type = ZEBRA_ROUTE_BGP;
4130 new->sub_type = BGP_ROUTE_AGGREGATE;
4131 new->peer = bgp->peer_self;
4132 SET_FLAG (new->flags, BGP_INFO_VALID);
4133 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4134 new->uptime = time (NULL);
4135
4136 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004137 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004138 bgp_process (bgp, rn, afi, safi);
4139 }
4140 else
4141 {
4142 if (aspath)
4143 aspath_free (aspath);
4144 if (community)
4145 community_free (community);
4146 }
4147}
4148
4149void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4150 struct bgp_aggregate *);
4151
4152void
4153bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4154 struct bgp_info *ri, afi_t afi, safi_t safi)
4155{
4156 struct bgp_node *child;
4157 struct bgp_node *rn;
4158 struct bgp_aggregate *aggregate;
4159
4160 /* MPLS-VPN aggregation is not yet supported. */
4161 if (safi == SAFI_MPLS_VPN)
4162 return;
4163
4164 if (p->prefixlen == 0)
4165 return;
4166
4167 if (BGP_INFO_HOLDDOWN (ri))
4168 return;
4169
4170 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4171
4172 /* Aggregate address configuration check. */
4173 for (rn = child; rn; rn = rn->parent)
4174 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4175 {
4176 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004177 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004178 }
4179 bgp_unlock_node (child);
4180}
4181
4182void
4183bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4184 struct bgp_info *del, afi_t afi, safi_t safi)
4185{
4186 struct bgp_node *child;
4187 struct bgp_node *rn;
4188 struct bgp_aggregate *aggregate;
4189
4190 /* MPLS-VPN aggregation is not yet supported. */
4191 if (safi == SAFI_MPLS_VPN)
4192 return;
4193
4194 if (p->prefixlen == 0)
4195 return;
4196
4197 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4198
4199 /* Aggregate address configuration check. */
4200 for (rn = child; rn; rn = rn->parent)
4201 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4202 {
4203 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004204 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004205 }
4206 bgp_unlock_node (child);
4207}
4208
paul94f2b392005-06-28 12:44:16 +00004209static void
paul718e3742002-12-13 20:15:29 +00004210bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4211 struct bgp_aggregate *aggregate)
4212{
4213 struct bgp_table *table;
4214 struct bgp_node *top;
4215 struct bgp_node *rn;
4216 struct bgp_info *new;
4217 struct bgp_info *ri;
4218 unsigned long match;
4219 u_char origin = BGP_ORIGIN_IGP;
4220 struct aspath *aspath = NULL;
4221 struct aspath *asmerge = NULL;
4222 struct community *community = NULL;
4223 struct community *commerge = NULL;
4224
4225 table = bgp->rib[afi][safi];
4226
4227 /* Sanity check. */
4228 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4229 return;
4230 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4231 return;
4232
4233 /* If routes exists below this node, generate aggregate routes. */
4234 top = bgp_node_get (table, p);
4235 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4236 if (rn->p.prefixlen > p->prefixlen)
4237 {
4238 match = 0;
4239
4240 for (ri = rn->info; ri; ri = ri->next)
4241 {
4242 if (BGP_INFO_HOLDDOWN (ri))
4243 continue;
4244
4245 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4246 {
4247 /* summary-only aggregate route suppress aggregated
4248 route announcement. */
4249 if (aggregate->summary_only)
4250 {
4251 ri->suppress++;
4252 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4253 match++;
4254 }
4255 /* as-set aggregate route generate origin, as path,
4256 community aggregation. */
4257 if (aggregate->as_set)
4258 {
4259 if (origin < ri->attr->origin)
4260 origin = ri->attr->origin;
4261
4262 if (aspath)
4263 {
4264 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4265 aspath_free (aspath);
4266 aspath = asmerge;
4267 }
4268 else
4269 aspath = aspath_dup (ri->attr->aspath);
4270
4271 if (ri->attr->community)
4272 {
4273 if (community)
4274 {
4275 commerge = community_merge (community,
4276 ri->attr->community);
4277 community = community_uniq_sort (commerge);
4278 community_free (commerge);
4279 }
4280 else
4281 community = community_dup (ri->attr->community);
4282 }
4283 }
4284 aggregate->count++;
4285 }
4286 }
4287
4288 /* If this node is suppressed, process the change. */
4289 if (match)
4290 bgp_process (bgp, rn, afi, safi);
4291 }
4292 bgp_unlock_node (top);
4293
4294 /* Add aggregate route to BGP table. */
4295 if (aggregate->count)
4296 {
4297 rn = bgp_node_get (table, p);
4298
4299 new = bgp_info_new ();
4300 new->type = ZEBRA_ROUTE_BGP;
4301 new->sub_type = BGP_ROUTE_AGGREGATE;
4302 new->peer = bgp->peer_self;
4303 SET_FLAG (new->flags, BGP_INFO_VALID);
4304 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4305 new->uptime = time (NULL);
4306
4307 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004308 bgp_unlock_node (rn);
4309
paul718e3742002-12-13 20:15:29 +00004310 /* Process change. */
4311 bgp_process (bgp, rn, afi, safi);
4312 }
4313}
4314
4315void
4316bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4317 safi_t safi, struct bgp_aggregate *aggregate)
4318{
4319 struct bgp_table *table;
4320 struct bgp_node *top;
4321 struct bgp_node *rn;
4322 struct bgp_info *ri;
4323 unsigned long match;
4324
4325 table = bgp->rib[afi][safi];
4326
4327 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4328 return;
4329 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4330 return;
4331
4332 /* If routes exists below this node, generate aggregate routes. */
4333 top = bgp_node_get (table, p);
4334 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4335 if (rn->p.prefixlen > p->prefixlen)
4336 {
4337 match = 0;
4338
4339 for (ri = rn->info; ri; ri = ri->next)
4340 {
4341 if (BGP_INFO_HOLDDOWN (ri))
4342 continue;
4343
4344 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4345 {
4346 if (aggregate->summary_only)
4347 {
4348 ri->suppress--;
4349
4350 if (ri->suppress == 0)
4351 {
4352 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4353 match++;
4354 }
4355 }
4356 aggregate->count--;
4357 }
4358 }
4359
4360 /* If this node is suppressed, process the change. */
4361 if (match)
4362 bgp_process (bgp, rn, afi, safi);
4363 }
4364 bgp_unlock_node (top);
4365
4366 /* Delete aggregate route from BGP table. */
4367 rn = bgp_node_get (table, p);
4368
4369 for (ri = rn->info; ri; ri = ri->next)
4370 if (ri->peer == bgp->peer_self
4371 && ri->type == ZEBRA_ROUTE_BGP
4372 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4373 break;
4374
4375 /* Withdraw static BGP route from routing table. */
4376 if (ri)
4377 {
4378 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4379 bgp_process (bgp, rn, afi, safi);
4380 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004381 }
4382
4383 /* Unlock bgp_node_lookup. */
4384 bgp_unlock_node (rn);
4385}
4386
4387/* Aggregate route attribute. */
4388#define AGGREGATE_SUMMARY_ONLY 1
4389#define AGGREGATE_AS_SET 1
4390
paul94f2b392005-06-28 12:44:16 +00004391static int
paulfd79ac92004-10-13 05:06:08 +00004392bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4393 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004394 u_char summary_only, u_char as_set)
4395{
4396 int ret;
4397 struct prefix p;
4398 struct bgp_node *rn;
4399 struct bgp *bgp;
4400 struct bgp_aggregate *aggregate;
4401
4402 /* Convert string to prefix structure. */
4403 ret = str2prefix (prefix_str, &p);
4404 if (!ret)
4405 {
4406 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4407 return CMD_WARNING;
4408 }
4409 apply_mask (&p);
4410
4411 /* Get BGP structure. */
4412 bgp = vty->index;
4413
4414 /* Old configuration check. */
4415 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4416
4417 if (rn->info)
4418 {
4419 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4420 bgp_unlock_node (rn);
4421 return CMD_WARNING;
4422 }
4423
4424 /* Make aggregate address structure. */
4425 aggregate = bgp_aggregate_new ();
4426 aggregate->summary_only = summary_only;
4427 aggregate->as_set = as_set;
4428 aggregate->safi = safi;
4429 rn->info = aggregate;
4430
4431 /* Aggregate address insert into BGP routing table. */
4432 if (safi & SAFI_UNICAST)
4433 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4434 if (safi & SAFI_MULTICAST)
4435 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4436
4437 return CMD_SUCCESS;
4438}
4439
paul94f2b392005-06-28 12:44:16 +00004440static int
paulfd79ac92004-10-13 05:06:08 +00004441bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4442 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004443{
4444 int ret;
4445 struct prefix p;
4446 struct bgp_node *rn;
4447 struct bgp *bgp;
4448 struct bgp_aggregate *aggregate;
4449
4450 /* Convert string to prefix structure. */
4451 ret = str2prefix (prefix_str, &p);
4452 if (!ret)
4453 {
4454 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4455 return CMD_WARNING;
4456 }
4457 apply_mask (&p);
4458
4459 /* Get BGP structure. */
4460 bgp = vty->index;
4461
4462 /* Old configuration check. */
4463 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4464 if (! rn)
4465 {
4466 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4467 VTY_NEWLINE);
4468 return CMD_WARNING;
4469 }
4470
4471 aggregate = rn->info;
4472 if (aggregate->safi & SAFI_UNICAST)
4473 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4474 if (aggregate->safi & SAFI_MULTICAST)
4475 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4476
4477 /* Unlock aggregate address configuration. */
4478 rn->info = NULL;
4479 bgp_aggregate_free (aggregate);
4480 bgp_unlock_node (rn);
4481 bgp_unlock_node (rn);
4482
4483 return CMD_SUCCESS;
4484}
4485
4486DEFUN (aggregate_address,
4487 aggregate_address_cmd,
4488 "aggregate-address A.B.C.D/M",
4489 "Configure BGP aggregate entries\n"
4490 "Aggregate prefix\n")
4491{
4492 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4493}
4494
4495DEFUN (aggregate_address_mask,
4496 aggregate_address_mask_cmd,
4497 "aggregate-address A.B.C.D A.B.C.D",
4498 "Configure BGP aggregate entries\n"
4499 "Aggregate address\n"
4500 "Aggregate mask\n")
4501{
4502 int ret;
4503 char prefix_str[BUFSIZ];
4504
4505 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4506
4507 if (! ret)
4508 {
4509 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4510 return CMD_WARNING;
4511 }
4512
4513 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4514 0, 0);
4515}
4516
4517DEFUN (aggregate_address_summary_only,
4518 aggregate_address_summary_only_cmd,
4519 "aggregate-address A.B.C.D/M summary-only",
4520 "Configure BGP aggregate entries\n"
4521 "Aggregate prefix\n"
4522 "Filter more specific routes from updates\n")
4523{
4524 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4525 AGGREGATE_SUMMARY_ONLY, 0);
4526}
4527
4528DEFUN (aggregate_address_mask_summary_only,
4529 aggregate_address_mask_summary_only_cmd,
4530 "aggregate-address A.B.C.D A.B.C.D summary-only",
4531 "Configure BGP aggregate entries\n"
4532 "Aggregate address\n"
4533 "Aggregate mask\n"
4534 "Filter more specific routes from updates\n")
4535{
4536 int ret;
4537 char prefix_str[BUFSIZ];
4538
4539 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4540
4541 if (! ret)
4542 {
4543 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4544 return CMD_WARNING;
4545 }
4546
4547 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4548 AGGREGATE_SUMMARY_ONLY, 0);
4549}
4550
4551DEFUN (aggregate_address_as_set,
4552 aggregate_address_as_set_cmd,
4553 "aggregate-address A.B.C.D/M as-set",
4554 "Configure BGP aggregate entries\n"
4555 "Aggregate prefix\n"
4556 "Generate AS set path information\n")
4557{
4558 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4559 0, AGGREGATE_AS_SET);
4560}
4561
4562DEFUN (aggregate_address_mask_as_set,
4563 aggregate_address_mask_as_set_cmd,
4564 "aggregate-address A.B.C.D A.B.C.D as-set",
4565 "Configure BGP aggregate entries\n"
4566 "Aggregate address\n"
4567 "Aggregate mask\n"
4568 "Generate AS set path information\n")
4569{
4570 int ret;
4571 char prefix_str[BUFSIZ];
4572
4573 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4574
4575 if (! ret)
4576 {
4577 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4578 return CMD_WARNING;
4579 }
4580
4581 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4582 0, AGGREGATE_AS_SET);
4583}
4584
4585
4586DEFUN (aggregate_address_as_set_summary,
4587 aggregate_address_as_set_summary_cmd,
4588 "aggregate-address A.B.C.D/M as-set summary-only",
4589 "Configure BGP aggregate entries\n"
4590 "Aggregate prefix\n"
4591 "Generate AS set path information\n"
4592 "Filter more specific routes from updates\n")
4593{
4594 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4595 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4596}
4597
4598ALIAS (aggregate_address_as_set_summary,
4599 aggregate_address_summary_as_set_cmd,
4600 "aggregate-address A.B.C.D/M summary-only as-set",
4601 "Configure BGP aggregate entries\n"
4602 "Aggregate prefix\n"
4603 "Filter more specific routes from updates\n"
4604 "Generate AS set path information\n")
4605
4606DEFUN (aggregate_address_mask_as_set_summary,
4607 aggregate_address_mask_as_set_summary_cmd,
4608 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4609 "Configure BGP aggregate entries\n"
4610 "Aggregate address\n"
4611 "Aggregate mask\n"
4612 "Generate AS set path information\n"
4613 "Filter more specific routes from updates\n")
4614{
4615 int ret;
4616 char prefix_str[BUFSIZ];
4617
4618 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4619
4620 if (! ret)
4621 {
4622 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4623 return CMD_WARNING;
4624 }
4625
4626 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4627 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4628}
4629
4630ALIAS (aggregate_address_mask_as_set_summary,
4631 aggregate_address_mask_summary_as_set_cmd,
4632 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4633 "Configure BGP aggregate entries\n"
4634 "Aggregate address\n"
4635 "Aggregate mask\n"
4636 "Filter more specific routes from updates\n"
4637 "Generate AS set path information\n")
4638
4639DEFUN (no_aggregate_address,
4640 no_aggregate_address_cmd,
4641 "no aggregate-address A.B.C.D/M",
4642 NO_STR
4643 "Configure BGP aggregate entries\n"
4644 "Aggregate prefix\n")
4645{
4646 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4647}
4648
4649ALIAS (no_aggregate_address,
4650 no_aggregate_address_summary_only_cmd,
4651 "no aggregate-address A.B.C.D/M summary-only",
4652 NO_STR
4653 "Configure BGP aggregate entries\n"
4654 "Aggregate prefix\n"
4655 "Filter more specific routes from updates\n")
4656
4657ALIAS (no_aggregate_address,
4658 no_aggregate_address_as_set_cmd,
4659 "no aggregate-address A.B.C.D/M as-set",
4660 NO_STR
4661 "Configure BGP aggregate entries\n"
4662 "Aggregate prefix\n"
4663 "Generate AS set path information\n")
4664
4665ALIAS (no_aggregate_address,
4666 no_aggregate_address_as_set_summary_cmd,
4667 "no aggregate-address A.B.C.D/M as-set summary-only",
4668 NO_STR
4669 "Configure BGP aggregate entries\n"
4670 "Aggregate prefix\n"
4671 "Generate AS set path information\n"
4672 "Filter more specific routes from updates\n")
4673
4674ALIAS (no_aggregate_address,
4675 no_aggregate_address_summary_as_set_cmd,
4676 "no aggregate-address A.B.C.D/M summary-only as-set",
4677 NO_STR
4678 "Configure BGP aggregate entries\n"
4679 "Aggregate prefix\n"
4680 "Filter more specific routes from updates\n"
4681 "Generate AS set path information\n")
4682
4683DEFUN (no_aggregate_address_mask,
4684 no_aggregate_address_mask_cmd,
4685 "no aggregate-address A.B.C.D A.B.C.D",
4686 NO_STR
4687 "Configure BGP aggregate entries\n"
4688 "Aggregate address\n"
4689 "Aggregate mask\n")
4690{
4691 int ret;
4692 char prefix_str[BUFSIZ];
4693
4694 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4695
4696 if (! ret)
4697 {
4698 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4699 return CMD_WARNING;
4700 }
4701
4702 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4703}
4704
4705ALIAS (no_aggregate_address_mask,
4706 no_aggregate_address_mask_summary_only_cmd,
4707 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4708 NO_STR
4709 "Configure BGP aggregate entries\n"
4710 "Aggregate address\n"
4711 "Aggregate mask\n"
4712 "Filter more specific routes from updates\n")
4713
4714ALIAS (no_aggregate_address_mask,
4715 no_aggregate_address_mask_as_set_cmd,
4716 "no aggregate-address A.B.C.D A.B.C.D as-set",
4717 NO_STR
4718 "Configure BGP aggregate entries\n"
4719 "Aggregate address\n"
4720 "Aggregate mask\n"
4721 "Generate AS set path information\n")
4722
4723ALIAS (no_aggregate_address_mask,
4724 no_aggregate_address_mask_as_set_summary_cmd,
4725 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4726 NO_STR
4727 "Configure BGP aggregate entries\n"
4728 "Aggregate address\n"
4729 "Aggregate mask\n"
4730 "Generate AS set path information\n"
4731 "Filter more specific routes from updates\n")
4732
4733ALIAS (no_aggregate_address_mask,
4734 no_aggregate_address_mask_summary_as_set_cmd,
4735 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4736 NO_STR
4737 "Configure BGP aggregate entries\n"
4738 "Aggregate address\n"
4739 "Aggregate mask\n"
4740 "Filter more specific routes from updates\n"
4741 "Generate AS set path information\n")
4742
4743#ifdef HAVE_IPV6
4744DEFUN (ipv6_aggregate_address,
4745 ipv6_aggregate_address_cmd,
4746 "aggregate-address X:X::X:X/M",
4747 "Configure BGP aggregate entries\n"
4748 "Aggregate prefix\n")
4749{
4750 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4751}
4752
4753DEFUN (ipv6_aggregate_address_summary_only,
4754 ipv6_aggregate_address_summary_only_cmd,
4755 "aggregate-address X:X::X:X/M summary-only",
4756 "Configure BGP aggregate entries\n"
4757 "Aggregate prefix\n"
4758 "Filter more specific routes from updates\n")
4759{
4760 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4761 AGGREGATE_SUMMARY_ONLY, 0);
4762}
4763
4764DEFUN (no_ipv6_aggregate_address,
4765 no_ipv6_aggregate_address_cmd,
4766 "no aggregate-address X:X::X:X/M",
4767 NO_STR
4768 "Configure BGP aggregate entries\n"
4769 "Aggregate prefix\n")
4770{
4771 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4772}
4773
4774DEFUN (no_ipv6_aggregate_address_summary_only,
4775 no_ipv6_aggregate_address_summary_only_cmd,
4776 "no aggregate-address X:X::X:X/M summary-only",
4777 NO_STR
4778 "Configure BGP aggregate entries\n"
4779 "Aggregate prefix\n"
4780 "Filter more specific routes from updates\n")
4781{
4782 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4783}
4784
4785ALIAS (ipv6_aggregate_address,
4786 old_ipv6_aggregate_address_cmd,
4787 "ipv6 bgp aggregate-address X:X::X:X/M",
4788 IPV6_STR
4789 BGP_STR
4790 "Configure BGP aggregate entries\n"
4791 "Aggregate prefix\n")
4792
4793ALIAS (ipv6_aggregate_address_summary_only,
4794 old_ipv6_aggregate_address_summary_only_cmd,
4795 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4796 IPV6_STR
4797 BGP_STR
4798 "Configure BGP aggregate entries\n"
4799 "Aggregate prefix\n"
4800 "Filter more specific routes from updates\n")
4801
4802ALIAS (no_ipv6_aggregate_address,
4803 old_no_ipv6_aggregate_address_cmd,
4804 "no ipv6 bgp aggregate-address X:X::X:X/M",
4805 NO_STR
4806 IPV6_STR
4807 BGP_STR
4808 "Configure BGP aggregate entries\n"
4809 "Aggregate prefix\n")
4810
4811ALIAS (no_ipv6_aggregate_address_summary_only,
4812 old_no_ipv6_aggregate_address_summary_only_cmd,
4813 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4814 NO_STR
4815 IPV6_STR
4816 BGP_STR
4817 "Configure BGP aggregate entries\n"
4818 "Aggregate prefix\n"
4819 "Filter more specific routes from updates\n")
4820#endif /* HAVE_IPV6 */
4821
4822/* Redistribute route treatment. */
4823void
4824bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4825 u_int32_t metric, u_char type)
4826{
4827 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004828 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004829 struct bgp_info *new;
4830 struct bgp_info *bi;
4831 struct bgp_info info;
4832 struct bgp_node *bn;
4833 struct attr attr;
4834 struct attr attr_new;
4835 struct attr *new_attr;
4836 afi_t afi;
4837 int ret;
4838
4839 /* Make default attribute. */
4840 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4841 if (nexthop)
4842 attr.nexthop = *nexthop;
4843
4844 attr.med = metric;
4845 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4846
paul1eb8ef22005-04-07 07:30:20 +00004847 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004848 {
4849 afi = family2afi (p->family);
4850
4851 if (bgp->redist[afi][type])
4852 {
4853 /* Copy attribute for modification. */
4854 attr_new = attr;
4855
4856 if (bgp->redist_metric_flag[afi][type])
4857 attr_new.med = bgp->redist_metric[afi][type];
4858
4859 /* Apply route-map. */
4860 if (bgp->rmap[afi][type].map)
4861 {
4862 info.peer = bgp->peer_self;
4863 info.attr = &attr_new;
4864
paulfee0f4c2004-09-13 05:12:46 +00004865 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4866
paul718e3742002-12-13 20:15:29 +00004867 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4868 &info);
paulfee0f4c2004-09-13 05:12:46 +00004869
4870 bgp->peer_self->rmap_type = 0;
4871
paul718e3742002-12-13 20:15:29 +00004872 if (ret == RMAP_DENYMATCH)
4873 {
4874 /* Free uninterned attribute. */
4875 bgp_attr_flush (&attr_new);
4876
4877 /* Unintern original. */
4878 aspath_unintern (attr.aspath);
4879 bgp_redistribute_delete (p, type);
4880 return;
4881 }
4882 }
4883
paulfee0f4c2004-09-13 05:12:46 +00004884 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004885 new_attr = bgp_attr_intern (&attr_new);
4886
4887 for (bi = bn->info; bi; bi = bi->next)
4888 if (bi->peer == bgp->peer_self
4889 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4890 break;
4891
4892 if (bi)
4893 {
4894 if (attrhash_cmp (bi->attr, new_attr))
4895 {
4896 bgp_attr_unintern (new_attr);
4897 aspath_unintern (attr.aspath);
4898 bgp_unlock_node (bn);
4899 return;
4900 }
4901 else
4902 {
4903 /* The attribute is changed. */
4904 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4905
4906 /* Rewrite BGP route information. */
4907 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4908 bgp_attr_unintern (bi->attr);
4909 bi->attr = new_attr;
4910 bi->uptime = time (NULL);
4911
4912 /* Process change. */
4913 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4914 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4915 bgp_unlock_node (bn);
4916 aspath_unintern (attr.aspath);
4917 return;
4918 }
4919 }
4920
4921 new = bgp_info_new ();
4922 new->type = type;
4923 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4924 new->peer = bgp->peer_self;
4925 SET_FLAG (new->flags, BGP_INFO_VALID);
4926 new->attr = new_attr;
4927 new->uptime = time (NULL);
4928
4929 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4930 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004931 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004932 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4933 }
4934 }
4935
4936 /* Unintern original. */
4937 aspath_unintern (attr.aspath);
4938}
4939
4940void
4941bgp_redistribute_delete (struct prefix *p, u_char type)
4942{
4943 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004944 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004945 afi_t afi;
4946 struct bgp_node *rn;
4947 struct bgp_info *ri;
4948
paul1eb8ef22005-04-07 07:30:20 +00004949 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004950 {
4951 afi = family2afi (p->family);
4952
4953 if (bgp->redist[afi][type])
4954 {
paulfee0f4c2004-09-13 05:12:46 +00004955 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004956
4957 for (ri = rn->info; ri; ri = ri->next)
4958 if (ri->peer == bgp->peer_self
4959 && ri->type == type)
4960 break;
4961
4962 if (ri)
4963 {
4964 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4965 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4966 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4967 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004968 }
4969 bgp_unlock_node (rn);
4970 }
4971 }
4972}
4973
4974/* Withdraw specified route type's route. */
4975void
4976bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
4977{
4978 struct bgp_node *rn;
4979 struct bgp_info *ri;
4980 struct bgp_table *table;
4981
4982 table = bgp->rib[afi][SAFI_UNICAST];
4983
4984 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4985 {
4986 for (ri = rn->info; ri; ri = ri->next)
4987 if (ri->peer == bgp->peer_self
4988 && ri->type == type)
4989 break;
4990
4991 if (ri)
4992 {
4993 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
4994 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4995 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4996 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004997 }
4998 }
4999}
5000
5001/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005002static void
paul718e3742002-12-13 20:15:29 +00005003route_vty_out_route (struct prefix *p, struct vty *vty)
5004{
5005 int len;
5006 u_int32_t destination;
5007 char buf[BUFSIZ];
5008
5009 if (p->family == AF_INET)
5010 {
5011 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5012 destination = ntohl (p->u.prefix4.s_addr);
5013
5014 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5015 || (IN_CLASSB (destination) && p->prefixlen == 16)
5016 || (IN_CLASSA (destination) && p->prefixlen == 8)
5017 || p->u.prefix4.s_addr == 0)
5018 {
5019 /* When mask is natural, mask is not displayed. */
5020 }
5021 else
5022 len += vty_out (vty, "/%d", p->prefixlen);
5023 }
5024 else
5025 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5026 p->prefixlen);
5027
5028 len = 17 - len;
5029 if (len < 1)
5030 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5031 else
5032 vty_out (vty, "%*s", len, " ");
5033}
5034
paul718e3742002-12-13 20:15:29 +00005035enum bgp_display_type
5036{
5037 normal_list,
5038};
5039
paulb40d9392005-08-22 22:34:41 +00005040/* Print the short form route status for a bgp_info */
5041static void
5042route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005043{
paulb40d9392005-08-22 22:34:41 +00005044 /* Route status display. */
5045 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5046 vty_out (vty, "R");
5047 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005048 vty_out (vty, "S");
5049 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005050 vty_out (vty, "s");
5051 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5052 vty_out (vty, "*");
5053 else
5054 vty_out (vty, " ");
5055
5056 /* Selected */
5057 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5058 vty_out (vty, "h");
5059 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5060 vty_out (vty, "d");
5061 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5062 vty_out (vty, ">");
5063 else
5064 vty_out (vty, " ");
5065
5066 /* Internal route. */
5067 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5068 vty_out (vty, "i");
5069 else
paulb40d9392005-08-22 22:34:41 +00005070 vty_out (vty, " ");
5071}
5072
5073/* called from terminal list command */
5074void
5075route_vty_out (struct vty *vty, struct prefix *p,
5076 struct bgp_info *binfo, int display, safi_t safi)
5077{
5078 struct attr *attr;
5079
5080 /* short status lead text */
5081 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005082
5083 /* print prefix and mask */
5084 if (! display)
5085 route_vty_out_route (p, vty);
5086 else
5087 vty_out (vty, "%*s", 17, " ");
5088
5089 /* Print attribute */
5090 attr = binfo->attr;
5091 if (attr)
5092 {
5093 if (p->family == AF_INET)
5094 {
5095 if (safi == SAFI_MPLS_VPN)
5096 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5097 else
5098 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5099 }
5100#ifdef HAVE_IPV6
5101 else if (p->family == AF_INET6)
5102 {
5103 int len;
5104 char buf[BUFSIZ];
5105
5106 len = vty_out (vty, "%s",
5107 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5108 len = 16 - len;
5109 if (len < 1)
5110 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5111 else
5112 vty_out (vty, "%*s", len, " ");
5113 }
5114#endif /* HAVE_IPV6 */
5115
5116 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5117 vty_out (vty, "%10d", attr->med);
5118 else
5119 vty_out (vty, " ");
5120
5121 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5122 vty_out (vty, "%7d", attr->local_pref);
5123 else
5124 vty_out (vty, " ");
5125
5126 vty_out (vty, "%7u ",attr->weight);
5127
5128 /* Print aspath */
5129 if (attr->aspath)
5130 aspath_print_vty (vty, attr->aspath);
5131
5132 /* Print origin */
5133 if (strlen (attr->aspath->str) == 0)
5134 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5135 else
5136 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5137 }
5138 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005139}
5140
5141/* called from terminal list command */
5142void
5143route_vty_out_tmp (struct vty *vty, struct prefix *p,
5144 struct attr *attr, safi_t safi)
5145{
5146 /* Route status display. */
5147 vty_out (vty, "*");
5148 vty_out (vty, ">");
5149 vty_out (vty, " ");
5150
5151 /* print prefix and mask */
5152 route_vty_out_route (p, vty);
5153
5154 /* Print attribute */
5155 if (attr)
5156 {
5157 if (p->family == AF_INET)
5158 {
5159 if (safi == SAFI_MPLS_VPN)
5160 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5161 else
5162 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5163 }
5164#ifdef HAVE_IPV6
5165 else if (p->family == AF_INET6)
5166 {
5167 int len;
5168 char buf[BUFSIZ];
5169
5170 len = vty_out (vty, "%s",
5171 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5172 len = 16 - len;
5173 if (len < 1)
5174 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5175 else
5176 vty_out (vty, "%*s", len, " ");
5177 }
5178#endif /* HAVE_IPV6 */
5179
5180 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5181 vty_out (vty, "%10d", attr->med);
5182 else
5183 vty_out (vty, " ");
5184
5185 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5186 vty_out (vty, "%7d", attr->local_pref);
5187 else
5188 vty_out (vty, " ");
5189
5190 vty_out (vty, "%7d ",attr->weight);
5191
5192 /* Print aspath */
5193 if (attr->aspath)
5194 aspath_print_vty (vty, attr->aspath);
5195
5196 /* Print origin */
5197 if (strlen (attr->aspath->str) == 0)
5198 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5199 else
5200 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5201 }
5202
5203 vty_out (vty, "%s", VTY_NEWLINE);
5204}
5205
ajs5a646652004-11-05 01:25:55 +00005206void
paul718e3742002-12-13 20:15:29 +00005207route_vty_out_tag (struct vty *vty, struct prefix *p,
5208 struct bgp_info *binfo, int display, safi_t safi)
5209{
5210 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005211 u_int32_t label = 0;
5212
paulb40d9392005-08-22 22:34:41 +00005213 /* short status lead text */
5214 route_vty_short_status_out (vty, binfo);
5215
paul718e3742002-12-13 20:15:29 +00005216 /* print prefix and mask */
5217 if (! display)
5218 route_vty_out_route (p, vty);
5219 else
5220 vty_out (vty, "%*s", 17, " ");
5221
5222 /* Print attribute */
5223 attr = binfo->attr;
5224 if (attr)
5225 {
5226 if (p->family == AF_INET)
5227 {
5228 if (safi == SAFI_MPLS_VPN)
5229 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5230 else
5231 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5232 }
5233#ifdef HAVE_IPV6
5234 else if (p->family == AF_INET6)
5235 {
5236 char buf[BUFSIZ];
5237 char buf1[BUFSIZ];
5238 if (attr->mp_nexthop_len == 16)
5239 vty_out (vty, "%s",
5240 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5241 else if (attr->mp_nexthop_len == 32)
5242 vty_out (vty, "%s(%s)",
5243 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5244 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5245
5246 }
5247#endif /* HAVE_IPV6 */
5248 }
5249
5250 label = decode_label (binfo->tag);
5251
5252 vty_out (vty, "notag/%d", label);
5253
5254 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005255}
5256
5257/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005258static void
paul718e3742002-12-13 20:15:29 +00005259damp_route_vty_out (struct vty *vty, struct prefix *p,
5260 struct bgp_info *binfo, int display, safi_t safi)
5261{
5262 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005263 int len;
5264
paulb40d9392005-08-22 22:34:41 +00005265 /* short status lead text */
5266 route_vty_short_status_out (vty, binfo);
5267
paul718e3742002-12-13 20:15:29 +00005268 /* print prefix and mask */
5269 if (! display)
5270 route_vty_out_route (p, vty);
5271 else
5272 vty_out (vty, "%*s", 17, " ");
5273
5274 len = vty_out (vty, "%s", binfo->peer->host);
5275 len = 17 - len;
5276 if (len < 1)
5277 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5278 else
5279 vty_out (vty, "%*s", len, " ");
5280
5281 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5282
5283 /* Print attribute */
5284 attr = binfo->attr;
5285 if (attr)
5286 {
5287 /* Print aspath */
5288 if (attr->aspath)
5289 aspath_print_vty (vty, attr->aspath);
5290
5291 /* Print origin */
5292 if (strlen (attr->aspath->str) == 0)
5293 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5294 else
5295 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5296 }
5297 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005298}
5299
5300#define BGP_UPTIME_LEN 25
5301
5302/* flap route */
ajs5a646652004-11-05 01:25:55 +00005303static void
paul718e3742002-12-13 20:15:29 +00005304flap_route_vty_out (struct vty *vty, struct prefix *p,
5305 struct bgp_info *binfo, int display, safi_t safi)
5306{
5307 struct attr *attr;
5308 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005309 char timebuf[BGP_UPTIME_LEN];
5310 int len;
5311
paul718e3742002-12-13 20:15:29 +00005312 bdi = binfo->damp_info;
5313
paulb40d9392005-08-22 22:34:41 +00005314 /* short status lead text */
5315 route_vty_short_status_out (vty, binfo);
5316
paul718e3742002-12-13 20:15:29 +00005317 /* print prefix and mask */
5318 if (! display)
5319 route_vty_out_route (p, vty);
5320 else
5321 vty_out (vty, "%*s", 17, " ");
5322
5323 len = vty_out (vty, "%s", binfo->peer->host);
5324 len = 16 - len;
5325 if (len < 1)
5326 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5327 else
5328 vty_out (vty, "%*s", len, " ");
5329
5330 len = vty_out (vty, "%d", bdi->flap);
5331 len = 5 - len;
5332 if (len < 1)
5333 vty_out (vty, " ");
5334 else
5335 vty_out (vty, "%*s ", len, " ");
5336
5337 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5338 timebuf, BGP_UPTIME_LEN));
5339
5340 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5341 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5342 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5343 else
5344 vty_out (vty, "%*s ", 8, " ");
5345
5346 /* Print attribute */
5347 attr = binfo->attr;
5348 if (attr)
5349 {
5350 /* Print aspath */
5351 if (attr->aspath)
5352 aspath_print_vty (vty, attr->aspath);
5353
5354 /* Print origin */
5355 if (strlen (attr->aspath->str) == 0)
5356 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5357 else
5358 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5359 }
5360 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005361}
5362
paul94f2b392005-06-28 12:44:16 +00005363static void
paul718e3742002-12-13 20:15:29 +00005364route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5365 struct bgp_info *binfo, afi_t afi, safi_t safi)
5366{
5367 char buf[INET6_ADDRSTRLEN];
5368 char buf1[BUFSIZ];
5369 struct attr *attr;
5370 int sockunion_vty_out (struct vty *, union sockunion *);
5371
5372 attr = binfo->attr;
5373
5374 if (attr)
5375 {
5376 /* Line1 display AS-path, Aggregator */
5377 if (attr->aspath)
5378 {
5379 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005380 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005381 vty_out (vty, "Local");
5382 else
5383 aspath_print_vty (vty, attr->aspath);
5384 }
5385
paulb40d9392005-08-22 22:34:41 +00005386 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5387 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005388 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5389 vty_out (vty, ", (stale)");
5390 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5391 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5392 inet_ntoa (attr->aggregator_addr));
5393 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5394 vty_out (vty, ", (Received from a RR-client)");
5395 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5396 vty_out (vty, ", (Received from a RS-client)");
5397 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5398 vty_out (vty, ", (history entry)");
5399 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5400 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005401 vty_out (vty, "%s", VTY_NEWLINE);
5402
5403 /* Line2 display Next-hop, Neighbor, Router-id */
5404 if (p->family == AF_INET)
5405 {
5406 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5407 inet_ntoa (attr->mp_nexthop_global_in) :
5408 inet_ntoa (attr->nexthop));
5409 }
5410#ifdef HAVE_IPV6
5411 else
5412 {
5413 vty_out (vty, " %s",
5414 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5415 buf, INET6_ADDRSTRLEN));
5416 }
5417#endif /* HAVE_IPV6 */
5418
5419 if (binfo->peer == bgp->peer_self)
5420 {
5421 vty_out (vty, " from %s ",
5422 p->family == AF_INET ? "0.0.0.0" : "::");
5423 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5424 }
5425 else
5426 {
5427 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5428 vty_out (vty, " (inaccessible)");
5429 else if (binfo->igpmetric)
5430 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005431 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005432 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5433 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5434 else
5435 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5436 }
5437 vty_out (vty, "%s", VTY_NEWLINE);
5438
5439#ifdef HAVE_IPV6
5440 /* display nexthop local */
5441 if (attr->mp_nexthop_len == 32)
5442 {
5443 vty_out (vty, " (%s)%s",
5444 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5445 buf, INET6_ADDRSTRLEN),
5446 VTY_NEWLINE);
5447 }
5448#endif /* HAVE_IPV6 */
5449
5450 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5451 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5452
5453 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5454 vty_out (vty, ", metric %d", attr->med);
5455
5456 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5457 vty_out (vty, ", localpref %d", attr->local_pref);
5458 else
5459 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5460
5461 if (attr->weight != 0)
5462 vty_out (vty, ", weight %d", attr->weight);
5463
5464 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5465 vty_out (vty, ", valid");
5466
5467 if (binfo->peer != bgp->peer_self)
5468 {
5469 if (binfo->peer->as == binfo->peer->local_as)
5470 vty_out (vty, ", internal");
5471 else
5472 vty_out (vty, ", %s",
5473 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5474 }
5475 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5476 vty_out (vty, ", aggregated, local");
5477 else if (binfo->type != ZEBRA_ROUTE_BGP)
5478 vty_out (vty, ", sourced");
5479 else
5480 vty_out (vty, ", sourced, local");
5481
5482 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5483 vty_out (vty, ", atomic-aggregate");
5484
5485 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5486 vty_out (vty, ", best");
5487
5488 vty_out (vty, "%s", VTY_NEWLINE);
5489
5490 /* Line 4 display Community */
5491 if (attr->community)
5492 vty_out (vty, " Community: %s%s", attr->community->str,
5493 VTY_NEWLINE);
5494
5495 /* Line 5 display Extended-community */
5496 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5497 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5498 VTY_NEWLINE);
5499
5500 /* Line 6 display Originator, Cluster-id */
5501 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5502 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5503 {
5504 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5505 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5506
5507 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5508 {
5509 int i;
5510 vty_out (vty, ", Cluster list: ");
5511 for (i = 0; i < attr->cluster->length / 4; i++)
5512 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5513 }
5514 vty_out (vty, "%s", VTY_NEWLINE);
5515 }
5516
5517 if (binfo->damp_info)
5518 bgp_damp_info_vty (vty, binfo);
5519
5520 /* Line 7 display Uptime */
5521 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5522 }
5523 vty_out (vty, "%s", VTY_NEWLINE);
5524}
5525
paulb40d9392005-08-22 22:34:41 +00005526#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 +00005527#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005528#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5529#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5530#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5531
5532enum bgp_show_type
5533{
5534 bgp_show_type_normal,
5535 bgp_show_type_regexp,
5536 bgp_show_type_prefix_list,
5537 bgp_show_type_filter_list,
5538 bgp_show_type_route_map,
5539 bgp_show_type_neighbor,
5540 bgp_show_type_cidr_only,
5541 bgp_show_type_prefix_longer,
5542 bgp_show_type_community_all,
5543 bgp_show_type_community,
5544 bgp_show_type_community_exact,
5545 bgp_show_type_community_list,
5546 bgp_show_type_community_list_exact,
5547 bgp_show_type_flap_statistics,
5548 bgp_show_type_flap_address,
5549 bgp_show_type_flap_prefix,
5550 bgp_show_type_flap_cidr_only,
5551 bgp_show_type_flap_regexp,
5552 bgp_show_type_flap_filter_list,
5553 bgp_show_type_flap_prefix_list,
5554 bgp_show_type_flap_prefix_longer,
5555 bgp_show_type_flap_route_map,
5556 bgp_show_type_flap_neighbor,
5557 bgp_show_type_dampend_paths,
5558 bgp_show_type_damp_neighbor
5559};
5560
ajs5a646652004-11-05 01:25:55 +00005561static int
paulfee0f4c2004-09-13 05:12:46 +00005562bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005563 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005564{
paul718e3742002-12-13 20:15:29 +00005565 struct bgp_info *ri;
5566 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005567 int header = 1;
paul718e3742002-12-13 20:15:29 +00005568 int display;
ajs5a646652004-11-05 01:25:55 +00005569 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005570
5571 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005572 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005573
paul718e3742002-12-13 20:15:29 +00005574 /* Start processing of routes. */
5575 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5576 if (rn->info != NULL)
5577 {
5578 display = 0;
5579
5580 for (ri = rn->info; ri; ri = ri->next)
5581 {
ajs5a646652004-11-05 01:25:55 +00005582 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005583 || type == bgp_show_type_flap_address
5584 || type == bgp_show_type_flap_prefix
5585 || type == bgp_show_type_flap_cidr_only
5586 || type == bgp_show_type_flap_regexp
5587 || type == bgp_show_type_flap_filter_list
5588 || type == bgp_show_type_flap_prefix_list
5589 || type == bgp_show_type_flap_prefix_longer
5590 || type == bgp_show_type_flap_route_map
5591 || type == bgp_show_type_flap_neighbor
5592 || type == bgp_show_type_dampend_paths
5593 || type == bgp_show_type_damp_neighbor)
5594 {
5595 if (! ri->damp_info)
5596 continue;
5597 }
5598 if (type == bgp_show_type_regexp
5599 || type == bgp_show_type_flap_regexp)
5600 {
ajs5a646652004-11-05 01:25:55 +00005601 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005602
5603 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5604 continue;
5605 }
5606 if (type == bgp_show_type_prefix_list
5607 || type == bgp_show_type_flap_prefix_list)
5608 {
ajs5a646652004-11-05 01:25:55 +00005609 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005610
5611 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5612 continue;
5613 }
5614 if (type == bgp_show_type_filter_list
5615 || type == bgp_show_type_flap_filter_list)
5616 {
ajs5a646652004-11-05 01:25:55 +00005617 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005618
5619 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5620 continue;
5621 }
5622 if (type == bgp_show_type_route_map
5623 || type == bgp_show_type_flap_route_map)
5624 {
ajs5a646652004-11-05 01:25:55 +00005625 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005626 struct bgp_info binfo;
5627 struct attr dummy_attr;
5628 int ret;
5629
5630 dummy_attr = *ri->attr;
5631 binfo.peer = ri->peer;
5632 binfo.attr = &dummy_attr;
5633
5634 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5635
5636 if (ret == RMAP_DENYMATCH)
5637 continue;
5638 }
5639 if (type == bgp_show_type_neighbor
5640 || type == bgp_show_type_flap_neighbor
5641 || type == bgp_show_type_damp_neighbor)
5642 {
ajs5a646652004-11-05 01:25:55 +00005643 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005644
5645 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5646 continue;
5647 }
5648 if (type == bgp_show_type_cidr_only
5649 || type == bgp_show_type_flap_cidr_only)
5650 {
5651 u_int32_t destination;
5652
5653 destination = ntohl (rn->p.u.prefix4.s_addr);
5654 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5655 continue;
5656 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5657 continue;
5658 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5659 continue;
5660 }
5661 if (type == bgp_show_type_prefix_longer
5662 || type == bgp_show_type_flap_prefix_longer)
5663 {
ajs5a646652004-11-05 01:25:55 +00005664 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005665
5666 if (! prefix_match (p, &rn->p))
5667 continue;
5668 }
5669 if (type == bgp_show_type_community_all)
5670 {
5671 if (! ri->attr->community)
5672 continue;
5673 }
5674 if (type == bgp_show_type_community)
5675 {
ajs5a646652004-11-05 01:25:55 +00005676 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005677
5678 if (! ri->attr->community ||
5679 ! community_match (ri->attr->community, com))
5680 continue;
5681 }
5682 if (type == bgp_show_type_community_exact)
5683 {
ajs5a646652004-11-05 01:25:55 +00005684 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005685
5686 if (! ri->attr->community ||
5687 ! community_cmp (ri->attr->community, com))
5688 continue;
5689 }
5690 if (type == bgp_show_type_community_list)
5691 {
ajs5a646652004-11-05 01:25:55 +00005692 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005693
5694 if (! community_list_match (ri->attr->community, list))
5695 continue;
5696 }
5697 if (type == bgp_show_type_community_list_exact)
5698 {
ajs5a646652004-11-05 01:25:55 +00005699 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005700
5701 if (! community_list_exact_match (ri->attr->community, list))
5702 continue;
5703 }
5704 if (type == bgp_show_type_flap_address
5705 || type == bgp_show_type_flap_prefix)
5706 {
ajs5a646652004-11-05 01:25:55 +00005707 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005708
5709 if (! prefix_match (&rn->p, p))
5710 continue;
5711
5712 if (type == bgp_show_type_flap_prefix)
5713 if (p->prefixlen != rn->p.prefixlen)
5714 continue;
5715 }
5716 if (type == bgp_show_type_dampend_paths
5717 || type == bgp_show_type_damp_neighbor)
5718 {
5719 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5720 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5721 continue;
5722 }
5723
5724 if (header)
5725 {
hasso93406d82005-02-02 14:40:33 +00005726 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5727 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5728 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005729 if (type == bgp_show_type_dampend_paths
5730 || type == bgp_show_type_damp_neighbor)
5731 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5732 else if (type == bgp_show_type_flap_statistics
5733 || type == bgp_show_type_flap_address
5734 || type == bgp_show_type_flap_prefix
5735 || type == bgp_show_type_flap_cidr_only
5736 || type == bgp_show_type_flap_regexp
5737 || type == bgp_show_type_flap_filter_list
5738 || type == bgp_show_type_flap_prefix_list
5739 || type == bgp_show_type_flap_prefix_longer
5740 || type == bgp_show_type_flap_route_map
5741 || type == bgp_show_type_flap_neighbor)
5742 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5743 else
5744 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005745 header = 0;
5746 }
5747
5748 if (type == bgp_show_type_dampend_paths
5749 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005750 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005751 else if (type == bgp_show_type_flap_statistics
5752 || type == bgp_show_type_flap_address
5753 || type == bgp_show_type_flap_prefix
5754 || type == bgp_show_type_flap_cidr_only
5755 || type == bgp_show_type_flap_regexp
5756 || type == bgp_show_type_flap_filter_list
5757 || type == bgp_show_type_flap_prefix_list
5758 || type == bgp_show_type_flap_prefix_longer
5759 || type == bgp_show_type_flap_route_map
5760 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005761 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005762 else
ajs5a646652004-11-05 01:25:55 +00005763 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005764 display++;
5765 }
5766 if (display)
ajs5a646652004-11-05 01:25:55 +00005767 output_count++;
paul718e3742002-12-13 20:15:29 +00005768 }
5769
5770 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005771 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005772 {
5773 if (type == bgp_show_type_normal)
5774 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5775 }
5776 else
5777 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005778 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005779
5780 return CMD_SUCCESS;
5781}
5782
ajs5a646652004-11-05 01:25:55 +00005783static int
paulfee0f4c2004-09-13 05:12:46 +00005784bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005785 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005786{
5787 struct bgp_table *table;
5788
5789 if (bgp == NULL) {
5790 bgp = bgp_get_default ();
5791 }
5792
5793 if (bgp == NULL)
5794 {
5795 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5796 return CMD_WARNING;
5797 }
5798
5799
5800 table = bgp->rib[afi][safi];
5801
ajs5a646652004-11-05 01:25:55 +00005802 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005803}
5804
paul718e3742002-12-13 20:15:29 +00005805/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005806static void
paul718e3742002-12-13 20:15:29 +00005807route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5808 struct bgp_node *rn,
5809 struct prefix_rd *prd, afi_t afi, safi_t safi)
5810{
5811 struct bgp_info *ri;
5812 struct prefix *p;
5813 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005814 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005815 char buf1[INET6_ADDRSTRLEN];
5816 char buf2[INET6_ADDRSTRLEN];
5817 int count = 0;
5818 int best = 0;
5819 int suppress = 0;
5820 int no_export = 0;
5821 int no_advertise = 0;
5822 int local_as = 0;
5823 int first = 0;
5824
5825 p = &rn->p;
5826 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5827 (safi == SAFI_MPLS_VPN ?
5828 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5829 safi == SAFI_MPLS_VPN ? ":" : "",
5830 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5831 p->prefixlen, VTY_NEWLINE);
5832
5833 for (ri = rn->info; ri; ri = ri->next)
5834 {
5835 count++;
5836 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5837 {
5838 best = count;
5839 if (ri->suppress)
5840 suppress = 1;
5841 if (ri->attr->community != NULL)
5842 {
5843 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5844 no_advertise = 1;
5845 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5846 no_export = 1;
5847 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5848 local_as = 1;
5849 }
5850 }
5851 }
5852
5853 vty_out (vty, "Paths: (%d available", count);
5854 if (best)
5855 {
5856 vty_out (vty, ", best #%d", best);
5857 if (safi == SAFI_UNICAST)
5858 vty_out (vty, ", table Default-IP-Routing-Table");
5859 }
5860 else
5861 vty_out (vty, ", no best path");
5862 if (no_advertise)
5863 vty_out (vty, ", not advertised to any peer");
5864 else if (no_export)
5865 vty_out (vty, ", not advertised to EBGP peer");
5866 else if (local_as)
5867 vty_out (vty, ", not advertised outside local AS");
5868 if (suppress)
5869 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5870 vty_out (vty, ")%s", VTY_NEWLINE);
5871
5872 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005873 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005874 {
5875 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5876 {
5877 if (! first)
5878 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5879 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5880 first = 1;
5881 }
5882 }
5883 if (! first)
5884 vty_out (vty, " Not advertised to any peer");
5885 vty_out (vty, "%s", VTY_NEWLINE);
5886}
5887
5888/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005889static int
paulfee0f4c2004-09-13 05:12:46 +00005890bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005891 struct bgp_table *rib, const char *ip_str,
5892 afi_t afi, safi_t safi, struct prefix_rd *prd,
5893 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005894{
5895 int ret;
5896 int header;
5897 int display = 0;
5898 struct prefix match;
5899 struct bgp_node *rn;
5900 struct bgp_node *rm;
5901 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005902 struct bgp_table *table;
5903
paul718e3742002-12-13 20:15:29 +00005904 /* Check IP address argument. */
5905 ret = str2prefix (ip_str, &match);
5906 if (! ret)
5907 {
5908 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5909 return CMD_WARNING;
5910 }
5911
5912 match.family = afi2family (afi);
5913
5914 if (safi == SAFI_MPLS_VPN)
5915 {
paulfee0f4c2004-09-13 05:12:46 +00005916 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005917 {
5918 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5919 continue;
5920
5921 if ((table = rn->info) != NULL)
5922 {
5923 header = 1;
5924
5925 if ((rm = bgp_node_match (table, &match)) != NULL)
5926 {
5927 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5928 continue;
5929
5930 for (ri = rm->info; ri; ri = ri->next)
5931 {
5932 if (header)
5933 {
5934 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5935 AFI_IP, SAFI_MPLS_VPN);
5936
5937 header = 0;
5938 }
5939 display++;
5940 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5941 }
5942 }
5943 }
5944 }
5945 }
5946 else
5947 {
5948 header = 1;
5949
paulfee0f4c2004-09-13 05:12:46 +00005950 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005951 {
5952 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5953 {
5954 for (ri = rn->info; ri; ri = ri->next)
5955 {
5956 if (header)
5957 {
5958 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5959 header = 0;
5960 }
5961 display++;
5962 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5963 }
5964 }
5965 }
5966 }
5967
5968 if (! display)
5969 {
5970 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5971 return CMD_WARNING;
5972 }
5973
5974 return CMD_SUCCESS;
5975}
5976
paulfee0f4c2004-09-13 05:12:46 +00005977/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00005978static int
paulfd79ac92004-10-13 05:06:08 +00005979bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00005980 afi_t afi, safi_t safi, struct prefix_rd *prd,
5981 int prefix_check)
5982{
5983 struct bgp *bgp;
5984
5985 /* BGP structure lookup. */
5986 if (view_name)
5987 {
5988 bgp = bgp_lookup_by_name (view_name);
5989 if (bgp == NULL)
5990 {
5991 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
5992 return CMD_WARNING;
5993 }
5994 }
5995 else
5996 {
5997 bgp = bgp_get_default ();
5998 if (bgp == NULL)
5999 {
6000 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6001 return CMD_WARNING;
6002 }
6003 }
6004
6005 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6006 afi, safi, prd, prefix_check);
6007}
6008
paul718e3742002-12-13 20:15:29 +00006009/* BGP route print out function. */
6010DEFUN (show_ip_bgp,
6011 show_ip_bgp_cmd,
6012 "show ip bgp",
6013 SHOW_STR
6014 IP_STR
6015 BGP_STR)
6016{
ajs5a646652004-11-05 01:25:55 +00006017 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006018}
6019
6020DEFUN (show_ip_bgp_ipv4,
6021 show_ip_bgp_ipv4_cmd,
6022 "show ip bgp ipv4 (unicast|multicast)",
6023 SHOW_STR
6024 IP_STR
6025 BGP_STR
6026 "Address family\n"
6027 "Address Family modifier\n"
6028 "Address Family modifier\n")
6029{
6030 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006031 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6032 NULL);
paul718e3742002-12-13 20:15:29 +00006033
ajs5a646652004-11-05 01:25:55 +00006034 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006035}
6036
6037DEFUN (show_ip_bgp_route,
6038 show_ip_bgp_route_cmd,
6039 "show ip bgp A.B.C.D",
6040 SHOW_STR
6041 IP_STR
6042 BGP_STR
6043 "Network in the BGP routing table to display\n")
6044{
6045 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6046}
6047
6048DEFUN (show_ip_bgp_ipv4_route,
6049 show_ip_bgp_ipv4_route_cmd,
6050 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6051 SHOW_STR
6052 IP_STR
6053 BGP_STR
6054 "Address family\n"
6055 "Address Family modifier\n"
6056 "Address Family modifier\n"
6057 "Network in the BGP routing table to display\n")
6058{
6059 if (strncmp (argv[0], "m", 1) == 0)
6060 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6061
6062 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6063}
6064
6065DEFUN (show_ip_bgp_vpnv4_all_route,
6066 show_ip_bgp_vpnv4_all_route_cmd,
6067 "show ip bgp vpnv4 all A.B.C.D",
6068 SHOW_STR
6069 IP_STR
6070 BGP_STR
6071 "Display VPNv4 NLRI specific information\n"
6072 "Display information about all VPNv4 NLRIs\n"
6073 "Network in the BGP routing table to display\n")
6074{
6075 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6076}
6077
6078DEFUN (show_ip_bgp_vpnv4_rd_route,
6079 show_ip_bgp_vpnv4_rd_route_cmd,
6080 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6081 SHOW_STR
6082 IP_STR
6083 BGP_STR
6084 "Display VPNv4 NLRI specific information\n"
6085 "Display information for a route distinguisher\n"
6086 "VPN Route Distinguisher\n"
6087 "Network in the BGP routing table to display\n")
6088{
6089 int ret;
6090 struct prefix_rd prd;
6091
6092 ret = str2prefix_rd (argv[0], &prd);
6093 if (! ret)
6094 {
6095 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6096 return CMD_WARNING;
6097 }
6098 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6099}
6100
6101DEFUN (show_ip_bgp_prefix,
6102 show_ip_bgp_prefix_cmd,
6103 "show ip bgp A.B.C.D/M",
6104 SHOW_STR
6105 IP_STR
6106 BGP_STR
6107 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6108{
6109 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6110}
6111
6112DEFUN (show_ip_bgp_ipv4_prefix,
6113 show_ip_bgp_ipv4_prefix_cmd,
6114 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6115 SHOW_STR
6116 IP_STR
6117 BGP_STR
6118 "Address family\n"
6119 "Address Family modifier\n"
6120 "Address Family modifier\n"
6121 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6122{
6123 if (strncmp (argv[0], "m", 1) == 0)
6124 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6125
6126 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6127}
6128
6129DEFUN (show_ip_bgp_vpnv4_all_prefix,
6130 show_ip_bgp_vpnv4_all_prefix_cmd,
6131 "show ip bgp vpnv4 all A.B.C.D/M",
6132 SHOW_STR
6133 IP_STR
6134 BGP_STR
6135 "Display VPNv4 NLRI specific information\n"
6136 "Display information about all VPNv4 NLRIs\n"
6137 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6138{
6139 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6140}
6141
6142DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6143 show_ip_bgp_vpnv4_rd_prefix_cmd,
6144 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6145 SHOW_STR
6146 IP_STR
6147 BGP_STR
6148 "Display VPNv4 NLRI specific information\n"
6149 "Display information for a route distinguisher\n"
6150 "VPN Route Distinguisher\n"
6151 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6152{
6153 int ret;
6154 struct prefix_rd prd;
6155
6156 ret = str2prefix_rd (argv[0], &prd);
6157 if (! ret)
6158 {
6159 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6160 return CMD_WARNING;
6161 }
6162 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6163}
6164
6165DEFUN (show_ip_bgp_view,
6166 show_ip_bgp_view_cmd,
6167 "show ip bgp view WORD",
6168 SHOW_STR
6169 IP_STR
6170 BGP_STR
6171 "BGP view\n"
6172 "BGP view name\n")
6173{
paulbb46e942003-10-24 19:02:03 +00006174 struct bgp *bgp;
6175
6176 /* BGP structure lookup. */
6177 bgp = bgp_lookup_by_name (argv[0]);
6178 if (bgp == NULL)
6179 {
6180 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6181 return CMD_WARNING;
6182 }
6183
ajs5a646652004-11-05 01:25:55 +00006184 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006185}
6186
6187DEFUN (show_ip_bgp_view_route,
6188 show_ip_bgp_view_route_cmd,
6189 "show ip bgp view WORD A.B.C.D",
6190 SHOW_STR
6191 IP_STR
6192 BGP_STR
6193 "BGP view\n"
6194 "BGP view name\n"
6195 "Network in the BGP routing table to display\n")
6196{
6197 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6198}
6199
6200DEFUN (show_ip_bgp_view_prefix,
6201 show_ip_bgp_view_prefix_cmd,
6202 "show ip bgp view WORD A.B.C.D/M",
6203 SHOW_STR
6204 IP_STR
6205 BGP_STR
6206 "BGP view\n"
6207 "BGP view name\n"
6208 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6209{
6210 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6211}
6212
6213#ifdef HAVE_IPV6
6214DEFUN (show_bgp,
6215 show_bgp_cmd,
6216 "show bgp",
6217 SHOW_STR
6218 BGP_STR)
6219{
ajs5a646652004-11-05 01:25:55 +00006220 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6221 NULL);
paul718e3742002-12-13 20:15:29 +00006222}
6223
6224ALIAS (show_bgp,
6225 show_bgp_ipv6_cmd,
6226 "show bgp ipv6",
6227 SHOW_STR
6228 BGP_STR
6229 "Address family\n")
6230
6231/* old command */
6232DEFUN (show_ipv6_bgp,
6233 show_ipv6_bgp_cmd,
6234 "show ipv6 bgp",
6235 SHOW_STR
6236 IP_STR
6237 BGP_STR)
6238{
ajs5a646652004-11-05 01:25:55 +00006239 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6240 NULL);
paul718e3742002-12-13 20:15:29 +00006241}
6242
6243DEFUN (show_bgp_route,
6244 show_bgp_route_cmd,
6245 "show bgp X:X::X:X",
6246 SHOW_STR
6247 BGP_STR
6248 "Network in the BGP routing table to display\n")
6249{
6250 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6251}
6252
6253ALIAS (show_bgp_route,
6254 show_bgp_ipv6_route_cmd,
6255 "show bgp ipv6 X:X::X:X",
6256 SHOW_STR
6257 BGP_STR
6258 "Address family\n"
6259 "Network in the BGP routing table to display\n")
6260
6261/* old command */
6262DEFUN (show_ipv6_bgp_route,
6263 show_ipv6_bgp_route_cmd,
6264 "show ipv6 bgp X:X::X:X",
6265 SHOW_STR
6266 IP_STR
6267 BGP_STR
6268 "Network in the BGP routing table to display\n")
6269{
6270 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6271}
6272
6273DEFUN (show_bgp_prefix,
6274 show_bgp_prefix_cmd,
6275 "show bgp X:X::X:X/M",
6276 SHOW_STR
6277 BGP_STR
6278 "IPv6 prefix <network>/<length>\n")
6279{
6280 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6281}
6282
6283ALIAS (show_bgp_prefix,
6284 show_bgp_ipv6_prefix_cmd,
6285 "show bgp ipv6 X:X::X:X/M",
6286 SHOW_STR
6287 BGP_STR
6288 "Address family\n"
6289 "IPv6 prefix <network>/<length>\n")
6290
6291/* old command */
6292DEFUN (show_ipv6_bgp_prefix,
6293 show_ipv6_bgp_prefix_cmd,
6294 "show ipv6 bgp X:X::X:X/M",
6295 SHOW_STR
6296 IP_STR
6297 BGP_STR
6298 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6299{
6300 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6301}
6302
paulbb46e942003-10-24 19:02:03 +00006303DEFUN (show_bgp_view,
6304 show_bgp_view_cmd,
6305 "show bgp view WORD",
6306 SHOW_STR
6307 BGP_STR
6308 "BGP view\n"
6309 "View name\n")
6310{
6311 struct bgp *bgp;
6312
6313 /* BGP structure lookup. */
6314 bgp = bgp_lookup_by_name (argv[0]);
6315 if (bgp == NULL)
6316 {
6317 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6318 return CMD_WARNING;
6319 }
6320
ajs5a646652004-11-05 01:25:55 +00006321 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006322}
6323
6324ALIAS (show_bgp_view,
6325 show_bgp_view_ipv6_cmd,
6326 "show bgp view WORD ipv6",
6327 SHOW_STR
6328 BGP_STR
6329 "BGP view\n"
6330 "View name\n"
6331 "Address family\n")
6332
6333DEFUN (show_bgp_view_route,
6334 show_bgp_view_route_cmd,
6335 "show bgp view WORD X:X::X:X",
6336 SHOW_STR
6337 BGP_STR
6338 "BGP view\n"
6339 "View name\n"
6340 "Network in the BGP routing table to display\n")
6341{
6342 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6343}
6344
6345ALIAS (show_bgp_view_route,
6346 show_bgp_view_ipv6_route_cmd,
6347 "show bgp view WORD ipv6 X:X::X:X",
6348 SHOW_STR
6349 BGP_STR
6350 "BGP view\n"
6351 "View name\n"
6352 "Address family\n"
6353 "Network in the BGP routing table to display\n")
6354
6355DEFUN (show_bgp_view_prefix,
6356 show_bgp_view_prefix_cmd,
6357 "show bgp view WORD X:X::X:X/M",
6358 SHOW_STR
6359 BGP_STR
6360 "BGP view\n"
6361 "View name\n"
6362 "IPv6 prefix <network>/<length>\n")
6363{
6364 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6365}
6366
6367ALIAS (show_bgp_view_prefix,
6368 show_bgp_view_ipv6_prefix_cmd,
6369 "show bgp view WORD ipv6 X:X::X:X/M",
6370 SHOW_STR
6371 BGP_STR
6372 "BGP view\n"
6373 "View name\n"
6374 "Address family\n"
6375 "IPv6 prefix <network>/<length>\n")
6376
paul718e3742002-12-13 20:15:29 +00006377/* old command */
6378DEFUN (show_ipv6_mbgp,
6379 show_ipv6_mbgp_cmd,
6380 "show ipv6 mbgp",
6381 SHOW_STR
6382 IP_STR
6383 MBGP_STR)
6384{
ajs5a646652004-11-05 01:25:55 +00006385 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6386 NULL);
paul718e3742002-12-13 20:15:29 +00006387}
6388
6389/* old command */
6390DEFUN (show_ipv6_mbgp_route,
6391 show_ipv6_mbgp_route_cmd,
6392 "show ipv6 mbgp X:X::X:X",
6393 SHOW_STR
6394 IP_STR
6395 MBGP_STR
6396 "Network in the MBGP routing table to display\n")
6397{
6398 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6399}
6400
6401/* old command */
6402DEFUN (show_ipv6_mbgp_prefix,
6403 show_ipv6_mbgp_prefix_cmd,
6404 "show ipv6 mbgp X:X::X:X/M",
6405 SHOW_STR
6406 IP_STR
6407 MBGP_STR
6408 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6409{
6410 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6411}
6412#endif
6413
paul718e3742002-12-13 20:15:29 +00006414
paul94f2b392005-06-28 12:44:16 +00006415static int
paulfd79ac92004-10-13 05:06:08 +00006416bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006417 safi_t safi, enum bgp_show_type type)
6418{
6419 int i;
6420 struct buffer *b;
6421 char *regstr;
6422 int first;
6423 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006424 int rc;
paul718e3742002-12-13 20:15:29 +00006425
6426 first = 0;
6427 b = buffer_new (1024);
6428 for (i = 0; i < argc; i++)
6429 {
6430 if (first)
6431 buffer_putc (b, ' ');
6432 else
6433 {
6434 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6435 continue;
6436 first = 1;
6437 }
6438
6439 buffer_putstr (b, argv[i]);
6440 }
6441 buffer_putc (b, '\0');
6442
6443 regstr = buffer_getstr (b);
6444 buffer_free (b);
6445
6446 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006447 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006448 if (! regex)
6449 {
6450 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6451 VTY_NEWLINE);
6452 return CMD_WARNING;
6453 }
6454
ajs5a646652004-11-05 01:25:55 +00006455 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6456 bgp_regex_free (regex);
6457 return rc;
paul718e3742002-12-13 20:15:29 +00006458}
6459
6460DEFUN (show_ip_bgp_regexp,
6461 show_ip_bgp_regexp_cmd,
6462 "show ip bgp regexp .LINE",
6463 SHOW_STR
6464 IP_STR
6465 BGP_STR
6466 "Display routes matching the AS path regular expression\n"
6467 "A regular-expression to match the BGP AS paths\n")
6468{
6469 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6470 bgp_show_type_regexp);
6471}
6472
6473DEFUN (show_ip_bgp_flap_regexp,
6474 show_ip_bgp_flap_regexp_cmd,
6475 "show ip bgp flap-statistics regexp .LINE",
6476 SHOW_STR
6477 IP_STR
6478 BGP_STR
6479 "Display flap statistics of routes\n"
6480 "Display routes matching the AS path regular expression\n"
6481 "A regular-expression to match the BGP AS paths\n")
6482{
6483 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6484 bgp_show_type_flap_regexp);
6485}
6486
6487DEFUN (show_ip_bgp_ipv4_regexp,
6488 show_ip_bgp_ipv4_regexp_cmd,
6489 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6490 SHOW_STR
6491 IP_STR
6492 BGP_STR
6493 "Address family\n"
6494 "Address Family modifier\n"
6495 "Address Family modifier\n"
6496 "Display routes matching the AS path regular expression\n"
6497 "A regular-expression to match the BGP AS paths\n")
6498{
6499 if (strncmp (argv[0], "m", 1) == 0)
6500 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6501 bgp_show_type_regexp);
6502
6503 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6504 bgp_show_type_regexp);
6505}
6506
6507#ifdef HAVE_IPV6
6508DEFUN (show_bgp_regexp,
6509 show_bgp_regexp_cmd,
6510 "show bgp regexp .LINE",
6511 SHOW_STR
6512 BGP_STR
6513 "Display routes matching the AS path regular expression\n"
6514 "A regular-expression to match the BGP AS paths\n")
6515{
6516 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6517 bgp_show_type_regexp);
6518}
6519
6520ALIAS (show_bgp_regexp,
6521 show_bgp_ipv6_regexp_cmd,
6522 "show bgp ipv6 regexp .LINE",
6523 SHOW_STR
6524 BGP_STR
6525 "Address family\n"
6526 "Display routes matching the AS path regular expression\n"
6527 "A regular-expression to match the BGP AS paths\n")
6528
6529/* old command */
6530DEFUN (show_ipv6_bgp_regexp,
6531 show_ipv6_bgp_regexp_cmd,
6532 "show ipv6 bgp regexp .LINE",
6533 SHOW_STR
6534 IP_STR
6535 BGP_STR
6536 "Display routes matching the AS path regular expression\n"
6537 "A regular-expression to match the BGP AS paths\n")
6538{
6539 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6540 bgp_show_type_regexp);
6541}
6542
6543/* old command */
6544DEFUN (show_ipv6_mbgp_regexp,
6545 show_ipv6_mbgp_regexp_cmd,
6546 "show ipv6 mbgp regexp .LINE",
6547 SHOW_STR
6548 IP_STR
6549 BGP_STR
6550 "Display routes matching the AS path regular expression\n"
6551 "A regular-expression to match the MBGP AS paths\n")
6552{
6553 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6554 bgp_show_type_regexp);
6555}
6556#endif /* HAVE_IPV6 */
6557
paul94f2b392005-06-28 12:44:16 +00006558static int
paulfd79ac92004-10-13 05:06:08 +00006559bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006560 safi_t safi, enum bgp_show_type type)
6561{
6562 struct prefix_list *plist;
6563
6564 plist = prefix_list_lookup (afi, prefix_list_str);
6565 if (plist == NULL)
6566 {
6567 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6568 prefix_list_str, VTY_NEWLINE);
6569 return CMD_WARNING;
6570 }
6571
ajs5a646652004-11-05 01:25:55 +00006572 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006573}
6574
6575DEFUN (show_ip_bgp_prefix_list,
6576 show_ip_bgp_prefix_list_cmd,
6577 "show ip bgp prefix-list WORD",
6578 SHOW_STR
6579 IP_STR
6580 BGP_STR
6581 "Display routes conforming to the prefix-list\n"
6582 "IP prefix-list name\n")
6583{
6584 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6585 bgp_show_type_prefix_list);
6586}
6587
6588DEFUN (show_ip_bgp_flap_prefix_list,
6589 show_ip_bgp_flap_prefix_list_cmd,
6590 "show ip bgp flap-statistics prefix-list WORD",
6591 SHOW_STR
6592 IP_STR
6593 BGP_STR
6594 "Display flap statistics of routes\n"
6595 "Display routes conforming to the prefix-list\n"
6596 "IP prefix-list name\n")
6597{
6598 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6599 bgp_show_type_flap_prefix_list);
6600}
6601
6602DEFUN (show_ip_bgp_ipv4_prefix_list,
6603 show_ip_bgp_ipv4_prefix_list_cmd,
6604 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6605 SHOW_STR
6606 IP_STR
6607 BGP_STR
6608 "Address family\n"
6609 "Address Family modifier\n"
6610 "Address Family modifier\n"
6611 "Display routes conforming to the prefix-list\n"
6612 "IP prefix-list name\n")
6613{
6614 if (strncmp (argv[0], "m", 1) == 0)
6615 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6616 bgp_show_type_prefix_list);
6617
6618 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6619 bgp_show_type_prefix_list);
6620}
6621
6622#ifdef HAVE_IPV6
6623DEFUN (show_bgp_prefix_list,
6624 show_bgp_prefix_list_cmd,
6625 "show bgp prefix-list WORD",
6626 SHOW_STR
6627 BGP_STR
6628 "Display routes conforming to the prefix-list\n"
6629 "IPv6 prefix-list name\n")
6630{
6631 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6632 bgp_show_type_prefix_list);
6633}
6634
6635ALIAS (show_bgp_prefix_list,
6636 show_bgp_ipv6_prefix_list_cmd,
6637 "show bgp ipv6 prefix-list WORD",
6638 SHOW_STR
6639 BGP_STR
6640 "Address family\n"
6641 "Display routes conforming to the prefix-list\n"
6642 "IPv6 prefix-list name\n")
6643
6644/* old command */
6645DEFUN (show_ipv6_bgp_prefix_list,
6646 show_ipv6_bgp_prefix_list_cmd,
6647 "show ipv6 bgp prefix-list WORD",
6648 SHOW_STR
6649 IPV6_STR
6650 BGP_STR
6651 "Display routes matching the prefix-list\n"
6652 "IPv6 prefix-list name\n")
6653{
6654 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6655 bgp_show_type_prefix_list);
6656}
6657
6658/* old command */
6659DEFUN (show_ipv6_mbgp_prefix_list,
6660 show_ipv6_mbgp_prefix_list_cmd,
6661 "show ipv6 mbgp prefix-list WORD",
6662 SHOW_STR
6663 IPV6_STR
6664 MBGP_STR
6665 "Display routes matching the prefix-list\n"
6666 "IPv6 prefix-list name\n")
6667{
6668 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6669 bgp_show_type_prefix_list);
6670}
6671#endif /* HAVE_IPV6 */
6672
paul94f2b392005-06-28 12:44:16 +00006673static int
paulfd79ac92004-10-13 05:06:08 +00006674bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006675 safi_t safi, enum bgp_show_type type)
6676{
6677 struct as_list *as_list;
6678
6679 as_list = as_list_lookup (filter);
6680 if (as_list == NULL)
6681 {
6682 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6683 return CMD_WARNING;
6684 }
6685
ajs5a646652004-11-05 01:25:55 +00006686 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006687}
6688
6689DEFUN (show_ip_bgp_filter_list,
6690 show_ip_bgp_filter_list_cmd,
6691 "show ip bgp filter-list WORD",
6692 SHOW_STR
6693 IP_STR
6694 BGP_STR
6695 "Display routes conforming to the filter-list\n"
6696 "Regular expression access list name\n")
6697{
6698 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6699 bgp_show_type_filter_list);
6700}
6701
6702DEFUN (show_ip_bgp_flap_filter_list,
6703 show_ip_bgp_flap_filter_list_cmd,
6704 "show ip bgp flap-statistics filter-list WORD",
6705 SHOW_STR
6706 IP_STR
6707 BGP_STR
6708 "Display flap statistics of routes\n"
6709 "Display routes conforming to the filter-list\n"
6710 "Regular expression access list name\n")
6711{
6712 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6713 bgp_show_type_flap_filter_list);
6714}
6715
6716DEFUN (show_ip_bgp_ipv4_filter_list,
6717 show_ip_bgp_ipv4_filter_list_cmd,
6718 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6719 SHOW_STR
6720 IP_STR
6721 BGP_STR
6722 "Address family\n"
6723 "Address Family modifier\n"
6724 "Address Family modifier\n"
6725 "Display routes conforming to the filter-list\n"
6726 "Regular expression access list name\n")
6727{
6728 if (strncmp (argv[0], "m", 1) == 0)
6729 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6730 bgp_show_type_filter_list);
6731
6732 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6733 bgp_show_type_filter_list);
6734}
6735
6736#ifdef HAVE_IPV6
6737DEFUN (show_bgp_filter_list,
6738 show_bgp_filter_list_cmd,
6739 "show bgp filter-list WORD",
6740 SHOW_STR
6741 BGP_STR
6742 "Display routes conforming to the filter-list\n"
6743 "Regular expression access list name\n")
6744{
6745 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6746 bgp_show_type_filter_list);
6747}
6748
6749ALIAS (show_bgp_filter_list,
6750 show_bgp_ipv6_filter_list_cmd,
6751 "show bgp ipv6 filter-list WORD",
6752 SHOW_STR
6753 BGP_STR
6754 "Address family\n"
6755 "Display routes conforming to the filter-list\n"
6756 "Regular expression access list name\n")
6757
6758/* old command */
6759DEFUN (show_ipv6_bgp_filter_list,
6760 show_ipv6_bgp_filter_list_cmd,
6761 "show ipv6 bgp filter-list WORD",
6762 SHOW_STR
6763 IPV6_STR
6764 BGP_STR
6765 "Display routes conforming to the filter-list\n"
6766 "Regular expression access list name\n")
6767{
6768 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6769 bgp_show_type_filter_list);
6770}
6771
6772/* old command */
6773DEFUN (show_ipv6_mbgp_filter_list,
6774 show_ipv6_mbgp_filter_list_cmd,
6775 "show ipv6 mbgp filter-list WORD",
6776 SHOW_STR
6777 IPV6_STR
6778 MBGP_STR
6779 "Display routes conforming to the filter-list\n"
6780 "Regular expression access list name\n")
6781{
6782 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6783 bgp_show_type_filter_list);
6784}
6785#endif /* HAVE_IPV6 */
6786
paul94f2b392005-06-28 12:44:16 +00006787static int
paulfd79ac92004-10-13 05:06:08 +00006788bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006789 safi_t safi, enum bgp_show_type type)
6790{
6791 struct route_map *rmap;
6792
6793 rmap = route_map_lookup_by_name (rmap_str);
6794 if (! rmap)
6795 {
6796 vty_out (vty, "%% %s is not a valid route-map name%s",
6797 rmap_str, VTY_NEWLINE);
6798 return CMD_WARNING;
6799 }
6800
ajs5a646652004-11-05 01:25:55 +00006801 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006802}
6803
6804DEFUN (show_ip_bgp_route_map,
6805 show_ip_bgp_route_map_cmd,
6806 "show ip bgp route-map WORD",
6807 SHOW_STR
6808 IP_STR
6809 BGP_STR
6810 "Display routes matching the route-map\n"
6811 "A route-map to match on\n")
6812{
6813 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6814 bgp_show_type_route_map);
6815}
6816
6817DEFUN (show_ip_bgp_flap_route_map,
6818 show_ip_bgp_flap_route_map_cmd,
6819 "show ip bgp flap-statistics route-map WORD",
6820 SHOW_STR
6821 IP_STR
6822 BGP_STR
6823 "Display flap statistics of routes\n"
6824 "Display routes matching the route-map\n"
6825 "A route-map to match on\n")
6826{
6827 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6828 bgp_show_type_flap_route_map);
6829}
6830
6831DEFUN (show_ip_bgp_ipv4_route_map,
6832 show_ip_bgp_ipv4_route_map_cmd,
6833 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6834 SHOW_STR
6835 IP_STR
6836 BGP_STR
6837 "Address family\n"
6838 "Address Family modifier\n"
6839 "Address Family modifier\n"
6840 "Display routes matching the route-map\n"
6841 "A route-map to match on\n")
6842{
6843 if (strncmp (argv[0], "m", 1) == 0)
6844 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6845 bgp_show_type_route_map);
6846
6847 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6848 bgp_show_type_route_map);
6849}
6850
6851DEFUN (show_bgp_route_map,
6852 show_bgp_route_map_cmd,
6853 "show bgp route-map WORD",
6854 SHOW_STR
6855 BGP_STR
6856 "Display routes matching the route-map\n"
6857 "A route-map to match on\n")
6858{
6859 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6860 bgp_show_type_route_map);
6861}
6862
6863ALIAS (show_bgp_route_map,
6864 show_bgp_ipv6_route_map_cmd,
6865 "show bgp ipv6 route-map WORD",
6866 SHOW_STR
6867 BGP_STR
6868 "Address family\n"
6869 "Display routes matching the route-map\n"
6870 "A route-map to match on\n")
6871
6872DEFUN (show_ip_bgp_cidr_only,
6873 show_ip_bgp_cidr_only_cmd,
6874 "show ip bgp cidr-only",
6875 SHOW_STR
6876 IP_STR
6877 BGP_STR
6878 "Display only routes with non-natural netmasks\n")
6879{
6880 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006881 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006882}
6883
6884DEFUN (show_ip_bgp_flap_cidr_only,
6885 show_ip_bgp_flap_cidr_only_cmd,
6886 "show ip bgp flap-statistics cidr-only",
6887 SHOW_STR
6888 IP_STR
6889 BGP_STR
6890 "Display flap statistics of routes\n"
6891 "Display only routes with non-natural netmasks\n")
6892{
6893 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006894 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006895}
6896
6897DEFUN (show_ip_bgp_ipv4_cidr_only,
6898 show_ip_bgp_ipv4_cidr_only_cmd,
6899 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6900 SHOW_STR
6901 IP_STR
6902 BGP_STR
6903 "Address family\n"
6904 "Address Family modifier\n"
6905 "Address Family modifier\n"
6906 "Display only routes with non-natural netmasks\n")
6907{
6908 if (strncmp (argv[0], "m", 1) == 0)
6909 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006910 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006911
6912 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006913 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006914}
6915
6916DEFUN (show_ip_bgp_community_all,
6917 show_ip_bgp_community_all_cmd,
6918 "show ip bgp community",
6919 SHOW_STR
6920 IP_STR
6921 BGP_STR
6922 "Display routes matching the communities\n")
6923{
6924 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006925 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006926}
6927
6928DEFUN (show_ip_bgp_ipv4_community_all,
6929 show_ip_bgp_ipv4_community_all_cmd,
6930 "show ip bgp ipv4 (unicast|multicast) community",
6931 SHOW_STR
6932 IP_STR
6933 BGP_STR
6934 "Address family\n"
6935 "Address Family modifier\n"
6936 "Address Family modifier\n"
6937 "Display routes matching the communities\n")
6938{
6939 if (strncmp (argv[0], "m", 1) == 0)
6940 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006941 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006942
6943 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006944 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006945}
6946
6947#ifdef HAVE_IPV6
6948DEFUN (show_bgp_community_all,
6949 show_bgp_community_all_cmd,
6950 "show bgp community",
6951 SHOW_STR
6952 BGP_STR
6953 "Display routes matching the communities\n")
6954{
6955 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006956 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006957}
6958
6959ALIAS (show_bgp_community_all,
6960 show_bgp_ipv6_community_all_cmd,
6961 "show bgp ipv6 community",
6962 SHOW_STR
6963 BGP_STR
6964 "Address family\n"
6965 "Display routes matching the communities\n")
6966
6967/* old command */
6968DEFUN (show_ipv6_bgp_community_all,
6969 show_ipv6_bgp_community_all_cmd,
6970 "show ipv6 bgp community",
6971 SHOW_STR
6972 IPV6_STR
6973 BGP_STR
6974 "Display routes matching the communities\n")
6975{
6976 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006977 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006978}
6979
6980/* old command */
6981DEFUN (show_ipv6_mbgp_community_all,
6982 show_ipv6_mbgp_community_all_cmd,
6983 "show ipv6 mbgp community",
6984 SHOW_STR
6985 IPV6_STR
6986 MBGP_STR
6987 "Display routes matching the communities\n")
6988{
6989 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006990 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006991}
6992#endif /* HAVE_IPV6 */
6993
paul94f2b392005-06-28 12:44:16 +00006994static int
paulfd79ac92004-10-13 05:06:08 +00006995bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
6996 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00006997{
6998 struct community *com;
6999 struct buffer *b;
7000 int i;
7001 char *str;
7002 int first = 0;
7003
7004 b = buffer_new (1024);
7005 for (i = 0; i < argc; i++)
7006 {
7007 if (first)
7008 buffer_putc (b, ' ');
7009 else
7010 {
7011 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7012 continue;
7013 first = 1;
7014 }
7015
7016 buffer_putstr (b, argv[i]);
7017 }
7018 buffer_putc (b, '\0');
7019
7020 str = buffer_getstr (b);
7021 buffer_free (b);
7022
7023 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007024 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007025 if (! com)
7026 {
7027 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7028 return CMD_WARNING;
7029 }
7030
ajs5a646652004-11-05 01:25:55 +00007031 return bgp_show (vty, NULL, afi, safi,
7032 (exact ? bgp_show_type_community_exact :
7033 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007034}
7035
7036DEFUN (show_ip_bgp_community,
7037 show_ip_bgp_community_cmd,
7038 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7039 SHOW_STR
7040 IP_STR
7041 BGP_STR
7042 "Display routes matching the communities\n"
7043 "community number\n"
7044 "Do not send outside local AS (well-known community)\n"
7045 "Do not advertise to any peer (well-known community)\n"
7046 "Do not export to next AS (well-known community)\n")
7047{
7048 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7049}
7050
7051ALIAS (show_ip_bgp_community,
7052 show_ip_bgp_community2_cmd,
7053 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7054 SHOW_STR
7055 IP_STR
7056 BGP_STR
7057 "Display routes matching the communities\n"
7058 "community number\n"
7059 "Do not send outside local AS (well-known community)\n"
7060 "Do not advertise to any peer (well-known community)\n"
7061 "Do not export to next AS (well-known community)\n"
7062 "community number\n"
7063 "Do not send outside local AS (well-known community)\n"
7064 "Do not advertise to any peer (well-known community)\n"
7065 "Do not export to next AS (well-known community)\n")
7066
7067ALIAS (show_ip_bgp_community,
7068 show_ip_bgp_community3_cmd,
7069 "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)",
7070 SHOW_STR
7071 IP_STR
7072 BGP_STR
7073 "Display routes matching the communities\n"
7074 "community number\n"
7075 "Do not send outside local AS (well-known community)\n"
7076 "Do not advertise to any peer (well-known community)\n"
7077 "Do not export to next AS (well-known community)\n"
7078 "community number\n"
7079 "Do not send outside local AS (well-known community)\n"
7080 "Do not advertise to any peer (well-known community)\n"
7081 "Do not export to next AS (well-known community)\n"
7082 "community number\n"
7083 "Do not send outside local AS (well-known community)\n"
7084 "Do not advertise to any peer (well-known community)\n"
7085 "Do not export to next AS (well-known community)\n")
7086
7087ALIAS (show_ip_bgp_community,
7088 show_ip_bgp_community4_cmd,
7089 "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)",
7090 SHOW_STR
7091 IP_STR
7092 BGP_STR
7093 "Display routes matching the communities\n"
7094 "community number\n"
7095 "Do not send outside local AS (well-known community)\n"
7096 "Do not advertise to any peer (well-known community)\n"
7097 "Do not export to next AS (well-known community)\n"
7098 "community number\n"
7099 "Do not send outside local AS (well-known community)\n"
7100 "Do not advertise to any peer (well-known community)\n"
7101 "Do not export to next AS (well-known community)\n"
7102 "community number\n"
7103 "Do not send outside local AS (well-known community)\n"
7104 "Do not advertise to any peer (well-known community)\n"
7105 "Do not export to next AS (well-known community)\n"
7106 "community number\n"
7107 "Do not send outside local AS (well-known community)\n"
7108 "Do not advertise to any peer (well-known community)\n"
7109 "Do not export to next AS (well-known community)\n")
7110
7111DEFUN (show_ip_bgp_ipv4_community,
7112 show_ip_bgp_ipv4_community_cmd,
7113 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7114 SHOW_STR
7115 IP_STR
7116 BGP_STR
7117 "Address family\n"
7118 "Address Family modifier\n"
7119 "Address Family modifier\n"
7120 "Display routes matching the communities\n"
7121 "community number\n"
7122 "Do not send outside local AS (well-known community)\n"
7123 "Do not advertise to any peer (well-known community)\n"
7124 "Do not export to next AS (well-known community)\n")
7125{
7126 if (strncmp (argv[0], "m", 1) == 0)
7127 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7128
7129 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7130}
7131
7132ALIAS (show_ip_bgp_ipv4_community,
7133 show_ip_bgp_ipv4_community2_cmd,
7134 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7135 SHOW_STR
7136 IP_STR
7137 BGP_STR
7138 "Address family\n"
7139 "Address Family modifier\n"
7140 "Address Family modifier\n"
7141 "Display routes matching the communities\n"
7142 "community number\n"
7143 "Do not send outside local AS (well-known community)\n"
7144 "Do not advertise to any peer (well-known community)\n"
7145 "Do not export to next AS (well-known community)\n"
7146 "community number\n"
7147 "Do not send outside local AS (well-known community)\n"
7148 "Do not advertise to any peer (well-known community)\n"
7149 "Do not export to next AS (well-known community)\n")
7150
7151ALIAS (show_ip_bgp_ipv4_community,
7152 show_ip_bgp_ipv4_community3_cmd,
7153 "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)",
7154 SHOW_STR
7155 IP_STR
7156 BGP_STR
7157 "Address family\n"
7158 "Address Family modifier\n"
7159 "Address Family modifier\n"
7160 "Display routes matching the communities\n"
7161 "community number\n"
7162 "Do not send outside local AS (well-known community)\n"
7163 "Do not advertise to any peer (well-known community)\n"
7164 "Do not export to next AS (well-known community)\n"
7165 "community number\n"
7166 "Do not send outside local AS (well-known community)\n"
7167 "Do not advertise to any peer (well-known community)\n"
7168 "Do not export to next AS (well-known community)\n"
7169 "community number\n"
7170 "Do not send outside local AS (well-known community)\n"
7171 "Do not advertise to any peer (well-known community)\n"
7172 "Do not export to next AS (well-known community)\n")
7173
7174ALIAS (show_ip_bgp_ipv4_community,
7175 show_ip_bgp_ipv4_community4_cmd,
7176 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7177 SHOW_STR
7178 IP_STR
7179 BGP_STR
7180 "Address family\n"
7181 "Address Family modifier\n"
7182 "Address Family modifier\n"
7183 "Display routes matching the communities\n"
7184 "community number\n"
7185 "Do not send outside local AS (well-known community)\n"
7186 "Do not advertise to any peer (well-known community)\n"
7187 "Do not export to next AS (well-known community)\n"
7188 "community number\n"
7189 "Do not send outside local AS (well-known community)\n"
7190 "Do not advertise to any peer (well-known community)\n"
7191 "Do not export to next AS (well-known community)\n"
7192 "community number\n"
7193 "Do not send outside local AS (well-known community)\n"
7194 "Do not advertise to any peer (well-known community)\n"
7195 "Do not export to next AS (well-known community)\n"
7196 "community number\n"
7197 "Do not send outside local AS (well-known community)\n"
7198 "Do not advertise to any peer (well-known community)\n"
7199 "Do not export to next AS (well-known community)\n")
7200
7201DEFUN (show_ip_bgp_community_exact,
7202 show_ip_bgp_community_exact_cmd,
7203 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7204 SHOW_STR
7205 IP_STR
7206 BGP_STR
7207 "Display routes matching the communities\n"
7208 "community number\n"
7209 "Do not send outside local AS (well-known community)\n"
7210 "Do not advertise to any peer (well-known community)\n"
7211 "Do not export to next AS (well-known community)\n"
7212 "Exact match of the communities")
7213{
7214 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7215}
7216
7217ALIAS (show_ip_bgp_community_exact,
7218 show_ip_bgp_community2_exact_cmd,
7219 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7220 SHOW_STR
7221 IP_STR
7222 BGP_STR
7223 "Display routes matching the communities\n"
7224 "community number\n"
7225 "Do not send outside local AS (well-known community)\n"
7226 "Do not advertise to any peer (well-known community)\n"
7227 "Do not export to next AS (well-known community)\n"
7228 "community number\n"
7229 "Do not send outside local AS (well-known community)\n"
7230 "Do not advertise to any peer (well-known community)\n"
7231 "Do not export to next AS (well-known community)\n"
7232 "Exact match of the communities")
7233
7234ALIAS (show_ip_bgp_community_exact,
7235 show_ip_bgp_community3_exact_cmd,
7236 "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",
7237 SHOW_STR
7238 IP_STR
7239 BGP_STR
7240 "Display routes matching the communities\n"
7241 "community number\n"
7242 "Do not send outside local AS (well-known community)\n"
7243 "Do not advertise to any peer (well-known community)\n"
7244 "Do not export to next AS (well-known community)\n"
7245 "community number\n"
7246 "Do not send outside local AS (well-known community)\n"
7247 "Do not advertise to any peer (well-known community)\n"
7248 "Do not export to next AS (well-known community)\n"
7249 "community number\n"
7250 "Do not send outside local AS (well-known community)\n"
7251 "Do not advertise to any peer (well-known community)\n"
7252 "Do not export to next AS (well-known community)\n"
7253 "Exact match of the communities")
7254
7255ALIAS (show_ip_bgp_community_exact,
7256 show_ip_bgp_community4_exact_cmd,
7257 "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",
7258 SHOW_STR
7259 IP_STR
7260 BGP_STR
7261 "Display routes matching the communities\n"
7262 "community number\n"
7263 "Do not send outside local AS (well-known community)\n"
7264 "Do not advertise to any peer (well-known community)\n"
7265 "Do not export to next AS (well-known community)\n"
7266 "community number\n"
7267 "Do not send outside local AS (well-known community)\n"
7268 "Do not advertise to any peer (well-known community)\n"
7269 "Do not export to next AS (well-known community)\n"
7270 "community number\n"
7271 "Do not send outside local AS (well-known community)\n"
7272 "Do not advertise to any peer (well-known community)\n"
7273 "Do not export to next AS (well-known community)\n"
7274 "community number\n"
7275 "Do not send outside local AS (well-known community)\n"
7276 "Do not advertise to any peer (well-known community)\n"
7277 "Do not export to next AS (well-known community)\n"
7278 "Exact match of the communities")
7279
7280DEFUN (show_ip_bgp_ipv4_community_exact,
7281 show_ip_bgp_ipv4_community_exact_cmd,
7282 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7283 SHOW_STR
7284 IP_STR
7285 BGP_STR
7286 "Address family\n"
7287 "Address Family modifier\n"
7288 "Address Family modifier\n"
7289 "Display routes matching the communities\n"
7290 "community number\n"
7291 "Do not send outside local AS (well-known community)\n"
7292 "Do not advertise to any peer (well-known community)\n"
7293 "Do not export to next AS (well-known community)\n"
7294 "Exact match of the communities")
7295{
7296 if (strncmp (argv[0], "m", 1) == 0)
7297 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7298
7299 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7300}
7301
7302ALIAS (show_ip_bgp_ipv4_community_exact,
7303 show_ip_bgp_ipv4_community2_exact_cmd,
7304 "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",
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 "community number\n"
7317 "Do not send outside local AS (well-known community)\n"
7318 "Do not advertise to any peer (well-known community)\n"
7319 "Do not export to next AS (well-known community)\n"
7320 "Exact match of the communities")
7321
7322ALIAS (show_ip_bgp_ipv4_community_exact,
7323 show_ip_bgp_ipv4_community3_exact_cmd,
7324 "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",
7325 SHOW_STR
7326 IP_STR
7327 BGP_STR
7328 "Address family\n"
7329 "Address Family modifier\n"
7330 "Address Family modifier\n"
7331 "Display routes matching the communities\n"
7332 "community number\n"
7333 "Do not send outside local AS (well-known community)\n"
7334 "Do not advertise to any peer (well-known community)\n"
7335 "Do not export to next AS (well-known community)\n"
7336 "community number\n"
7337 "Do not send outside local AS (well-known community)\n"
7338 "Do not advertise to any peer (well-known community)\n"
7339 "Do not export to next AS (well-known community)\n"
7340 "community number\n"
7341 "Do not send outside local AS (well-known community)\n"
7342 "Do not advertise to any peer (well-known community)\n"
7343 "Do not export to next AS (well-known community)\n"
7344 "Exact match of the communities")
7345
7346ALIAS (show_ip_bgp_ipv4_community_exact,
7347 show_ip_bgp_ipv4_community4_exact_cmd,
7348 "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",
7349 SHOW_STR
7350 IP_STR
7351 BGP_STR
7352 "Address family\n"
7353 "Address Family modifier\n"
7354 "Address Family modifier\n"
7355 "Display routes matching the communities\n"
7356 "community number\n"
7357 "Do not send outside local AS (well-known community)\n"
7358 "Do not advertise to any peer (well-known community)\n"
7359 "Do not export to next AS (well-known community)\n"
7360 "community number\n"
7361 "Do not send outside local AS (well-known community)\n"
7362 "Do not advertise to any peer (well-known community)\n"
7363 "Do not export to next AS (well-known community)\n"
7364 "community number\n"
7365 "Do not send outside local AS (well-known community)\n"
7366 "Do not advertise to any peer (well-known community)\n"
7367 "Do not export to next AS (well-known community)\n"
7368 "community number\n"
7369 "Do not send outside local AS (well-known community)\n"
7370 "Do not advertise to any peer (well-known community)\n"
7371 "Do not export to next AS (well-known community)\n"
7372 "Exact match of the communities")
7373
7374#ifdef HAVE_IPV6
7375DEFUN (show_bgp_community,
7376 show_bgp_community_cmd,
7377 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7378 SHOW_STR
7379 BGP_STR
7380 "Display routes matching the communities\n"
7381 "community number\n"
7382 "Do not send outside local AS (well-known community)\n"
7383 "Do not advertise to any peer (well-known community)\n"
7384 "Do not export to next AS (well-known community)\n")
7385{
7386 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7387}
7388
7389ALIAS (show_bgp_community,
7390 show_bgp_ipv6_community_cmd,
7391 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7392 SHOW_STR
7393 BGP_STR
7394 "Address family\n"
7395 "Display routes matching the communities\n"
7396 "community number\n"
7397 "Do not send outside local AS (well-known community)\n"
7398 "Do not advertise to any peer (well-known community)\n"
7399 "Do not export to next AS (well-known community)\n")
7400
7401ALIAS (show_bgp_community,
7402 show_bgp_community2_cmd,
7403 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7404 SHOW_STR
7405 BGP_STR
7406 "Display routes matching the communities\n"
7407 "community number\n"
7408 "Do not send outside local AS (well-known community)\n"
7409 "Do not advertise to any peer (well-known community)\n"
7410 "Do not export to next AS (well-known community)\n"
7411 "community number\n"
7412 "Do not send outside local AS (well-known community)\n"
7413 "Do not advertise to any peer (well-known community)\n"
7414 "Do not export to next AS (well-known community)\n")
7415
7416ALIAS (show_bgp_community,
7417 show_bgp_ipv6_community2_cmd,
7418 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7419 SHOW_STR
7420 BGP_STR
7421 "Address family\n"
7422 "Display routes matching the communities\n"
7423 "community number\n"
7424 "Do not send outside local AS (well-known community)\n"
7425 "Do not advertise to any peer (well-known community)\n"
7426 "Do not export to next AS (well-known community)\n"
7427 "community number\n"
7428 "Do not send outside local AS (well-known community)\n"
7429 "Do not advertise to any peer (well-known community)\n"
7430 "Do not export to next AS (well-known community)\n")
7431
7432ALIAS (show_bgp_community,
7433 show_bgp_community3_cmd,
7434 "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)",
7435 SHOW_STR
7436 BGP_STR
7437 "Display routes matching the communities\n"
7438 "community number\n"
7439 "Do not send outside local AS (well-known community)\n"
7440 "Do not advertise to any peer (well-known community)\n"
7441 "Do not export to next AS (well-known community)\n"
7442 "community number\n"
7443 "Do not send outside local AS (well-known community)\n"
7444 "Do not advertise to any peer (well-known community)\n"
7445 "Do not export to next AS (well-known community)\n"
7446 "community number\n"
7447 "Do not send outside local AS (well-known community)\n"
7448 "Do not advertise to any peer (well-known community)\n"
7449 "Do not export to next AS (well-known community)\n")
7450
7451ALIAS (show_bgp_community,
7452 show_bgp_ipv6_community3_cmd,
7453 "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)",
7454 SHOW_STR
7455 BGP_STR
7456 "Address family\n"
7457 "Display routes matching the communities\n"
7458 "community number\n"
7459 "Do not send outside local AS (well-known community)\n"
7460 "Do not advertise to any peer (well-known community)\n"
7461 "Do not export to next AS (well-known community)\n"
7462 "community number\n"
7463 "Do not send outside local AS (well-known community)\n"
7464 "Do not advertise to any peer (well-known community)\n"
7465 "Do not export to next AS (well-known community)\n"
7466 "community number\n"
7467 "Do not send outside local AS (well-known community)\n"
7468 "Do not advertise to any peer (well-known community)\n"
7469 "Do not export to next AS (well-known community)\n")
7470
7471ALIAS (show_bgp_community,
7472 show_bgp_community4_cmd,
7473 "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)",
7474 SHOW_STR
7475 BGP_STR
7476 "Display routes matching the communities\n"
7477 "community number\n"
7478 "Do not send outside local AS (well-known community)\n"
7479 "Do not advertise to any peer (well-known community)\n"
7480 "Do not export to next AS (well-known community)\n"
7481 "community number\n"
7482 "Do not send outside local AS (well-known community)\n"
7483 "Do not advertise to any peer (well-known community)\n"
7484 "Do not export to next AS (well-known community)\n"
7485 "community number\n"
7486 "Do not send outside local AS (well-known community)\n"
7487 "Do not advertise to any peer (well-known community)\n"
7488 "Do not export to next AS (well-known community)\n"
7489 "community number\n"
7490 "Do not send outside local AS (well-known community)\n"
7491 "Do not advertise to any peer (well-known community)\n"
7492 "Do not export to next AS (well-known community)\n")
7493
7494ALIAS (show_bgp_community,
7495 show_bgp_ipv6_community4_cmd,
7496 "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)",
7497 SHOW_STR
7498 BGP_STR
7499 "Address family\n"
7500 "Display routes matching the communities\n"
7501 "community number\n"
7502 "Do not send outside local AS (well-known community)\n"
7503 "Do not advertise to any peer (well-known community)\n"
7504 "Do not export to next AS (well-known community)\n"
7505 "community number\n"
7506 "Do not send outside local AS (well-known community)\n"
7507 "Do not advertise to any peer (well-known community)\n"
7508 "Do not export to next AS (well-known community)\n"
7509 "community number\n"
7510 "Do not send outside local AS (well-known community)\n"
7511 "Do not advertise to any peer (well-known community)\n"
7512 "Do not export to next AS (well-known community)\n"
7513 "community number\n"
7514 "Do not send outside local AS (well-known community)\n"
7515 "Do not advertise to any peer (well-known community)\n"
7516 "Do not export to next AS (well-known community)\n")
7517
7518/* old command */
7519DEFUN (show_ipv6_bgp_community,
7520 show_ipv6_bgp_community_cmd,
7521 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7522 SHOW_STR
7523 IPV6_STR
7524 BGP_STR
7525 "Display routes matching the communities\n"
7526 "community number\n"
7527 "Do not send outside local AS (well-known community)\n"
7528 "Do not advertise to any peer (well-known community)\n"
7529 "Do not export to next AS (well-known community)\n")
7530{
7531 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7532}
7533
7534/* old command */
7535ALIAS (show_ipv6_bgp_community,
7536 show_ipv6_bgp_community2_cmd,
7537 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7538 SHOW_STR
7539 IPV6_STR
7540 BGP_STR
7541 "Display routes matching the communities\n"
7542 "community number\n"
7543 "Do not send outside local AS (well-known community)\n"
7544 "Do not advertise to any peer (well-known community)\n"
7545 "Do not export to next AS (well-known community)\n"
7546 "community number\n"
7547 "Do not send outside local AS (well-known community)\n"
7548 "Do not advertise to any peer (well-known community)\n"
7549 "Do not export to next AS (well-known community)\n")
7550
7551/* old command */
7552ALIAS (show_ipv6_bgp_community,
7553 show_ipv6_bgp_community3_cmd,
7554 "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)",
7555 SHOW_STR
7556 IPV6_STR
7557 BGP_STR
7558 "Display routes matching the communities\n"
7559 "community number\n"
7560 "Do not send outside local AS (well-known community)\n"
7561 "Do not advertise to any peer (well-known community)\n"
7562 "Do not export to next AS (well-known community)\n"
7563 "community number\n"
7564 "Do not send outside local AS (well-known community)\n"
7565 "Do not advertise to any peer (well-known community)\n"
7566 "Do not export to next AS (well-known community)\n"
7567 "community number\n"
7568 "Do not send outside local AS (well-known community)\n"
7569 "Do not advertise to any peer (well-known community)\n"
7570 "Do not export to next AS (well-known community)\n")
7571
7572/* old command */
7573ALIAS (show_ipv6_bgp_community,
7574 show_ipv6_bgp_community4_cmd,
7575 "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)",
7576 SHOW_STR
7577 IPV6_STR
7578 BGP_STR
7579 "Display routes matching the communities\n"
7580 "community number\n"
7581 "Do not send outside local AS (well-known community)\n"
7582 "Do not advertise to any peer (well-known community)\n"
7583 "Do not export to next AS (well-known community)\n"
7584 "community number\n"
7585 "Do not send outside local AS (well-known community)\n"
7586 "Do not advertise to any peer (well-known community)\n"
7587 "Do not export to next AS (well-known community)\n"
7588 "community number\n"
7589 "Do not send outside local AS (well-known community)\n"
7590 "Do not advertise to any peer (well-known community)\n"
7591 "Do not export to next AS (well-known community)\n"
7592 "community number\n"
7593 "Do not send outside local AS (well-known community)\n"
7594 "Do not advertise to any peer (well-known community)\n"
7595 "Do not export to next AS (well-known community)\n")
7596
7597DEFUN (show_bgp_community_exact,
7598 show_bgp_community_exact_cmd,
7599 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7600 SHOW_STR
7601 BGP_STR
7602 "Display routes matching the communities\n"
7603 "community number\n"
7604 "Do not send outside local AS (well-known community)\n"
7605 "Do not advertise to any peer (well-known community)\n"
7606 "Do not export to next AS (well-known community)\n"
7607 "Exact match of the communities")
7608{
7609 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7610}
7611
7612ALIAS (show_bgp_community_exact,
7613 show_bgp_ipv6_community_exact_cmd,
7614 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7615 SHOW_STR
7616 BGP_STR
7617 "Address family\n"
7618 "Display routes matching the communities\n"
7619 "community number\n"
7620 "Do not send outside local AS (well-known community)\n"
7621 "Do not advertise to any peer (well-known community)\n"
7622 "Do not export to next AS (well-known community)\n"
7623 "Exact match of the communities")
7624
7625ALIAS (show_bgp_community_exact,
7626 show_bgp_community2_exact_cmd,
7627 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7628 SHOW_STR
7629 BGP_STR
7630 "Display routes matching the communities\n"
7631 "community number\n"
7632 "Do not send outside local AS (well-known community)\n"
7633 "Do not advertise to any peer (well-known community)\n"
7634 "Do not export to next AS (well-known community)\n"
7635 "community number\n"
7636 "Do not send outside local AS (well-known community)\n"
7637 "Do not advertise to any peer (well-known community)\n"
7638 "Do not export to next AS (well-known community)\n"
7639 "Exact match of the communities")
7640
7641ALIAS (show_bgp_community_exact,
7642 show_bgp_ipv6_community2_exact_cmd,
7643 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7644 SHOW_STR
7645 BGP_STR
7646 "Address family\n"
7647 "Display routes matching the communities\n"
7648 "community number\n"
7649 "Do not send outside local AS (well-known community)\n"
7650 "Do not advertise to any peer (well-known community)\n"
7651 "Do not export to next AS (well-known community)\n"
7652 "community number\n"
7653 "Do not send outside local AS (well-known community)\n"
7654 "Do not advertise to any peer (well-known community)\n"
7655 "Do not export to next AS (well-known community)\n"
7656 "Exact match of the communities")
7657
7658ALIAS (show_bgp_community_exact,
7659 show_bgp_community3_exact_cmd,
7660 "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",
7661 SHOW_STR
7662 BGP_STR
7663 "Display routes matching the communities\n"
7664 "community number\n"
7665 "Do not send outside local AS (well-known community)\n"
7666 "Do not advertise to any peer (well-known community)\n"
7667 "Do not export to next AS (well-known community)\n"
7668 "community number\n"
7669 "Do not send outside local AS (well-known community)\n"
7670 "Do not advertise to any peer (well-known community)\n"
7671 "Do not export to next AS (well-known community)\n"
7672 "community number\n"
7673 "Do not send outside local AS (well-known community)\n"
7674 "Do not advertise to any peer (well-known community)\n"
7675 "Do not export to next AS (well-known community)\n"
7676 "Exact match of the communities")
7677
7678ALIAS (show_bgp_community_exact,
7679 show_bgp_ipv6_community3_exact_cmd,
7680 "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",
7681 SHOW_STR
7682 BGP_STR
7683 "Address family\n"
7684 "Display routes matching the communities\n"
7685 "community number\n"
7686 "Do not send outside local AS (well-known community)\n"
7687 "Do not advertise to any peer (well-known community)\n"
7688 "Do not export to next AS (well-known community)\n"
7689 "community number\n"
7690 "Do not send outside local AS (well-known community)\n"
7691 "Do not advertise to any peer (well-known community)\n"
7692 "Do not export to next AS (well-known community)\n"
7693 "community number\n"
7694 "Do not send outside local AS (well-known community)\n"
7695 "Do not advertise to any peer (well-known community)\n"
7696 "Do not export to next AS (well-known community)\n"
7697 "Exact match of the communities")
7698
7699ALIAS (show_bgp_community_exact,
7700 show_bgp_community4_exact_cmd,
7701 "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",
7702 SHOW_STR
7703 BGP_STR
7704 "Display routes matching the communities\n"
7705 "community number\n"
7706 "Do not send outside local AS (well-known community)\n"
7707 "Do not advertise to any peer (well-known community)\n"
7708 "Do not export to next AS (well-known community)\n"
7709 "community number\n"
7710 "Do not send outside local AS (well-known community)\n"
7711 "Do not advertise to any peer (well-known community)\n"
7712 "Do not export to next AS (well-known community)\n"
7713 "community number\n"
7714 "Do not send outside local AS (well-known community)\n"
7715 "Do not advertise to any peer (well-known community)\n"
7716 "Do not export to next AS (well-known community)\n"
7717 "community number\n"
7718 "Do not send outside local AS (well-known community)\n"
7719 "Do not advertise to any peer (well-known community)\n"
7720 "Do not export to next AS (well-known community)\n"
7721 "Exact match of the communities")
7722
7723ALIAS (show_bgp_community_exact,
7724 show_bgp_ipv6_community4_exact_cmd,
7725 "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",
7726 SHOW_STR
7727 BGP_STR
7728 "Address family\n"
7729 "Display routes matching the communities\n"
7730 "community number\n"
7731 "Do not send outside local AS (well-known community)\n"
7732 "Do not advertise to any peer (well-known community)\n"
7733 "Do not export to next AS (well-known community)\n"
7734 "community number\n"
7735 "Do not send outside local AS (well-known community)\n"
7736 "Do not advertise to any peer (well-known community)\n"
7737 "Do not export to next AS (well-known community)\n"
7738 "community number\n"
7739 "Do not send outside local AS (well-known community)\n"
7740 "Do not advertise to any peer (well-known community)\n"
7741 "Do not export to next AS (well-known community)\n"
7742 "community number\n"
7743 "Do not send outside local AS (well-known community)\n"
7744 "Do not advertise to any peer (well-known community)\n"
7745 "Do not export to next AS (well-known community)\n"
7746 "Exact match of the communities")
7747
7748/* old command */
7749DEFUN (show_ipv6_bgp_community_exact,
7750 show_ipv6_bgp_community_exact_cmd,
7751 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7752 SHOW_STR
7753 IPV6_STR
7754 BGP_STR
7755 "Display routes matching the communities\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 "Exact match of the communities")
7761{
7762 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7763}
7764
7765/* old command */
7766ALIAS (show_ipv6_bgp_community_exact,
7767 show_ipv6_bgp_community2_exact_cmd,
7768 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7769 SHOW_STR
7770 IPV6_STR
7771 BGP_STR
7772 "Display routes matching the communities\n"
7773 "community number\n"
7774 "Do not send outside local AS (well-known community)\n"
7775 "Do not advertise to any peer (well-known community)\n"
7776 "Do not export to next AS (well-known community)\n"
7777 "community number\n"
7778 "Do not send outside local AS (well-known community)\n"
7779 "Do not advertise to any peer (well-known community)\n"
7780 "Do not export to next AS (well-known community)\n"
7781 "Exact match of the communities")
7782
7783/* old command */
7784ALIAS (show_ipv6_bgp_community_exact,
7785 show_ipv6_bgp_community3_exact_cmd,
7786 "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",
7787 SHOW_STR
7788 IPV6_STR
7789 BGP_STR
7790 "Display routes matching the communities\n"
7791 "community number\n"
7792 "Do not send outside local AS (well-known community)\n"
7793 "Do not advertise to any peer (well-known community)\n"
7794 "Do not export to next AS (well-known community)\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_community4_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) (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 "community number\n"
7826 "Do not send outside local AS (well-known community)\n"
7827 "Do not advertise to any peer (well-known community)\n"
7828 "Do not export to next AS (well-known community)\n"
7829 "Exact match of the communities")
7830
7831/* old command */
7832DEFUN (show_ipv6_mbgp_community,
7833 show_ipv6_mbgp_community_cmd,
7834 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7835 SHOW_STR
7836 IPV6_STR
7837 MBGP_STR
7838 "Display routes matching the communities\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{
7844 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7845}
7846
7847/* old command */
7848ALIAS (show_ipv6_mbgp_community,
7849 show_ipv6_mbgp_community2_cmd,
7850 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7851 SHOW_STR
7852 IPV6_STR
7853 MBGP_STR
7854 "Display routes matching the communities\n"
7855 "community number\n"
7856 "Do not send outside local AS (well-known community)\n"
7857 "Do not advertise to any peer (well-known community)\n"
7858 "Do not export to next AS (well-known community)\n"
7859 "community number\n"
7860 "Do not send outside local AS (well-known community)\n"
7861 "Do not advertise to any peer (well-known community)\n"
7862 "Do not export to next AS (well-known community)\n")
7863
7864/* old command */
7865ALIAS (show_ipv6_mbgp_community,
7866 show_ipv6_mbgp_community3_cmd,
7867 "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)",
7868 SHOW_STR
7869 IPV6_STR
7870 MBGP_STR
7871 "Display routes matching the communities\n"
7872 "community number\n"
7873 "Do not send outside local AS (well-known community)\n"
7874 "Do not advertise to any peer (well-known community)\n"
7875 "Do not export to next AS (well-known community)\n"
7876 "community number\n"
7877 "Do not send outside local AS (well-known community)\n"
7878 "Do not advertise to any peer (well-known community)\n"
7879 "Do not export to next AS (well-known community)\n"
7880 "community number\n"
7881 "Do not send outside local AS (well-known community)\n"
7882 "Do not advertise to any peer (well-known community)\n"
7883 "Do not export to next AS (well-known community)\n")
7884
7885/* old command */
7886ALIAS (show_ipv6_mbgp_community,
7887 show_ipv6_mbgp_community4_cmd,
7888 "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)",
7889 SHOW_STR
7890 IPV6_STR
7891 MBGP_STR
7892 "Display routes matching the communities\n"
7893 "community number\n"
7894 "Do not send outside local AS (well-known community)\n"
7895 "Do not advertise to any peer (well-known community)\n"
7896 "Do not export to next AS (well-known community)\n"
7897 "community number\n"
7898 "Do not send outside local AS (well-known community)\n"
7899 "Do not advertise to any peer (well-known community)\n"
7900 "Do not export to next AS (well-known community)\n"
7901 "community number\n"
7902 "Do not send outside local AS (well-known community)\n"
7903 "Do not advertise to any peer (well-known community)\n"
7904 "Do not export to next AS (well-known community)\n"
7905 "community number\n"
7906 "Do not send outside local AS (well-known community)\n"
7907 "Do not advertise to any peer (well-known community)\n"
7908 "Do not export to next AS (well-known community)\n")
7909
7910/* old command */
7911DEFUN (show_ipv6_mbgp_community_exact,
7912 show_ipv6_mbgp_community_exact_cmd,
7913 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7914 SHOW_STR
7915 IPV6_STR
7916 MBGP_STR
7917 "Display routes matching the communities\n"
7918 "community number\n"
7919 "Do not send outside local AS (well-known community)\n"
7920 "Do not advertise to any peer (well-known community)\n"
7921 "Do not export to next AS (well-known community)\n"
7922 "Exact match of the communities")
7923{
7924 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7925}
7926
7927/* old command */
7928ALIAS (show_ipv6_mbgp_community_exact,
7929 show_ipv6_mbgp_community2_exact_cmd,
7930 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7931 SHOW_STR
7932 IPV6_STR
7933 MBGP_STR
7934 "Display routes matching the communities\n"
7935 "community number\n"
7936 "Do not send outside local AS (well-known community)\n"
7937 "Do not advertise to any peer (well-known community)\n"
7938 "Do not export to next AS (well-known community)\n"
7939 "community number\n"
7940 "Do not send outside local AS (well-known community)\n"
7941 "Do not advertise to any peer (well-known community)\n"
7942 "Do not export to next AS (well-known community)\n"
7943 "Exact match of the communities")
7944
7945/* old command */
7946ALIAS (show_ipv6_mbgp_community_exact,
7947 show_ipv6_mbgp_community3_exact_cmd,
7948 "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",
7949 SHOW_STR
7950 IPV6_STR
7951 MBGP_STR
7952 "Display routes matching the communities\n"
7953 "community number\n"
7954 "Do not send outside local AS (well-known community)\n"
7955 "Do not advertise to any peer (well-known community)\n"
7956 "Do not export to next AS (well-known community)\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_community4_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) (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 "community number\n"
7988 "Do not send outside local AS (well-known community)\n"
7989 "Do not advertise to any peer (well-known community)\n"
7990 "Do not export to next AS (well-known community)\n"
7991 "Exact match of the communities")
7992#endif /* HAVE_IPV6 */
7993
paul94f2b392005-06-28 12:44:16 +00007994static int
paulfd79ac92004-10-13 05:06:08 +00007995bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00007996 u_int16_t afi, u_char safi)
7997{
7998 struct community_list *list;
7999
hassofee6e4e2005-02-02 16:29:31 +00008000 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008001 if (list == NULL)
8002 {
8003 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8004 VTY_NEWLINE);
8005 return CMD_WARNING;
8006 }
8007
ajs5a646652004-11-05 01:25:55 +00008008 return bgp_show (vty, NULL, afi, safi,
8009 (exact ? bgp_show_type_community_list_exact :
8010 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008011}
8012
8013DEFUN (show_ip_bgp_community_list,
8014 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008015 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008016 SHOW_STR
8017 IP_STR
8018 BGP_STR
8019 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008020 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008021 "community-list name\n")
8022{
8023 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8024}
8025
8026DEFUN (show_ip_bgp_ipv4_community_list,
8027 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008028 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008029 SHOW_STR
8030 IP_STR
8031 BGP_STR
8032 "Address family\n"
8033 "Address Family modifier\n"
8034 "Address Family modifier\n"
8035 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008036 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008037 "community-list name\n")
8038{
8039 if (strncmp (argv[0], "m", 1) == 0)
8040 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8041
8042 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8043}
8044
8045DEFUN (show_ip_bgp_community_list_exact,
8046 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008047 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008048 SHOW_STR
8049 IP_STR
8050 BGP_STR
8051 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008052 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008053 "community-list name\n"
8054 "Exact match of the communities\n")
8055{
8056 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8057}
8058
8059DEFUN (show_ip_bgp_ipv4_community_list_exact,
8060 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008061 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008062 SHOW_STR
8063 IP_STR
8064 BGP_STR
8065 "Address family\n"
8066 "Address Family modifier\n"
8067 "Address Family modifier\n"
8068 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008069 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008070 "community-list name\n"
8071 "Exact match of the communities\n")
8072{
8073 if (strncmp (argv[0], "m", 1) == 0)
8074 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8075
8076 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8077}
8078
8079#ifdef HAVE_IPV6
8080DEFUN (show_bgp_community_list,
8081 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008082 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008083 SHOW_STR
8084 BGP_STR
8085 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008086 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008087 "community-list name\n")
8088{
8089 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8090}
8091
8092ALIAS (show_bgp_community_list,
8093 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008094 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008095 SHOW_STR
8096 BGP_STR
8097 "Address family\n"
8098 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008099 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008100 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008101
8102/* old command */
8103DEFUN (show_ipv6_bgp_community_list,
8104 show_ipv6_bgp_community_list_cmd,
8105 "show ipv6 bgp community-list WORD",
8106 SHOW_STR
8107 IPV6_STR
8108 BGP_STR
8109 "Display routes matching the community-list\n"
8110 "community-list name\n")
8111{
8112 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8113}
8114
8115/* old command */
8116DEFUN (show_ipv6_mbgp_community_list,
8117 show_ipv6_mbgp_community_list_cmd,
8118 "show ipv6 mbgp community-list WORD",
8119 SHOW_STR
8120 IPV6_STR
8121 MBGP_STR
8122 "Display routes matching the community-list\n"
8123 "community-list name\n")
8124{
8125 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8126}
8127
8128DEFUN (show_bgp_community_list_exact,
8129 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008130 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008131 SHOW_STR
8132 BGP_STR
8133 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008134 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008135 "community-list name\n"
8136 "Exact match of the communities\n")
8137{
8138 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8139}
8140
8141ALIAS (show_bgp_community_list_exact,
8142 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008143 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008144 SHOW_STR
8145 BGP_STR
8146 "Address family\n"
8147 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008148 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008149 "community-list name\n"
8150 "Exact match of the communities\n")
8151
8152/* old command */
8153DEFUN (show_ipv6_bgp_community_list_exact,
8154 show_ipv6_bgp_community_list_exact_cmd,
8155 "show ipv6 bgp community-list WORD exact-match",
8156 SHOW_STR
8157 IPV6_STR
8158 BGP_STR
8159 "Display routes matching the community-list\n"
8160 "community-list name\n"
8161 "Exact match of the communities\n")
8162{
8163 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8164}
8165
8166/* old command */
8167DEFUN (show_ipv6_mbgp_community_list_exact,
8168 show_ipv6_mbgp_community_list_exact_cmd,
8169 "show ipv6 mbgp community-list WORD exact-match",
8170 SHOW_STR
8171 IPV6_STR
8172 MBGP_STR
8173 "Display routes matching the community-list\n"
8174 "community-list name\n"
8175 "Exact match of the communities\n")
8176{
8177 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8178}
8179#endif /* HAVE_IPV6 */
8180
paul94f2b392005-06-28 12:44:16 +00008181static int
paulfd79ac92004-10-13 05:06:08 +00008182bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008183 safi_t safi, enum bgp_show_type type)
8184{
8185 int ret;
8186 struct prefix *p;
8187
8188 p = prefix_new();
8189
8190 ret = str2prefix (prefix, p);
8191 if (! ret)
8192 {
8193 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8194 return CMD_WARNING;
8195 }
8196
ajs5a646652004-11-05 01:25:55 +00008197 ret = bgp_show (vty, NULL, afi, safi, type, p);
8198 prefix_free(p);
8199 return ret;
paul718e3742002-12-13 20:15:29 +00008200}
8201
8202DEFUN (show_ip_bgp_prefix_longer,
8203 show_ip_bgp_prefix_longer_cmd,
8204 "show ip bgp A.B.C.D/M longer-prefixes",
8205 SHOW_STR
8206 IP_STR
8207 BGP_STR
8208 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8209 "Display route and more specific routes\n")
8210{
8211 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8212 bgp_show_type_prefix_longer);
8213}
8214
8215DEFUN (show_ip_bgp_flap_prefix_longer,
8216 show_ip_bgp_flap_prefix_longer_cmd,
8217 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8218 SHOW_STR
8219 IP_STR
8220 BGP_STR
8221 "Display flap statistics of routes\n"
8222 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8223 "Display route and more specific routes\n")
8224{
8225 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8226 bgp_show_type_flap_prefix_longer);
8227}
8228
8229DEFUN (show_ip_bgp_ipv4_prefix_longer,
8230 show_ip_bgp_ipv4_prefix_longer_cmd,
8231 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8232 SHOW_STR
8233 IP_STR
8234 BGP_STR
8235 "Address family\n"
8236 "Address Family modifier\n"
8237 "Address Family modifier\n"
8238 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8239 "Display route and more specific routes\n")
8240{
8241 if (strncmp (argv[0], "m", 1) == 0)
8242 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8243 bgp_show_type_prefix_longer);
8244
8245 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8246 bgp_show_type_prefix_longer);
8247}
8248
8249DEFUN (show_ip_bgp_flap_address,
8250 show_ip_bgp_flap_address_cmd,
8251 "show ip bgp flap-statistics A.B.C.D",
8252 SHOW_STR
8253 IP_STR
8254 BGP_STR
8255 "Display flap statistics of routes\n"
8256 "Network in the BGP routing table to display\n")
8257{
8258 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8259 bgp_show_type_flap_address);
8260}
8261
8262DEFUN (show_ip_bgp_flap_prefix,
8263 show_ip_bgp_flap_prefix_cmd,
8264 "show ip bgp flap-statistics A.B.C.D/M",
8265 SHOW_STR
8266 IP_STR
8267 BGP_STR
8268 "Display flap statistics of routes\n"
8269 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8270{
8271 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8272 bgp_show_type_flap_prefix);
8273}
8274#ifdef HAVE_IPV6
8275DEFUN (show_bgp_prefix_longer,
8276 show_bgp_prefix_longer_cmd,
8277 "show bgp X:X::X:X/M longer-prefixes",
8278 SHOW_STR
8279 BGP_STR
8280 "IPv6 prefix <network>/<length>\n"
8281 "Display route and more specific routes\n")
8282{
8283 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8284 bgp_show_type_prefix_longer);
8285}
8286
8287ALIAS (show_bgp_prefix_longer,
8288 show_bgp_ipv6_prefix_longer_cmd,
8289 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8290 SHOW_STR
8291 BGP_STR
8292 "Address family\n"
8293 "IPv6 prefix <network>/<length>\n"
8294 "Display route and more specific routes\n")
8295
8296/* old command */
8297DEFUN (show_ipv6_bgp_prefix_longer,
8298 show_ipv6_bgp_prefix_longer_cmd,
8299 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8300 SHOW_STR
8301 IPV6_STR
8302 BGP_STR
8303 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8304 "Display route and more specific routes\n")
8305{
8306 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8307 bgp_show_type_prefix_longer);
8308}
8309
8310/* old command */
8311DEFUN (show_ipv6_mbgp_prefix_longer,
8312 show_ipv6_mbgp_prefix_longer_cmd,
8313 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8314 SHOW_STR
8315 IPV6_STR
8316 MBGP_STR
8317 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8318 "Display route and more specific routes\n")
8319{
8320 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8321 bgp_show_type_prefix_longer);
8322}
8323#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008324
paul94f2b392005-06-28 12:44:16 +00008325static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008326peer_lookup_in_view (struct vty *vty, const char *view_name,
8327 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008328{
8329 int ret;
8330 struct bgp *bgp;
8331 struct peer *peer;
8332 union sockunion su;
8333
8334 /* BGP structure lookup. */
8335 if (view_name)
8336 {
8337 bgp = bgp_lookup_by_name (view_name);
8338 if (! bgp)
8339 {
8340 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8341 return NULL;
8342 }
8343 }
paul5228ad22004-06-04 17:58:18 +00008344 else
paulbb46e942003-10-24 19:02:03 +00008345 {
8346 bgp = bgp_get_default ();
8347 if (! bgp)
8348 {
8349 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8350 return NULL;
8351 }
8352 }
8353
8354 /* Get peer sockunion. */
8355 ret = str2sockunion (ip_str, &su);
8356 if (ret < 0)
8357 {
8358 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8359 return NULL;
8360 }
8361
8362 /* Peer structure lookup. */
8363 peer = peer_lookup (bgp, &su);
8364 if (! peer)
8365 {
8366 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8367 return NULL;
8368 }
8369
8370 return peer;
8371}
8372
paul94f2b392005-06-28 12:44:16 +00008373static void
paul718e3742002-12-13 20:15:29 +00008374show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8375 int in)
8376{
8377 struct bgp_table *table;
8378 struct bgp_adj_in *ain;
8379 struct bgp_adj_out *adj;
8380 unsigned long output_count;
8381 struct bgp_node *rn;
8382 int header1 = 1;
8383 struct bgp *bgp;
8384 int header2 = 1;
8385
paulbb46e942003-10-24 19:02:03 +00008386 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008387
8388 if (! bgp)
8389 return;
8390
8391 table = bgp->rib[afi][safi];
8392
8393 output_count = 0;
8394
8395 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8396 PEER_STATUS_DEFAULT_ORIGINATE))
8397 {
8398 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 +00008399 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8400 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008401
8402 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8403 VTY_NEWLINE, VTY_NEWLINE);
8404 header1 = 0;
8405 }
8406
8407 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8408 if (in)
8409 {
8410 for (ain = rn->adj_in; ain; ain = ain->next)
8411 if (ain->peer == peer)
8412 {
8413 if (header1)
8414 {
8415 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 +00008416 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8417 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008418 header1 = 0;
8419 }
8420 if (header2)
8421 {
8422 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8423 header2 = 0;
8424 }
8425 if (ain->attr)
8426 {
8427 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8428 output_count++;
8429 }
8430 }
8431 }
8432 else
8433 {
8434 for (adj = rn->adj_out; adj; adj = adj->next)
8435 if (adj->peer == peer)
8436 {
8437 if (header1)
8438 {
8439 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 +00008440 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8441 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008442 header1 = 0;
8443 }
8444 if (header2)
8445 {
8446 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8447 header2 = 0;
8448 }
8449 if (adj->attr)
8450 {
8451 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8452 output_count++;
8453 }
8454 }
8455 }
8456
8457 if (output_count != 0)
8458 vty_out (vty, "%sTotal number of prefixes %ld%s",
8459 VTY_NEWLINE, output_count, VTY_NEWLINE);
8460}
8461
paul94f2b392005-06-28 12:44:16 +00008462static int
paulbb46e942003-10-24 19:02:03 +00008463peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8464{
paul718e3742002-12-13 20:15:29 +00008465 if (! peer || ! peer->afc[afi][safi])
8466 {
8467 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8468 return CMD_WARNING;
8469 }
8470
8471 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8472 {
8473 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8474 VTY_NEWLINE);
8475 return CMD_WARNING;
8476 }
8477
8478 show_adj_route (vty, peer, afi, safi, in);
8479
8480 return CMD_SUCCESS;
8481}
8482
8483DEFUN (show_ip_bgp_neighbor_advertised_route,
8484 show_ip_bgp_neighbor_advertised_route_cmd,
8485 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8486 SHOW_STR
8487 IP_STR
8488 BGP_STR
8489 "Detailed information on TCP and BGP neighbor connections\n"
8490 "Neighbor to display information about\n"
8491 "Neighbor to display information about\n"
8492 "Display the routes advertised to a BGP neighbor\n")
8493{
paulbb46e942003-10-24 19:02:03 +00008494 struct peer *peer;
8495
8496 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8497 if (! peer)
8498 return CMD_WARNING;
8499
8500 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008501}
8502
8503DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8504 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8505 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8506 SHOW_STR
8507 IP_STR
8508 BGP_STR
8509 "Address family\n"
8510 "Address Family modifier\n"
8511 "Address Family modifier\n"
8512 "Detailed information on TCP and BGP neighbor connections\n"
8513 "Neighbor to display information about\n"
8514 "Neighbor to display information about\n"
8515 "Display the routes advertised to a BGP neighbor\n")
8516{
paulbb46e942003-10-24 19:02:03 +00008517 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008518
paulbb46e942003-10-24 19:02:03 +00008519 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8520 if (! peer)
8521 return CMD_WARNING;
8522
8523 if (strncmp (argv[0], "m", 1) == 0)
8524 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8525
8526 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008527}
8528
8529#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008530DEFUN (show_bgp_view_neighbor_advertised_route,
8531 show_bgp_view_neighbor_advertised_route_cmd,
8532 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8533 SHOW_STR
8534 BGP_STR
8535 "BGP view\n"
8536 "View name\n"
8537 "Detailed information on TCP and BGP neighbor connections\n"
8538 "Neighbor to display information about\n"
8539 "Neighbor to display information about\n"
8540 "Display the routes advertised to a BGP neighbor\n")
8541{
8542 struct peer *peer;
8543
8544 if (argc == 2)
8545 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8546 else
8547 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8548
8549 if (! peer)
8550 return CMD_WARNING;
8551
8552 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8553}
8554
8555ALIAS (show_bgp_view_neighbor_advertised_route,
8556 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8557 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8558 SHOW_STR
8559 BGP_STR
8560 "BGP view\n"
8561 "View name\n"
8562 "Address family\n"
8563 "Detailed information on TCP and BGP neighbor connections\n"
8564 "Neighbor to display information about\n"
8565 "Neighbor to display information about\n"
8566 "Display the routes advertised to a BGP neighbor\n")
8567
8568DEFUN (show_bgp_view_neighbor_received_routes,
8569 show_bgp_view_neighbor_received_routes_cmd,
8570 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8571 SHOW_STR
8572 BGP_STR
8573 "BGP view\n"
8574 "View name\n"
8575 "Detailed information on TCP and BGP neighbor connections\n"
8576 "Neighbor to display information about\n"
8577 "Neighbor to display information about\n"
8578 "Display the received routes from neighbor\n")
8579{
8580 struct peer *peer;
8581
8582 if (argc == 2)
8583 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8584 else
8585 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8586
8587 if (! peer)
8588 return CMD_WARNING;
8589
8590 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8591}
8592
8593ALIAS (show_bgp_view_neighbor_received_routes,
8594 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8595 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8596 SHOW_STR
8597 BGP_STR
8598 "BGP view\n"
8599 "View name\n"
8600 "Address family\n"
8601 "Detailed information on TCP and BGP neighbor connections\n"
8602 "Neighbor to display information about\n"
8603 "Neighbor to display information about\n"
8604 "Display the received routes from neighbor\n")
8605
8606ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008607 show_bgp_neighbor_advertised_route_cmd,
8608 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8609 SHOW_STR
8610 BGP_STR
8611 "Detailed information on TCP and BGP neighbor connections\n"
8612 "Neighbor to display information about\n"
8613 "Neighbor to display information about\n"
8614 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008615
8616ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008617 show_bgp_ipv6_neighbor_advertised_route_cmd,
8618 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8619 SHOW_STR
8620 BGP_STR
8621 "Address family\n"
8622 "Detailed information on TCP and BGP neighbor connections\n"
8623 "Neighbor to display information about\n"
8624 "Neighbor to display information about\n"
8625 "Display the routes advertised to a BGP neighbor\n")
8626
8627/* old command */
paulbb46e942003-10-24 19:02:03 +00008628ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008629 ipv6_bgp_neighbor_advertised_route_cmd,
8630 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8631 SHOW_STR
8632 IPV6_STR
8633 BGP_STR
8634 "Detailed information on TCP and BGP neighbor connections\n"
8635 "Neighbor to display information about\n"
8636 "Neighbor to display information about\n"
8637 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008638
paul718e3742002-12-13 20:15:29 +00008639/* old command */
8640DEFUN (ipv6_mbgp_neighbor_advertised_route,
8641 ipv6_mbgp_neighbor_advertised_route_cmd,
8642 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8643 SHOW_STR
8644 IPV6_STR
8645 MBGP_STR
8646 "Detailed information on TCP and BGP neighbor connections\n"
8647 "Neighbor to display information about\n"
8648 "Neighbor to display information about\n"
8649 "Display the routes advertised to a BGP neighbor\n")
8650{
paulbb46e942003-10-24 19:02:03 +00008651 struct peer *peer;
8652
8653 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8654 if (! peer)
8655 return CMD_WARNING;
8656
8657 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008658}
8659#endif /* HAVE_IPV6 */
8660
8661DEFUN (show_ip_bgp_neighbor_received_routes,
8662 show_ip_bgp_neighbor_received_routes_cmd,
8663 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8664 SHOW_STR
8665 IP_STR
8666 BGP_STR
8667 "Detailed information on TCP and BGP neighbor connections\n"
8668 "Neighbor to display information about\n"
8669 "Neighbor to display information about\n"
8670 "Display the received routes from neighbor\n")
8671{
paulbb46e942003-10-24 19:02:03 +00008672 struct peer *peer;
8673
8674 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8675 if (! peer)
8676 return CMD_WARNING;
8677
8678 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008679}
8680
8681DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8682 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8683 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8684 SHOW_STR
8685 IP_STR
8686 BGP_STR
8687 "Address family\n"
8688 "Address Family modifier\n"
8689 "Address Family modifier\n"
8690 "Detailed information on TCP and BGP neighbor connections\n"
8691 "Neighbor to display information about\n"
8692 "Neighbor to display information about\n"
8693 "Display the received routes from neighbor\n")
8694{
paulbb46e942003-10-24 19:02:03 +00008695 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008696
paulbb46e942003-10-24 19:02:03 +00008697 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8698 if (! peer)
8699 return CMD_WARNING;
8700
8701 if (strncmp (argv[0], "m", 1) == 0)
8702 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8703
8704 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008705}
8706
8707DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8708 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8709 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8710 SHOW_STR
8711 IP_STR
8712 BGP_STR
8713 "Detailed information on TCP and BGP neighbor connections\n"
8714 "Neighbor to display information about\n"
8715 "Neighbor to display information about\n"
8716 "Display information received from a BGP neighbor\n"
8717 "Display the prefixlist filter\n")
8718{
8719 char name[BUFSIZ];
8720 union sockunion *su;
8721 struct peer *peer;
8722 int count;
8723
8724 su = sockunion_str2su (argv[0]);
8725 if (su == NULL)
8726 return CMD_WARNING;
8727
8728 peer = peer_lookup (NULL, su);
8729 if (! peer)
8730 return CMD_WARNING;
8731
8732 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8733 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8734 if (count)
8735 {
8736 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8737 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8738 }
8739
8740 return CMD_SUCCESS;
8741}
8742
8743DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8744 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8745 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8746 SHOW_STR
8747 IP_STR
8748 BGP_STR
8749 "Address family\n"
8750 "Address Family modifier\n"
8751 "Address Family modifier\n"
8752 "Detailed information on TCP and BGP neighbor connections\n"
8753 "Neighbor to display information about\n"
8754 "Neighbor to display information about\n"
8755 "Display information received from a BGP neighbor\n"
8756 "Display the prefixlist filter\n")
8757{
8758 char name[BUFSIZ];
8759 union sockunion *su;
8760 struct peer *peer;
8761 int count;
8762
8763 su = sockunion_str2su (argv[1]);
8764 if (su == NULL)
8765 return CMD_WARNING;
8766
8767 peer = peer_lookup (NULL, su);
8768 if (! peer)
8769 return CMD_WARNING;
8770
8771 if (strncmp (argv[0], "m", 1) == 0)
8772 {
8773 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8774 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8775 if (count)
8776 {
8777 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8778 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8779 }
8780 }
8781 else
8782 {
8783 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8784 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8785 if (count)
8786 {
8787 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8788 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8789 }
8790 }
8791
8792 return CMD_SUCCESS;
8793}
8794
8795
8796#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008797ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008798 show_bgp_neighbor_received_routes_cmd,
8799 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8800 SHOW_STR
8801 BGP_STR
8802 "Detailed information on TCP and BGP neighbor connections\n"
8803 "Neighbor to display information about\n"
8804 "Neighbor to display information about\n"
8805 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008806
paulbb46e942003-10-24 19:02:03 +00008807ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008808 show_bgp_ipv6_neighbor_received_routes_cmd,
8809 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8810 SHOW_STR
8811 BGP_STR
8812 "Address family\n"
8813 "Detailed information on TCP and BGP neighbor connections\n"
8814 "Neighbor to display information about\n"
8815 "Neighbor to display information about\n"
8816 "Display the received routes from neighbor\n")
8817
8818DEFUN (show_bgp_neighbor_received_prefix_filter,
8819 show_bgp_neighbor_received_prefix_filter_cmd,
8820 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8821 SHOW_STR
8822 BGP_STR
8823 "Detailed information on TCP and BGP neighbor connections\n"
8824 "Neighbor to display information about\n"
8825 "Neighbor to display information about\n"
8826 "Display information received from a BGP neighbor\n"
8827 "Display the prefixlist filter\n")
8828{
8829 char name[BUFSIZ];
8830 union sockunion *su;
8831 struct peer *peer;
8832 int count;
8833
8834 su = sockunion_str2su (argv[0]);
8835 if (su == NULL)
8836 return CMD_WARNING;
8837
8838 peer = peer_lookup (NULL, su);
8839 if (! peer)
8840 return CMD_WARNING;
8841
8842 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8843 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8844 if (count)
8845 {
8846 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8847 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8848 }
8849
8850 return CMD_SUCCESS;
8851}
8852
8853ALIAS (show_bgp_neighbor_received_prefix_filter,
8854 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8855 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8856 SHOW_STR
8857 BGP_STR
8858 "Address family\n"
8859 "Detailed information on TCP and BGP neighbor connections\n"
8860 "Neighbor to display information about\n"
8861 "Neighbor to display information about\n"
8862 "Display information received from a BGP neighbor\n"
8863 "Display the prefixlist filter\n")
8864
8865/* old command */
paulbb46e942003-10-24 19:02:03 +00008866ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008867 ipv6_bgp_neighbor_received_routes_cmd,
8868 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8869 SHOW_STR
8870 IPV6_STR
8871 BGP_STR
8872 "Detailed information on TCP and BGP neighbor connections\n"
8873 "Neighbor to display information about\n"
8874 "Neighbor to display information about\n"
8875 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008876
8877/* old command */
8878DEFUN (ipv6_mbgp_neighbor_received_routes,
8879 ipv6_mbgp_neighbor_received_routes_cmd,
8880 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8881 SHOW_STR
8882 IPV6_STR
8883 MBGP_STR
8884 "Detailed information on TCP and BGP neighbor connections\n"
8885 "Neighbor to display information about\n"
8886 "Neighbor to display information about\n"
8887 "Display the received routes from neighbor\n")
8888{
paulbb46e942003-10-24 19:02:03 +00008889 struct peer *peer;
8890
8891 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8892 if (! peer)
8893 return CMD_WARNING;
8894
8895 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00008896}
paulbb46e942003-10-24 19:02:03 +00008897
8898DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8899 show_bgp_view_neighbor_received_prefix_filter_cmd,
8900 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8901 SHOW_STR
8902 BGP_STR
8903 "BGP view\n"
8904 "View name\n"
8905 "Detailed information on TCP and BGP neighbor connections\n"
8906 "Neighbor to display information about\n"
8907 "Neighbor to display information about\n"
8908 "Display information received from a BGP neighbor\n"
8909 "Display the prefixlist filter\n")
8910{
8911 char name[BUFSIZ];
8912 union sockunion *su;
8913 struct peer *peer;
8914 struct bgp *bgp;
8915 int count;
8916
8917 /* BGP structure lookup. */
8918 bgp = bgp_lookup_by_name (argv[0]);
8919 if (bgp == NULL)
8920 {
8921 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8922 return CMD_WARNING;
8923 }
8924
8925 su = sockunion_str2su (argv[1]);
8926 if (su == NULL)
8927 return CMD_WARNING;
8928
8929 peer = peer_lookup (bgp, su);
8930 if (! peer)
8931 return CMD_WARNING;
8932
8933 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8934 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8935 if (count)
8936 {
8937 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8938 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8939 }
8940
8941 return CMD_SUCCESS;
8942}
8943
8944ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8945 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8946 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8947 SHOW_STR
8948 BGP_STR
8949 "BGP view\n"
8950 "View name\n"
8951 "Address family\n"
8952 "Detailed information on TCP and BGP neighbor connections\n"
8953 "Neighbor to display information about\n"
8954 "Neighbor to display information about\n"
8955 "Display information received from a BGP neighbor\n"
8956 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008957#endif /* HAVE_IPV6 */
8958
paul94f2b392005-06-28 12:44:16 +00008959static int
paulbb46e942003-10-24 19:02:03 +00008960bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008961 safi_t safi, enum bgp_show_type type)
8962{
paul718e3742002-12-13 20:15:29 +00008963 if (! peer || ! peer->afc[afi][safi])
8964 {
8965 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008966 return CMD_WARNING;
8967 }
8968
ajs5a646652004-11-05 01:25:55 +00008969 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00008970}
8971
8972DEFUN (show_ip_bgp_neighbor_routes,
8973 show_ip_bgp_neighbor_routes_cmd,
8974 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8975 SHOW_STR
8976 IP_STR
8977 BGP_STR
8978 "Detailed information on TCP and BGP neighbor connections\n"
8979 "Neighbor to display information about\n"
8980 "Neighbor to display information about\n"
8981 "Display routes learned from neighbor\n")
8982{
paulbb46e942003-10-24 19:02:03 +00008983 struct peer *peer;
8984
8985 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8986 if (! peer)
8987 return CMD_WARNING;
8988
8989 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008990 bgp_show_type_neighbor);
8991}
8992
8993DEFUN (show_ip_bgp_neighbor_flap,
8994 show_ip_bgp_neighbor_flap_cmd,
8995 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8996 SHOW_STR
8997 IP_STR
8998 BGP_STR
8999 "Detailed information on TCP and BGP neighbor connections\n"
9000 "Neighbor to display information about\n"
9001 "Neighbor to display information about\n"
9002 "Display flap statistics of the routes learned from neighbor\n")
9003{
paulbb46e942003-10-24 19:02:03 +00009004 struct peer *peer;
9005
9006 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9007 if (! peer)
9008 return CMD_WARNING;
9009
9010 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009011 bgp_show_type_flap_neighbor);
9012}
9013
9014DEFUN (show_ip_bgp_neighbor_damp,
9015 show_ip_bgp_neighbor_damp_cmd,
9016 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9017 SHOW_STR
9018 IP_STR
9019 BGP_STR
9020 "Detailed information on TCP and BGP neighbor connections\n"
9021 "Neighbor to display information about\n"
9022 "Neighbor to display information about\n"
9023 "Display the dampened routes received from neighbor\n")
9024{
paulbb46e942003-10-24 19:02:03 +00009025 struct peer *peer;
9026
9027 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9028 if (! peer)
9029 return CMD_WARNING;
9030
9031 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009032 bgp_show_type_damp_neighbor);
9033}
9034
9035DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9036 show_ip_bgp_ipv4_neighbor_routes_cmd,
9037 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9038 SHOW_STR
9039 IP_STR
9040 BGP_STR
9041 "Address family\n"
9042 "Address Family modifier\n"
9043 "Address Family modifier\n"
9044 "Detailed information on TCP and BGP neighbor connections\n"
9045 "Neighbor to display information about\n"
9046 "Neighbor to display information about\n"
9047 "Display routes learned from neighbor\n")
9048{
paulbb46e942003-10-24 19:02:03 +00009049 struct peer *peer;
9050
9051 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9052 if (! peer)
9053 return CMD_WARNING;
9054
paul718e3742002-12-13 20:15:29 +00009055 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009056 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009057 bgp_show_type_neighbor);
9058
paulbb46e942003-10-24 19:02:03 +00009059 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009060 bgp_show_type_neighbor);
9061}
paulbb46e942003-10-24 19:02:03 +00009062
paulfee0f4c2004-09-13 05:12:46 +00009063DEFUN (show_ip_bgp_view_rsclient,
9064 show_ip_bgp_view_rsclient_cmd,
9065 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9066 SHOW_STR
9067 IP_STR
9068 BGP_STR
9069 "BGP view\n"
9070 "BGP view name\n"
9071 "Information about Route Server Client\n"
9072 NEIGHBOR_ADDR_STR)
9073{
9074 struct bgp_table *table;
9075 struct peer *peer;
9076
9077 if (argc == 2)
9078 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9079 else
9080 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9081
9082 if (! peer)
9083 return CMD_WARNING;
9084
9085 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9086 {
9087 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9088 VTY_NEWLINE);
9089 return CMD_WARNING;
9090 }
9091
9092 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9093 PEER_FLAG_RSERVER_CLIENT))
9094 {
9095 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9096 VTY_NEWLINE);
9097 return CMD_WARNING;
9098 }
9099
9100 table = peer->rib[AFI_IP][SAFI_UNICAST];
9101
ajs5a646652004-11-05 01:25:55 +00009102 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009103}
9104
9105ALIAS (show_ip_bgp_view_rsclient,
9106 show_ip_bgp_rsclient_cmd,
9107 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9108 SHOW_STR
9109 IP_STR
9110 BGP_STR
9111 "Information about Route Server Client\n"
9112 NEIGHBOR_ADDR_STR)
9113
9114DEFUN (show_ip_bgp_view_rsclient_route,
9115 show_ip_bgp_view_rsclient_route_cmd,
9116 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9117 SHOW_STR
9118 IP_STR
9119 BGP_STR
9120 "BGP view\n"
9121 "BGP view name\n"
9122 "Information about Route Server Client\n"
9123 NEIGHBOR_ADDR_STR
9124 "Network in the BGP routing table to display\n")
9125{
9126 struct bgp *bgp;
9127 struct peer *peer;
9128
9129 /* BGP structure lookup. */
9130 if (argc == 3)
9131 {
9132 bgp = bgp_lookup_by_name (argv[0]);
9133 if (bgp == NULL)
9134 {
9135 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9136 return CMD_WARNING;
9137 }
9138 }
9139 else
9140 {
9141 bgp = bgp_get_default ();
9142 if (bgp == NULL)
9143 {
9144 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9145 return CMD_WARNING;
9146 }
9147 }
9148
9149 if (argc == 3)
9150 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9151 else
9152 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9153
9154 if (! peer)
9155 return CMD_WARNING;
9156
9157 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9158 {
9159 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9160 VTY_NEWLINE);
9161 return CMD_WARNING;
9162}
9163
9164 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9165 PEER_FLAG_RSERVER_CLIENT))
9166 {
9167 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9168 VTY_NEWLINE);
9169 return CMD_WARNING;
9170 }
9171
9172 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9173 (argc == 3) ? argv[2] : argv[1],
9174 AFI_IP, SAFI_UNICAST, NULL, 0);
9175}
9176
9177ALIAS (show_ip_bgp_view_rsclient_route,
9178 show_ip_bgp_rsclient_route_cmd,
9179 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9180 SHOW_STR
9181 IP_STR
9182 BGP_STR
9183 "Information about Route Server Client\n"
9184 NEIGHBOR_ADDR_STR
9185 "Network in the BGP routing table to display\n")
9186
9187DEFUN (show_ip_bgp_view_rsclient_prefix,
9188 show_ip_bgp_view_rsclient_prefix_cmd,
9189 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9190 SHOW_STR
9191 IP_STR
9192 BGP_STR
9193 "BGP view\n"
9194 "BGP view name\n"
9195 "Information about Route Server Client\n"
9196 NEIGHBOR_ADDR_STR
9197 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9198{
9199 struct bgp *bgp;
9200 struct peer *peer;
9201
9202 /* BGP structure lookup. */
9203 if (argc == 3)
9204 {
9205 bgp = bgp_lookup_by_name (argv[0]);
9206 if (bgp == NULL)
9207 {
9208 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9209 return CMD_WARNING;
9210 }
9211 }
9212 else
9213 {
9214 bgp = bgp_get_default ();
9215 if (bgp == NULL)
9216 {
9217 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9218 return CMD_WARNING;
9219 }
9220 }
9221
9222 if (argc == 3)
9223 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9224 else
9225 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9226
9227 if (! peer)
9228 return CMD_WARNING;
9229
9230 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9231 {
9232 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9233 VTY_NEWLINE);
9234 return CMD_WARNING;
9235}
9236
9237 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9238 PEER_FLAG_RSERVER_CLIENT))
9239{
9240 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9241 VTY_NEWLINE);
9242 return CMD_WARNING;
9243 }
9244
9245 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9246 (argc == 3) ? argv[2] : argv[1],
9247 AFI_IP, SAFI_UNICAST, NULL, 1);
9248}
9249
9250ALIAS (show_ip_bgp_view_rsclient_prefix,
9251 show_ip_bgp_rsclient_prefix_cmd,
9252 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9253 SHOW_STR
9254 IP_STR
9255 BGP_STR
9256 "Information about Route Server Client\n"
9257 NEIGHBOR_ADDR_STR
9258 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9259
9260
paul718e3742002-12-13 20:15:29 +00009261#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009262DEFUN (show_bgp_view_neighbor_routes,
9263 show_bgp_view_neighbor_routes_cmd,
9264 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9265 SHOW_STR
9266 BGP_STR
9267 "BGP view\n"
9268 "BGP view name\n"
9269 "Detailed information on TCP and BGP neighbor connections\n"
9270 "Neighbor to display information about\n"
9271 "Neighbor to display information about\n"
9272 "Display routes learned from neighbor\n")
9273{
9274 struct peer *peer;
9275
9276 if (argc == 2)
9277 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9278 else
9279 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9280
9281 if (! peer)
9282 return CMD_WARNING;
9283
9284 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9285 bgp_show_type_neighbor);
9286}
9287
9288ALIAS (show_bgp_view_neighbor_routes,
9289 show_bgp_view_ipv6_neighbor_routes_cmd,
9290 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9291 SHOW_STR
9292 BGP_STR
9293 "BGP view\n"
9294 "BGP view name\n"
9295 "Address family\n"
9296 "Detailed information on TCP and BGP neighbor connections\n"
9297 "Neighbor to display information about\n"
9298 "Neighbor to display information about\n"
9299 "Display routes learned from neighbor\n")
9300
9301DEFUN (show_bgp_view_neighbor_damp,
9302 show_bgp_view_neighbor_damp_cmd,
9303 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9304 SHOW_STR
9305 BGP_STR
9306 "BGP view\n"
9307 "BGP view name\n"
9308 "Detailed information on TCP and BGP neighbor connections\n"
9309 "Neighbor to display information about\n"
9310 "Neighbor to display information about\n"
9311 "Display the dampened routes received from neighbor\n")
9312{
9313 struct peer *peer;
9314
9315 if (argc == 2)
9316 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9317 else
9318 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9319
9320 if (! peer)
9321 return CMD_WARNING;
9322
9323 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9324 bgp_show_type_damp_neighbor);
9325}
9326
9327ALIAS (show_bgp_view_neighbor_damp,
9328 show_bgp_view_ipv6_neighbor_damp_cmd,
9329 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9330 SHOW_STR
9331 BGP_STR
9332 "BGP view\n"
9333 "BGP view name\n"
9334 "Address family\n"
9335 "Detailed information on TCP and BGP neighbor connections\n"
9336 "Neighbor to display information about\n"
9337 "Neighbor to display information about\n"
9338 "Display the dampened routes received from neighbor\n")
9339
9340DEFUN (show_bgp_view_neighbor_flap,
9341 show_bgp_view_neighbor_flap_cmd,
9342 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9343 SHOW_STR
9344 BGP_STR
9345 "BGP view\n"
9346 "BGP view name\n"
9347 "Detailed information on TCP and BGP neighbor connections\n"
9348 "Neighbor to display information about\n"
9349 "Neighbor to display information about\n"
9350 "Display flap statistics of the routes learned from neighbor\n")
9351{
9352 struct peer *peer;
9353
9354 if (argc == 2)
9355 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9356 else
9357 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9358
9359 if (! peer)
9360 return CMD_WARNING;
9361
9362 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9363 bgp_show_type_flap_neighbor);
9364}
9365
9366ALIAS (show_bgp_view_neighbor_flap,
9367 show_bgp_view_ipv6_neighbor_flap_cmd,
9368 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9369 SHOW_STR
9370 BGP_STR
9371 "BGP view\n"
9372 "BGP view name\n"
9373 "Address family\n"
9374 "Detailed information on TCP and BGP neighbor connections\n"
9375 "Neighbor to display information about\n"
9376 "Neighbor to display information about\n"
9377 "Display flap statistics of the routes learned from neighbor\n")
9378
9379ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009380 show_bgp_neighbor_routes_cmd,
9381 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9382 SHOW_STR
9383 BGP_STR
9384 "Detailed information on TCP and BGP neighbor connections\n"
9385 "Neighbor to display information about\n"
9386 "Neighbor to display information about\n"
9387 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009388
paulbb46e942003-10-24 19:02:03 +00009389
9390ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009391 show_bgp_ipv6_neighbor_routes_cmd,
9392 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9393 SHOW_STR
9394 BGP_STR
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 routes learned from neighbor\n")
9400
9401/* old command */
paulbb46e942003-10-24 19:02:03 +00009402ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009403 ipv6_bgp_neighbor_routes_cmd,
9404 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9405 SHOW_STR
9406 IPV6_STR
9407 BGP_STR
9408 "Detailed information on TCP and BGP neighbor connections\n"
9409 "Neighbor to display information about\n"
9410 "Neighbor to display information about\n"
9411 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009412
9413/* old command */
9414DEFUN (ipv6_mbgp_neighbor_routes,
9415 ipv6_mbgp_neighbor_routes_cmd,
9416 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9417 SHOW_STR
9418 IPV6_STR
9419 MBGP_STR
9420 "Detailed information on TCP and BGP neighbor connections\n"
9421 "Neighbor to display information about\n"
9422 "Neighbor to display information about\n"
9423 "Display routes learned from neighbor\n")
9424{
paulbb46e942003-10-24 19:02:03 +00009425 struct peer *peer;
9426
9427 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9428 if (! peer)
9429 return CMD_WARNING;
9430
9431 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009432 bgp_show_type_neighbor);
9433}
paulbb46e942003-10-24 19:02:03 +00009434
9435ALIAS (show_bgp_view_neighbor_flap,
9436 show_bgp_neighbor_flap_cmd,
9437 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9438 SHOW_STR
9439 BGP_STR
9440 "Detailed information on TCP and BGP neighbor connections\n"
9441 "Neighbor to display information about\n"
9442 "Neighbor to display information about\n"
9443 "Display flap statistics of the routes learned from neighbor\n")
9444
9445ALIAS (show_bgp_view_neighbor_flap,
9446 show_bgp_ipv6_neighbor_flap_cmd,
9447 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9448 SHOW_STR
9449 BGP_STR
9450 "Address family\n"
9451 "Detailed information on TCP and BGP neighbor connections\n"
9452 "Neighbor to display information about\n"
9453 "Neighbor to display information about\n"
9454 "Display flap statistics of the routes learned from neighbor\n")
9455
9456ALIAS (show_bgp_view_neighbor_damp,
9457 show_bgp_neighbor_damp_cmd,
9458 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9459 SHOW_STR
9460 BGP_STR
9461 "Detailed information on TCP and BGP neighbor connections\n"
9462 "Neighbor to display information about\n"
9463 "Neighbor to display information about\n"
9464 "Display the dampened routes received from neighbor\n")
9465
9466ALIAS (show_bgp_view_neighbor_damp,
9467 show_bgp_ipv6_neighbor_damp_cmd,
9468 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9469 SHOW_STR
9470 BGP_STR
9471 "Address family\n"
9472 "Detailed information on TCP and BGP neighbor connections\n"
9473 "Neighbor to display information about\n"
9474 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009475 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009476
9477DEFUN (show_bgp_view_rsclient,
9478 show_bgp_view_rsclient_cmd,
9479 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9480 SHOW_STR
9481 BGP_STR
9482 "BGP view\n"
9483 "BGP view name\n"
9484 "Information about Route Server Client\n"
9485 NEIGHBOR_ADDR_STR)
9486{
9487 struct bgp_table *table;
9488 struct peer *peer;
9489
9490 if (argc == 2)
9491 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9492 else
9493 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9494
9495 if (! peer)
9496 return CMD_WARNING;
9497
9498 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9499 {
9500 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9501 VTY_NEWLINE);
9502 return CMD_WARNING;
9503 }
9504
9505 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9506 PEER_FLAG_RSERVER_CLIENT))
9507 {
9508 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9509 VTY_NEWLINE);
9510 return CMD_WARNING;
9511 }
9512
9513 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9514
ajs5a646652004-11-05 01:25:55 +00009515 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009516}
9517
9518ALIAS (show_bgp_view_rsclient,
9519 show_bgp_rsclient_cmd,
9520 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9521 SHOW_STR
9522 BGP_STR
9523 "Information about Route Server Client\n"
9524 NEIGHBOR_ADDR_STR)
9525
9526DEFUN (show_bgp_view_rsclient_route,
9527 show_bgp_view_rsclient_route_cmd,
9528 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9529 SHOW_STR
9530 BGP_STR
9531 "BGP view\n"
9532 "BGP view name\n"
9533 "Information about Route Server Client\n"
9534 NEIGHBOR_ADDR_STR
9535 "Network in the BGP routing table to display\n")
9536{
9537 struct bgp *bgp;
9538 struct peer *peer;
9539
9540 /* BGP structure lookup. */
9541 if (argc == 3)
9542 {
9543 bgp = bgp_lookup_by_name (argv[0]);
9544 if (bgp == NULL)
9545 {
9546 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9547 return CMD_WARNING;
9548 }
9549 }
9550 else
9551 {
9552 bgp = bgp_get_default ();
9553 if (bgp == NULL)
9554 {
9555 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9556 return CMD_WARNING;
9557 }
9558 }
9559
9560 if (argc == 3)
9561 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9562 else
9563 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9564
9565 if (! peer)
9566 return CMD_WARNING;
9567
9568 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9569 {
9570 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9571 VTY_NEWLINE);
9572 return CMD_WARNING;
9573 }
9574
9575 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9576 PEER_FLAG_RSERVER_CLIENT))
9577 {
9578 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9579 VTY_NEWLINE);
9580 return CMD_WARNING;
9581 }
9582
9583 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9584 (argc == 3) ? argv[2] : argv[1],
9585 AFI_IP6, SAFI_UNICAST, NULL, 0);
9586}
9587
9588ALIAS (show_bgp_view_rsclient_route,
9589 show_bgp_rsclient_route_cmd,
9590 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9591 SHOW_STR
9592 BGP_STR
9593 "Information about Route Server Client\n"
9594 NEIGHBOR_ADDR_STR
9595 "Network in the BGP routing table to display\n")
9596
9597DEFUN (show_bgp_view_rsclient_prefix,
9598 show_bgp_view_rsclient_prefix_cmd,
9599 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9600 SHOW_STR
9601 BGP_STR
9602 "BGP view\n"
9603 "BGP view name\n"
9604 "Information about Route Server Client\n"
9605 NEIGHBOR_ADDR_STR
9606 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9607{
9608 struct bgp *bgp;
9609 struct peer *peer;
9610
9611 /* BGP structure lookup. */
9612 if (argc == 3)
9613 {
9614 bgp = bgp_lookup_by_name (argv[0]);
9615 if (bgp == NULL)
9616 {
9617 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9618 return CMD_WARNING;
9619 }
9620 }
9621 else
9622 {
9623 bgp = bgp_get_default ();
9624 if (bgp == NULL)
9625 {
9626 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9627 return CMD_WARNING;
9628 }
9629 }
9630
9631 if (argc == 3)
9632 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9633 else
9634 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9635
9636 if (! peer)
9637 return CMD_WARNING;
9638
9639 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9640 {
9641 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9642 VTY_NEWLINE);
9643 return CMD_WARNING;
9644 }
9645
9646 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9647 PEER_FLAG_RSERVER_CLIENT))
9648 {
9649 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9650 VTY_NEWLINE);
9651 return CMD_WARNING;
9652 }
9653
9654 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9655 (argc == 3) ? argv[2] : argv[1],
9656 AFI_IP6, SAFI_UNICAST, NULL, 1);
9657}
9658
9659ALIAS (show_bgp_view_rsclient_prefix,
9660 show_bgp_rsclient_prefix_cmd,
9661 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9662 SHOW_STR
9663 BGP_STR
9664 "Information about Route Server Client\n"
9665 NEIGHBOR_ADDR_STR
9666 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9667
paul718e3742002-12-13 20:15:29 +00009668#endif /* HAVE_IPV6 */
9669
9670struct bgp_table *bgp_distance_table;
9671
9672struct bgp_distance
9673{
9674 /* Distance value for the IP source prefix. */
9675 u_char distance;
9676
9677 /* Name of the access-list to be matched. */
9678 char *access_list;
9679};
9680
paul94f2b392005-06-28 12:44:16 +00009681static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +00009682bgp_distance_new ()
9683{
9684 struct bgp_distance *new;
9685 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9686 memset (new, 0, sizeof (struct bgp_distance));
9687 return new;
9688}
9689
paul94f2b392005-06-28 12:44:16 +00009690static void
paul718e3742002-12-13 20:15:29 +00009691bgp_distance_free (struct bgp_distance *bdistance)
9692{
9693 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9694}
9695
paul94f2b392005-06-28 12:44:16 +00009696static int
paulfd79ac92004-10-13 05:06:08 +00009697bgp_distance_set (struct vty *vty, const char *distance_str,
9698 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009699{
9700 int ret;
9701 struct prefix_ipv4 p;
9702 u_char distance;
9703 struct bgp_node *rn;
9704 struct bgp_distance *bdistance;
9705
9706 ret = str2prefix_ipv4 (ip_str, &p);
9707 if (ret == 0)
9708 {
9709 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9710 return CMD_WARNING;
9711 }
9712
9713 distance = atoi (distance_str);
9714
9715 /* Get BGP distance node. */
9716 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9717 if (rn->info)
9718 {
9719 bdistance = rn->info;
9720 bgp_unlock_node (rn);
9721 }
9722 else
9723 {
9724 bdistance = bgp_distance_new ();
9725 rn->info = bdistance;
9726 }
9727
9728 /* Set distance value. */
9729 bdistance->distance = distance;
9730
9731 /* Reset access-list configuration. */
9732 if (bdistance->access_list)
9733 {
9734 free (bdistance->access_list);
9735 bdistance->access_list = NULL;
9736 }
9737 if (access_list_str)
9738 bdistance->access_list = strdup (access_list_str);
9739
9740 return CMD_SUCCESS;
9741}
9742
paul94f2b392005-06-28 12:44:16 +00009743static int
paulfd79ac92004-10-13 05:06:08 +00009744bgp_distance_unset (struct vty *vty, const char *distance_str,
9745 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009746{
9747 int ret;
9748 struct prefix_ipv4 p;
9749 u_char distance;
9750 struct bgp_node *rn;
9751 struct bgp_distance *bdistance;
9752
9753 ret = str2prefix_ipv4 (ip_str, &p);
9754 if (ret == 0)
9755 {
9756 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9757 return CMD_WARNING;
9758 }
9759
9760 distance = atoi (distance_str);
9761
9762 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9763 if (! rn)
9764 {
9765 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9766 return CMD_WARNING;
9767 }
9768
9769 bdistance = rn->info;
9770
9771 if (bdistance->access_list)
9772 free (bdistance->access_list);
9773 bgp_distance_free (bdistance);
9774
9775 rn->info = NULL;
9776 bgp_unlock_node (rn);
9777 bgp_unlock_node (rn);
9778
9779 return CMD_SUCCESS;
9780}
9781
paul94f2b392005-06-28 12:44:16 +00009782static void
paul718e3742002-12-13 20:15:29 +00009783bgp_distance_reset ()
9784{
9785 struct bgp_node *rn;
9786 struct bgp_distance *bdistance;
9787
9788 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9789 if ((bdistance = rn->info) != NULL)
9790 {
9791 if (bdistance->access_list)
9792 free (bdistance->access_list);
9793 bgp_distance_free (bdistance);
9794 rn->info = NULL;
9795 bgp_unlock_node (rn);
9796 }
9797}
9798
9799/* Apply BGP information to distance method. */
9800u_char
9801bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9802{
9803 struct bgp_node *rn;
9804 struct prefix_ipv4 q;
9805 struct peer *peer;
9806 struct bgp_distance *bdistance;
9807 struct access_list *alist;
9808 struct bgp_static *bgp_static;
9809
9810 if (! bgp)
9811 return 0;
9812
9813 if (p->family != AF_INET)
9814 return 0;
9815
9816 peer = rinfo->peer;
9817
9818 if (peer->su.sa.sa_family != AF_INET)
9819 return 0;
9820
9821 memset (&q, 0, sizeof (struct prefix_ipv4));
9822 q.family = AF_INET;
9823 q.prefix = peer->su.sin.sin_addr;
9824 q.prefixlen = IPV4_MAX_BITLEN;
9825
9826 /* Check source address. */
9827 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9828 if (rn)
9829 {
9830 bdistance = rn->info;
9831 bgp_unlock_node (rn);
9832
9833 if (bdistance->access_list)
9834 {
9835 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9836 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9837 return bdistance->distance;
9838 }
9839 else
9840 return bdistance->distance;
9841 }
9842
9843 /* Backdoor check. */
9844 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9845 if (rn)
9846 {
9847 bgp_static = rn->info;
9848 bgp_unlock_node (rn);
9849
9850 if (bgp_static->backdoor)
9851 {
9852 if (bgp->distance_local)
9853 return bgp->distance_local;
9854 else
9855 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9856 }
9857 }
9858
9859 if (peer_sort (peer) == BGP_PEER_EBGP)
9860 {
9861 if (bgp->distance_ebgp)
9862 return bgp->distance_ebgp;
9863 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9864 }
9865 else
9866 {
9867 if (bgp->distance_ibgp)
9868 return bgp->distance_ibgp;
9869 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9870 }
9871}
9872
9873DEFUN (bgp_distance,
9874 bgp_distance_cmd,
9875 "distance bgp <1-255> <1-255> <1-255>",
9876 "Define an administrative distance\n"
9877 "BGP distance\n"
9878 "Distance for routes external to the AS\n"
9879 "Distance for routes internal to the AS\n"
9880 "Distance for local routes\n")
9881{
9882 struct bgp *bgp;
9883
9884 bgp = vty->index;
9885
9886 bgp->distance_ebgp = atoi (argv[0]);
9887 bgp->distance_ibgp = atoi (argv[1]);
9888 bgp->distance_local = atoi (argv[2]);
9889 return CMD_SUCCESS;
9890}
9891
9892DEFUN (no_bgp_distance,
9893 no_bgp_distance_cmd,
9894 "no distance bgp <1-255> <1-255> <1-255>",
9895 NO_STR
9896 "Define an administrative distance\n"
9897 "BGP distance\n"
9898 "Distance for routes external to the AS\n"
9899 "Distance for routes internal to the AS\n"
9900 "Distance for local routes\n")
9901{
9902 struct bgp *bgp;
9903
9904 bgp = vty->index;
9905
9906 bgp->distance_ebgp= 0;
9907 bgp->distance_ibgp = 0;
9908 bgp->distance_local = 0;
9909 return CMD_SUCCESS;
9910}
9911
9912ALIAS (no_bgp_distance,
9913 no_bgp_distance2_cmd,
9914 "no distance bgp",
9915 NO_STR
9916 "Define an administrative distance\n"
9917 "BGP distance\n")
9918
9919DEFUN (bgp_distance_source,
9920 bgp_distance_source_cmd,
9921 "distance <1-255> A.B.C.D/M",
9922 "Define an administrative distance\n"
9923 "Administrative distance\n"
9924 "IP source prefix\n")
9925{
9926 bgp_distance_set (vty, argv[0], argv[1], NULL);
9927 return CMD_SUCCESS;
9928}
9929
9930DEFUN (no_bgp_distance_source,
9931 no_bgp_distance_source_cmd,
9932 "no distance <1-255> A.B.C.D/M",
9933 NO_STR
9934 "Define an administrative distance\n"
9935 "Administrative distance\n"
9936 "IP source prefix\n")
9937{
9938 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9939 return CMD_SUCCESS;
9940}
9941
9942DEFUN (bgp_distance_source_access_list,
9943 bgp_distance_source_access_list_cmd,
9944 "distance <1-255> A.B.C.D/M WORD",
9945 "Define an administrative distance\n"
9946 "Administrative distance\n"
9947 "IP source prefix\n"
9948 "Access list name\n")
9949{
9950 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9951 return CMD_SUCCESS;
9952}
9953
9954DEFUN (no_bgp_distance_source_access_list,
9955 no_bgp_distance_source_access_list_cmd,
9956 "no distance <1-255> A.B.C.D/M WORD",
9957 NO_STR
9958 "Define an administrative distance\n"
9959 "Administrative distance\n"
9960 "IP source prefix\n"
9961 "Access list name\n")
9962{
9963 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9964 return CMD_SUCCESS;
9965}
9966
9967DEFUN (bgp_damp_set,
9968 bgp_damp_set_cmd,
9969 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9970 "BGP Specific commands\n"
9971 "Enable route-flap dampening\n"
9972 "Half-life time for the penalty\n"
9973 "Value to start reusing a route\n"
9974 "Value to start suppressing a route\n"
9975 "Maximum duration to suppress a stable route\n")
9976{
9977 struct bgp *bgp;
9978 int half = DEFAULT_HALF_LIFE * 60;
9979 int reuse = DEFAULT_REUSE;
9980 int suppress = DEFAULT_SUPPRESS;
9981 int max = 4 * half;
9982
9983 if (argc == 4)
9984 {
9985 half = atoi (argv[0]) * 60;
9986 reuse = atoi (argv[1]);
9987 suppress = atoi (argv[2]);
9988 max = atoi (argv[3]) * 60;
9989 }
9990 else if (argc == 1)
9991 {
9992 half = atoi (argv[0]) * 60;
9993 max = 4 * half;
9994 }
9995
9996 bgp = vty->index;
9997 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
9998 half, reuse, suppress, max);
9999}
10000
10001ALIAS (bgp_damp_set,
10002 bgp_damp_set2_cmd,
10003 "bgp dampening <1-45>",
10004 "BGP Specific commands\n"
10005 "Enable route-flap dampening\n"
10006 "Half-life time for the penalty\n")
10007
10008ALIAS (bgp_damp_set,
10009 bgp_damp_set3_cmd,
10010 "bgp dampening",
10011 "BGP Specific commands\n"
10012 "Enable route-flap dampening\n")
10013
10014DEFUN (bgp_damp_unset,
10015 bgp_damp_unset_cmd,
10016 "no bgp dampening",
10017 NO_STR
10018 "BGP Specific commands\n"
10019 "Enable route-flap dampening\n")
10020{
10021 struct bgp *bgp;
10022
10023 bgp = vty->index;
10024 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10025}
10026
10027ALIAS (bgp_damp_unset,
10028 bgp_damp_unset2_cmd,
10029 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10030 NO_STR
10031 "BGP Specific commands\n"
10032 "Enable route-flap dampening\n"
10033 "Half-life time for the penalty\n"
10034 "Value to start reusing a route\n"
10035 "Value to start suppressing a route\n"
10036 "Maximum duration to suppress a stable route\n")
10037
10038DEFUN (show_ip_bgp_dampened_paths,
10039 show_ip_bgp_dampened_paths_cmd,
10040 "show ip bgp dampened-paths",
10041 SHOW_STR
10042 IP_STR
10043 BGP_STR
10044 "Display paths suppressed due to dampening\n")
10045{
ajs5a646652004-11-05 01:25:55 +000010046 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10047 NULL);
paul718e3742002-12-13 20:15:29 +000010048}
10049
10050DEFUN (show_ip_bgp_flap_statistics,
10051 show_ip_bgp_flap_statistics_cmd,
10052 "show ip bgp flap-statistics",
10053 SHOW_STR
10054 IP_STR
10055 BGP_STR
10056 "Display flap statistics of routes\n")
10057{
ajs5a646652004-11-05 01:25:55 +000010058 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10059 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010060}
10061
10062/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010063static int
paulfd79ac92004-10-13 05:06:08 +000010064bgp_clear_damp_route (struct vty *vty, const char *view_name,
10065 const char *ip_str, afi_t afi, safi_t safi,
10066 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010067{
10068 int ret;
10069 struct prefix match;
10070 struct bgp_node *rn;
10071 struct bgp_node *rm;
10072 struct bgp_info *ri;
10073 struct bgp_info *ri_temp;
10074 struct bgp *bgp;
10075 struct bgp_table *table;
10076
10077 /* BGP structure lookup. */
10078 if (view_name)
10079 {
10080 bgp = bgp_lookup_by_name (view_name);
10081 if (bgp == NULL)
10082 {
10083 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10084 return CMD_WARNING;
10085 }
10086 }
10087 else
10088 {
10089 bgp = bgp_get_default ();
10090 if (bgp == NULL)
10091 {
10092 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10093 return CMD_WARNING;
10094 }
10095 }
10096
10097 /* Check IP address argument. */
10098 ret = str2prefix (ip_str, &match);
10099 if (! ret)
10100 {
10101 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10102 return CMD_WARNING;
10103 }
10104
10105 match.family = afi2family (afi);
10106
10107 if (safi == SAFI_MPLS_VPN)
10108 {
10109 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10110 {
10111 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10112 continue;
10113
10114 if ((table = rn->info) != NULL)
10115 if ((rm = bgp_node_match (table, &match)) != NULL)
10116 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10117 {
10118 ri = rm->info;
10119 while (ri)
10120 {
10121 if (ri->damp_info)
10122 {
10123 ri_temp = ri->next;
10124 bgp_damp_info_free (ri->damp_info, 1);
10125 ri = ri_temp;
10126 }
10127 else
10128 ri = ri->next;
10129 }
10130 }
10131 }
10132 }
10133 else
10134 {
10135 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10136 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10137 {
10138 ri = rn->info;
10139 while (ri)
10140 {
10141 if (ri->damp_info)
10142 {
10143 ri_temp = ri->next;
10144 bgp_damp_info_free (ri->damp_info, 1);
10145 ri = ri_temp;
10146 }
10147 else
10148 ri = ri->next;
10149 }
10150 }
10151 }
10152
10153 return CMD_SUCCESS;
10154}
10155
10156DEFUN (clear_ip_bgp_dampening,
10157 clear_ip_bgp_dampening_cmd,
10158 "clear ip bgp dampening",
10159 CLEAR_STR
10160 IP_STR
10161 BGP_STR
10162 "Clear route flap dampening information\n")
10163{
10164 bgp_damp_info_clean ();
10165 return CMD_SUCCESS;
10166}
10167
10168DEFUN (clear_ip_bgp_dampening_prefix,
10169 clear_ip_bgp_dampening_prefix_cmd,
10170 "clear ip bgp dampening A.B.C.D/M",
10171 CLEAR_STR
10172 IP_STR
10173 BGP_STR
10174 "Clear route flap dampening information\n"
10175 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10176{
10177 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10178 SAFI_UNICAST, NULL, 1);
10179}
10180
10181DEFUN (clear_ip_bgp_dampening_address,
10182 clear_ip_bgp_dampening_address_cmd,
10183 "clear ip bgp dampening A.B.C.D",
10184 CLEAR_STR
10185 IP_STR
10186 BGP_STR
10187 "Clear route flap dampening information\n"
10188 "Network to clear damping information\n")
10189{
10190 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10191 SAFI_UNICAST, NULL, 0);
10192}
10193
10194DEFUN (clear_ip_bgp_dampening_address_mask,
10195 clear_ip_bgp_dampening_address_mask_cmd,
10196 "clear ip bgp dampening A.B.C.D A.B.C.D",
10197 CLEAR_STR
10198 IP_STR
10199 BGP_STR
10200 "Clear route flap dampening information\n"
10201 "Network to clear damping information\n"
10202 "Network mask\n")
10203{
10204 int ret;
10205 char prefix_str[BUFSIZ];
10206
10207 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10208 if (! ret)
10209 {
10210 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10211 return CMD_WARNING;
10212 }
10213
10214 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10215 SAFI_UNICAST, NULL, 0);
10216}
10217
paul94f2b392005-06-28 12:44:16 +000010218static int
paul718e3742002-12-13 20:15:29 +000010219bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10220 afi_t afi, safi_t safi, int *write)
10221{
10222 struct bgp_node *prn;
10223 struct bgp_node *rn;
10224 struct bgp_table *table;
10225 struct prefix *p;
10226 struct prefix_rd *prd;
10227 struct bgp_static *bgp_static;
10228 u_int32_t label;
10229 char buf[SU_ADDRSTRLEN];
10230 char rdbuf[RD_ADDRSTRLEN];
10231
10232 /* Network configuration. */
10233 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10234 if ((table = prn->info) != NULL)
10235 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10236 if ((bgp_static = rn->info) != NULL)
10237 {
10238 p = &rn->p;
10239 prd = (struct prefix_rd *) &prn->p;
10240
10241 /* "address-family" display. */
10242 bgp_config_write_family_header (vty, afi, safi, write);
10243
10244 /* "network" configuration display. */
10245 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10246 label = decode_label (bgp_static->tag);
10247
10248 vty_out (vty, " network %s/%d rd %s tag %d",
10249 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10250 p->prefixlen,
10251 rdbuf, label);
10252 vty_out (vty, "%s", VTY_NEWLINE);
10253 }
10254 return 0;
10255}
10256
10257/* Configuration of static route announcement and aggregate
10258 information. */
10259int
10260bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10261 afi_t afi, safi_t safi, int *write)
10262{
10263 struct bgp_node *rn;
10264 struct prefix *p;
10265 struct bgp_static *bgp_static;
10266 struct bgp_aggregate *bgp_aggregate;
10267 char buf[SU_ADDRSTRLEN];
10268
10269 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10270 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10271
10272 /* Network configuration. */
10273 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10274 if ((bgp_static = rn->info) != NULL)
10275 {
10276 p = &rn->p;
10277
10278 /* "address-family" display. */
10279 bgp_config_write_family_header (vty, afi, safi, write);
10280
10281 /* "network" configuration display. */
10282 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10283 {
10284 u_int32_t destination;
10285 struct in_addr netmask;
10286
10287 destination = ntohl (p->u.prefix4.s_addr);
10288 masklen2ip (p->prefixlen, &netmask);
10289 vty_out (vty, " network %s",
10290 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10291
10292 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10293 || (IN_CLASSB (destination) && p->prefixlen == 16)
10294 || (IN_CLASSA (destination) && p->prefixlen == 8)
10295 || p->u.prefix4.s_addr == 0)
10296 {
10297 /* Natural mask is not display. */
10298 }
10299 else
10300 vty_out (vty, " mask %s", inet_ntoa (netmask));
10301 }
10302 else
10303 {
10304 vty_out (vty, " network %s/%d",
10305 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10306 p->prefixlen);
10307 }
10308
10309 if (bgp_static->rmap.name)
10310 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10311 else if (bgp_static->backdoor)
10312 vty_out (vty, " backdoor");
10313
10314 vty_out (vty, "%s", VTY_NEWLINE);
10315 }
10316
10317 /* Aggregate-address configuration. */
10318 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10319 if ((bgp_aggregate = rn->info) != NULL)
10320 {
10321 p = &rn->p;
10322
10323 /* "address-family" display. */
10324 bgp_config_write_family_header (vty, afi, safi, write);
10325
10326 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10327 {
10328 struct in_addr netmask;
10329
10330 masklen2ip (p->prefixlen, &netmask);
10331 vty_out (vty, " aggregate-address %s %s",
10332 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10333 inet_ntoa (netmask));
10334 }
10335 else
10336 {
10337 vty_out (vty, " aggregate-address %s/%d",
10338 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10339 p->prefixlen);
10340 }
10341
10342 if (bgp_aggregate->as_set)
10343 vty_out (vty, " as-set");
10344
10345 if (bgp_aggregate->summary_only)
10346 vty_out (vty, " summary-only");
10347
10348 vty_out (vty, "%s", VTY_NEWLINE);
10349 }
10350
10351 return 0;
10352}
10353
10354int
10355bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10356{
10357 struct bgp_node *rn;
10358 struct bgp_distance *bdistance;
10359
10360 /* Distance configuration. */
10361 if (bgp->distance_ebgp
10362 && bgp->distance_ibgp
10363 && bgp->distance_local
10364 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10365 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10366 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10367 vty_out (vty, " distance bgp %d %d %d%s",
10368 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10369 VTY_NEWLINE);
10370
10371 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10372 if ((bdistance = rn->info) != NULL)
10373 {
10374 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10375 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10376 bdistance->access_list ? bdistance->access_list : "",
10377 VTY_NEWLINE);
10378 }
10379
10380 return 0;
10381}
10382
10383/* Allocate routing table structure and install commands. */
10384void
10385bgp_route_init ()
10386{
10387 /* Init BGP distance table. */
10388 bgp_distance_table = bgp_table_init ();
10389
10390 /* IPv4 BGP commands. */
10391 install_element (BGP_NODE, &bgp_network_cmd);
10392 install_element (BGP_NODE, &bgp_network_mask_cmd);
10393 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10394 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10395 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10396 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10397 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10398 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10399 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10400 install_element (BGP_NODE, &no_bgp_network_cmd);
10401 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10402 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10403 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10404 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10405 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10406 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10407 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10408 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10409
10410 install_element (BGP_NODE, &aggregate_address_cmd);
10411 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10412 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10413 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10414 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10415 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10416 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10417 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10418 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10419 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10420 install_element (BGP_NODE, &no_aggregate_address_cmd);
10421 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10422 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10423 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10424 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10425 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10426 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10427 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10428 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10429 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10430
10431 /* IPv4 unicast configuration. */
10432 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10433 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10434 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10435 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10436 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10437 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10438 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10439 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10440 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10441 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10442 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10443 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10444 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10445 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10446 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10447 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10448 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10449 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10450 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10451 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10452 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10453 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10454 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10455 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10456 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10457 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10458 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10459 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10460 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10461 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10462 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10463 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10464
10465 /* IPv4 multicast configuration. */
10466 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10467 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10468 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10469 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10470 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10471 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10472 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10473 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10474 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10475 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10476 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10477 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10478 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10479 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10480 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10481 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10482 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10483 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10484 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10485 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10486 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10487 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10488 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10489 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10495 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10496 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10497 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10498
10499 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10501 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10503 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10504 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10505 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10506 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10507 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10508 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10509 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10510 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10511 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10512 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10513 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10514 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10516 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10518 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10520 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10522 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10524 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10525 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10526 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10527 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10532 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10533 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10534 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10535 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10536 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10537 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10540 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10542 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10543 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10544 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10545 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10546 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10547 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10548 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10549 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10550 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10551 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10552 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10553 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10554 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10555 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10556 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10557 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10558 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10559 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10560 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10561 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10562 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10563 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10564 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10565 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010566 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10567 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10568 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10569 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10570 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10571 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010572
10573 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10574 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10575 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10576 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10577 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10578 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10579 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10580 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10581 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10582 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10583 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10584 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10585 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10586 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10587 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10588 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10590 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10592 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10593 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10594 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10595 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10596 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10597 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10598 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10599 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10600 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10601 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10602 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10603 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10606 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10607 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10608 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10609 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10611 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10613 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10614 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10616 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10618 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10619 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10620 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10621 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10622 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10624 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10626 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10628 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10629 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10630 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10631 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10632 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10633 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10634 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10635 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10636 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10637 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10638 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10639 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010640 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10641 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10642 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10643 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10644 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10645 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010646
10647 /* BGP dampening clear commands */
10648 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10649 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10650 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10651 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10652
10653#ifdef HAVE_IPV6
10654 /* New config IPv6 BGP commands. */
10655 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10656 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10657 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10658 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10659
10660 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10661 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10662 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10663 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10664
10665 /* Old config IPv6 BGP commands. */
10666 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10667 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10668
10669 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10670 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10671 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10672 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10673
10674 install_element (VIEW_NODE, &show_bgp_cmd);
10675 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10676 install_element (VIEW_NODE, &show_bgp_route_cmd);
10677 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10678 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10679 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10680 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10681 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10682 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10683 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10684 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10685 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10686 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10687 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10688 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10689 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10690 install_element (VIEW_NODE, &show_bgp_community_cmd);
10691 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10692 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10693 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10694 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10695 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10696 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10697 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10698 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10699 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10700 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10701 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10702 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10703 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10704 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10705 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10706 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10707 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10708 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10709 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10710 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10711 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10712 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10713 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10714 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10715 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10716 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10717 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10718 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10719 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010720 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10721 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10722 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10723 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010724 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10725 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10726 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010727 install_element (VIEW_NODE, &show_bgp_view_cmd);
10728 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10729 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10730 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10731 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10732 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10733 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10734 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10735 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10736 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10737 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10738 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10739 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10740 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10741 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10742 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10743 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10744 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010745 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10746 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10747 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010748
10749 install_element (ENABLE_NODE, &show_bgp_cmd);
10750 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10751 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10752 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10753 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10754 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10755 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10756 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10757 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10758 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10759 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10760 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10761 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10762 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10763 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10764 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10765 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10766 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10767 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10768 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10769 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10770 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10771 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10772 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10773 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10774 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10775 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10776 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10777 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10778 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10779 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10780 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10781 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10782 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10783 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10784 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10785 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10786 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10787 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10788 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10789 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10790 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10791 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10792 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10793 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10794 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010795 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10796 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10797 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10798 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010799 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10800 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10801 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010802 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10803 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10804 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10805 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10806 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10807 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10808 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10809 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10810 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10811 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10812 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10813 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10814 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10815 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10816 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10817 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10818 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10819 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010820 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10821 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10822 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010823
10824 /* old command */
10825 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10826 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10827 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10828 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10829 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10830 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10831 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10832 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10833 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10834 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10835 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10836 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10837 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10838 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10839 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10840 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10841 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10842 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10843 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10844 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10845 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10846 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10847 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10848 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10849 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10850 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10851 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10852 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10853 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10854 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10855 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10856 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10857 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10858 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10859 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10860 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000010861
paul718e3742002-12-13 20:15:29 +000010862 /* old command */
10863 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10864 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10865 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10866 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10867 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10868 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10869 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10870 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10871 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10872 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10873 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10874 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10875 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10876 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10877 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10878 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10879 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10880 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10881 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10882 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10883 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10884 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10885 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10886 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10887 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10888 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10889 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10890 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10891 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10892 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10893 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10894 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10895 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10896 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10897 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10898 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10899
10900 /* old command */
10901 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10902 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10903 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10904 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10905
10906 /* old command */
10907 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10908 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10909 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10910 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10911
10912 /* old command */
10913 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10914 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10915 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10916 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10917#endif /* HAVE_IPV6 */
10918
10919 install_element (BGP_NODE, &bgp_distance_cmd);
10920 install_element (BGP_NODE, &no_bgp_distance_cmd);
10921 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10922 install_element (BGP_NODE, &bgp_distance_source_cmd);
10923 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10924 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10925 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10926
10927 install_element (BGP_NODE, &bgp_damp_set_cmd);
10928 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10929 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10930 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10931 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10932 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10933 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10934 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10935 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10936 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
10937}