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