blob: 5dde41de7a0258e032907905e12376375fbe114a [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;
Paul Jakmada5b30f2006-05-08 14:37:17 +000068
69 assert (table);
70 if (!table)
71 return NULL;
72
paul718e3742002-12-13 20:15:29 +000073 if (safi == SAFI_MPLS_VPN)
74 {
paulfee0f4c2004-09-13 05:12:46 +000075 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000076
77 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000078 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000079 else
80 bgp_unlock_node (prn);
81 table = prn->info;
82 }
paul718e3742002-12-13 20:15:29 +000083
84 rn = bgp_node_get (table, p);
85
86 if (safi == SAFI_MPLS_VPN)
87 rn->prn = prn;
88
89 return rn;
90}
91
92/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +000093static struct bgp_info *
paul718e3742002-12-13 20:15:29 +000094bgp_info_new ()
95{
96 struct bgp_info *new;
97
98 new = XMALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
99 memset (new, 0, sizeof (struct bgp_info));
100
101 return new;
102}
103
104/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000105static void
paul718e3742002-12-13 20:15:29 +0000106bgp_info_free (struct bgp_info *binfo)
107{
108 if (binfo->attr)
109 bgp_attr_unintern (binfo->attr);
110
111 if (binfo->damp_info)
112 bgp_damp_info_free (binfo->damp_info, 0);
113
paul200df112005-06-01 11:17:05 +0000114 peer_unlock (binfo->peer); /* bgp_info peer reference */
115
paul718e3742002-12-13 20:15:29 +0000116 XFREE (MTYPE_BGP_ROUTE, binfo);
117}
118
paul200df112005-06-01 11:17:05 +0000119struct bgp_info *
120bgp_info_lock (struct bgp_info *binfo)
121{
122 binfo->lock++;
123 return binfo;
124}
125
126struct bgp_info *
127bgp_info_unlock (struct bgp_info *binfo)
128{
129 assert (binfo && binfo->lock > 0);
130 binfo->lock--;
131
132 if (binfo->lock == 0)
133 {
134#if 0
135 zlog_debug ("%s: unlocked and freeing", __func__);
136 zlog_backtrace (LOG_DEBUG);
137#endif
138 bgp_info_free (binfo);
139 return NULL;
140 }
141
142#if 0
143 if (binfo->lock == 1)
144 {
145 zlog_debug ("%s: unlocked to 1", __func__);
146 zlog_backtrace (LOG_DEBUG);
147 }
148#endif
149
150 return binfo;
151}
152
paul718e3742002-12-13 20:15:29 +0000153void
154bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
155{
156 struct bgp_info *top;
157
158 top = rn->info;
paul200df112005-06-01 11:17:05 +0000159
paul718e3742002-12-13 20:15:29 +0000160 ri->next = rn->info;
161 ri->prev = NULL;
162 if (top)
163 top->prev = ri;
164 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000165
166 bgp_info_lock (ri);
167 bgp_lock_node (rn);
168 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000169}
170
paulb40d9392005-08-22 22:34:41 +0000171/* Do the actual removal of info from RIB, for use by bgp_process
172 completion callback *only* */
173static void
174bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000175{
176 if (ri->next)
177 ri->next->prev = ri->prev;
178 if (ri->prev)
179 ri->prev->next = ri->next;
180 else
181 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000182
183 bgp_info_unlock (ri);
184 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000185}
186
paulb40d9392005-08-22 22:34:41 +0000187void
188bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
189{
Paul Jakma1a392d42006-09-07 00:24:49 +0000190 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
191 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000192 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
193}
194
Paul Jakma1a392d42006-09-07 00:24:49 +0000195/* Adjust pcount as required */
196static void
197bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
198{
199 /* Ignore 'pcount' for RS-client tables */
200 if (rn->table->type != BGP_TABLE_MAIN
201 || ri->peer == ri->peer->bgp->peer_self)
202 return;
203
204 if (BGP_INFO_HOLDDOWN (ri)
205 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
206 {
207
208 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
209
210 /* slight hack, but more robust against errors. */
211 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
212 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
213 else
214 {
215 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
216 __func__, ri->peer->host);
217 zlog_backtrace (LOG_WARNING);
218 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
219 }
220 }
221 else if (!BGP_INFO_HOLDDOWN (ri)
222 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
223 {
224 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
225 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
226 }
227}
228
229
230/* Set/unset bgp_info flags, adjusting any other state as needed.
231 * This is here primarily to keep prefix-count in check.
232 */
233void
234bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
235{
236 SET_FLAG (ri->flags, flag);
237
238 /* early bath if we know it's not a flag that changes useability state */
239 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
240 return;
241
242 bgp_pcount_adjust (rn, ri);
243}
244
245void
246bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
247{
248 UNSET_FLAG (ri->flags, flag);
249
250 /* early bath if we know it's not a flag that changes useability state */
251 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
252 return;
253
254 bgp_pcount_adjust (rn, ri);
255}
256
paul718e3742002-12-13 20:15:29 +0000257/* Get MED value. If MED value is missing and "bgp bestpath
258 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000259static u_int32_t
paul718e3742002-12-13 20:15:29 +0000260bgp_med_value (struct attr *attr, struct bgp *bgp)
261{
262 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
263 return attr->med;
264 else
265 {
266 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000267 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000268 else
269 return 0;
270 }
271}
272
273/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000274static int
paul718e3742002-12-13 20:15:29 +0000275bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
276{
277 u_int32_t new_pref;
278 u_int32_t exist_pref;
279 u_int32_t new_med;
280 u_int32_t exist_med;
281 struct in_addr new_id;
282 struct in_addr exist_id;
283 int new_cluster;
284 int exist_cluster;
285 int internal_as_route = 0;
286 int confed_as_route = 0;
287 int ret;
288
289 /* 0. Null check. */
290 if (new == NULL)
291 return 0;
292 if (exist == NULL)
293 return 1;
294
295 /* 1. Weight check. */
296 if (new->attr->weight > exist->attr->weight)
297 return 1;
298 if (new->attr->weight < exist->attr->weight)
299 return 0;
300
301 /* 2. Local preference check. */
302 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
303 new_pref = new->attr->local_pref;
304 else
305 new_pref = bgp->default_local_pref;
306
307 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
308 exist_pref = exist->attr->local_pref;
309 else
310 exist_pref = bgp->default_local_pref;
311
312 if (new_pref > exist_pref)
313 return 1;
314 if (new_pref < exist_pref)
315 return 0;
316
317 /* 3. Local route check. */
318 if (new->sub_type == BGP_ROUTE_STATIC)
319 return 1;
320 if (exist->sub_type == BGP_ROUTE_STATIC)
321 return 0;
322
323 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
324 return 1;
325 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
326 return 0;
327
328 if (new->sub_type == BGP_ROUTE_AGGREGATE)
329 return 1;
330 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
331 return 0;
332
333 /* 4. AS path length check. */
334 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
335 {
paulfe69a502005-09-10 16:55:02 +0000336 int exist_hops = aspath_count_hops (exist->attr->aspath);
337 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
338
hasso68118452005-04-08 15:40:36 +0000339 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
340 {
paulfe69a502005-09-10 16:55:02 +0000341 int aspath_hops;
342
343 aspath_hops = aspath_count_hops (new->attr->aspath);
344 aspath_hops += aspath_count_confeds (new->attr->aspath);
345
346 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000347 return 1;
paulfe69a502005-09-10 16:55:02 +0000348 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000349 return 0;
350 }
351 else
352 {
paulfe69a502005-09-10 16:55:02 +0000353 int newhops = aspath_count_hops (new->attr->aspath);
354
355 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000356 return 1;
paulfe69a502005-09-10 16:55:02 +0000357 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000358 return 0;
359 }
paul718e3742002-12-13 20:15:29 +0000360 }
361
362 /* 5. Origin check. */
363 if (new->attr->origin < exist->attr->origin)
364 return 1;
365 if (new->attr->origin > exist->attr->origin)
366 return 0;
367
368 /* 6. MED check. */
paulfe69a502005-09-10 16:55:02 +0000369 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
370 && aspath_count_hops (exist->attr->aspath) == 0);
371 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
372 && aspath_count_confeds (exist->attr->aspath) > 0
373 && aspath_count_hops (new->attr->aspath) == 0
374 && aspath_count_hops (exist->attr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000375
376 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
377 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
378 && confed_as_route)
379 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
380 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
381 || internal_as_route)
382 {
383 new_med = bgp_med_value (new->attr, bgp);
384 exist_med = bgp_med_value (exist->attr, bgp);
385
386 if (new_med < exist_med)
387 return 1;
388 if (new_med > exist_med)
389 return 0;
390 }
391
392 /* 7. Peer type check. */
393 if (peer_sort (new->peer) == BGP_PEER_EBGP
394 && peer_sort (exist->peer) == BGP_PEER_IBGP)
395 return 1;
396 if (peer_sort (new->peer) == BGP_PEER_EBGP
397 && peer_sort (exist->peer) == BGP_PEER_CONFED)
398 return 1;
399 if (peer_sort (new->peer) == BGP_PEER_IBGP
400 && peer_sort (exist->peer) == BGP_PEER_EBGP)
401 return 0;
402 if (peer_sort (new->peer) == BGP_PEER_CONFED
403 && peer_sort (exist->peer) == BGP_PEER_EBGP)
404 return 0;
405
406 /* 8. IGP metric check. */
407 if (new->igpmetric < exist->igpmetric)
408 return 1;
409 if (new->igpmetric > exist->igpmetric)
410 return 0;
411
412 /* 9. Maximum path check. */
413
414 /* 10. If both paths are external, prefer the path that was received
415 first (the oldest one). This step minimizes route-flap, since a
416 newer path won't displace an older one, even if it was the
417 preferred route based on the additional decision criteria below. */
418 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
419 && peer_sort (new->peer) == BGP_PEER_EBGP
420 && peer_sort (exist->peer) == BGP_PEER_EBGP)
421 {
422 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
423 return 1;
424 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
425 return 0;
426 }
427
428 /* 11. Rourter-ID comparision. */
429 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
430 new_id.s_addr = new->attr->originator_id.s_addr;
431 else
432 new_id.s_addr = new->peer->remote_id.s_addr;
433 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
434 exist_id.s_addr = exist->attr->originator_id.s_addr;
435 else
436 exist_id.s_addr = exist->peer->remote_id.s_addr;
437
438 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
439 return 1;
440 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
441 return 0;
442
443 /* 12. Cluster length comparision. */
444 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
445 new_cluster = new->attr->cluster->length;
446 else
447 new_cluster = 0;
448 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
449 exist_cluster = exist->attr->cluster->length;
450 else
451 exist_cluster = 0;
452
453 if (new_cluster < exist_cluster)
454 return 1;
455 if (new_cluster > exist_cluster)
456 return 0;
457
458 /* 13. Neighbor address comparision. */
459 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
460
461 if (ret == 1)
462 return 0;
463 if (ret == -1)
464 return 1;
465
466 return 1;
467}
468
paul94f2b392005-06-28 12:44:16 +0000469static enum filter_type
paul718e3742002-12-13 20:15:29 +0000470bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
471 afi_t afi, safi_t safi)
472{
473 struct bgp_filter *filter;
474
475 filter = &peer->filter[afi][safi];
476
477 if (DISTRIBUTE_IN_NAME (filter))
478 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
479 return FILTER_DENY;
480
481 if (PREFIX_LIST_IN_NAME (filter))
482 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
483 return FILTER_DENY;
484
485 if (FILTER_LIST_IN_NAME (filter))
486 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
487 return FILTER_DENY;
488
489 return FILTER_PERMIT;
490}
491
paul94f2b392005-06-28 12:44:16 +0000492static enum filter_type
paul718e3742002-12-13 20:15:29 +0000493bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
494 afi_t afi, safi_t safi)
495{
496 struct bgp_filter *filter;
497
498 filter = &peer->filter[afi][safi];
499
500 if (DISTRIBUTE_OUT_NAME (filter))
501 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
502 return FILTER_DENY;
503
504 if (PREFIX_LIST_OUT_NAME (filter))
505 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
506 return FILTER_DENY;
507
508 if (FILTER_LIST_OUT_NAME (filter))
509 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
510 return FILTER_DENY;
511
512 return FILTER_PERMIT;
513}
514
515/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000516static int
paul718e3742002-12-13 20:15:29 +0000517bgp_community_filter (struct peer *peer, struct attr *attr)
518{
519 if (attr->community)
520 {
521 /* NO_ADVERTISE check. */
522 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
523 return 1;
524
525 /* NO_EXPORT check. */
526 if (peer_sort (peer) == BGP_PEER_EBGP &&
527 community_include (attr->community, COMMUNITY_NO_EXPORT))
528 return 1;
529
530 /* NO_EXPORT_SUBCONFED check. */
531 if (peer_sort (peer) == BGP_PEER_EBGP
532 || peer_sort (peer) == BGP_PEER_CONFED)
533 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
534 return 1;
535 }
536 return 0;
537}
538
539/* Route reflection loop check. */
540static int
541bgp_cluster_filter (struct peer *peer, struct attr *attr)
542{
543 struct in_addr cluster_id;
544
545 if (attr->cluster)
546 {
547 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
548 cluster_id = peer->bgp->cluster_id;
549 else
550 cluster_id = peer->bgp->router_id;
551
552 if (cluster_loop_check (attr->cluster, cluster_id))
553 return 1;
554 }
555 return 0;
556}
557
paul94f2b392005-06-28 12:44:16 +0000558static int
paul718e3742002-12-13 20:15:29 +0000559bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
560 afi_t afi, safi_t safi)
561{
562 struct bgp_filter *filter;
563 struct bgp_info info;
564 route_map_result_t ret;
565
566 filter = &peer->filter[afi][safi];
567
568 /* Apply default weight value. */
569 attr->weight = peer->weight;
570
571 /* Route map apply. */
572 if (ROUTE_MAP_IN_NAME (filter))
573 {
574 /* Duplicate current value to new strucutre for modification. */
575 info.peer = peer;
576 info.attr = attr;
577
paulac41b2a2003-08-12 05:32:27 +0000578 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
579
paul718e3742002-12-13 20:15:29 +0000580 /* Apply BGP route map to the attribute. */
581 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000582
583 peer->rmap_type = 0;
584
paul718e3742002-12-13 20:15:29 +0000585 if (ret == RMAP_DENYMATCH)
586 {
587 /* Free newly generated AS path and community by route-map. */
588 bgp_attr_flush (attr);
589 return RMAP_DENY;
590 }
591 }
592 return RMAP_PERMIT;
593}
594
paul94f2b392005-06-28 12:44:16 +0000595static int
paulfee0f4c2004-09-13 05:12:46 +0000596bgp_export_modifier (struct peer *rsclient, struct peer *peer,
597 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
598{
599 struct bgp_filter *filter;
600 struct bgp_info info;
601 route_map_result_t ret;
602
603 filter = &peer->filter[afi][safi];
604
605 /* Route map apply. */
606 if (ROUTE_MAP_EXPORT_NAME (filter))
607 {
608 /* Duplicate current value to new strucutre for modification. */
609 info.peer = rsclient;
610 info.attr = attr;
611
612 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
613
614 /* Apply BGP route map to the attribute. */
615 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
616
617 rsclient->rmap_type = 0;
618
619 if (ret == RMAP_DENYMATCH)
620 {
621 /* Free newly generated AS path and community by route-map. */
622 bgp_attr_flush (attr);
623 return RMAP_DENY;
624 }
625 }
626 return RMAP_PERMIT;
627}
628
paul94f2b392005-06-28 12:44:16 +0000629static int
paulfee0f4c2004-09-13 05:12:46 +0000630bgp_import_modifier (struct peer *rsclient, struct peer *peer,
631 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
632{
633 struct bgp_filter *filter;
634 struct bgp_info info;
635 route_map_result_t ret;
636
637 filter = &rsclient->filter[afi][safi];
638
639 /* Apply default weight value. */
640 attr->weight = peer->weight;
641
642 /* Route map apply. */
643 if (ROUTE_MAP_IMPORT_NAME (filter))
644 {
645 /* Duplicate current value to new strucutre for modification. */
646 info.peer = peer;
647 info.attr = attr;
648
649 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
650
651 /* Apply BGP route map to the attribute. */
652 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
653
654 peer->rmap_type = 0;
655
656 if (ret == RMAP_DENYMATCH)
657 {
658 /* Free newly generated AS path and community by route-map. */
659 bgp_attr_flush (attr);
660 return RMAP_DENY;
661 }
662 }
663 return RMAP_PERMIT;
664}
665
paul94f2b392005-06-28 12:44:16 +0000666static int
paul718e3742002-12-13 20:15:29 +0000667bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
668 struct attr *attr, afi_t afi, safi_t safi)
669{
670 int ret;
671 char buf[SU_ADDRSTRLEN];
672 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000673 struct peer *from;
674 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000675 int transparent;
676 int reflect;
677
678 from = ri->peer;
679 filter = &peer->filter[afi][safi];
680 bgp = peer->bgp;
681
682#ifdef DISABLE_BGP_ANNOUNCE
683 return 0;
684#endif
685
paulfee0f4c2004-09-13 05:12:46 +0000686 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
687 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
688 return 0;
689
paul718e3742002-12-13 20:15:29 +0000690 /* Do not send back route to sender. */
691 if (from == peer)
692 return 0;
693
paul35be31b2004-05-01 18:17:04 +0000694 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
695 if (p->family == AF_INET
696 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
697 return 0;
698#ifdef HAVE_IPV6
699 if (p->family == AF_INET6
700 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
701 return 0;
702#endif
703
paul718e3742002-12-13 20:15:29 +0000704 /* Aggregate-address suppress check. */
705 if (ri->suppress)
706 if (! UNSUPPRESS_MAP_NAME (filter))
707 return 0;
708
709 /* Default route check. */
710 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
711 {
712 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
713 return 0;
714#ifdef HAVE_IPV6
715 else if (p->family == AF_INET6 && p->prefixlen == 0)
716 return 0;
717#endif /* HAVE_IPV6 */
718 }
719
paul286e1e72003-08-08 00:24:31 +0000720 /* Transparency check. */
721 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
722 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
723 transparent = 1;
724 else
725 transparent = 0;
726
paul718e3742002-12-13 20:15:29 +0000727 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000728 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000729 return 0;
730
731 /* If the attribute has originator-id and it is same as remote
732 peer's id. */
733 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
734 {
735 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
736 {
737 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000738 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000739 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
740 peer->host,
741 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
742 p->prefixlen);
743 return 0;
744 }
745 }
746
747 /* ORF prefix-list filter check */
748 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
749 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
750 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
751 if (peer->orf_plist[afi][safi])
752 {
753 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
754 return 0;
755 }
756
757 /* Output filter check. */
758 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
759 {
760 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000761 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000762 "%s [Update:SEND] %s/%d is filtered",
763 peer->host,
764 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
765 p->prefixlen);
766 return 0;
767 }
768
769#ifdef BGP_SEND_ASPATH_CHECK
770 /* AS path loop check. */
771 if (aspath_loop_check (ri->attr->aspath, peer->as))
772 {
773 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000774 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000775 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
776 peer->host, peer->as);
777 return 0;
778 }
779#endif /* BGP_SEND_ASPATH_CHECK */
780
781 /* If we're a CONFED we need to loop check the CONFED ID too */
782 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
783 {
784 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
785 {
786 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000787 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000788 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
789 peer->host,
790 bgp->confed_id);
791 return 0;
792 }
793 }
794
795 /* Route-Reflect check. */
796 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
797 reflect = 1;
798 else
799 reflect = 0;
800
801 /* IBGP reflection check. */
802 if (reflect)
803 {
804 /* A route from a Client peer. */
805 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
806 {
807 /* Reflect to all the Non-Client peers and also to the
808 Client peers other than the originator. Originator check
809 is already done. So there is noting to do. */
810 /* no bgp client-to-client reflection check. */
811 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
812 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
813 return 0;
814 }
815 else
816 {
817 /* A route from a Non-client peer. Reflect to all other
818 clients. */
819 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
820 return 0;
821 }
822 }
823
824 /* For modify attribute, copy it to temporary structure. */
825 *attr = *ri->attr;
826
827 /* If local-preference is not set. */
828 if ((peer_sort (peer) == BGP_PEER_IBGP
829 || peer_sort (peer) == BGP_PEER_CONFED)
830 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
831 {
832 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
833 attr->local_pref = bgp->default_local_pref;
834 }
835
paul718e3742002-12-13 20:15:29 +0000836 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
837 if (peer_sort (peer) == BGP_PEER_EBGP
838 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
839 {
840 if (ri->peer != bgp->peer_self && ! transparent
841 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
842 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
843 }
844
845 /* next-hop-set */
846 if (transparent || reflect
847 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
848 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000849#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000850 || (p->family == AF_INET6 &&
851 ! IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000852#endif /* HAVE_IPV6 */
853 )))
paul718e3742002-12-13 20:15:29 +0000854 {
855 /* NEXT-HOP Unchanged. */
856 }
857 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
858 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
859#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000860 || (p->family == AF_INET6 &&
861 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000862#endif /* HAVE_IPV6 */
863 || (peer_sort (peer) == BGP_PEER_EBGP
864 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
865 {
866 /* Set IPv4 nexthop. */
867 if (p->family == AF_INET)
868 {
869 if (safi == SAFI_MPLS_VPN)
870 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
871 else
872 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
873 }
874#ifdef HAVE_IPV6
875 /* Set IPv6 nexthop. */
876 if (p->family == AF_INET6)
877 {
878 /* IPv6 global nexthop must be included. */
879 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
880 IPV6_MAX_BYTELEN);
881 attr->mp_nexthop_len = 16;
882 }
883#endif /* HAVE_IPV6 */
884 }
885
886#ifdef HAVE_IPV6
887 if (p->family == AF_INET6)
888 {
paulfee0f4c2004-09-13 05:12:46 +0000889 /* Left nexthop_local unchanged if so configured. */
890 if ( CHECK_FLAG (peer->af_flags[afi][safi],
891 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
892 {
893 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
894 attr->mp_nexthop_len=32;
895 else
896 attr->mp_nexthop_len=16;
897 }
898
899 /* Default nexthop_local treatment for non-RS-Clients */
900 else
901 {
paul718e3742002-12-13 20:15:29 +0000902 /* Link-local address should not be transit to different peer. */
903 attr->mp_nexthop_len = 16;
904
905 /* Set link-local address for shared network peer. */
906 if (peer->shared_network
907 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
908 {
909 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
910 IPV6_MAX_BYTELEN);
911 attr->mp_nexthop_len = 32;
912 }
913
914 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
915 address.*/
916 if (reflect)
917 attr->mp_nexthop_len = 16;
918
919 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
920 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
921 attr->mp_nexthop_len = 16;
922 }
paulfee0f4c2004-09-13 05:12:46 +0000923
924 }
paul718e3742002-12-13 20:15:29 +0000925#endif /* HAVE_IPV6 */
926
927 /* If this is EBGP peer and remove-private-AS is set. */
928 if (peer_sort (peer) == BGP_PEER_EBGP
929 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
930 && aspath_private_as_check (attr->aspath))
931 attr->aspath = aspath_empty_get ();
932
933 /* Route map & unsuppress-map apply. */
934 if (ROUTE_MAP_OUT_NAME (filter)
935 || ri->suppress)
936 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +0000937 struct bgp_info info;
938 struct attr dummy_attr;
939
paul718e3742002-12-13 20:15:29 +0000940 info.peer = peer;
941 info.attr = attr;
942
943 /* The route reflector is not allowed to modify the attributes
944 of the reflected IBGP routes. */
945 if (peer_sort (from) == BGP_PEER_IBGP
946 && peer_sort (peer) == BGP_PEER_IBGP)
947 {
948 dummy_attr = *attr;
949 info.attr = &dummy_attr;
950 }
paulac41b2a2003-08-12 05:32:27 +0000951
952 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
953
paul718e3742002-12-13 20:15:29 +0000954 if (ri->suppress)
955 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
956 else
957 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
958
paulac41b2a2003-08-12 05:32:27 +0000959 peer->rmap_type = 0;
960
paul718e3742002-12-13 20:15:29 +0000961 if (ret == RMAP_DENYMATCH)
962 {
963 bgp_attr_flush (attr);
964 return 0;
965 }
966 }
967 return 1;
968}
969
paul94f2b392005-06-28 12:44:16 +0000970static int
paulfee0f4c2004-09-13 05:12:46 +0000971bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
972 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000973{
paulfee0f4c2004-09-13 05:12:46 +0000974 int ret;
975 char buf[SU_ADDRSTRLEN];
976 struct bgp_filter *filter;
977 struct bgp_info info;
978 struct peer *from;
979 struct bgp *bgp;
980
981 from = ri->peer;
982 filter = &rsclient->filter[afi][safi];
983 bgp = rsclient->bgp;
984
985#ifdef DISABLE_BGP_ANNOUNCE
986 return 0;
987#endif
988
989 /* Do not send back route to sender. */
990 if (from == rsclient)
991 return 0;
992
993 /* Aggregate-address suppress check. */
994 if (ri->suppress)
995 if (! UNSUPPRESS_MAP_NAME (filter))
996 return 0;
997
998 /* Default route check. */
999 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1000 PEER_STATUS_DEFAULT_ORIGINATE))
1001 {
1002 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1003 return 0;
1004#ifdef HAVE_IPV6
1005 else if (p->family == AF_INET6 && p->prefixlen == 0)
1006 return 0;
1007#endif /* HAVE_IPV6 */
1008 }
1009
1010 /* If the attribute has originator-id and it is same as remote
1011 peer's id. */
1012 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1013 {
1014 if (IPV4_ADDR_SAME (&rsclient->remote_id, &ri->attr->originator_id))
1015 {
1016 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001017 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001018 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1019 rsclient->host,
1020 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1021 p->prefixlen);
1022 return 0;
1023 }
1024 }
1025
1026 /* ORF prefix-list filter check */
1027 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1028 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1029 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1030 if (rsclient->orf_plist[afi][safi])
1031 {
1032 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1033 return 0;
1034 }
1035
1036 /* Output filter check. */
1037 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1038 {
1039 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001040 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001041 "%s [Update:SEND] %s/%d is filtered",
1042 rsclient->host,
1043 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1044 p->prefixlen);
1045 return 0;
1046 }
1047
1048#ifdef BGP_SEND_ASPATH_CHECK
1049 /* AS path loop check. */
1050 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1051 {
1052 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001053 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001054 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
1055 rsclient->host, rsclient->as);
1056 return 0;
1057 }
1058#endif /* BGP_SEND_ASPATH_CHECK */
1059
1060 /* For modify attribute, copy it to temporary structure. */
1061 *attr = *ri->attr;
1062
1063 /* next-hop-set */
1064 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1065#ifdef HAVE_IPV6
1066 || (p->family == AF_INET6 &&
1067 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
1068#endif /* HAVE_IPV6 */
1069 )
1070 {
1071 /* Set IPv4 nexthop. */
1072 if (p->family == AF_INET)
1073 {
1074 if (safi == SAFI_MPLS_VPN)
1075 memcpy (&attr->mp_nexthop_global_in, &rsclient->nexthop.v4,
1076 IPV4_MAX_BYTELEN);
1077 else
1078 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1079 }
1080#ifdef HAVE_IPV6
1081 /* Set IPv6 nexthop. */
1082 if (p->family == AF_INET6)
1083 {
1084 /* IPv6 global nexthop must be included. */
1085 memcpy (&attr->mp_nexthop_global, &rsclient->nexthop.v6_global,
1086
1087 IPV6_MAX_BYTELEN);
1088 attr->mp_nexthop_len = 16;
1089 }
1090#endif /* HAVE_IPV6 */
1091 }
1092
1093#ifdef HAVE_IPV6
1094 if (p->family == AF_INET6)
1095 {
1096 /* Left nexthop_local unchanged if so configured. */
1097 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1098 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1099 {
1100 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1101 attr->mp_nexthop_len=32;
1102 else
1103 attr->mp_nexthop_len=16;
1104 }
1105
1106 /* Default nexthop_local treatment for RS-Clients */
1107 else
1108 {
1109 /* Announcer and RS-Client are both in the same network */
1110 if (rsclient->shared_network && from->shared_network &&
1111 (rsclient->ifindex == from->ifindex))
1112 {
1113 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1114 attr->mp_nexthop_len=32;
1115 else
1116 attr->mp_nexthop_len=16;
1117 }
1118
1119 /* Set link-local address for shared network peer. */
1120 else if (rsclient->shared_network
1121 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1122 {
1123 memcpy (&attr->mp_nexthop_local, &rsclient->nexthop.v6_local,
1124 IPV6_MAX_BYTELEN);
1125 attr->mp_nexthop_len = 32;
1126 }
1127
1128 else
1129 attr->mp_nexthop_len = 16;
1130 }
1131
1132 }
1133#endif /* HAVE_IPV6 */
1134
1135
1136 /* If this is EBGP peer and remove-private-AS is set. */
1137 if (peer_sort (rsclient) == BGP_PEER_EBGP
1138 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1139 && aspath_private_as_check (attr->aspath))
1140 attr->aspath = aspath_empty_get ();
1141
1142 /* Route map & unsuppress-map apply. */
1143 if (ROUTE_MAP_OUT_NAME (filter) || ri->suppress)
1144 {
1145 info.peer = rsclient;
1146 info.attr = attr;
1147
1148 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1149
1150 if (ri->suppress)
1151 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1152 else
1153 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1154
1155 rsclient->rmap_type = 0;
1156
1157 if (ret == RMAP_DENYMATCH)
1158 {
1159 bgp_attr_flush (attr);
1160 return 0;
1161 }
1162 }
1163
1164 return 1;
1165}
1166
1167struct bgp_info_pair
1168{
1169 struct bgp_info *old;
1170 struct bgp_info *new;
1171};
1172
paul94f2b392005-06-28 12:44:16 +00001173static void
paulfee0f4c2004-09-13 05:12:46 +00001174bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1175{
paul718e3742002-12-13 20:15:29 +00001176 struct bgp_info *new_select;
1177 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001178 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001179 struct bgp_info *ri1;
1180 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001181 struct bgp_info *nextri = NULL;
1182
paul718e3742002-12-13 20:15:29 +00001183 /* bgp deterministic-med */
1184 new_select = NULL;
1185 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1186 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1187 {
1188 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1189 continue;
1190 if (BGP_INFO_HOLDDOWN (ri1))
1191 continue;
1192
1193 new_select = ri1;
1194 if (ri1->next)
1195 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1196 {
1197 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1198 continue;
1199 if (BGP_INFO_HOLDDOWN (ri2))
1200 continue;
1201
1202 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1203 || aspath_cmp_left_confed (ri1->attr->aspath,
1204 ri2->attr->aspath))
1205 {
1206 if (bgp_info_cmp (bgp, ri2, new_select))
1207 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001208 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001209 new_select = ri2;
1210 }
1211
Paul Jakma1a392d42006-09-07 00:24:49 +00001212 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001213 }
1214 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001215 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1216 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001217 }
1218
1219 /* Check old selected route and new selected route. */
1220 old_select = NULL;
1221 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001222 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001223 {
1224 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1225 old_select = ri;
1226
1227 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001228 {
1229 /* reap REMOVED routes, if needs be
1230 * selected route must stay for a while longer though
1231 */
1232 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1233 && (ri != old_select))
1234 bgp_info_reap (rn, ri);
1235
1236 continue;
1237 }
paul718e3742002-12-13 20:15:29 +00001238
1239 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1240 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1241 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001242 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001243 continue;
1244 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001245 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1246 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001247
1248 if (bgp_info_cmp (bgp, ri, new_select))
1249 new_select = ri;
1250 }
paulb40d9392005-08-22 22:34:41 +00001251
paulfee0f4c2004-09-13 05:12:46 +00001252 result->old = old_select;
1253 result->new = new_select;
1254
1255 return;
1256}
1257
paul94f2b392005-06-28 12:44:16 +00001258static int
paulfee0f4c2004-09-13 05:12:46 +00001259bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1260 struct bgp_node *rn, struct attr *attr, afi_t afi, safi_t safi)
1261 {
1262 struct prefix *p;
1263
1264 p = &rn->p;
1265
1266 /* Announce route to Established peer. */
1267 if (peer->status != Established)
1268 return 0;
1269
1270 /* Address family configuration check. */
1271 if (! peer->afc_nego[afi][safi])
1272 return 0;
1273
1274 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1275 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1276 PEER_STATUS_ORF_WAIT_REFRESH))
1277 return 0;
1278
1279 switch (rn->table->type)
1280 {
1281 case BGP_TABLE_MAIN:
1282 /* Announcement to peer->conf. If the route is filtered,
1283 withdraw it. */
1284 if (selected && bgp_announce_check (selected, peer, p, attr, afi, safi))
1285 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1286 else
1287 bgp_adj_out_unset (rn, peer, p, afi, safi);
1288 break;
1289 case BGP_TABLE_RSCLIENT:
1290 /* Announcement to peer->conf. If the route is filtered,
1291 withdraw it. */
1292 if (selected && bgp_announce_check_rsclient
1293 (selected, peer, p, attr, afi, safi))
1294 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1295 else
1296 bgp_adj_out_unset (rn, peer, p, afi, safi);
1297 break;
1298 }
1299 return 0;
paul200df112005-06-01 11:17:05 +00001300}
paulfee0f4c2004-09-13 05:12:46 +00001301
paul200df112005-06-01 11:17:05 +00001302struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001303{
paul200df112005-06-01 11:17:05 +00001304 struct bgp *bgp;
1305 struct bgp_node *rn;
1306 afi_t afi;
1307 safi_t safi;
1308};
1309
1310static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001311bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001312{
paul0fb58d52005-11-14 14:31:49 +00001313 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001314 struct bgp *bgp = pq->bgp;
1315 struct bgp_node *rn = pq->rn;
1316 afi_t afi = pq->afi;
1317 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001318 struct bgp_info *new_select;
1319 struct bgp_info *old_select;
1320 struct bgp_info_pair old_and_new;
1321 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001322 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001323 struct peer *rsclient = rn->table->owner;
1324
paulfee0f4c2004-09-13 05:12:46 +00001325 /* Best path selection. */
1326 bgp_best_selection (bgp, rn, &old_and_new);
1327 new_select = old_and_new.new;
1328 old_select = old_and_new.old;
1329
paul200df112005-06-01 11:17:05 +00001330 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1331 {
1332 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1333 {
1334 /* Nothing to do. */
1335 if (old_select && old_select == new_select)
1336 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1337 continue;
paulfee0f4c2004-09-13 05:12:46 +00001338
paul200df112005-06-01 11:17:05 +00001339 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001340 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
paul200df112005-06-01 11:17:05 +00001341 if (new_select)
1342 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001343 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1344 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
paul200df112005-06-01 11:17:05 +00001345 }
paulfee0f4c2004-09-13 05:12:46 +00001346
paul200df112005-06-01 11:17:05 +00001347 bgp_process_announce_selected (rsclient, new_select, rn, &attr,
1348 afi, safi);
1349 }
1350 }
1351 else
1352 {
hassob7395792005-08-26 12:58:38 +00001353 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001354 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001355 if (new_select)
1356 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1358 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001359 }
paul200df112005-06-01 11:17:05 +00001360 bgp_process_announce_selected (rsclient, new_select, rn,
1361 &attr, afi, safi);
1362 }
paulfee0f4c2004-09-13 05:12:46 +00001363
paulb40d9392005-08-22 22:34:41 +00001364 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1365 bgp_info_reap (rn, old_select);
1366
paul200df112005-06-01 11:17:05 +00001367 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1368 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001369}
1370
paul200df112005-06-01 11:17:05 +00001371static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001372bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001373{
paul0fb58d52005-11-14 14:31:49 +00001374 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001375 struct bgp *bgp = pq->bgp;
1376 struct bgp_node *rn = pq->rn;
1377 afi_t afi = pq->afi;
1378 safi_t safi = pq->safi;
1379 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001380 struct bgp_info *new_select;
1381 struct bgp_info *old_select;
1382 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001383 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001384 struct peer *peer;
1385 struct attr attr;
paul200df112005-06-01 11:17:05 +00001386
paulfee0f4c2004-09-13 05:12:46 +00001387 /* Best path selection. */
1388 bgp_best_selection (bgp, rn, &old_and_new);
1389 old_select = old_and_new.old;
1390 new_select = old_and_new.new;
1391
1392 /* Nothing to do. */
1393 if (old_select && old_select == new_select)
1394 {
1395 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001396 {
1397 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1398 bgp_zebra_announce (p, old_select, bgp);
1399
1400 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1401 return WQ_SUCCESS;
1402 }
paulfee0f4c2004-09-13 05:12:46 +00001403 }
paul718e3742002-12-13 20:15:29 +00001404
hasso338b3422005-02-23 14:27:24 +00001405 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001406 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001407 if (new_select)
1408 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001409 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1410 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001411 }
1412
1413
paul718e3742002-12-13 20:15:29 +00001414 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001415 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001416 {
paulfee0f4c2004-09-13 05:12:46 +00001417 bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi);
paul718e3742002-12-13 20:15:29 +00001418 }
1419
1420 /* FIB update. */
1421 if (safi == SAFI_UNICAST && ! bgp->name &&
1422 ! bgp_option_check (BGP_OPT_NO_FIB))
1423 {
1424 if (new_select
1425 && new_select->type == ZEBRA_ROUTE_BGP
1426 && new_select->sub_type == BGP_ROUTE_NORMAL)
1427 bgp_zebra_announce (p, new_select, bgp);
1428 else
1429 {
1430 /* Withdraw the route from the kernel. */
1431 if (old_select
1432 && old_select->type == ZEBRA_ROUTE_BGP
1433 && old_select->sub_type == BGP_ROUTE_NORMAL)
1434 bgp_zebra_withdraw (p, old_select);
1435 }
1436 }
paulb40d9392005-08-22 22:34:41 +00001437
1438 /* Reap old select bgp_info, it it has been removed */
1439 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1440 bgp_info_reap (rn, old_select);
1441
paul200df112005-06-01 11:17:05 +00001442 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1443 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001444}
1445
paul200df112005-06-01 11:17:05 +00001446static void
paul0fb58d52005-11-14 14:31:49 +00001447bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001448{
paul0fb58d52005-11-14 14:31:49 +00001449 struct bgp_process_queue *pq = data;
1450
paul200df112005-06-01 11:17:05 +00001451 bgp_unlock_node (pq->rn);
1452 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1453}
1454
1455static void
1456bgp_process_queue_init (void)
1457{
1458 bm->process_main_queue
1459 = work_queue_new (bm->master, "process_main_queue");
1460 bm->process_rsclient_queue
1461 = work_queue_new (bm->master, "process_rsclient_queue");
1462
1463 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1464 {
1465 zlog_err ("%s: Failed to allocate work queue", __func__);
1466 exit (1);
1467 }
1468
1469 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1470 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1471 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1472 bm->process_rsclient_queue->spec.del_item_data
1473 = bm->process_main_queue->spec.del_item_data;
1474 bm->process_main_queue->spec.max_retries
1475 = bm->process_main_queue->spec.max_retries = 0;
1476 bm->process_rsclient_queue->spec.hold
1477 = bm->process_main_queue->spec.hold = 500;
paul200df112005-06-01 11:17:05 +00001478}
1479
1480void
paulfee0f4c2004-09-13 05:12:46 +00001481bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1482{
paul200df112005-06-01 11:17:05 +00001483 struct bgp_process_queue *pqnode;
1484
1485 /* already scheduled for processing? */
1486 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1487 return;
1488
1489 if ( (bm->process_main_queue == NULL) ||
1490 (bm->process_rsclient_queue == NULL) )
1491 bgp_process_queue_init ();
1492
1493 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1494 sizeof (struct bgp_process_queue));
1495 if (!pqnode)
1496 return;
1497
1498 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1499 pqnode->bgp = bgp;
1500 pqnode->afi = afi;
1501 pqnode->safi = safi;
1502
paulfee0f4c2004-09-13 05:12:46 +00001503 switch (rn->table->type)
1504 {
paul200df112005-06-01 11:17:05 +00001505 case BGP_TABLE_MAIN:
1506 work_queue_add (bm->process_main_queue, pqnode);
1507 break;
1508 case BGP_TABLE_RSCLIENT:
1509 work_queue_add (bm->process_rsclient_queue, pqnode);
1510 break;
paulfee0f4c2004-09-13 05:12:46 +00001511 }
paul200df112005-06-01 11:17:05 +00001512
1513 return;
paulfee0f4c2004-09-13 05:12:46 +00001514}
hasso0a486e52005-02-01 20:57:17 +00001515
paul94f2b392005-06-28 12:44:16 +00001516static int
hasso0a486e52005-02-01 20:57:17 +00001517bgp_maximum_prefix_restart_timer (struct thread *thread)
1518{
1519 struct peer *peer;
1520
1521 peer = THREAD_ARG (thread);
1522 peer->t_pmax_restart = NULL;
1523
1524 if (BGP_DEBUG (events, EVENTS))
1525 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1526 peer->host);
1527
1528 peer_clear (peer);
1529
1530 return 0;
1531}
1532
paulfee0f4c2004-09-13 05:12:46 +00001533int
paul5228ad22004-06-04 17:58:18 +00001534bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1535 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001536{
hassoe0701b72004-05-20 09:19:34 +00001537 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1538 return 0;
1539
1540 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001541 {
hassoe0701b72004-05-20 09:19:34 +00001542 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1543 && ! always)
1544 return 0;
paul718e3742002-12-13 20:15:29 +00001545
hassoe0701b72004-05-20 09:19:34 +00001546 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001547 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1548 "limit %ld", afi_safi_print (afi, safi), peer->host,
1549 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001550 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001551
hassoe0701b72004-05-20 09:19:34 +00001552 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1553 return 0;
paul718e3742002-12-13 20:15:29 +00001554
hassoe0701b72004-05-20 09:19:34 +00001555 {
paul5228ad22004-06-04 17:58:18 +00001556 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001557
1558 if (safi == SAFI_MPLS_VPN)
1559 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001560
1561 ndata[0] = (afi >> 8);
1562 ndata[1] = afi;
1563 ndata[2] = safi;
1564 ndata[3] = (peer->pmax[afi][safi] >> 24);
1565 ndata[4] = (peer->pmax[afi][safi] >> 16);
1566 ndata[5] = (peer->pmax[afi][safi] >> 8);
1567 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001568
1569 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1570 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1571 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1572 }
hasso0a486e52005-02-01 20:57:17 +00001573
1574 /* restart timer start */
1575 if (peer->pmax_restart[afi][safi])
1576 {
1577 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1578
1579 if (BGP_DEBUG (events, EVENTS))
1580 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1581 peer->host, peer->v_pmax_restart);
1582
1583 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1584 peer->v_pmax_restart);
1585 }
1586
hassoe0701b72004-05-20 09:19:34 +00001587 return 1;
paul718e3742002-12-13 20:15:29 +00001588 }
hassoe0701b72004-05-20 09:19:34 +00001589 else
1590 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1591
1592 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1593 {
1594 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1595 && ! always)
1596 return 0;
1597
1598 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001599 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1600 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1601 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001602 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1603 }
1604 else
1605 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001606 return 0;
1607}
1608
paulb40d9392005-08-22 22:34:41 +00001609/* Unconditionally remove the route from the RIB, without taking
1610 * damping into consideration (eg, because the session went down)
1611 */
paul94f2b392005-06-28 12:44:16 +00001612static void
paul718e3742002-12-13 20:15:29 +00001613bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1614 afi_t afi, safi_t safi)
1615{
paul902212c2006-02-05 17:51:19 +00001616 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1617
1618 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1619 bgp_info_delete (rn, ri); /* keep historical info */
1620
paulb40d9392005-08-22 22:34:41 +00001621 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001622}
1623
paul94f2b392005-06-28 12:44:16 +00001624static void
paul718e3742002-12-13 20:15:29 +00001625bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001626 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001627{
paul718e3742002-12-13 20:15:29 +00001628 int status = BGP_DAMP_NONE;
1629
paulb40d9392005-08-22 22:34:41 +00001630 /* apply dampening, if result is suppressed, we'll be retaining
1631 * the bgp_info in the RIB for historical reference.
1632 */
1633 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1634 && peer_sort (peer) == BGP_PEER_EBGP)
1635 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1636 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001637 {
paul902212c2006-02-05 17:51:19 +00001638 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1639 return;
1640 }
1641
1642 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001643}
1644
paul94f2b392005-06-28 12:44:16 +00001645static void
paulfee0f4c2004-09-13 05:12:46 +00001646bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1647 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1648 int sub_type, struct prefix_rd *prd, u_char *tag)
1649{
1650 struct bgp_node *rn;
1651 struct bgp *bgp;
1652 struct attr new_attr;
1653 struct attr *attr_new;
1654 struct attr *attr_new2;
1655 struct bgp_info *ri;
1656 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001657 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001658 char buf[SU_ADDRSTRLEN];
1659
1660 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1661 if (peer == rsclient)
1662 return;
1663
1664 bgp = peer->bgp;
1665 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1666
1667 /* Check previously received route. */
1668 for (ri = rn->info; ri; ri = ri->next)
1669 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1670 break;
1671
1672 /* AS path loop check. */
1673 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1674 {
1675 reason = "as-path contains our own AS;";
1676 goto filtered;
1677 }
1678
1679 /* Route reflector originator ID check. */
1680 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1681 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->originator_id))
1682 {
1683 reason = "originator is us;";
1684 goto filtered;
1685 }
1686
1687 new_attr = *attr;
1688
1689 /* Apply export policy. */
1690 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1691 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1692 {
1693 reason = "export-policy;";
1694 goto filtered;
1695 }
1696
1697 attr_new2 = bgp_attr_intern (&new_attr);
1698
1699 /* Apply import policy. */
1700 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1701 {
1702 bgp_attr_unintern (attr_new2);
1703
1704 reason = "import-policy;";
1705 goto filtered;
1706 }
1707
1708 attr_new = bgp_attr_intern (&new_attr);
1709 bgp_attr_unintern (attr_new2);
1710
1711 /* IPv4 unicast next hop check. */
1712 if (afi == AFI_IP && safi == SAFI_UNICAST)
1713 {
1714 /* Next hop must not be 0.0.0.0 nor Class E address. */
1715 if (new_attr.nexthop.s_addr == 0
1716 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1717 {
1718 bgp_attr_unintern (attr_new);
1719
1720 reason = "martian next-hop;";
1721 goto filtered;
1722 }
1723 }
1724
1725 /* If the update is implicit withdraw. */
1726 if (ri)
1727 {
1728 ri->uptime = time (NULL);
1729
1730 /* Same attribute comes in. */
1731 if (attrhash_cmp (ri->attr, attr_new))
1732 {
1733
Paul Jakma1a392d42006-09-07 00:24:49 +00001734 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001735
1736 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001737 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001738 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1739 peer->host,
1740 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1741 p->prefixlen, rsclient->host);
1742
1743 bgp_unlock_node (rn);
1744 bgp_attr_unintern (attr_new);
1745
1746 return;
1747 }
1748
1749 /* Received Logging. */
1750 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001751 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001752 peer->host,
1753 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1754 p->prefixlen, rsclient->host);
1755
1756 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001757 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001758
1759 /* Update to new attribute. */
1760 bgp_attr_unintern (ri->attr);
1761 ri->attr = attr_new;
1762
1763 /* Update MPLS tag. */
1764 if (safi == SAFI_MPLS_VPN)
1765 memcpy (ri->tag, tag, 3);
1766
Paul Jakma1a392d42006-09-07 00:24:49 +00001767 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001768
1769 /* Process change. */
1770 bgp_process (bgp, rn, afi, safi);
1771 bgp_unlock_node (rn);
1772
1773 return;
1774 }
1775
1776 /* Received Logging. */
1777 if (BGP_DEBUG (update, UPDATE_IN))
1778 {
ajsd2c1f162004-12-08 21:10:20 +00001779 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001780 peer->host,
1781 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1782 p->prefixlen, rsclient->host);
1783 }
1784
1785 /* Make new BGP info. */
1786 new = bgp_info_new ();
1787 new->type = type;
1788 new->sub_type = sub_type;
1789 new->peer = peer;
1790 new->attr = attr_new;
1791 new->uptime = time (NULL);
1792
1793 /* Update MPLS tag. */
1794 if (safi == SAFI_MPLS_VPN)
1795 memcpy (new->tag, tag, 3);
1796
Paul Jakma1a392d42006-09-07 00:24:49 +00001797 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001798
1799 /* Register new BGP information. */
1800 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001801
1802 /* route_node_get lock */
1803 bgp_unlock_node (rn);
1804
paulfee0f4c2004-09-13 05:12:46 +00001805 /* Process change. */
1806 bgp_process (bgp, rn, afi, safi);
1807
1808 return;
1809
1810 filtered:
1811
1812 /* This BGP update is filtered. Log the reason then update BGP entry. */
1813 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001814 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001815 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1816 peer->host,
1817 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1818 p->prefixlen, rsclient->host, reason);
1819
1820 if (ri)
paulb40d9392005-08-22 22:34:41 +00001821 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001822
1823 bgp_unlock_node (rn);
1824
1825 return;
1826}
1827
paul94f2b392005-06-28 12:44:16 +00001828static void
paulfee0f4c2004-09-13 05:12:46 +00001829bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1830 struct peer *peer, struct prefix *p, int type, int sub_type,
1831 struct prefix_rd *prd, u_char *tag)
1832 {
1833 struct bgp_node *rn;
1834 struct bgp_info *ri;
1835 char buf[SU_ADDRSTRLEN];
1836
1837 if (rsclient == peer)
1838 return;
1839
1840 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1841
1842 /* Lookup withdrawn route. */
1843 for (ri = rn->info; ri; ri = ri->next)
1844 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1845 break;
1846
1847 /* Withdraw specified route from routing table. */
1848 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001849 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001850 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001851 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001852 "%s Can't find the route %s/%d", peer->host,
1853 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1854 p->prefixlen);
1855
1856 /* Unlock bgp_node_get() lock. */
1857 bgp_unlock_node (rn);
1858 }
1859
paul94f2b392005-06-28 12:44:16 +00001860static int
paulfee0f4c2004-09-13 05:12:46 +00001861bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001862 afi_t afi, safi_t safi, int type, int sub_type,
1863 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1864{
1865 int ret;
1866 int aspath_loop_count = 0;
1867 struct bgp_node *rn;
1868 struct bgp *bgp;
1869 struct attr new_attr;
1870 struct attr *attr_new;
1871 struct bgp_info *ri;
1872 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001873 const char *reason;
paul718e3742002-12-13 20:15:29 +00001874 char buf[SU_ADDRSTRLEN];
1875
1876 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001877 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00001878
1879 /* When peer's soft reconfiguration enabled. Record input packet in
1880 Adj-RIBs-In. */
1881 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1882 && peer != bgp->peer_self && ! soft_reconfig)
1883 bgp_adj_in_set (rn, peer, attr);
1884
1885 /* Check previously received route. */
1886 for (ri = rn->info; ri; ri = ri->next)
1887 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1888 break;
1889
1890 /* AS path local-as loop check. */
1891 if (peer->change_local_as)
1892 {
1893 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1894 aspath_loop_count = 1;
1895
1896 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1897 {
1898 reason = "as-path contains our own AS;";
1899 goto filtered;
1900 }
1901 }
1902
1903 /* AS path loop check. */
1904 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1905 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1906 && aspath_loop_check(attr->aspath, bgp->confed_id)
1907 > peer->allowas_in[afi][safi]))
1908 {
1909 reason = "as-path contains our own AS;";
1910 goto filtered;
1911 }
1912
1913 /* Route reflector originator ID check. */
1914 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1915 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1916 {
1917 reason = "originator is us;";
1918 goto filtered;
1919 }
1920
1921 /* Route reflector cluster ID check. */
1922 if (bgp_cluster_filter (peer, attr))
1923 {
1924 reason = "reflected from the same cluster;";
1925 goto filtered;
1926 }
1927
1928 /* Apply incoming filter. */
1929 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1930 {
1931 reason = "filter;";
1932 goto filtered;
1933 }
1934
1935 /* Apply incoming route-map. */
1936 new_attr = *attr;
1937
1938 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1939 {
1940 reason = "route-map;";
1941 goto filtered;
1942 }
1943
1944 /* IPv4 unicast next hop check. */
1945 if (afi == AFI_IP && safi == SAFI_UNICAST)
1946 {
1947 /* If the peer is EBGP and nexthop is not on connected route,
1948 discard it. */
1949 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1950 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00001951 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00001952 {
1953 reason = "non-connected next-hop;";
1954 goto filtered;
1955 }
1956
1957 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1958 must not be my own address. */
1959 if (bgp_nexthop_self (afi, &new_attr)
1960 || new_attr.nexthop.s_addr == 0
1961 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1962 {
1963 reason = "martian next-hop;";
1964 goto filtered;
1965 }
1966 }
1967
1968 attr_new = bgp_attr_intern (&new_attr);
1969
1970 /* If the update is implicit withdraw. */
1971 if (ri)
1972 {
1973 ri->uptime = time (NULL);
1974
1975 /* Same attribute comes in. */
1976 if (attrhash_cmp (ri->attr, attr_new))
1977 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001978 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00001979
1980 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1981 && peer_sort (peer) == BGP_PEER_EBGP
1982 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1983 {
1984 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001985 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001986 peer->host,
1987 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1988 p->prefixlen);
1989
paul902212c2006-02-05 17:51:19 +00001990 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
1991 {
1992 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1993 bgp_process (bgp, rn, afi, safi);
1994 }
paul718e3742002-12-13 20:15:29 +00001995 }
1996 else
1997 {
1998 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001999 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002000 "%s rcvd %s/%d...duplicate ignored",
2001 peer->host,
2002 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2003 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002004
2005 /* graceful restart STALE flag unset. */
2006 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2007 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002008 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002009 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002010 }
paul718e3742002-12-13 20:15:29 +00002011 }
2012
2013 bgp_unlock_node (rn);
2014 bgp_attr_unintern (attr_new);
2015 return 0;
2016 }
2017
2018 /* Received Logging. */
2019 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002020 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002021 peer->host,
2022 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2023 p->prefixlen);
2024
hasso93406d82005-02-02 14:40:33 +00002025 /* graceful restart STALE flag unset. */
2026 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002027 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002028
paul718e3742002-12-13 20:15:29 +00002029 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002030 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002031
2032 /* implicit withdraw, decrement aggregate and pcount here.
2033 * only if update is accepted, they'll increment below.
2034 */
paul902212c2006-02-05 17:51:19 +00002035 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2036
paul718e3742002-12-13 20:15:29 +00002037 /* Update bgp route dampening information. */
2038 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2039 && peer_sort (peer) == BGP_PEER_EBGP)
2040 {
2041 /* This is implicit withdraw so we should update dampening
2042 information. */
2043 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2044 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002045 }
2046
paul718e3742002-12-13 20:15:29 +00002047 /* Update to new attribute. */
2048 bgp_attr_unintern (ri->attr);
2049 ri->attr = attr_new;
2050
2051 /* Update MPLS tag. */
2052 if (safi == SAFI_MPLS_VPN)
2053 memcpy (ri->tag, tag, 3);
2054
2055 /* Update bgp route dampening information. */
2056 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2057 && peer_sort (peer) == BGP_PEER_EBGP)
2058 {
2059 /* Now we do normal update dampening. */
2060 ret = bgp_damp_update (ri, rn, afi, safi);
2061 if (ret == BGP_DAMP_SUPPRESSED)
2062 {
2063 bgp_unlock_node (rn);
2064 return 0;
2065 }
2066 }
2067
2068 /* Nexthop reachability check. */
2069 if ((afi == AFI_IP || afi == AFI_IP6)
2070 && safi == SAFI_UNICAST
2071 && (peer_sort (peer) == BGP_PEER_IBGP
2072 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002073 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002074 {
2075 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002076 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002077 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002078 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002079 }
2080 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002081 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002082
2083 /* Process change. */
2084 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2085
2086 bgp_process (bgp, rn, afi, safi);
2087 bgp_unlock_node (rn);
2088 return 0;
2089 }
2090
2091 /* Received Logging. */
2092 if (BGP_DEBUG (update, UPDATE_IN))
2093 {
ajsd2c1f162004-12-08 21:10:20 +00002094 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002095 peer->host,
2096 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2097 p->prefixlen);
2098 }
2099
paul718e3742002-12-13 20:15:29 +00002100 /* Make new BGP info. */
2101 new = bgp_info_new ();
2102 new->type = type;
2103 new->sub_type = sub_type;
2104 new->peer = peer;
2105 new->attr = attr_new;
2106 new->uptime = time (NULL);
2107
2108 /* Update MPLS tag. */
2109 if (safi == SAFI_MPLS_VPN)
2110 memcpy (new->tag, tag, 3);
2111
2112 /* Nexthop reachability check. */
2113 if ((afi == AFI_IP || afi == AFI_IP6)
2114 && safi == SAFI_UNICAST
2115 && (peer_sort (peer) == BGP_PEER_IBGP
2116 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002117 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002118 {
2119 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002120 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002121 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002122 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002123 }
2124 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002125 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002126
paul902212c2006-02-05 17:51:19 +00002127 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002128 bgp_aggregate_increment (bgp, p, new, afi, safi);
2129
2130 /* Register new BGP information. */
2131 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002132
2133 /* route_node_get lock */
2134 bgp_unlock_node (rn);
2135
paul718e3742002-12-13 20:15:29 +00002136 /* If maximum prefix count is configured and current prefix
2137 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002138 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2139 return -1;
paul718e3742002-12-13 20:15:29 +00002140
2141 /* Process change. */
2142 bgp_process (bgp, rn, afi, safi);
2143
2144 return 0;
2145
2146 /* This BGP update is filtered. Log the reason then update BGP
2147 entry. */
2148 filtered:
2149 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002150 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002151 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2152 peer->host,
2153 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2154 p->prefixlen, reason);
2155
2156 if (ri)
paulb40d9392005-08-22 22:34:41 +00002157 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002158
2159 bgp_unlock_node (rn);
2160
2161 return 0;
2162}
2163
2164int
paulfee0f4c2004-09-13 05:12:46 +00002165bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2166 afi_t afi, safi_t safi, int type, int sub_type,
2167 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2168{
2169 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002170 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002171 struct bgp *bgp;
2172 int ret;
2173
2174 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2175 soft_reconfig);
2176
2177 bgp = peer->bgp;
2178
2179 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002180 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002181 {
2182 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2183 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2184 sub_type, prd, tag);
2185 }
2186
2187 return ret;
2188}
2189
2190int
paul718e3742002-12-13 20:15:29 +00002191bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002192 afi_t afi, safi_t safi, int type, int sub_type,
2193 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002194{
2195 struct bgp *bgp;
2196 char buf[SU_ADDRSTRLEN];
2197 struct bgp_node *rn;
2198 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002199 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002200 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002201
2202 bgp = peer->bgp;
2203
paulfee0f4c2004-09-13 05:12:46 +00002204 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002205 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002206 {
2207 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2208 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2209 }
2210
paul718e3742002-12-13 20:15:29 +00002211 /* Logging. */
2212 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002213 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002214 peer->host,
2215 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2216 p->prefixlen);
2217
2218 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002219 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002220
2221 /* If peer is soft reconfiguration enabled. Record input packet for
2222 further calculation. */
2223 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2224 && peer != bgp->peer_self)
2225 bgp_adj_in_unset (rn, peer);
2226
2227 /* Lookup withdrawn route. */
2228 for (ri = rn->info; ri; ri = ri->next)
2229 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2230 break;
2231
2232 /* Withdraw specified route from routing table. */
2233 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002234 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002235 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002236 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002237 "%s Can't find the route %s/%d", peer->host,
2238 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2239 p->prefixlen);
2240
2241 /* Unlock bgp_node_get() lock. */
2242 bgp_unlock_node (rn);
2243
2244 return 0;
2245}
2246
2247void
2248bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2249{
2250 struct bgp *bgp;
2251 struct attr attr;
2252 struct aspath *aspath;
2253 struct prefix p;
2254 struct bgp_info binfo;
2255 struct peer *from;
2256 int ret = RMAP_DENYMATCH;
2257
2258 bgp = peer->bgp;
2259 from = bgp->peer_self;
2260
2261 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2262 aspath = attr.aspath;
2263 attr.local_pref = bgp->default_local_pref;
2264 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2265
2266 if (afi == AFI_IP)
2267 str2prefix ("0.0.0.0/0", &p);
2268#ifdef HAVE_IPV6
2269 else if (afi == AFI_IP6)
2270 {
2271 str2prefix ("::/0", &p);
2272
2273 /* IPv6 global nexthop must be included. */
2274 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2275 IPV6_MAX_BYTELEN);
2276 attr.mp_nexthop_len = 16;
2277
2278 /* If the peer is on shared nextwork and we have link-local
2279 nexthop set it. */
2280 if (peer->shared_network
2281 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2282 {
2283 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2284 IPV6_MAX_BYTELEN);
2285 attr.mp_nexthop_len = 32;
2286 }
2287 }
2288#endif /* HAVE_IPV6 */
2289 else
2290 return;
2291
2292 if (peer->default_rmap[afi][safi].name)
2293 {
2294 binfo.peer = bgp->peer_self;
2295 binfo.attr = &attr;
2296
paulfee0f4c2004-09-13 05:12:46 +00002297 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2298
paul718e3742002-12-13 20:15:29 +00002299 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2300 RMAP_BGP, &binfo);
2301
paulfee0f4c2004-09-13 05:12:46 +00002302 bgp->peer_self->rmap_type = 0;
2303
paul718e3742002-12-13 20:15:29 +00002304 if (ret == RMAP_DENYMATCH)
2305 {
2306 bgp_attr_flush (&attr);
2307 withdraw = 1;
2308 }
2309 }
2310
2311 if (withdraw)
2312 {
2313 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2314 bgp_default_withdraw_send (peer, afi, safi);
2315 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2316 }
2317 else
2318 {
2319 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2320 bgp_default_update_send (peer, &attr, afi, safi, from);
2321 }
2322
2323 aspath_unintern (aspath);
2324}
2325
2326static void
2327bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002328 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002329{
2330 struct bgp_node *rn;
2331 struct bgp_info *ri;
2332 struct attr attr;
2333
2334 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002335 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002336
2337 if (safi != SAFI_MPLS_VPN
2338 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2339 bgp_default_originate (peer, afi, safi, 0);
2340
2341 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2342 for (ri = rn->info; ri; ri = ri->next)
2343 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2344 {
paulfee0f4c2004-09-13 05:12:46 +00002345 if ( (rsclient) ?
2346 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2347 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002348 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2349 else
2350 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2351 }
2352}
2353
2354void
2355bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2356{
2357 struct bgp_node *rn;
2358 struct bgp_table *table;
2359
2360 if (peer->status != Established)
2361 return;
2362
2363 if (! peer->afc_nego[afi][safi])
2364 return;
2365
2366 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2367 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2368 return;
2369
2370 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002371 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002372 else
2373 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2374 rn = bgp_route_next(rn))
2375 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002376 bgp_announce_table (peer, afi, safi, table, 0);
2377
2378 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2379 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002380}
2381
2382void
2383bgp_announce_route_all (struct peer *peer)
2384{
2385 afi_t afi;
2386 safi_t safi;
2387
2388 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2389 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2390 bgp_announce_route (peer, afi, safi);
2391}
2392
2393static void
paulfee0f4c2004-09-13 05:12:46 +00002394bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2395 safi_t safi, struct bgp_table *table)
2396{
2397 struct bgp_node *rn;
2398 struct bgp_adj_in *ain;
2399
2400 if (! table)
2401 table = rsclient->bgp->rib[afi][safi];
2402
2403 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2404 for (ain = rn->adj_in; ain; ain = ain->next)
2405 {
2406 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2407 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2408 }
2409}
2410
2411void
2412bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2413{
2414 struct bgp_table *table;
2415 struct bgp_node *rn;
2416
2417 if (safi != SAFI_MPLS_VPN)
2418 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2419
2420 else
2421 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2422 rn = bgp_route_next (rn))
2423 if ((table = rn->info) != NULL)
2424 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2425}
2426
2427static void
paul718e3742002-12-13 20:15:29 +00002428bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2429 struct bgp_table *table)
2430{
2431 int ret;
2432 struct bgp_node *rn;
2433 struct bgp_adj_in *ain;
2434
2435 if (! table)
2436 table = peer->bgp->rib[afi][safi];
2437
2438 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2439 for (ain = rn->adj_in; ain; ain = ain->next)
2440 {
2441 if (ain->peer == peer)
2442 {
2443 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2444 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2445 NULL, NULL, 1);
2446 if (ret < 0)
2447 {
2448 bgp_unlock_node (rn);
2449 return;
2450 }
2451 continue;
2452 }
2453 }
2454}
2455
2456void
2457bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2458{
2459 struct bgp_node *rn;
2460 struct bgp_table *table;
2461
2462 if (peer->status != Established)
2463 return;
2464
2465 if (safi != SAFI_MPLS_VPN)
2466 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2467 else
2468 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2469 rn = bgp_route_next (rn))
2470 if ((table = rn->info) != NULL)
2471 bgp_soft_reconfig_table (peer, afi, safi, table);
2472}
2473
paul200df112005-06-01 11:17:05 +00002474static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002475bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002476{
Paul Jakma64e580a2006-02-21 01:09:01 +00002477 struct bgp_node *rn = data;
2478 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002479 struct bgp_adj_in *ain;
2480 struct bgp_adj_out *aout;
2481 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002482 afi_t afi = rn->table->afi;
2483 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002484
Paul Jakma64e580a2006-02-21 01:09:01 +00002485 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002486
Paul Jakma64e580a2006-02-21 01:09:01 +00002487 for (ri = rn->info; ri; ri = ri->next)
2488 if (ri->peer == peer)
paul200df112005-06-01 11:17:05 +00002489 {
2490 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002491 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2492 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002493 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002494 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2495 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002496 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002497 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002498 break;
2499 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002500 for (ain = rn->adj_in; ain; ain = ain->next)
2501 if (ain->peer == peer)
paul200df112005-06-01 11:17:05 +00002502 {
Paul Jakma64e580a2006-02-21 01:09:01 +00002503 bgp_adj_in_remove (rn, ain);
2504 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002505 break;
2506 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002507 for (aout = rn->adj_out; aout; aout = aout->next)
2508 if (aout->peer == peer)
paul200df112005-06-01 11:17:05 +00002509 {
Paul Jakma64e580a2006-02-21 01:09:01 +00002510 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2511 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002512 break;
2513 }
2514 return WQ_SUCCESS;
2515}
2516
2517static void
paul0fb58d52005-11-14 14:31:49 +00002518bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002519{
Paul Jakma64e580a2006-02-21 01:09:01 +00002520 struct bgp_node *rn = data;
2521
2522 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002523}
2524
2525static void
paul94f2b392005-06-28 12:44:16 +00002526bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002527{
Paul Jakma64e580a2006-02-21 01:09:01 +00002528 struct peer *peer = wq->spec.data;
2529
Paul Jakma64e580a2006-02-21 01:09:01 +00002530 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002531
2532 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002533 BGP_EVENT_ADD (peer, Clearing_Completed);
paul200df112005-06-01 11:17:05 +00002534}
2535
2536static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002537bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002538{
Paul Jakma64e580a2006-02-21 01:09:01 +00002539#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2540 char wname[CLEAR_QUEUE_NAME_LEN];
2541
2542 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2543#undef CLEAR_QUEUE_NAME_LEN
2544
2545 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002546 {
2547 zlog_err ("%s: Failed to allocate work queue", __func__);
2548 exit (1);
2549 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002550 peer->clear_node_queue->spec.hold = 10;
2551 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2552 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2553 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2554 peer->clear_node_queue->spec.max_retries = 0;
2555
2556 /* we only 'lock' this peer reference when the queue is actually active */
2557 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002558}
2559
paul718e3742002-12-13 20:15:29 +00002560static void
2561bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002562 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002563{
2564 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002565
paul718e3742002-12-13 20:15:29 +00002566 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002567 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002568
hasso6cf159b2005-03-21 10:28:14 +00002569 /* If still no table => afi/safi isn't configured at all or smth. */
2570 if (! table)
2571 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002572
2573 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2574 {
2575 if (rn->info == NULL)
2576 continue;
2577
2578 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2579 work_queue_add (peer->clear_node_queue, rn);
2580 }
2581 return;
2582}
2583
2584void
2585bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2586{
2587 struct bgp_node *rn;
2588 struct bgp_table *table;
2589 struct peer *rsclient;
2590 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002591
Paul Jakma64e580a2006-02-21 01:09:01 +00002592 if (peer->clear_node_queue == NULL)
2593 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002594
Paul Jakmaca058a32006-09-14 02:58:49 +00002595 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2596 * Idle until it receives a Clearing_Completed event. This protects
2597 * against peers which flap faster than we can we clear, which could
2598 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002599 *
2600 * a) race with routes from the new session being installed before
2601 * clear_route_node visits the node (to delete the route of that
2602 * peer)
2603 * b) resource exhaustion, clear_route_node likely leads to an entry
2604 * on the process_main queue. Fast-flapping could cause that queue
2605 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002606 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002607 if (!peer->clear_node_queue->thread)
2608 peer_lock (peer); /* bgp_clear_node_complete */
paul200df112005-06-01 11:17:05 +00002609
paul718e3742002-12-13 20:15:29 +00002610 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002611 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002612 else
2613 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2614 rn = bgp_route_next (rn))
2615 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002616 bgp_clear_route_table (peer, afi, safi, table, NULL);
2617
paul1eb8ef22005-04-07 07:30:20 +00002618 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002619 {
2620 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2621 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2622 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002623
Paul Jakmaca058a32006-09-14 02:58:49 +00002624 /* If no routes were cleared, nothing was added to workqueue, the
2625 * completion function won't be run by workqueue code - call it here.
2626 *
2627 * Additionally, there is a presumption in FSM that clearing is only
2628 * needed if peer state is Established - peers in pre-Established states
2629 * shouldn't have any route-update state associated with them (in or out).
2630 *
2631 * We still get here from FSM through bgp_stop->clear_route_all in
2632 * pre-Established though, so this is a useful sanity check to ensure
2633 * the assumption above holds.
2634 *
2635 * At some future point, this check could be move to the top of the
2636 * function, and do a quick early-return when state is
2637 * pre-Established, avoiding above list and table scans. Once we're
2638 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002639 */
2640 if (!peer->clear_node_queue->thread)
2641 bgp_clear_node_complete (peer->clear_node_queue);
Paul Jakmaca058a32006-09-14 02:58:49 +00002642 else
2643 {
2644 /* clearing queue scheduled. Normal if in Established state
2645 * (and about to transition out of it), but otherwise...
2646 */
2647 if (peer->status != Established)
2648 {
2649 plog_err (peer->log, "%s [Error] State %s is not Established,"
2650 " but routes were cleared - bug!",
2651 peer->host, LOOKUP (bgp_status_msg, peer->status));
2652 assert (peer->status == Established);
2653 }
2654 }
paul718e3742002-12-13 20:15:29 +00002655}
2656
2657void
2658bgp_clear_route_all (struct peer *peer)
2659{
2660 afi_t afi;
2661 safi_t safi;
2662
2663 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2664 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2665 bgp_clear_route (peer, afi, safi);
2666}
2667
2668void
2669bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2670{
2671 struct bgp_table *table;
2672 struct bgp_node *rn;
2673 struct bgp_adj_in *ain;
2674
2675 table = peer->bgp->rib[afi][safi];
2676
2677 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2678 for (ain = rn->adj_in; ain ; ain = ain->next)
2679 if (ain->peer == peer)
2680 {
2681 bgp_adj_in_remove (rn, ain);
2682 bgp_unlock_node (rn);
2683 break;
2684 }
2685}
hasso93406d82005-02-02 14:40:33 +00002686
2687void
2688bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2689{
2690 struct bgp_node *rn;
2691 struct bgp_info *ri;
2692 struct bgp_table *table;
2693
2694 table = peer->bgp->rib[afi][safi];
2695
2696 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2697 {
2698 for (ri = rn->info; ri; ri = ri->next)
2699 if (ri->peer == peer)
2700 {
2701 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2702 bgp_rib_remove (rn, ri, peer, afi, safi);
2703 break;
2704 }
2705 }
2706}
paul718e3742002-12-13 20:15:29 +00002707
2708/* Delete all kernel routes. */
2709void
paul545acaf2004-04-20 15:13:15 +00002710bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002711{
2712 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002713 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002714 struct bgp_node *rn;
2715 struct bgp_table *table;
2716 struct bgp_info *ri;
2717
paul1eb8ef22005-04-07 07:30:20 +00002718 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002719 {
2720 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2721
2722 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2723 for (ri = rn->info; ri; ri = ri->next)
2724 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2725 && ri->type == ZEBRA_ROUTE_BGP
2726 && ri->sub_type == BGP_ROUTE_NORMAL)
2727 bgp_zebra_withdraw (&rn->p, ri);
2728
2729 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2730
2731 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2732 for (ri = rn->info; ri; ri = ri->next)
2733 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2734 && ri->type == ZEBRA_ROUTE_BGP
2735 && ri->sub_type == BGP_ROUTE_NORMAL)
2736 bgp_zebra_withdraw (&rn->p, ri);
2737 }
2738}
2739
2740void
2741bgp_reset ()
2742{
2743 vty_reset ();
2744 bgp_zclient_reset ();
2745 access_list_reset ();
2746 prefix_list_reset ();
2747}
2748
2749/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2750 value. */
2751int
2752bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2753{
2754 u_char *pnt;
2755 u_char *lim;
2756 struct prefix p;
2757 int psize;
2758 int ret;
2759
2760 /* Check peer status. */
2761 if (peer->status != Established)
2762 return 0;
2763
2764 pnt = packet->nlri;
2765 lim = pnt + packet->length;
2766
2767 for (; pnt < lim; pnt += psize)
2768 {
2769 /* Clear prefix structure. */
2770 memset (&p, 0, sizeof (struct prefix));
2771
2772 /* Fetch prefix length. */
2773 p.prefixlen = *pnt++;
2774 p.family = afi2family (packet->afi);
2775
2776 /* Already checked in nlri_sanity_check(). We do double check
2777 here. */
2778 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2779 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2780 return -1;
2781
2782 /* Packet size overflow check. */
2783 psize = PSIZE (p.prefixlen);
2784
2785 /* When packet overflow occur return immediately. */
2786 if (pnt + psize > lim)
2787 return -1;
2788
2789 /* Fetch prefix from NLRI packet. */
2790 memcpy (&p.u.prefix, pnt, psize);
2791
2792 /* Check address. */
2793 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2794 {
2795 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2796 {
paulf5ba3872004-07-09 12:11:31 +00002797 /*
2798 * From draft-ietf-idr-bgp4-22, Section 6.3:
2799 * If a BGP router receives an UPDATE message with a
2800 * semantically incorrect NLRI field, in which a prefix is
2801 * semantically incorrect (eg. an unexpected multicast IP
2802 * address), it should ignore the prefix.
2803 */
paul718e3742002-12-13 20:15:29 +00002804 zlog (peer->log, LOG_ERR,
2805 "IPv4 unicast NLRI is multicast address %s",
2806 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002807
paul718e3742002-12-13 20:15:29 +00002808 return -1;
2809 }
2810 }
2811
2812#ifdef HAVE_IPV6
2813 /* Check address. */
2814 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2815 {
2816 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2817 {
2818 char buf[BUFSIZ];
2819
2820 zlog (peer->log, LOG_WARNING,
2821 "IPv6 link-local NLRI received %s ignore this NLRI",
2822 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2823
2824 continue;
2825 }
2826 }
2827#endif /* HAVE_IPV6 */
2828
2829 /* Normal process. */
2830 if (attr)
2831 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2832 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2833 else
2834 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2835 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2836
2837 /* Address family configuration mismatch or maximum-prefix count
2838 overflow. */
2839 if (ret < 0)
2840 return -1;
2841 }
2842
2843 /* Packet length consistency check. */
2844 if (pnt != lim)
2845 return -1;
2846
2847 return 0;
2848}
2849
2850/* NLRI encode syntax check routine. */
2851int
2852bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2853 bgp_size_t length)
2854{
2855 u_char *end;
2856 u_char prefixlen;
2857 int psize;
2858
2859 end = pnt + length;
2860
2861 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2862 syntactic validity. If the field is syntactically incorrect,
2863 then the Error Subcode is set to Invalid Network Field. */
2864
2865 while (pnt < end)
2866 {
2867 prefixlen = *pnt++;
2868
2869 /* Prefix length check. */
2870 if ((afi == AFI_IP && prefixlen > 32)
2871 || (afi == AFI_IP6 && prefixlen > 128))
2872 {
2873 plog_err (peer->log,
2874 "%s [Error] Update packet error (wrong prefix length %d)",
2875 peer->host, prefixlen);
2876 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2877 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2878 return -1;
2879 }
2880
2881 /* Packet size overflow check. */
2882 psize = PSIZE (prefixlen);
2883
2884 if (pnt + psize > end)
2885 {
2886 plog_err (peer->log,
2887 "%s [Error] Update packet error"
2888 " (prefix data overflow prefix size is %d)",
2889 peer->host, psize);
2890 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2891 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2892 return -1;
2893 }
2894
2895 pnt += psize;
2896 }
2897
2898 /* Packet length consistency check. */
2899 if (pnt != end)
2900 {
2901 plog_err (peer->log,
2902 "%s [Error] Update packet error"
2903 " (prefix length mismatch with total length)",
2904 peer->host);
2905 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2906 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2907 return -1;
2908 }
2909 return 0;
2910}
2911
paul94f2b392005-06-28 12:44:16 +00002912static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002913bgp_static_new ()
2914{
2915 struct bgp_static *new;
2916 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2917 memset (new, 0, sizeof (struct bgp_static));
2918 return new;
2919}
2920
paul94f2b392005-06-28 12:44:16 +00002921static void
paul718e3742002-12-13 20:15:29 +00002922bgp_static_free (struct bgp_static *bgp_static)
2923{
2924 if (bgp_static->rmap.name)
2925 free (bgp_static->rmap.name);
2926 XFREE (MTYPE_BGP_STATIC, bgp_static);
2927}
2928
paul94f2b392005-06-28 12:44:16 +00002929static void
paulfee0f4c2004-09-13 05:12:46 +00002930bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2931 struct prefix *p, afi_t afi, safi_t safi)
2932{
2933 struct bgp_node *rn;
2934 struct bgp_info *ri;
2935
2936 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2937
2938 /* Check selected route and self inserted route. */
2939 for (ri = rn->info; ri; ri = ri->next)
2940 if (ri->peer == bgp->peer_self
2941 && ri->type == ZEBRA_ROUTE_BGP
2942 && ri->sub_type == BGP_ROUTE_STATIC)
2943 break;
2944
2945 /* Withdraw static BGP route from routing table. */
2946 if (ri)
2947 {
paulfee0f4c2004-09-13 05:12:46 +00002948 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00002949 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002950 }
2951
2952 /* Unlock bgp_node_lookup. */
2953 bgp_unlock_node (rn);
2954}
2955
paul94f2b392005-06-28 12:44:16 +00002956static void
paulfee0f4c2004-09-13 05:12:46 +00002957bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2958 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2959{
2960 struct bgp_node *rn;
2961 struct bgp_info *ri;
2962 struct bgp_info *new;
2963 struct bgp_info info;
2964 struct attr new_attr;
2965 struct attr *attr_new;
2966 struct attr attr;
2967 struct bgp *bgp;
2968 int ret;
2969 char buf[SU_ADDRSTRLEN];
2970
2971 bgp = rsclient->bgp;
2972
Paul Jakma06e110f2006-05-12 23:29:22 +00002973 assert (bgp_static);
2974 if (!bgp_static)
2975 return;
2976
paulfee0f4c2004-09-13 05:12:46 +00002977 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2978
2979 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00002980
2981 attr.nexthop = bgp_static->igpnexthop;
2982 attr.med = bgp_static->igpmetric;
2983 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paulfee0f4c2004-09-13 05:12:46 +00002984
2985 new_attr = attr;
2986
2987 /* Apply network route-map for export to this rsclient. */
2988 if (bgp_static->rmap.name)
2989 {
2990 info.peer = rsclient;
2991 info.attr = &new_attr;
2992
2993 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2994 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2995
2996 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2997
2998 rsclient->rmap_type = 0;
2999
3000 if (ret == RMAP_DENYMATCH)
3001 {
3002 /* Free uninterned attribute. */
3003 bgp_attr_flush (&new_attr);
3004
3005 /* Unintern original. */
3006 aspath_unintern (attr.aspath);
3007 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3008
3009 return;
3010 }
3011 attr_new = bgp_attr_intern (&new_attr);
3012 }
3013 else
3014 attr_new = bgp_attr_intern (&attr);
3015
3016 new_attr = *attr_new;
3017
3018 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3019
3020 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
3021{
3022 /* This BGP update is filtered. Log the reason then update BGP entry. */
3023 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003024 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003025 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3026 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3027 p->prefixlen, rsclient->host);
3028
3029 bgp->peer_self->rmap_type = 0;
3030
3031 bgp_attr_unintern (attr_new);
3032 aspath_unintern (attr.aspath);
3033
3034 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3035
3036 return;
3037 }
3038
3039 bgp->peer_self->rmap_type = 0;
3040
3041 bgp_attr_unintern (attr_new);
3042 attr_new = bgp_attr_intern (&new_attr);
3043
3044 for (ri = rn->info; ri; ri = ri->next)
3045 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3046 && ri->sub_type == BGP_ROUTE_STATIC)
3047 break;
3048
3049 if (ri)
3050 {
3051 if (attrhash_cmp (ri->attr, attr_new))
3052 {
3053 bgp_unlock_node (rn);
3054 bgp_attr_unintern (attr_new);
3055 aspath_unintern (attr.aspath);
3056 return;
3057 }
3058 else
3059 {
3060 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003061 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003062
3063 /* Rewrite BGP route information. */
3064 bgp_attr_unintern (ri->attr);
3065 ri->attr = attr_new;
3066 ri->uptime = time (NULL);
3067
3068 /* Process change. */
3069 bgp_process (bgp, rn, afi, safi);
3070 bgp_unlock_node (rn);
3071 aspath_unintern (attr.aspath);
3072 return;
3073 }
3074}
3075
3076 /* Make new BGP info. */
3077 new = bgp_info_new ();
3078 new->type = ZEBRA_ROUTE_BGP;
3079 new->sub_type = BGP_ROUTE_STATIC;
3080 new->peer = bgp->peer_self;
3081 SET_FLAG (new->flags, BGP_INFO_VALID);
3082 new->attr = attr_new;
3083 new->uptime = time (NULL);
3084
3085 /* Register new BGP information. */
3086 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003087
3088 /* route_node_get lock */
3089 bgp_unlock_node (rn);
3090
paulfee0f4c2004-09-13 05:12:46 +00003091 /* Process change. */
3092 bgp_process (bgp, rn, afi, safi);
3093
3094 /* Unintern original. */
3095 aspath_unintern (attr.aspath);
3096}
3097
paul94f2b392005-06-28 12:44:16 +00003098static void
paulfee0f4c2004-09-13 05:12:46 +00003099bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003100 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3101{
3102 struct bgp_node *rn;
3103 struct bgp_info *ri;
3104 struct bgp_info *new;
3105 struct bgp_info info;
3106 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003107 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003108 struct attr *attr_new;
3109 int ret;
3110
Paul Jakmadd8103a2006-05-12 23:27:30 +00003111 assert (bgp_static);
3112 if (!bgp_static)
3113 return;
3114
paulfee0f4c2004-09-13 05:12:46 +00003115 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003116
3117 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003118
3119 attr.nexthop = bgp_static->igpnexthop;
3120 attr.med = bgp_static->igpmetric;
3121 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003122
3123 /* Apply route-map. */
3124 if (bgp_static->rmap.name)
3125 {
paul286e1e72003-08-08 00:24:31 +00003126 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003127 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003128 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003129
paulfee0f4c2004-09-13 05:12:46 +00003130 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3131
paul718e3742002-12-13 20:15:29 +00003132 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003133
paulfee0f4c2004-09-13 05:12:46 +00003134 bgp->peer_self->rmap_type = 0;
3135
paul718e3742002-12-13 20:15:29 +00003136 if (ret == RMAP_DENYMATCH)
3137 {
3138 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003139 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003140
3141 /* Unintern original. */
3142 aspath_unintern (attr.aspath);
3143 bgp_static_withdraw (bgp, p, afi, safi);
3144 return;
3145 }
paul286e1e72003-08-08 00:24:31 +00003146 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003147 }
paul286e1e72003-08-08 00:24:31 +00003148 else
3149 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003150
3151 for (ri = rn->info; ri; ri = ri->next)
3152 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3153 && ri->sub_type == BGP_ROUTE_STATIC)
3154 break;
3155
3156 if (ri)
3157 {
3158 if (attrhash_cmp (ri->attr, attr_new))
3159 {
3160 bgp_unlock_node (rn);
3161 bgp_attr_unintern (attr_new);
3162 aspath_unintern (attr.aspath);
3163 return;
3164 }
3165 else
3166 {
3167 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003168 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003169
3170 /* Rewrite BGP route information. */
3171 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3172 bgp_attr_unintern (ri->attr);
3173 ri->attr = attr_new;
3174 ri->uptime = time (NULL);
3175
3176 /* Process change. */
3177 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3178 bgp_process (bgp, rn, afi, safi);
3179 bgp_unlock_node (rn);
3180 aspath_unintern (attr.aspath);
3181 return;
3182 }
3183 }
3184
3185 /* Make new BGP info. */
3186 new = bgp_info_new ();
3187 new->type = ZEBRA_ROUTE_BGP;
3188 new->sub_type = BGP_ROUTE_STATIC;
3189 new->peer = bgp->peer_self;
3190 SET_FLAG (new->flags, BGP_INFO_VALID);
3191 new->attr = attr_new;
3192 new->uptime = time (NULL);
3193
3194 /* Aggregate address increment. */
3195 bgp_aggregate_increment (bgp, p, new, afi, safi);
3196
3197 /* Register new BGP information. */
3198 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003199
3200 /* route_node_get lock */
3201 bgp_unlock_node (rn);
3202
paul718e3742002-12-13 20:15:29 +00003203 /* Process change. */
3204 bgp_process (bgp, rn, afi, safi);
3205
3206 /* Unintern original. */
3207 aspath_unintern (attr.aspath);
3208}
3209
3210void
paulfee0f4c2004-09-13 05:12:46 +00003211bgp_static_update (struct bgp *bgp, struct prefix *p,
3212 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3213{
3214 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003215 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003216
3217 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3218
paul1eb8ef22005-04-07 07:30:20 +00003219 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003220 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003221 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3222 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003223 }
3224}
3225
paul94f2b392005-06-28 12:44:16 +00003226static void
paul718e3742002-12-13 20:15:29 +00003227bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3228 u_char safi, struct prefix_rd *prd, u_char *tag)
3229{
3230 struct bgp_node *rn;
3231 struct bgp_info *new;
3232
paulfee0f4c2004-09-13 05:12:46 +00003233 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003234
3235 /* Make new BGP info. */
3236 new = bgp_info_new ();
3237 new->type = ZEBRA_ROUTE_BGP;
3238 new->sub_type = BGP_ROUTE_STATIC;
3239 new->peer = bgp->peer_self;
3240 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3241 SET_FLAG (new->flags, BGP_INFO_VALID);
3242 new->uptime = time (NULL);
3243 memcpy (new->tag, tag, 3);
3244
3245 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003246 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003247
3248 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003249 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003250
paul200df112005-06-01 11:17:05 +00003251 /* route_node_get lock */
3252 bgp_unlock_node (rn);
3253
paul718e3742002-12-13 20:15:29 +00003254 /* Process change. */
3255 bgp_process (bgp, rn, afi, safi);
3256}
3257
3258void
3259bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3260 safi_t safi)
3261{
3262 struct bgp_node *rn;
3263 struct bgp_info *ri;
3264
paulfee0f4c2004-09-13 05:12:46 +00003265 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003266
3267 /* Check selected route and self inserted route. */
3268 for (ri = rn->info; ri; ri = ri->next)
3269 if (ri->peer == bgp->peer_self
3270 && ri->type == ZEBRA_ROUTE_BGP
3271 && ri->sub_type == BGP_ROUTE_STATIC)
3272 break;
3273
3274 /* Withdraw static BGP route from routing table. */
3275 if (ri)
3276 {
3277 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003278 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003279 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003280 }
3281
3282 /* Unlock bgp_node_lookup. */
3283 bgp_unlock_node (rn);
3284}
3285
3286void
paulfee0f4c2004-09-13 05:12:46 +00003287bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3288{
3289 struct bgp_static *bgp_static;
3290 struct bgp *bgp;
3291 struct bgp_node *rn;
3292 struct prefix *p;
3293
3294 bgp = rsclient->bgp;
3295
3296 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3297 if ((bgp_static = rn->info) != NULL)
3298 {
3299 p = &rn->p;
3300
3301 bgp_static_update_rsclient (rsclient, p, bgp_static,
3302 afi, safi);
3303 }
3304}
3305
paul94f2b392005-06-28 12:44:16 +00003306static void
paul718e3742002-12-13 20:15:29 +00003307bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3308 u_char safi, struct prefix_rd *prd, u_char *tag)
3309{
3310 struct bgp_node *rn;
3311 struct bgp_info *ri;
3312
paulfee0f4c2004-09-13 05:12:46 +00003313 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003314
3315 /* Check selected route and self inserted route. */
3316 for (ri = rn->info; ri; ri = ri->next)
3317 if (ri->peer == bgp->peer_self
3318 && ri->type == ZEBRA_ROUTE_BGP
3319 && ri->sub_type == BGP_ROUTE_STATIC)
3320 break;
3321
3322 /* Withdraw static BGP route from routing table. */
3323 if (ri)
3324 {
3325 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003326 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003327 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003328 }
3329
3330 /* Unlock bgp_node_lookup. */
3331 bgp_unlock_node (rn);
3332}
3333
3334/* Configure static BGP network. When user don't run zebra, static
3335 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003336static int
paulfd79ac92004-10-13 05:06:08 +00003337bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3338 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003339{
3340 int ret;
3341 struct prefix p;
3342 struct bgp_static *bgp_static;
3343 struct bgp_node *rn;
3344 int need_update = 0;
3345
3346 /* Convert IP prefix string to struct prefix. */
3347 ret = str2prefix (ip_str, &p);
3348 if (! ret)
3349 {
3350 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3351 return CMD_WARNING;
3352 }
3353#ifdef HAVE_IPV6
3354 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3355 {
3356 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3357 VTY_NEWLINE);
3358 return CMD_WARNING;
3359 }
3360#endif /* HAVE_IPV6 */
3361
3362 apply_mask (&p);
3363
3364 /* Set BGP static route configuration. */
3365 rn = bgp_node_get (bgp->route[afi][safi], &p);
3366
3367 if (rn->info)
3368 {
3369 /* Configuration change. */
3370 bgp_static = rn->info;
3371
3372 /* Check previous routes are installed into BGP. */
3373 if (! bgp_static->backdoor && bgp_static->valid)
3374 need_update = 1;
3375
3376 bgp_static->backdoor = backdoor;
3377 if (rmap)
3378 {
3379 if (bgp_static->rmap.name)
3380 free (bgp_static->rmap.name);
3381 bgp_static->rmap.name = strdup (rmap);
3382 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3383 }
3384 else
3385 {
3386 if (bgp_static->rmap.name)
3387 free (bgp_static->rmap.name);
3388 bgp_static->rmap.name = NULL;
3389 bgp_static->rmap.map = NULL;
3390 bgp_static->valid = 0;
3391 }
3392 bgp_unlock_node (rn);
3393 }
3394 else
3395 {
3396 /* New configuration. */
3397 bgp_static = bgp_static_new ();
3398 bgp_static->backdoor = backdoor;
3399 bgp_static->valid = 0;
3400 bgp_static->igpmetric = 0;
3401 bgp_static->igpnexthop.s_addr = 0;
3402 if (rmap)
3403 {
3404 if (bgp_static->rmap.name)
3405 free (bgp_static->rmap.name);
3406 bgp_static->rmap.name = strdup (rmap);
3407 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3408 }
3409 rn->info = bgp_static;
3410 }
3411
3412 /* If BGP scan is not enabled, we should install this route here. */
3413 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3414 {
3415 bgp_static->valid = 1;
3416
3417 if (need_update)
3418 bgp_static_withdraw (bgp, &p, afi, safi);
3419
3420 if (! bgp_static->backdoor)
3421 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3422 }
3423
3424 return CMD_SUCCESS;
3425}
3426
3427/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003428static int
paulfd79ac92004-10-13 05:06:08 +00003429bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003430 u_int16_t afi, u_char safi)
3431{
3432 int ret;
3433 struct prefix p;
3434 struct bgp_static *bgp_static;
3435 struct bgp_node *rn;
3436
3437 /* Convert IP prefix string to struct prefix. */
3438 ret = str2prefix (ip_str, &p);
3439 if (! ret)
3440 {
3441 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3442 return CMD_WARNING;
3443 }
3444#ifdef HAVE_IPV6
3445 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3446 {
3447 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3448 VTY_NEWLINE);
3449 return CMD_WARNING;
3450 }
3451#endif /* HAVE_IPV6 */
3452
3453 apply_mask (&p);
3454
3455 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3456 if (! rn)
3457 {
3458 vty_out (vty, "%% Can't find specified static route configuration.%s",
3459 VTY_NEWLINE);
3460 return CMD_WARNING;
3461 }
3462
3463 bgp_static = rn->info;
3464
3465 /* Update BGP RIB. */
3466 if (! bgp_static->backdoor)
3467 bgp_static_withdraw (bgp, &p, afi, safi);
3468
3469 /* Clear configuration. */
3470 bgp_static_free (bgp_static);
3471 rn->info = NULL;
3472 bgp_unlock_node (rn);
3473 bgp_unlock_node (rn);
3474
3475 return CMD_SUCCESS;
3476}
3477
3478/* Called from bgp_delete(). Delete all static routes from the BGP
3479 instance. */
3480void
3481bgp_static_delete (struct bgp *bgp)
3482{
3483 afi_t afi;
3484 safi_t safi;
3485 struct bgp_node *rn;
3486 struct bgp_node *rm;
3487 struct bgp_table *table;
3488 struct bgp_static *bgp_static;
3489
3490 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3491 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3492 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3493 if (rn->info != NULL)
3494 {
3495 if (safi == SAFI_MPLS_VPN)
3496 {
3497 table = rn->info;
3498
3499 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3500 {
3501 bgp_static = rn->info;
3502 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3503 AFI_IP, SAFI_MPLS_VPN,
3504 (struct prefix_rd *)&rn->p,
3505 bgp_static->tag);
3506 bgp_static_free (bgp_static);
3507 rn->info = NULL;
3508 bgp_unlock_node (rn);
3509 }
3510 }
3511 else
3512 {
3513 bgp_static = rn->info;
3514 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3515 bgp_static_free (bgp_static);
3516 rn->info = NULL;
3517 bgp_unlock_node (rn);
3518 }
3519 }
3520}
3521
3522int
paulfd79ac92004-10-13 05:06:08 +00003523bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3524 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003525{
3526 int ret;
3527 struct prefix p;
3528 struct prefix_rd prd;
3529 struct bgp *bgp;
3530 struct bgp_node *prn;
3531 struct bgp_node *rn;
3532 struct bgp_table *table;
3533 struct bgp_static *bgp_static;
3534 u_char tag[3];
3535
3536 bgp = vty->index;
3537
3538 ret = str2prefix (ip_str, &p);
3539 if (! ret)
3540 {
3541 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3542 return CMD_WARNING;
3543 }
3544 apply_mask (&p);
3545
3546 ret = str2prefix_rd (rd_str, &prd);
3547 if (! ret)
3548 {
3549 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3550 return CMD_WARNING;
3551 }
3552
3553 ret = str2tag (tag_str, tag);
3554 if (! ret)
3555 {
3556 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3557 return CMD_WARNING;
3558 }
3559
3560 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3561 (struct prefix *)&prd);
3562 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003563 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003564 else
3565 bgp_unlock_node (prn);
3566 table = prn->info;
3567
3568 rn = bgp_node_get (table, &p);
3569
3570 if (rn->info)
3571 {
3572 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3573 bgp_unlock_node (rn);
3574 }
3575 else
3576 {
3577 /* New configuration. */
3578 bgp_static = bgp_static_new ();
3579 bgp_static->valid = 1;
3580 memcpy (bgp_static->tag, tag, 3);
3581 rn->info = bgp_static;
3582
3583 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3584 }
3585
3586 return CMD_SUCCESS;
3587}
3588
3589/* Configure static BGP network. */
3590int
paulfd79ac92004-10-13 05:06:08 +00003591bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3592 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003593{
3594 int ret;
3595 struct bgp *bgp;
3596 struct prefix p;
3597 struct prefix_rd prd;
3598 struct bgp_node *prn;
3599 struct bgp_node *rn;
3600 struct bgp_table *table;
3601 struct bgp_static *bgp_static;
3602 u_char tag[3];
3603
3604 bgp = vty->index;
3605
3606 /* Convert IP prefix string to struct prefix. */
3607 ret = str2prefix (ip_str, &p);
3608 if (! ret)
3609 {
3610 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3611 return CMD_WARNING;
3612 }
3613 apply_mask (&p);
3614
3615 ret = str2prefix_rd (rd_str, &prd);
3616 if (! ret)
3617 {
3618 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3619 return CMD_WARNING;
3620 }
3621
3622 ret = str2tag (tag_str, tag);
3623 if (! ret)
3624 {
3625 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3626 return CMD_WARNING;
3627 }
3628
3629 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3630 (struct prefix *)&prd);
3631 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003632 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003633 else
3634 bgp_unlock_node (prn);
3635 table = prn->info;
3636
3637 rn = bgp_node_lookup (table, &p);
3638
3639 if (rn)
3640 {
3641 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3642
3643 bgp_static = rn->info;
3644 bgp_static_free (bgp_static);
3645 rn->info = NULL;
3646 bgp_unlock_node (rn);
3647 bgp_unlock_node (rn);
3648 }
3649 else
3650 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3651
3652 return CMD_SUCCESS;
3653}
3654
3655DEFUN (bgp_network,
3656 bgp_network_cmd,
3657 "network A.B.C.D/M",
3658 "Specify a network to announce via BGP\n"
3659 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3660{
3661 return bgp_static_set (vty, vty->index, argv[0],
3662 AFI_IP, bgp_node_safi (vty), NULL, 0);
3663}
3664
3665DEFUN (bgp_network_route_map,
3666 bgp_network_route_map_cmd,
3667 "network A.B.C.D/M route-map WORD",
3668 "Specify a network to announce via BGP\n"
3669 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3670 "Route-map to modify the attributes\n"
3671 "Name of the route map\n")
3672{
3673 return bgp_static_set (vty, vty->index, argv[0],
3674 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3675}
3676
3677DEFUN (bgp_network_backdoor,
3678 bgp_network_backdoor_cmd,
3679 "network A.B.C.D/M backdoor",
3680 "Specify a network to announce via BGP\n"
3681 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3682 "Specify a BGP backdoor route\n")
3683{
3684 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3685}
3686
3687DEFUN (bgp_network_mask,
3688 bgp_network_mask_cmd,
3689 "network A.B.C.D mask A.B.C.D",
3690 "Specify a network to announce via BGP\n"
3691 "Network number\n"
3692 "Network mask\n"
3693 "Network mask\n")
3694{
3695 int ret;
3696 char prefix_str[BUFSIZ];
3697
3698 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3699 if (! ret)
3700 {
3701 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3702 return CMD_WARNING;
3703 }
3704
3705 return bgp_static_set (vty, vty->index, prefix_str,
3706 AFI_IP, bgp_node_safi (vty), NULL, 0);
3707}
3708
3709DEFUN (bgp_network_mask_route_map,
3710 bgp_network_mask_route_map_cmd,
3711 "network A.B.C.D mask A.B.C.D route-map WORD",
3712 "Specify a network to announce via BGP\n"
3713 "Network number\n"
3714 "Network mask\n"
3715 "Network mask\n"
3716 "Route-map to modify the attributes\n"
3717 "Name of the route map\n")
3718{
3719 int ret;
3720 char prefix_str[BUFSIZ];
3721
3722 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3723 if (! ret)
3724 {
3725 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3726 return CMD_WARNING;
3727 }
3728
3729 return bgp_static_set (vty, vty->index, prefix_str,
3730 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3731}
3732
3733DEFUN (bgp_network_mask_backdoor,
3734 bgp_network_mask_backdoor_cmd,
3735 "network A.B.C.D mask A.B.C.D backdoor",
3736 "Specify a network to announce via BGP\n"
3737 "Network number\n"
3738 "Network mask\n"
3739 "Network mask\n"
3740 "Specify a BGP backdoor route\n")
3741{
3742 int ret;
3743 char prefix_str[BUFSIZ];
3744
3745 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3746 if (! ret)
3747 {
3748 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3749 return CMD_WARNING;
3750 }
3751
3752 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3753}
3754
3755DEFUN (bgp_network_mask_natural,
3756 bgp_network_mask_natural_cmd,
3757 "network A.B.C.D",
3758 "Specify a network to announce via BGP\n"
3759 "Network number\n")
3760{
3761 int ret;
3762 char prefix_str[BUFSIZ];
3763
3764 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3765 if (! ret)
3766 {
3767 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3768 return CMD_WARNING;
3769 }
3770
3771 return bgp_static_set (vty, vty->index, prefix_str,
3772 AFI_IP, bgp_node_safi (vty), NULL, 0);
3773}
3774
3775DEFUN (bgp_network_mask_natural_route_map,
3776 bgp_network_mask_natural_route_map_cmd,
3777 "network A.B.C.D route-map WORD",
3778 "Specify a network to announce via BGP\n"
3779 "Network number\n"
3780 "Route-map to modify the attributes\n"
3781 "Name of the route map\n")
3782{
3783 int ret;
3784 char prefix_str[BUFSIZ];
3785
3786 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3787 if (! ret)
3788 {
3789 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3790 return CMD_WARNING;
3791 }
3792
3793 return bgp_static_set (vty, vty->index, prefix_str,
3794 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3795}
3796
3797DEFUN (bgp_network_mask_natural_backdoor,
3798 bgp_network_mask_natural_backdoor_cmd,
3799 "network A.B.C.D backdoor",
3800 "Specify a network to announce via BGP\n"
3801 "Network number\n"
3802 "Specify a BGP backdoor route\n")
3803{
3804 int ret;
3805 char prefix_str[BUFSIZ];
3806
3807 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3808 if (! ret)
3809 {
3810 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3811 return CMD_WARNING;
3812 }
3813
3814 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3815}
3816
3817DEFUN (no_bgp_network,
3818 no_bgp_network_cmd,
3819 "no network A.B.C.D/M",
3820 NO_STR
3821 "Specify a network to announce via BGP\n"
3822 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3823{
3824 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3825 bgp_node_safi (vty));
3826}
3827
3828ALIAS (no_bgp_network,
3829 no_bgp_network_route_map_cmd,
3830 "no network A.B.C.D/M route-map WORD",
3831 NO_STR
3832 "Specify a network to announce via BGP\n"
3833 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3834 "Route-map to modify the attributes\n"
3835 "Name of the route map\n")
3836
3837ALIAS (no_bgp_network,
3838 no_bgp_network_backdoor_cmd,
3839 "no network A.B.C.D/M backdoor",
3840 NO_STR
3841 "Specify a network to announce via BGP\n"
3842 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3843 "Specify a BGP backdoor route\n")
3844
3845DEFUN (no_bgp_network_mask,
3846 no_bgp_network_mask_cmd,
3847 "no network A.B.C.D mask A.B.C.D",
3848 NO_STR
3849 "Specify a network to announce via BGP\n"
3850 "Network number\n"
3851 "Network mask\n"
3852 "Network mask\n")
3853{
3854 int ret;
3855 char prefix_str[BUFSIZ];
3856
3857 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3858 if (! ret)
3859 {
3860 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3861 return CMD_WARNING;
3862 }
3863
3864 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3865 bgp_node_safi (vty));
3866}
3867
3868ALIAS (no_bgp_network_mask,
3869 no_bgp_network_mask_route_map_cmd,
3870 "no network A.B.C.D mask A.B.C.D route-map WORD",
3871 NO_STR
3872 "Specify a network to announce via BGP\n"
3873 "Network number\n"
3874 "Network mask\n"
3875 "Network mask\n"
3876 "Route-map to modify the attributes\n"
3877 "Name of the route map\n")
3878
3879ALIAS (no_bgp_network_mask,
3880 no_bgp_network_mask_backdoor_cmd,
3881 "no network A.B.C.D mask A.B.C.D backdoor",
3882 NO_STR
3883 "Specify a network to announce via BGP\n"
3884 "Network number\n"
3885 "Network mask\n"
3886 "Network mask\n"
3887 "Specify a BGP backdoor route\n")
3888
3889DEFUN (no_bgp_network_mask_natural,
3890 no_bgp_network_mask_natural_cmd,
3891 "no network A.B.C.D",
3892 NO_STR
3893 "Specify a network to announce via BGP\n"
3894 "Network number\n")
3895{
3896 int ret;
3897 char prefix_str[BUFSIZ];
3898
3899 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3900 if (! ret)
3901 {
3902 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3903 return CMD_WARNING;
3904 }
3905
3906 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3907 bgp_node_safi (vty));
3908}
3909
3910ALIAS (no_bgp_network_mask_natural,
3911 no_bgp_network_mask_natural_route_map_cmd,
3912 "no network A.B.C.D route-map WORD",
3913 NO_STR
3914 "Specify a network to announce via BGP\n"
3915 "Network number\n"
3916 "Route-map to modify the attributes\n"
3917 "Name of the route map\n")
3918
3919ALIAS (no_bgp_network_mask_natural,
3920 no_bgp_network_mask_natural_backdoor_cmd,
3921 "no network A.B.C.D backdoor",
3922 NO_STR
3923 "Specify a network to announce via BGP\n"
3924 "Network number\n"
3925 "Specify a BGP backdoor route\n")
3926
3927#ifdef HAVE_IPV6
3928DEFUN (ipv6_bgp_network,
3929 ipv6_bgp_network_cmd,
3930 "network X:X::X:X/M",
3931 "Specify a network to announce via BGP\n"
3932 "IPv6 prefix <network>/<length>\n")
3933{
3934 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3935}
3936
3937DEFUN (ipv6_bgp_network_route_map,
3938 ipv6_bgp_network_route_map_cmd,
3939 "network X:X::X:X/M route-map WORD",
3940 "Specify a network to announce via BGP\n"
3941 "IPv6 prefix <network>/<length>\n"
3942 "Route-map to modify the attributes\n"
3943 "Name of the route map\n")
3944{
3945 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3946 bgp_node_safi (vty), argv[1], 0);
3947}
3948
3949DEFUN (no_ipv6_bgp_network,
3950 no_ipv6_bgp_network_cmd,
3951 "no network X:X::X:X/M",
3952 NO_STR
3953 "Specify a network to announce via BGP\n"
3954 "IPv6 prefix <network>/<length>\n")
3955{
3956 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3957}
3958
3959ALIAS (no_ipv6_bgp_network,
3960 no_ipv6_bgp_network_route_map_cmd,
3961 "no network X:X::X:X/M route-map WORD",
3962 NO_STR
3963 "Specify a network to announce via BGP\n"
3964 "IPv6 prefix <network>/<length>\n"
3965 "Route-map to modify the attributes\n"
3966 "Name of the route map\n")
3967
3968ALIAS (ipv6_bgp_network,
3969 old_ipv6_bgp_network_cmd,
3970 "ipv6 bgp network X:X::X:X/M",
3971 IPV6_STR
3972 BGP_STR
3973 "Specify a network to announce via BGP\n"
3974 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3975
3976ALIAS (no_ipv6_bgp_network,
3977 old_no_ipv6_bgp_network_cmd,
3978 "no ipv6 bgp network X:X::X:X/M",
3979 NO_STR
3980 IPV6_STR
3981 BGP_STR
3982 "Specify a network to announce via BGP\n"
3983 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3984#endif /* HAVE_IPV6 */
3985
3986/* Aggreagete address:
3987
3988 advertise-map Set condition to advertise attribute
3989 as-set Generate AS set path information
3990 attribute-map Set attributes of aggregate
3991 route-map Set parameters of aggregate
3992 summary-only Filter more specific routes from updates
3993 suppress-map Conditionally filter more specific routes from updates
3994 <cr>
3995 */
3996struct bgp_aggregate
3997{
3998 /* Summary-only flag. */
3999 u_char summary_only;
4000
4001 /* AS set generation. */
4002 u_char as_set;
4003
4004 /* Route-map for aggregated route. */
4005 struct route_map *map;
4006
4007 /* Suppress-count. */
4008 unsigned long count;
4009
4010 /* SAFI configuration. */
4011 safi_t safi;
4012};
4013
paul94f2b392005-06-28 12:44:16 +00004014static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00004015bgp_aggregate_new ()
4016{
4017 struct bgp_aggregate *new;
4018 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4019 memset (new, 0, sizeof (struct bgp_aggregate));
4020 return new;
4021}
4022
paul94f2b392005-06-28 12:44:16 +00004023static void
paul718e3742002-12-13 20:15:29 +00004024bgp_aggregate_free (struct bgp_aggregate *aggregate)
4025{
4026 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4027}
4028
paul94f2b392005-06-28 12:44:16 +00004029static void
paul718e3742002-12-13 20:15:29 +00004030bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4031 afi_t afi, safi_t safi, struct bgp_info *del,
4032 struct bgp_aggregate *aggregate)
4033{
4034 struct bgp_table *table;
4035 struct bgp_node *top;
4036 struct bgp_node *rn;
4037 u_char origin;
4038 struct aspath *aspath = NULL;
4039 struct aspath *asmerge = NULL;
4040 struct community *community = NULL;
4041 struct community *commerge = NULL;
4042 struct in_addr nexthop;
4043 u_int32_t med = 0;
4044 struct bgp_info *ri;
4045 struct bgp_info *new;
4046 int first = 1;
4047 unsigned long match = 0;
4048
4049 /* Record adding route's nexthop and med. */
4050 if (rinew)
4051 {
4052 nexthop = rinew->attr->nexthop;
4053 med = rinew->attr->med;
4054 }
4055
4056 /* ORIGIN attribute: If at least one route among routes that are
4057 aggregated has ORIGIN with the value INCOMPLETE, then the
4058 aggregated route must have the ORIGIN attribute with the value
4059 INCOMPLETE. Otherwise, if at least one route among routes that
4060 are aggregated has ORIGIN with the value EGP, then the aggregated
4061 route must have the origin attribute with the value EGP. In all
4062 other case the value of the ORIGIN attribute of the aggregated
4063 route is INTERNAL. */
4064 origin = BGP_ORIGIN_IGP;
4065
4066 table = bgp->rib[afi][safi];
4067
4068 top = bgp_node_get (table, p);
4069 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4070 if (rn->p.prefixlen > p->prefixlen)
4071 {
4072 match = 0;
4073
4074 for (ri = rn->info; ri; ri = ri->next)
4075 {
4076 if (BGP_INFO_HOLDDOWN (ri))
4077 continue;
4078
4079 if (del && ri == del)
4080 continue;
4081
4082 if (! rinew && first)
4083 {
4084 nexthop = ri->attr->nexthop;
4085 med = ri->attr->med;
4086 first = 0;
4087 }
4088
4089#ifdef AGGREGATE_NEXTHOP_CHECK
4090 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4091 || ri->attr->med != med)
4092 {
4093 if (aspath)
4094 aspath_free (aspath);
4095 if (community)
4096 community_free (community);
4097 bgp_unlock_node (rn);
4098 bgp_unlock_node (top);
4099 return;
4100 }
4101#endif /* AGGREGATE_NEXTHOP_CHECK */
4102
4103 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4104 {
4105 if (aggregate->summary_only)
4106 {
4107 ri->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004108 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004109 match++;
4110 }
4111
4112 aggregate->count++;
4113
4114 if (aggregate->as_set)
4115 {
4116 if (origin < ri->attr->origin)
4117 origin = ri->attr->origin;
4118
4119 if (aspath)
4120 {
4121 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4122 aspath_free (aspath);
4123 aspath = asmerge;
4124 }
4125 else
4126 aspath = aspath_dup (ri->attr->aspath);
4127
4128 if (ri->attr->community)
4129 {
4130 if (community)
4131 {
4132 commerge = community_merge (community,
4133 ri->attr->community);
4134 community = community_uniq_sort (commerge);
4135 community_free (commerge);
4136 }
4137 else
4138 community = community_dup (ri->attr->community);
4139 }
4140 }
4141 }
4142 }
4143 if (match)
4144 bgp_process (bgp, rn, afi, safi);
4145 }
4146 bgp_unlock_node (top);
4147
4148 if (rinew)
4149 {
4150 aggregate->count++;
4151
4152 if (aggregate->summary_only)
4153 rinew->suppress++;
4154
4155 if (aggregate->as_set)
4156 {
4157 if (origin < rinew->attr->origin)
4158 origin = rinew->attr->origin;
4159
4160 if (aspath)
4161 {
4162 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4163 aspath_free (aspath);
4164 aspath = asmerge;
4165 }
4166 else
4167 aspath = aspath_dup (rinew->attr->aspath);
4168
4169 if (rinew->attr->community)
4170 {
4171 if (community)
4172 {
4173 commerge = community_merge (community,
4174 rinew->attr->community);
4175 community = community_uniq_sort (commerge);
4176 community_free (commerge);
4177 }
4178 else
4179 community = community_dup (rinew->attr->community);
4180 }
4181 }
4182 }
4183
4184 if (aggregate->count > 0)
4185 {
4186 rn = bgp_node_get (table, p);
4187 new = bgp_info_new ();
4188 new->type = ZEBRA_ROUTE_BGP;
4189 new->sub_type = BGP_ROUTE_AGGREGATE;
4190 new->peer = bgp->peer_self;
4191 SET_FLAG (new->flags, BGP_INFO_VALID);
4192 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4193 new->uptime = time (NULL);
4194
4195 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004196 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004197 bgp_process (bgp, rn, afi, safi);
4198 }
4199 else
4200 {
4201 if (aspath)
4202 aspath_free (aspath);
4203 if (community)
4204 community_free (community);
4205 }
4206}
4207
4208void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4209 struct bgp_aggregate *);
4210
4211void
4212bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4213 struct bgp_info *ri, afi_t afi, safi_t safi)
4214{
4215 struct bgp_node *child;
4216 struct bgp_node *rn;
4217 struct bgp_aggregate *aggregate;
4218
4219 /* MPLS-VPN aggregation is not yet supported. */
4220 if (safi == SAFI_MPLS_VPN)
4221 return;
4222
4223 if (p->prefixlen == 0)
4224 return;
4225
4226 if (BGP_INFO_HOLDDOWN (ri))
4227 return;
4228
4229 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4230
4231 /* Aggregate address configuration check. */
4232 for (rn = child; rn; rn = rn->parent)
4233 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4234 {
4235 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004236 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004237 }
4238 bgp_unlock_node (child);
4239}
4240
4241void
4242bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4243 struct bgp_info *del, afi_t afi, safi_t safi)
4244{
4245 struct bgp_node *child;
4246 struct bgp_node *rn;
4247 struct bgp_aggregate *aggregate;
4248
4249 /* MPLS-VPN aggregation is not yet supported. */
4250 if (safi == SAFI_MPLS_VPN)
4251 return;
4252
4253 if (p->prefixlen == 0)
4254 return;
4255
4256 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4257
4258 /* Aggregate address configuration check. */
4259 for (rn = child; rn; rn = rn->parent)
4260 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4261 {
4262 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004263 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004264 }
4265 bgp_unlock_node (child);
4266}
4267
paul94f2b392005-06-28 12:44:16 +00004268static void
paul718e3742002-12-13 20:15:29 +00004269bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4270 struct bgp_aggregate *aggregate)
4271{
4272 struct bgp_table *table;
4273 struct bgp_node *top;
4274 struct bgp_node *rn;
4275 struct bgp_info *new;
4276 struct bgp_info *ri;
4277 unsigned long match;
4278 u_char origin = BGP_ORIGIN_IGP;
4279 struct aspath *aspath = NULL;
4280 struct aspath *asmerge = NULL;
4281 struct community *community = NULL;
4282 struct community *commerge = NULL;
4283
4284 table = bgp->rib[afi][safi];
4285
4286 /* Sanity check. */
4287 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4288 return;
4289 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4290 return;
4291
4292 /* If routes exists below this node, generate aggregate routes. */
4293 top = bgp_node_get (table, p);
4294 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4295 if (rn->p.prefixlen > p->prefixlen)
4296 {
4297 match = 0;
4298
4299 for (ri = rn->info; ri; ri = ri->next)
4300 {
4301 if (BGP_INFO_HOLDDOWN (ri))
4302 continue;
4303
4304 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4305 {
4306 /* summary-only aggregate route suppress aggregated
4307 route announcement. */
4308 if (aggregate->summary_only)
4309 {
4310 ri->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004311 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004312 match++;
4313 }
4314 /* as-set aggregate route generate origin, as path,
4315 community aggregation. */
4316 if (aggregate->as_set)
4317 {
4318 if (origin < ri->attr->origin)
4319 origin = ri->attr->origin;
4320
4321 if (aspath)
4322 {
4323 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4324 aspath_free (aspath);
4325 aspath = asmerge;
4326 }
4327 else
4328 aspath = aspath_dup (ri->attr->aspath);
4329
4330 if (ri->attr->community)
4331 {
4332 if (community)
4333 {
4334 commerge = community_merge (community,
4335 ri->attr->community);
4336 community = community_uniq_sort (commerge);
4337 community_free (commerge);
4338 }
4339 else
4340 community = community_dup (ri->attr->community);
4341 }
4342 }
4343 aggregate->count++;
4344 }
4345 }
4346
4347 /* If this node is suppressed, process the change. */
4348 if (match)
4349 bgp_process (bgp, rn, afi, safi);
4350 }
4351 bgp_unlock_node (top);
4352
4353 /* Add aggregate route to BGP table. */
4354 if (aggregate->count)
4355 {
4356 rn = bgp_node_get (table, p);
4357
4358 new = bgp_info_new ();
4359 new->type = ZEBRA_ROUTE_BGP;
4360 new->sub_type = BGP_ROUTE_AGGREGATE;
4361 new->peer = bgp->peer_self;
4362 SET_FLAG (new->flags, BGP_INFO_VALID);
4363 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4364 new->uptime = time (NULL);
4365
4366 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004367 bgp_unlock_node (rn);
4368
paul718e3742002-12-13 20:15:29 +00004369 /* Process change. */
4370 bgp_process (bgp, rn, afi, safi);
4371 }
4372}
4373
4374void
4375bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4376 safi_t safi, struct bgp_aggregate *aggregate)
4377{
4378 struct bgp_table *table;
4379 struct bgp_node *top;
4380 struct bgp_node *rn;
4381 struct bgp_info *ri;
4382 unsigned long match;
4383
4384 table = bgp->rib[afi][safi];
4385
4386 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4387 return;
4388 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4389 return;
4390
4391 /* If routes exists below this node, generate aggregate routes. */
4392 top = bgp_node_get (table, p);
4393 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4394 if (rn->p.prefixlen > p->prefixlen)
4395 {
4396 match = 0;
4397
4398 for (ri = rn->info; ri; ri = ri->next)
4399 {
4400 if (BGP_INFO_HOLDDOWN (ri))
4401 continue;
4402
4403 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4404 {
4405 if (aggregate->summary_only)
4406 {
4407 ri->suppress--;
4408
4409 if (ri->suppress == 0)
4410 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004411 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004412 match++;
4413 }
4414 }
4415 aggregate->count--;
4416 }
4417 }
4418
4419 /* If this node is suppressed, process the change. */
4420 if (match)
4421 bgp_process (bgp, rn, afi, safi);
4422 }
4423 bgp_unlock_node (top);
4424
4425 /* Delete aggregate route from BGP table. */
4426 rn = bgp_node_get (table, p);
4427
4428 for (ri = rn->info; ri; ri = ri->next)
4429 if (ri->peer == bgp->peer_self
4430 && ri->type == ZEBRA_ROUTE_BGP
4431 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4432 break;
4433
4434 /* Withdraw static BGP route from routing table. */
4435 if (ri)
4436 {
paul718e3742002-12-13 20:15:29 +00004437 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004438 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004439 }
4440
4441 /* Unlock bgp_node_lookup. */
4442 bgp_unlock_node (rn);
4443}
4444
4445/* Aggregate route attribute. */
4446#define AGGREGATE_SUMMARY_ONLY 1
4447#define AGGREGATE_AS_SET 1
4448
paul94f2b392005-06-28 12:44:16 +00004449static int
paulfd79ac92004-10-13 05:06:08 +00004450bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4451 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004452 u_char summary_only, u_char as_set)
4453{
4454 int ret;
4455 struct prefix p;
4456 struct bgp_node *rn;
4457 struct bgp *bgp;
4458 struct bgp_aggregate *aggregate;
4459
4460 /* Convert string to prefix structure. */
4461 ret = str2prefix (prefix_str, &p);
4462 if (!ret)
4463 {
4464 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4465 return CMD_WARNING;
4466 }
4467 apply_mask (&p);
4468
4469 /* Get BGP structure. */
4470 bgp = vty->index;
4471
4472 /* Old configuration check. */
4473 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4474
4475 if (rn->info)
4476 {
4477 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4478 bgp_unlock_node (rn);
4479 return CMD_WARNING;
4480 }
4481
4482 /* Make aggregate address structure. */
4483 aggregate = bgp_aggregate_new ();
4484 aggregate->summary_only = summary_only;
4485 aggregate->as_set = as_set;
4486 aggregate->safi = safi;
4487 rn->info = aggregate;
4488
4489 /* Aggregate address insert into BGP routing table. */
4490 if (safi & SAFI_UNICAST)
4491 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4492 if (safi & SAFI_MULTICAST)
4493 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4494
4495 return CMD_SUCCESS;
4496}
4497
paul94f2b392005-06-28 12:44:16 +00004498static int
paulfd79ac92004-10-13 05:06:08 +00004499bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4500 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004501{
4502 int ret;
4503 struct prefix p;
4504 struct bgp_node *rn;
4505 struct bgp *bgp;
4506 struct bgp_aggregate *aggregate;
4507
4508 /* Convert string to prefix structure. */
4509 ret = str2prefix (prefix_str, &p);
4510 if (!ret)
4511 {
4512 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4513 return CMD_WARNING;
4514 }
4515 apply_mask (&p);
4516
4517 /* Get BGP structure. */
4518 bgp = vty->index;
4519
4520 /* Old configuration check. */
4521 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4522 if (! rn)
4523 {
4524 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4525 VTY_NEWLINE);
4526 return CMD_WARNING;
4527 }
4528
4529 aggregate = rn->info;
4530 if (aggregate->safi & SAFI_UNICAST)
4531 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4532 if (aggregate->safi & SAFI_MULTICAST)
4533 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4534
4535 /* Unlock aggregate address configuration. */
4536 rn->info = NULL;
4537 bgp_aggregate_free (aggregate);
4538 bgp_unlock_node (rn);
4539 bgp_unlock_node (rn);
4540
4541 return CMD_SUCCESS;
4542}
4543
4544DEFUN (aggregate_address,
4545 aggregate_address_cmd,
4546 "aggregate-address A.B.C.D/M",
4547 "Configure BGP aggregate entries\n"
4548 "Aggregate prefix\n")
4549{
4550 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4551}
4552
4553DEFUN (aggregate_address_mask,
4554 aggregate_address_mask_cmd,
4555 "aggregate-address A.B.C.D A.B.C.D",
4556 "Configure BGP aggregate entries\n"
4557 "Aggregate address\n"
4558 "Aggregate mask\n")
4559{
4560 int ret;
4561 char prefix_str[BUFSIZ];
4562
4563 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4564
4565 if (! ret)
4566 {
4567 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4568 return CMD_WARNING;
4569 }
4570
4571 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4572 0, 0);
4573}
4574
4575DEFUN (aggregate_address_summary_only,
4576 aggregate_address_summary_only_cmd,
4577 "aggregate-address A.B.C.D/M summary-only",
4578 "Configure BGP aggregate entries\n"
4579 "Aggregate prefix\n"
4580 "Filter more specific routes from updates\n")
4581{
4582 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4583 AGGREGATE_SUMMARY_ONLY, 0);
4584}
4585
4586DEFUN (aggregate_address_mask_summary_only,
4587 aggregate_address_mask_summary_only_cmd,
4588 "aggregate-address A.B.C.D A.B.C.D summary-only",
4589 "Configure BGP aggregate entries\n"
4590 "Aggregate address\n"
4591 "Aggregate mask\n"
4592 "Filter more specific routes from updates\n")
4593{
4594 int ret;
4595 char prefix_str[BUFSIZ];
4596
4597 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4598
4599 if (! ret)
4600 {
4601 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4602 return CMD_WARNING;
4603 }
4604
4605 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4606 AGGREGATE_SUMMARY_ONLY, 0);
4607}
4608
4609DEFUN (aggregate_address_as_set,
4610 aggregate_address_as_set_cmd,
4611 "aggregate-address A.B.C.D/M as-set",
4612 "Configure BGP aggregate entries\n"
4613 "Aggregate prefix\n"
4614 "Generate AS set path information\n")
4615{
4616 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4617 0, AGGREGATE_AS_SET);
4618}
4619
4620DEFUN (aggregate_address_mask_as_set,
4621 aggregate_address_mask_as_set_cmd,
4622 "aggregate-address A.B.C.D A.B.C.D as-set",
4623 "Configure BGP aggregate entries\n"
4624 "Aggregate address\n"
4625 "Aggregate mask\n"
4626 "Generate AS set path information\n")
4627{
4628 int ret;
4629 char prefix_str[BUFSIZ];
4630
4631 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4632
4633 if (! ret)
4634 {
4635 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4636 return CMD_WARNING;
4637 }
4638
4639 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4640 0, AGGREGATE_AS_SET);
4641}
4642
4643
4644DEFUN (aggregate_address_as_set_summary,
4645 aggregate_address_as_set_summary_cmd,
4646 "aggregate-address A.B.C.D/M as-set summary-only",
4647 "Configure BGP aggregate entries\n"
4648 "Aggregate prefix\n"
4649 "Generate AS set path information\n"
4650 "Filter more specific routes from updates\n")
4651{
4652 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4653 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4654}
4655
4656ALIAS (aggregate_address_as_set_summary,
4657 aggregate_address_summary_as_set_cmd,
4658 "aggregate-address A.B.C.D/M summary-only as-set",
4659 "Configure BGP aggregate entries\n"
4660 "Aggregate prefix\n"
4661 "Filter more specific routes from updates\n"
4662 "Generate AS set path information\n")
4663
4664DEFUN (aggregate_address_mask_as_set_summary,
4665 aggregate_address_mask_as_set_summary_cmd,
4666 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4667 "Configure BGP aggregate entries\n"
4668 "Aggregate address\n"
4669 "Aggregate mask\n"
4670 "Generate AS set path information\n"
4671 "Filter more specific routes from updates\n")
4672{
4673 int ret;
4674 char prefix_str[BUFSIZ];
4675
4676 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4677
4678 if (! ret)
4679 {
4680 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4681 return CMD_WARNING;
4682 }
4683
4684 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4685 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4686}
4687
4688ALIAS (aggregate_address_mask_as_set_summary,
4689 aggregate_address_mask_summary_as_set_cmd,
4690 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4691 "Configure BGP aggregate entries\n"
4692 "Aggregate address\n"
4693 "Aggregate mask\n"
4694 "Filter more specific routes from updates\n"
4695 "Generate AS set path information\n")
4696
4697DEFUN (no_aggregate_address,
4698 no_aggregate_address_cmd,
4699 "no aggregate-address A.B.C.D/M",
4700 NO_STR
4701 "Configure BGP aggregate entries\n"
4702 "Aggregate prefix\n")
4703{
4704 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4705}
4706
4707ALIAS (no_aggregate_address,
4708 no_aggregate_address_summary_only_cmd,
4709 "no aggregate-address A.B.C.D/M summary-only",
4710 NO_STR
4711 "Configure BGP aggregate entries\n"
4712 "Aggregate prefix\n"
4713 "Filter more specific routes from updates\n")
4714
4715ALIAS (no_aggregate_address,
4716 no_aggregate_address_as_set_cmd,
4717 "no aggregate-address A.B.C.D/M as-set",
4718 NO_STR
4719 "Configure BGP aggregate entries\n"
4720 "Aggregate prefix\n"
4721 "Generate AS set path information\n")
4722
4723ALIAS (no_aggregate_address,
4724 no_aggregate_address_as_set_summary_cmd,
4725 "no aggregate-address A.B.C.D/M as-set summary-only",
4726 NO_STR
4727 "Configure BGP aggregate entries\n"
4728 "Aggregate prefix\n"
4729 "Generate AS set path information\n"
4730 "Filter more specific routes from updates\n")
4731
4732ALIAS (no_aggregate_address,
4733 no_aggregate_address_summary_as_set_cmd,
4734 "no aggregate-address A.B.C.D/M summary-only as-set",
4735 NO_STR
4736 "Configure BGP aggregate entries\n"
4737 "Aggregate prefix\n"
4738 "Filter more specific routes from updates\n"
4739 "Generate AS set path information\n")
4740
4741DEFUN (no_aggregate_address_mask,
4742 no_aggregate_address_mask_cmd,
4743 "no aggregate-address A.B.C.D A.B.C.D",
4744 NO_STR
4745 "Configure BGP aggregate entries\n"
4746 "Aggregate address\n"
4747 "Aggregate mask\n")
4748{
4749 int ret;
4750 char prefix_str[BUFSIZ];
4751
4752 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4753
4754 if (! ret)
4755 {
4756 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4757 return CMD_WARNING;
4758 }
4759
4760 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4761}
4762
4763ALIAS (no_aggregate_address_mask,
4764 no_aggregate_address_mask_summary_only_cmd,
4765 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4766 NO_STR
4767 "Configure BGP aggregate entries\n"
4768 "Aggregate address\n"
4769 "Aggregate mask\n"
4770 "Filter more specific routes from updates\n")
4771
4772ALIAS (no_aggregate_address_mask,
4773 no_aggregate_address_mask_as_set_cmd,
4774 "no aggregate-address A.B.C.D A.B.C.D as-set",
4775 NO_STR
4776 "Configure BGP aggregate entries\n"
4777 "Aggregate address\n"
4778 "Aggregate mask\n"
4779 "Generate AS set path information\n")
4780
4781ALIAS (no_aggregate_address_mask,
4782 no_aggregate_address_mask_as_set_summary_cmd,
4783 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4784 NO_STR
4785 "Configure BGP aggregate entries\n"
4786 "Aggregate address\n"
4787 "Aggregate mask\n"
4788 "Generate AS set path information\n"
4789 "Filter more specific routes from updates\n")
4790
4791ALIAS (no_aggregate_address_mask,
4792 no_aggregate_address_mask_summary_as_set_cmd,
4793 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4794 NO_STR
4795 "Configure BGP aggregate entries\n"
4796 "Aggregate address\n"
4797 "Aggregate mask\n"
4798 "Filter more specific routes from updates\n"
4799 "Generate AS set path information\n")
4800
4801#ifdef HAVE_IPV6
4802DEFUN (ipv6_aggregate_address,
4803 ipv6_aggregate_address_cmd,
4804 "aggregate-address X:X::X:X/M",
4805 "Configure BGP aggregate entries\n"
4806 "Aggregate prefix\n")
4807{
4808 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4809}
4810
4811DEFUN (ipv6_aggregate_address_summary_only,
4812 ipv6_aggregate_address_summary_only_cmd,
4813 "aggregate-address X:X::X:X/M summary-only",
4814 "Configure BGP aggregate entries\n"
4815 "Aggregate prefix\n"
4816 "Filter more specific routes from updates\n")
4817{
4818 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4819 AGGREGATE_SUMMARY_ONLY, 0);
4820}
4821
4822DEFUN (no_ipv6_aggregate_address,
4823 no_ipv6_aggregate_address_cmd,
4824 "no aggregate-address X:X::X:X/M",
4825 NO_STR
4826 "Configure BGP aggregate entries\n"
4827 "Aggregate prefix\n")
4828{
4829 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4830}
4831
4832DEFUN (no_ipv6_aggregate_address_summary_only,
4833 no_ipv6_aggregate_address_summary_only_cmd,
4834 "no aggregate-address X:X::X:X/M summary-only",
4835 NO_STR
4836 "Configure BGP aggregate entries\n"
4837 "Aggregate prefix\n"
4838 "Filter more specific routes from updates\n")
4839{
4840 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4841}
4842
4843ALIAS (ipv6_aggregate_address,
4844 old_ipv6_aggregate_address_cmd,
4845 "ipv6 bgp aggregate-address X:X::X:X/M",
4846 IPV6_STR
4847 BGP_STR
4848 "Configure BGP aggregate entries\n"
4849 "Aggregate prefix\n")
4850
4851ALIAS (ipv6_aggregate_address_summary_only,
4852 old_ipv6_aggregate_address_summary_only_cmd,
4853 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4854 IPV6_STR
4855 BGP_STR
4856 "Configure BGP aggregate entries\n"
4857 "Aggregate prefix\n"
4858 "Filter more specific routes from updates\n")
4859
4860ALIAS (no_ipv6_aggregate_address,
4861 old_no_ipv6_aggregate_address_cmd,
4862 "no ipv6 bgp aggregate-address X:X::X:X/M",
4863 NO_STR
4864 IPV6_STR
4865 BGP_STR
4866 "Configure BGP aggregate entries\n"
4867 "Aggregate prefix\n")
4868
4869ALIAS (no_ipv6_aggregate_address_summary_only,
4870 old_no_ipv6_aggregate_address_summary_only_cmd,
4871 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4872 NO_STR
4873 IPV6_STR
4874 BGP_STR
4875 "Configure BGP aggregate entries\n"
4876 "Aggregate prefix\n"
4877 "Filter more specific routes from updates\n")
4878#endif /* HAVE_IPV6 */
4879
4880/* Redistribute route treatment. */
4881void
4882bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4883 u_int32_t metric, u_char type)
4884{
4885 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004886 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004887 struct bgp_info *new;
4888 struct bgp_info *bi;
4889 struct bgp_info info;
4890 struct bgp_node *bn;
4891 struct attr attr;
4892 struct attr attr_new;
4893 struct attr *new_attr;
4894 afi_t afi;
4895 int ret;
4896
4897 /* Make default attribute. */
4898 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4899 if (nexthop)
4900 attr.nexthop = *nexthop;
4901
4902 attr.med = metric;
4903 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4904
paul1eb8ef22005-04-07 07:30:20 +00004905 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004906 {
4907 afi = family2afi (p->family);
4908
4909 if (bgp->redist[afi][type])
4910 {
4911 /* Copy attribute for modification. */
4912 attr_new = attr;
4913
4914 if (bgp->redist_metric_flag[afi][type])
4915 attr_new.med = bgp->redist_metric[afi][type];
4916
4917 /* Apply route-map. */
4918 if (bgp->rmap[afi][type].map)
4919 {
4920 info.peer = bgp->peer_self;
4921 info.attr = &attr_new;
4922
paulfee0f4c2004-09-13 05:12:46 +00004923 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4924
paul718e3742002-12-13 20:15:29 +00004925 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4926 &info);
paulfee0f4c2004-09-13 05:12:46 +00004927
4928 bgp->peer_self->rmap_type = 0;
4929
paul718e3742002-12-13 20:15:29 +00004930 if (ret == RMAP_DENYMATCH)
4931 {
4932 /* Free uninterned attribute. */
4933 bgp_attr_flush (&attr_new);
4934
4935 /* Unintern original. */
4936 aspath_unintern (attr.aspath);
4937 bgp_redistribute_delete (p, type);
4938 return;
4939 }
4940 }
4941
paulfee0f4c2004-09-13 05:12:46 +00004942 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004943 new_attr = bgp_attr_intern (&attr_new);
4944
4945 for (bi = bn->info; bi; bi = bi->next)
4946 if (bi->peer == bgp->peer_self
4947 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4948 break;
4949
4950 if (bi)
4951 {
4952 if (attrhash_cmp (bi->attr, new_attr))
4953 {
4954 bgp_attr_unintern (new_attr);
4955 aspath_unintern (attr.aspath);
4956 bgp_unlock_node (bn);
4957 return;
4958 }
4959 else
4960 {
4961 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00004962 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004963
4964 /* Rewrite BGP route information. */
4965 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4966 bgp_attr_unintern (bi->attr);
4967 bi->attr = new_attr;
4968 bi->uptime = time (NULL);
4969
4970 /* Process change. */
4971 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4972 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4973 bgp_unlock_node (bn);
4974 aspath_unintern (attr.aspath);
4975 return;
4976 }
4977 }
4978
4979 new = bgp_info_new ();
4980 new->type = type;
4981 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4982 new->peer = bgp->peer_self;
4983 SET_FLAG (new->flags, BGP_INFO_VALID);
4984 new->attr = new_attr;
4985 new->uptime = time (NULL);
4986
4987 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4988 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004989 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004990 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4991 }
4992 }
4993
4994 /* Unintern original. */
4995 aspath_unintern (attr.aspath);
4996}
4997
4998void
4999bgp_redistribute_delete (struct prefix *p, u_char type)
5000{
5001 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005002 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005003 afi_t afi;
5004 struct bgp_node *rn;
5005 struct bgp_info *ri;
5006
paul1eb8ef22005-04-07 07:30:20 +00005007 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005008 {
5009 afi = family2afi (p->family);
5010
5011 if (bgp->redist[afi][type])
5012 {
paulfee0f4c2004-09-13 05:12:46 +00005013 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005014
5015 for (ri = rn->info; ri; ri = ri->next)
5016 if (ri->peer == bgp->peer_self
5017 && ri->type == type)
5018 break;
5019
5020 if (ri)
5021 {
5022 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005023 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005024 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005025 }
5026 bgp_unlock_node (rn);
5027 }
5028 }
5029}
5030
5031/* Withdraw specified route type's route. */
5032void
5033bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5034{
5035 struct bgp_node *rn;
5036 struct bgp_info *ri;
5037 struct bgp_table *table;
5038
5039 table = bgp->rib[afi][SAFI_UNICAST];
5040
5041 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5042 {
5043 for (ri = rn->info; ri; ri = ri->next)
5044 if (ri->peer == bgp->peer_self
5045 && ri->type == type)
5046 break;
5047
5048 if (ri)
5049 {
5050 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005051 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005052 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005053 }
5054 }
5055}
5056
5057/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005058static void
paul718e3742002-12-13 20:15:29 +00005059route_vty_out_route (struct prefix *p, struct vty *vty)
5060{
5061 int len;
5062 u_int32_t destination;
5063 char buf[BUFSIZ];
5064
5065 if (p->family == AF_INET)
5066 {
5067 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5068 destination = ntohl (p->u.prefix4.s_addr);
5069
5070 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5071 || (IN_CLASSB (destination) && p->prefixlen == 16)
5072 || (IN_CLASSA (destination) && p->prefixlen == 8)
5073 || p->u.prefix4.s_addr == 0)
5074 {
5075 /* When mask is natural, mask is not displayed. */
5076 }
5077 else
5078 len += vty_out (vty, "/%d", p->prefixlen);
5079 }
5080 else
5081 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5082 p->prefixlen);
5083
5084 len = 17 - len;
5085 if (len < 1)
5086 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5087 else
5088 vty_out (vty, "%*s", len, " ");
5089}
5090
paul718e3742002-12-13 20:15:29 +00005091enum bgp_display_type
5092{
5093 normal_list,
5094};
5095
paulb40d9392005-08-22 22:34:41 +00005096/* Print the short form route status for a bgp_info */
5097static void
5098route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005099{
paulb40d9392005-08-22 22:34:41 +00005100 /* Route status display. */
5101 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5102 vty_out (vty, "R");
5103 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005104 vty_out (vty, "S");
5105 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005106 vty_out (vty, "s");
5107 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5108 vty_out (vty, "*");
5109 else
5110 vty_out (vty, " ");
5111
5112 /* Selected */
5113 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5114 vty_out (vty, "h");
5115 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5116 vty_out (vty, "d");
5117 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5118 vty_out (vty, ">");
5119 else
5120 vty_out (vty, " ");
5121
5122 /* Internal route. */
5123 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5124 vty_out (vty, "i");
5125 else
paulb40d9392005-08-22 22:34:41 +00005126 vty_out (vty, " ");
5127}
5128
5129/* called from terminal list command */
5130void
5131route_vty_out (struct vty *vty, struct prefix *p,
5132 struct bgp_info *binfo, int display, safi_t safi)
5133{
5134 struct attr *attr;
5135
5136 /* short status lead text */
5137 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005138
5139 /* print prefix and mask */
5140 if (! display)
5141 route_vty_out_route (p, vty);
5142 else
5143 vty_out (vty, "%*s", 17, " ");
5144
5145 /* Print attribute */
5146 attr = binfo->attr;
5147 if (attr)
5148 {
5149 if (p->family == AF_INET)
5150 {
5151 if (safi == SAFI_MPLS_VPN)
5152 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5153 else
5154 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5155 }
5156#ifdef HAVE_IPV6
5157 else if (p->family == AF_INET6)
5158 {
5159 int len;
5160 char buf[BUFSIZ];
5161
5162 len = vty_out (vty, "%s",
5163 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5164 len = 16 - len;
5165 if (len < 1)
5166 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5167 else
5168 vty_out (vty, "%*s", len, " ");
5169 }
5170#endif /* HAVE_IPV6 */
5171
5172 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5173 vty_out (vty, "%10d", attr->med);
5174 else
5175 vty_out (vty, " ");
5176
5177 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5178 vty_out (vty, "%7d", attr->local_pref);
5179 else
5180 vty_out (vty, " ");
5181
5182 vty_out (vty, "%7u ",attr->weight);
5183
Paul Jakmab2518c12006-05-12 23:48:40 +00005184 /* Print aspath */
5185 if (attr->aspath)
5186 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005187
Paul Jakmab2518c12006-05-12 23:48:40 +00005188 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005189 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005190 }
paul718e3742002-12-13 20:15:29 +00005191 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005192}
5193
5194/* called from terminal list command */
5195void
5196route_vty_out_tmp (struct vty *vty, struct prefix *p,
5197 struct attr *attr, safi_t safi)
5198{
5199 /* Route status display. */
5200 vty_out (vty, "*");
5201 vty_out (vty, ">");
5202 vty_out (vty, " ");
5203
5204 /* print prefix and mask */
5205 route_vty_out_route (p, vty);
5206
5207 /* Print attribute */
5208 if (attr)
5209 {
5210 if (p->family == AF_INET)
5211 {
5212 if (safi == SAFI_MPLS_VPN)
5213 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5214 else
5215 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5216 }
5217#ifdef HAVE_IPV6
5218 else if (p->family == AF_INET6)
5219 {
5220 int len;
5221 char buf[BUFSIZ];
5222
5223 len = vty_out (vty, "%s",
5224 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5225 len = 16 - len;
5226 if (len < 1)
5227 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5228 else
5229 vty_out (vty, "%*s", len, " ");
5230 }
5231#endif /* HAVE_IPV6 */
5232
5233 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5234 vty_out (vty, "%10d", attr->med);
5235 else
5236 vty_out (vty, " ");
5237
5238 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5239 vty_out (vty, "%7d", attr->local_pref);
5240 else
5241 vty_out (vty, " ");
5242
5243 vty_out (vty, "%7d ",attr->weight);
5244
Paul Jakmab2518c12006-05-12 23:48:40 +00005245 /* Print aspath */
5246 if (attr->aspath)
5247 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005248
Paul Jakmab2518c12006-05-12 23:48:40 +00005249 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005250 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005251 }
paul718e3742002-12-13 20:15:29 +00005252
5253 vty_out (vty, "%s", VTY_NEWLINE);
5254}
5255
ajs5a646652004-11-05 01:25:55 +00005256void
paul718e3742002-12-13 20:15:29 +00005257route_vty_out_tag (struct vty *vty, struct prefix *p,
5258 struct bgp_info *binfo, int display, safi_t safi)
5259{
5260 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005261 u_int32_t label = 0;
5262
paulb40d9392005-08-22 22:34:41 +00005263 /* short status lead text */
5264 route_vty_short_status_out (vty, binfo);
5265
paul718e3742002-12-13 20:15:29 +00005266 /* print prefix and mask */
5267 if (! display)
5268 route_vty_out_route (p, vty);
5269 else
5270 vty_out (vty, "%*s", 17, " ");
5271
5272 /* Print attribute */
5273 attr = binfo->attr;
5274 if (attr)
5275 {
5276 if (p->family == AF_INET)
5277 {
5278 if (safi == SAFI_MPLS_VPN)
5279 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5280 else
5281 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5282 }
5283#ifdef HAVE_IPV6
5284 else if (p->family == AF_INET6)
5285 {
5286 char buf[BUFSIZ];
5287 char buf1[BUFSIZ];
5288 if (attr->mp_nexthop_len == 16)
5289 vty_out (vty, "%s",
5290 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5291 else if (attr->mp_nexthop_len == 32)
5292 vty_out (vty, "%s(%s)",
5293 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5294 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5295
5296 }
5297#endif /* HAVE_IPV6 */
5298 }
5299
5300 label = decode_label (binfo->tag);
5301
5302 vty_out (vty, "notag/%d", label);
5303
5304 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005305}
5306
5307/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005308static void
paul718e3742002-12-13 20:15:29 +00005309damp_route_vty_out (struct vty *vty, struct prefix *p,
5310 struct bgp_info *binfo, int display, safi_t safi)
5311{
5312 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005313 int len;
5314
paulb40d9392005-08-22 22:34:41 +00005315 /* short status lead text */
5316 route_vty_short_status_out (vty, binfo);
5317
paul718e3742002-12-13 20:15:29 +00005318 /* print prefix and mask */
5319 if (! display)
5320 route_vty_out_route (p, vty);
5321 else
5322 vty_out (vty, "%*s", 17, " ");
5323
5324 len = vty_out (vty, "%s", binfo->peer->host);
5325 len = 17 - len;
5326 if (len < 1)
5327 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5328 else
5329 vty_out (vty, "%*s", len, " ");
5330
5331 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5332
5333 /* Print attribute */
5334 attr = binfo->attr;
5335 if (attr)
5336 {
5337 /* Print aspath */
5338 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005339 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005340
5341 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005342 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005343 }
5344 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005345}
5346
5347#define BGP_UPTIME_LEN 25
5348
5349/* flap route */
ajs5a646652004-11-05 01:25:55 +00005350static void
paul718e3742002-12-13 20:15:29 +00005351flap_route_vty_out (struct vty *vty, struct prefix *p,
5352 struct bgp_info *binfo, int display, safi_t safi)
5353{
5354 struct attr *attr;
5355 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005356 char timebuf[BGP_UPTIME_LEN];
5357 int len;
5358
paul718e3742002-12-13 20:15:29 +00005359 bdi = binfo->damp_info;
5360
paulb40d9392005-08-22 22:34:41 +00005361 /* short status lead text */
5362 route_vty_short_status_out (vty, binfo);
5363
paul718e3742002-12-13 20:15:29 +00005364 /* print prefix and mask */
5365 if (! display)
5366 route_vty_out_route (p, vty);
5367 else
5368 vty_out (vty, "%*s", 17, " ");
5369
5370 len = vty_out (vty, "%s", binfo->peer->host);
5371 len = 16 - len;
5372 if (len < 1)
5373 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5374 else
5375 vty_out (vty, "%*s", len, " ");
5376
5377 len = vty_out (vty, "%d", bdi->flap);
5378 len = 5 - len;
5379 if (len < 1)
5380 vty_out (vty, " ");
5381 else
5382 vty_out (vty, "%*s ", len, " ");
5383
5384 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5385 timebuf, BGP_UPTIME_LEN));
5386
5387 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5388 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5389 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5390 else
5391 vty_out (vty, "%*s ", 8, " ");
5392
5393 /* Print attribute */
5394 attr = binfo->attr;
5395 if (attr)
5396 {
5397 /* Print aspath */
5398 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005399 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005400
5401 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005402 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005403 }
5404 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005405}
5406
paul94f2b392005-06-28 12:44:16 +00005407static void
paul718e3742002-12-13 20:15:29 +00005408route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5409 struct bgp_info *binfo, afi_t afi, safi_t safi)
5410{
5411 char buf[INET6_ADDRSTRLEN];
5412 char buf1[BUFSIZ];
5413 struct attr *attr;
5414 int sockunion_vty_out (struct vty *, union sockunion *);
5415
5416 attr = binfo->attr;
5417
5418 if (attr)
5419 {
5420 /* Line1 display AS-path, Aggregator */
5421 if (attr->aspath)
5422 {
5423 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005424 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005425 vty_out (vty, "Local");
5426 else
Paul Jakmab2518c12006-05-12 23:48:40 +00005427 aspath_print_vty (vty, "%s", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005428 }
5429
paulb40d9392005-08-22 22:34:41 +00005430 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5431 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005432 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5433 vty_out (vty, ", (stale)");
5434 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5435 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5436 inet_ntoa (attr->aggregator_addr));
5437 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5438 vty_out (vty, ", (Received from a RR-client)");
5439 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5440 vty_out (vty, ", (Received from a RS-client)");
5441 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5442 vty_out (vty, ", (history entry)");
5443 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5444 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005445 vty_out (vty, "%s", VTY_NEWLINE);
5446
5447 /* Line2 display Next-hop, Neighbor, Router-id */
5448 if (p->family == AF_INET)
5449 {
5450 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5451 inet_ntoa (attr->mp_nexthop_global_in) :
5452 inet_ntoa (attr->nexthop));
5453 }
5454#ifdef HAVE_IPV6
5455 else
5456 {
5457 vty_out (vty, " %s",
5458 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5459 buf, INET6_ADDRSTRLEN));
5460 }
5461#endif /* HAVE_IPV6 */
5462
5463 if (binfo->peer == bgp->peer_self)
5464 {
5465 vty_out (vty, " from %s ",
5466 p->family == AF_INET ? "0.0.0.0" : "::");
5467 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5468 }
5469 else
5470 {
5471 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5472 vty_out (vty, " (inaccessible)");
5473 else if (binfo->igpmetric)
5474 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005475 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005476 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5477 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5478 else
5479 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5480 }
5481 vty_out (vty, "%s", VTY_NEWLINE);
5482
5483#ifdef HAVE_IPV6
5484 /* display nexthop local */
5485 if (attr->mp_nexthop_len == 32)
5486 {
5487 vty_out (vty, " (%s)%s",
5488 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5489 buf, INET6_ADDRSTRLEN),
5490 VTY_NEWLINE);
5491 }
5492#endif /* HAVE_IPV6 */
5493
5494 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5495 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5496
5497 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5498 vty_out (vty, ", metric %d", attr->med);
5499
5500 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5501 vty_out (vty, ", localpref %d", attr->local_pref);
5502 else
5503 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5504
5505 if (attr->weight != 0)
5506 vty_out (vty, ", weight %d", attr->weight);
5507
5508 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5509 vty_out (vty, ", valid");
5510
5511 if (binfo->peer != bgp->peer_self)
5512 {
5513 if (binfo->peer->as == binfo->peer->local_as)
5514 vty_out (vty, ", internal");
5515 else
5516 vty_out (vty, ", %s",
5517 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5518 }
5519 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5520 vty_out (vty, ", aggregated, local");
5521 else if (binfo->type != ZEBRA_ROUTE_BGP)
5522 vty_out (vty, ", sourced");
5523 else
5524 vty_out (vty, ", sourced, local");
5525
5526 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5527 vty_out (vty, ", atomic-aggregate");
5528
5529 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5530 vty_out (vty, ", best");
5531
5532 vty_out (vty, "%s", VTY_NEWLINE);
5533
5534 /* Line 4 display Community */
5535 if (attr->community)
5536 vty_out (vty, " Community: %s%s", attr->community->str,
5537 VTY_NEWLINE);
5538
5539 /* Line 5 display Extended-community */
5540 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5541 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5542 VTY_NEWLINE);
5543
5544 /* Line 6 display Originator, Cluster-id */
5545 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5546 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5547 {
5548 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5549 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5550
5551 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5552 {
5553 int i;
5554 vty_out (vty, ", Cluster list: ");
5555 for (i = 0; i < attr->cluster->length / 4; i++)
5556 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5557 }
5558 vty_out (vty, "%s", VTY_NEWLINE);
5559 }
5560
5561 if (binfo->damp_info)
5562 bgp_damp_info_vty (vty, binfo);
5563
5564 /* Line 7 display Uptime */
5565 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5566 }
5567 vty_out (vty, "%s", VTY_NEWLINE);
5568}
5569
paulb40d9392005-08-22 22:34:41 +00005570#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 +00005571#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005572#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5573#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5574#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5575
5576enum bgp_show_type
5577{
5578 bgp_show_type_normal,
5579 bgp_show_type_regexp,
5580 bgp_show_type_prefix_list,
5581 bgp_show_type_filter_list,
5582 bgp_show_type_route_map,
5583 bgp_show_type_neighbor,
5584 bgp_show_type_cidr_only,
5585 bgp_show_type_prefix_longer,
5586 bgp_show_type_community_all,
5587 bgp_show_type_community,
5588 bgp_show_type_community_exact,
5589 bgp_show_type_community_list,
5590 bgp_show_type_community_list_exact,
5591 bgp_show_type_flap_statistics,
5592 bgp_show_type_flap_address,
5593 bgp_show_type_flap_prefix,
5594 bgp_show_type_flap_cidr_only,
5595 bgp_show_type_flap_regexp,
5596 bgp_show_type_flap_filter_list,
5597 bgp_show_type_flap_prefix_list,
5598 bgp_show_type_flap_prefix_longer,
5599 bgp_show_type_flap_route_map,
5600 bgp_show_type_flap_neighbor,
5601 bgp_show_type_dampend_paths,
5602 bgp_show_type_damp_neighbor
5603};
5604
ajs5a646652004-11-05 01:25:55 +00005605static int
paulfee0f4c2004-09-13 05:12:46 +00005606bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005607 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005608{
paul718e3742002-12-13 20:15:29 +00005609 struct bgp_info *ri;
5610 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005611 int header = 1;
paul718e3742002-12-13 20:15:29 +00005612 int display;
ajs5a646652004-11-05 01:25:55 +00005613 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005614
5615 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005616 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005617
paul718e3742002-12-13 20:15:29 +00005618 /* Start processing of routes. */
5619 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5620 if (rn->info != NULL)
5621 {
5622 display = 0;
5623
5624 for (ri = rn->info; ri; ri = ri->next)
5625 {
ajs5a646652004-11-05 01:25:55 +00005626 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005627 || type == bgp_show_type_flap_address
5628 || type == bgp_show_type_flap_prefix
5629 || type == bgp_show_type_flap_cidr_only
5630 || type == bgp_show_type_flap_regexp
5631 || type == bgp_show_type_flap_filter_list
5632 || type == bgp_show_type_flap_prefix_list
5633 || type == bgp_show_type_flap_prefix_longer
5634 || type == bgp_show_type_flap_route_map
5635 || type == bgp_show_type_flap_neighbor
5636 || type == bgp_show_type_dampend_paths
5637 || type == bgp_show_type_damp_neighbor)
5638 {
5639 if (! ri->damp_info)
5640 continue;
5641 }
5642 if (type == bgp_show_type_regexp
5643 || type == bgp_show_type_flap_regexp)
5644 {
ajs5a646652004-11-05 01:25:55 +00005645 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005646
5647 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5648 continue;
5649 }
5650 if (type == bgp_show_type_prefix_list
5651 || type == bgp_show_type_flap_prefix_list)
5652 {
ajs5a646652004-11-05 01:25:55 +00005653 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005654
5655 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5656 continue;
5657 }
5658 if (type == bgp_show_type_filter_list
5659 || type == bgp_show_type_flap_filter_list)
5660 {
ajs5a646652004-11-05 01:25:55 +00005661 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005662
5663 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5664 continue;
5665 }
5666 if (type == bgp_show_type_route_map
5667 || type == bgp_show_type_flap_route_map)
5668 {
ajs5a646652004-11-05 01:25:55 +00005669 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005670 struct bgp_info binfo;
5671 struct attr dummy_attr;
5672 int ret;
5673
5674 dummy_attr = *ri->attr;
5675 binfo.peer = ri->peer;
5676 binfo.attr = &dummy_attr;
5677
5678 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5679
5680 if (ret == RMAP_DENYMATCH)
5681 continue;
5682 }
5683 if (type == bgp_show_type_neighbor
5684 || type == bgp_show_type_flap_neighbor
5685 || type == bgp_show_type_damp_neighbor)
5686 {
ajs5a646652004-11-05 01:25:55 +00005687 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005688
5689 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5690 continue;
5691 }
5692 if (type == bgp_show_type_cidr_only
5693 || type == bgp_show_type_flap_cidr_only)
5694 {
5695 u_int32_t destination;
5696
5697 destination = ntohl (rn->p.u.prefix4.s_addr);
5698 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5699 continue;
5700 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5701 continue;
5702 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5703 continue;
5704 }
5705 if (type == bgp_show_type_prefix_longer
5706 || type == bgp_show_type_flap_prefix_longer)
5707 {
ajs5a646652004-11-05 01:25:55 +00005708 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005709
5710 if (! prefix_match (p, &rn->p))
5711 continue;
5712 }
5713 if (type == bgp_show_type_community_all)
5714 {
5715 if (! ri->attr->community)
5716 continue;
5717 }
5718 if (type == bgp_show_type_community)
5719 {
ajs5a646652004-11-05 01:25:55 +00005720 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005721
5722 if (! ri->attr->community ||
5723 ! community_match (ri->attr->community, com))
5724 continue;
5725 }
5726 if (type == bgp_show_type_community_exact)
5727 {
ajs5a646652004-11-05 01:25:55 +00005728 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005729
5730 if (! ri->attr->community ||
5731 ! community_cmp (ri->attr->community, com))
5732 continue;
5733 }
5734 if (type == bgp_show_type_community_list)
5735 {
ajs5a646652004-11-05 01:25:55 +00005736 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005737
5738 if (! community_list_match (ri->attr->community, list))
5739 continue;
5740 }
5741 if (type == bgp_show_type_community_list_exact)
5742 {
ajs5a646652004-11-05 01:25:55 +00005743 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005744
5745 if (! community_list_exact_match (ri->attr->community, list))
5746 continue;
5747 }
5748 if (type == bgp_show_type_flap_address
5749 || type == bgp_show_type_flap_prefix)
5750 {
ajs5a646652004-11-05 01:25:55 +00005751 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005752
5753 if (! prefix_match (&rn->p, p))
5754 continue;
5755
5756 if (type == bgp_show_type_flap_prefix)
5757 if (p->prefixlen != rn->p.prefixlen)
5758 continue;
5759 }
5760 if (type == bgp_show_type_dampend_paths
5761 || type == bgp_show_type_damp_neighbor)
5762 {
5763 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5764 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5765 continue;
5766 }
5767
5768 if (header)
5769 {
hasso93406d82005-02-02 14:40:33 +00005770 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5771 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5772 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005773 if (type == bgp_show_type_dampend_paths
5774 || type == bgp_show_type_damp_neighbor)
5775 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5776 else if (type == bgp_show_type_flap_statistics
5777 || type == bgp_show_type_flap_address
5778 || type == bgp_show_type_flap_prefix
5779 || type == bgp_show_type_flap_cidr_only
5780 || type == bgp_show_type_flap_regexp
5781 || type == bgp_show_type_flap_filter_list
5782 || type == bgp_show_type_flap_prefix_list
5783 || type == bgp_show_type_flap_prefix_longer
5784 || type == bgp_show_type_flap_route_map
5785 || type == bgp_show_type_flap_neighbor)
5786 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5787 else
5788 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005789 header = 0;
5790 }
5791
5792 if (type == bgp_show_type_dampend_paths
5793 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005794 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005795 else if (type == bgp_show_type_flap_statistics
5796 || type == bgp_show_type_flap_address
5797 || type == bgp_show_type_flap_prefix
5798 || type == bgp_show_type_flap_cidr_only
5799 || type == bgp_show_type_flap_regexp
5800 || type == bgp_show_type_flap_filter_list
5801 || type == bgp_show_type_flap_prefix_list
5802 || type == bgp_show_type_flap_prefix_longer
5803 || type == bgp_show_type_flap_route_map
5804 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005805 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005806 else
ajs5a646652004-11-05 01:25:55 +00005807 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005808 display++;
5809 }
5810 if (display)
ajs5a646652004-11-05 01:25:55 +00005811 output_count++;
paul718e3742002-12-13 20:15:29 +00005812 }
5813
5814 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005815 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005816 {
5817 if (type == bgp_show_type_normal)
5818 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5819 }
5820 else
5821 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005822 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005823
5824 return CMD_SUCCESS;
5825}
5826
ajs5a646652004-11-05 01:25:55 +00005827static int
paulfee0f4c2004-09-13 05:12:46 +00005828bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005829 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005830{
5831 struct bgp_table *table;
5832
5833 if (bgp == NULL) {
5834 bgp = bgp_get_default ();
5835 }
5836
5837 if (bgp == NULL)
5838 {
5839 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5840 return CMD_WARNING;
5841 }
5842
5843
5844 table = bgp->rib[afi][safi];
5845
ajs5a646652004-11-05 01:25:55 +00005846 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005847}
5848
paul718e3742002-12-13 20:15:29 +00005849/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005850static void
paul718e3742002-12-13 20:15:29 +00005851route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5852 struct bgp_node *rn,
5853 struct prefix_rd *prd, afi_t afi, safi_t safi)
5854{
5855 struct bgp_info *ri;
5856 struct prefix *p;
5857 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005858 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005859 char buf1[INET6_ADDRSTRLEN];
5860 char buf2[INET6_ADDRSTRLEN];
5861 int count = 0;
5862 int best = 0;
5863 int suppress = 0;
5864 int no_export = 0;
5865 int no_advertise = 0;
5866 int local_as = 0;
5867 int first = 0;
5868
5869 p = &rn->p;
5870 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5871 (safi == SAFI_MPLS_VPN ?
5872 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5873 safi == SAFI_MPLS_VPN ? ":" : "",
5874 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5875 p->prefixlen, VTY_NEWLINE);
5876
5877 for (ri = rn->info; ri; ri = ri->next)
5878 {
5879 count++;
5880 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5881 {
5882 best = count;
5883 if (ri->suppress)
5884 suppress = 1;
5885 if (ri->attr->community != NULL)
5886 {
5887 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5888 no_advertise = 1;
5889 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5890 no_export = 1;
5891 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5892 local_as = 1;
5893 }
5894 }
5895 }
5896
5897 vty_out (vty, "Paths: (%d available", count);
5898 if (best)
5899 {
5900 vty_out (vty, ", best #%d", best);
5901 if (safi == SAFI_UNICAST)
5902 vty_out (vty, ", table Default-IP-Routing-Table");
5903 }
5904 else
5905 vty_out (vty, ", no best path");
5906 if (no_advertise)
5907 vty_out (vty, ", not advertised to any peer");
5908 else if (no_export)
5909 vty_out (vty, ", not advertised to EBGP peer");
5910 else if (local_as)
5911 vty_out (vty, ", not advertised outside local AS");
5912 if (suppress)
5913 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5914 vty_out (vty, ")%s", VTY_NEWLINE);
5915
5916 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005917 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005918 {
5919 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5920 {
5921 if (! first)
5922 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5923 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5924 first = 1;
5925 }
5926 }
5927 if (! first)
5928 vty_out (vty, " Not advertised to any peer");
5929 vty_out (vty, "%s", VTY_NEWLINE);
5930}
5931
5932/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005933static int
paulfee0f4c2004-09-13 05:12:46 +00005934bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005935 struct bgp_table *rib, const char *ip_str,
5936 afi_t afi, safi_t safi, struct prefix_rd *prd,
5937 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005938{
5939 int ret;
5940 int header;
5941 int display = 0;
5942 struct prefix match;
5943 struct bgp_node *rn;
5944 struct bgp_node *rm;
5945 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005946 struct bgp_table *table;
5947
paul718e3742002-12-13 20:15:29 +00005948 /* Check IP address argument. */
5949 ret = str2prefix (ip_str, &match);
5950 if (! ret)
5951 {
5952 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5953 return CMD_WARNING;
5954 }
5955
5956 match.family = afi2family (afi);
5957
5958 if (safi == SAFI_MPLS_VPN)
5959 {
paulfee0f4c2004-09-13 05:12:46 +00005960 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005961 {
5962 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5963 continue;
5964
5965 if ((table = rn->info) != NULL)
5966 {
5967 header = 1;
5968
5969 if ((rm = bgp_node_match (table, &match)) != NULL)
5970 {
5971 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5972 continue;
5973
5974 for (ri = rm->info; ri; ri = ri->next)
5975 {
5976 if (header)
5977 {
5978 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5979 AFI_IP, SAFI_MPLS_VPN);
5980
5981 header = 0;
5982 }
5983 display++;
5984 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5985 }
5986 }
5987 }
5988 }
5989 }
5990 else
5991 {
5992 header = 1;
5993
paulfee0f4c2004-09-13 05:12:46 +00005994 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005995 {
5996 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5997 {
5998 for (ri = rn->info; ri; ri = ri->next)
5999 {
6000 if (header)
6001 {
6002 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6003 header = 0;
6004 }
6005 display++;
6006 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6007 }
6008 }
6009 }
6010 }
6011
6012 if (! display)
6013 {
6014 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6015 return CMD_WARNING;
6016 }
6017
6018 return CMD_SUCCESS;
6019}
6020
paulfee0f4c2004-09-13 05:12:46 +00006021/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006022static int
paulfd79ac92004-10-13 05:06:08 +00006023bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006024 afi_t afi, safi_t safi, struct prefix_rd *prd,
6025 int prefix_check)
6026{
6027 struct bgp *bgp;
6028
6029 /* BGP structure lookup. */
6030 if (view_name)
6031 {
6032 bgp = bgp_lookup_by_name (view_name);
6033 if (bgp == NULL)
6034 {
6035 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6036 return CMD_WARNING;
6037 }
6038 }
6039 else
6040 {
6041 bgp = bgp_get_default ();
6042 if (bgp == NULL)
6043 {
6044 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6045 return CMD_WARNING;
6046 }
6047 }
6048
6049 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6050 afi, safi, prd, prefix_check);
6051}
6052
paul718e3742002-12-13 20:15:29 +00006053/* BGP route print out function. */
6054DEFUN (show_ip_bgp,
6055 show_ip_bgp_cmd,
6056 "show ip bgp",
6057 SHOW_STR
6058 IP_STR
6059 BGP_STR)
6060{
ajs5a646652004-11-05 01:25:55 +00006061 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006062}
6063
6064DEFUN (show_ip_bgp_ipv4,
6065 show_ip_bgp_ipv4_cmd,
6066 "show ip bgp ipv4 (unicast|multicast)",
6067 SHOW_STR
6068 IP_STR
6069 BGP_STR
6070 "Address family\n"
6071 "Address Family modifier\n"
6072 "Address Family modifier\n")
6073{
6074 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006075 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6076 NULL);
paul718e3742002-12-13 20:15:29 +00006077
ajs5a646652004-11-05 01:25:55 +00006078 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006079}
6080
6081DEFUN (show_ip_bgp_route,
6082 show_ip_bgp_route_cmd,
6083 "show ip bgp A.B.C.D",
6084 SHOW_STR
6085 IP_STR
6086 BGP_STR
6087 "Network in the BGP routing table to display\n")
6088{
6089 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6090}
6091
6092DEFUN (show_ip_bgp_ipv4_route,
6093 show_ip_bgp_ipv4_route_cmd,
6094 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6095 SHOW_STR
6096 IP_STR
6097 BGP_STR
6098 "Address family\n"
6099 "Address Family modifier\n"
6100 "Address Family modifier\n"
6101 "Network in the BGP routing table to display\n")
6102{
6103 if (strncmp (argv[0], "m", 1) == 0)
6104 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6105
6106 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6107}
6108
6109DEFUN (show_ip_bgp_vpnv4_all_route,
6110 show_ip_bgp_vpnv4_all_route_cmd,
6111 "show ip bgp vpnv4 all A.B.C.D",
6112 SHOW_STR
6113 IP_STR
6114 BGP_STR
6115 "Display VPNv4 NLRI specific information\n"
6116 "Display information about all VPNv4 NLRIs\n"
6117 "Network in the BGP routing table to display\n")
6118{
6119 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6120}
6121
6122DEFUN (show_ip_bgp_vpnv4_rd_route,
6123 show_ip_bgp_vpnv4_rd_route_cmd,
6124 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6125 SHOW_STR
6126 IP_STR
6127 BGP_STR
6128 "Display VPNv4 NLRI specific information\n"
6129 "Display information for a route distinguisher\n"
6130 "VPN Route Distinguisher\n"
6131 "Network in the BGP routing table to display\n")
6132{
6133 int ret;
6134 struct prefix_rd prd;
6135
6136 ret = str2prefix_rd (argv[0], &prd);
6137 if (! ret)
6138 {
6139 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6140 return CMD_WARNING;
6141 }
6142 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6143}
6144
6145DEFUN (show_ip_bgp_prefix,
6146 show_ip_bgp_prefix_cmd,
6147 "show ip bgp A.B.C.D/M",
6148 SHOW_STR
6149 IP_STR
6150 BGP_STR
6151 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6152{
6153 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6154}
6155
6156DEFUN (show_ip_bgp_ipv4_prefix,
6157 show_ip_bgp_ipv4_prefix_cmd,
6158 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6159 SHOW_STR
6160 IP_STR
6161 BGP_STR
6162 "Address family\n"
6163 "Address Family modifier\n"
6164 "Address Family modifier\n"
6165 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6166{
6167 if (strncmp (argv[0], "m", 1) == 0)
6168 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6169
6170 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6171}
6172
6173DEFUN (show_ip_bgp_vpnv4_all_prefix,
6174 show_ip_bgp_vpnv4_all_prefix_cmd,
6175 "show ip bgp vpnv4 all A.B.C.D/M",
6176 SHOW_STR
6177 IP_STR
6178 BGP_STR
6179 "Display VPNv4 NLRI specific information\n"
6180 "Display information about all VPNv4 NLRIs\n"
6181 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6182{
6183 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6184}
6185
6186DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6187 show_ip_bgp_vpnv4_rd_prefix_cmd,
6188 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6189 SHOW_STR
6190 IP_STR
6191 BGP_STR
6192 "Display VPNv4 NLRI specific information\n"
6193 "Display information for a route distinguisher\n"
6194 "VPN Route Distinguisher\n"
6195 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6196{
6197 int ret;
6198 struct prefix_rd prd;
6199
6200 ret = str2prefix_rd (argv[0], &prd);
6201 if (! ret)
6202 {
6203 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6204 return CMD_WARNING;
6205 }
6206 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6207}
6208
6209DEFUN (show_ip_bgp_view,
6210 show_ip_bgp_view_cmd,
6211 "show ip bgp view WORD",
6212 SHOW_STR
6213 IP_STR
6214 BGP_STR
6215 "BGP view\n"
6216 "BGP view name\n")
6217{
paulbb46e942003-10-24 19:02:03 +00006218 struct bgp *bgp;
6219
6220 /* BGP structure lookup. */
6221 bgp = bgp_lookup_by_name (argv[0]);
6222 if (bgp == NULL)
6223 {
6224 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6225 return CMD_WARNING;
6226 }
6227
ajs5a646652004-11-05 01:25:55 +00006228 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006229}
6230
6231DEFUN (show_ip_bgp_view_route,
6232 show_ip_bgp_view_route_cmd,
6233 "show ip bgp view WORD A.B.C.D",
6234 SHOW_STR
6235 IP_STR
6236 BGP_STR
6237 "BGP view\n"
6238 "BGP view name\n"
6239 "Network in the BGP routing table to display\n")
6240{
6241 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6242}
6243
6244DEFUN (show_ip_bgp_view_prefix,
6245 show_ip_bgp_view_prefix_cmd,
6246 "show ip bgp view WORD A.B.C.D/M",
6247 SHOW_STR
6248 IP_STR
6249 BGP_STR
6250 "BGP view\n"
6251 "BGP view name\n"
6252 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6253{
6254 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6255}
6256
6257#ifdef HAVE_IPV6
6258DEFUN (show_bgp,
6259 show_bgp_cmd,
6260 "show bgp",
6261 SHOW_STR
6262 BGP_STR)
6263{
ajs5a646652004-11-05 01:25:55 +00006264 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6265 NULL);
paul718e3742002-12-13 20:15:29 +00006266}
6267
6268ALIAS (show_bgp,
6269 show_bgp_ipv6_cmd,
6270 "show bgp ipv6",
6271 SHOW_STR
6272 BGP_STR
6273 "Address family\n")
6274
6275/* old command */
6276DEFUN (show_ipv6_bgp,
6277 show_ipv6_bgp_cmd,
6278 "show ipv6 bgp",
6279 SHOW_STR
6280 IP_STR
6281 BGP_STR)
6282{
ajs5a646652004-11-05 01:25:55 +00006283 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6284 NULL);
paul718e3742002-12-13 20:15:29 +00006285}
6286
6287DEFUN (show_bgp_route,
6288 show_bgp_route_cmd,
6289 "show bgp X:X::X:X",
6290 SHOW_STR
6291 BGP_STR
6292 "Network in the BGP routing table to display\n")
6293{
6294 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6295}
6296
6297ALIAS (show_bgp_route,
6298 show_bgp_ipv6_route_cmd,
6299 "show bgp ipv6 X:X::X:X",
6300 SHOW_STR
6301 BGP_STR
6302 "Address family\n"
6303 "Network in the BGP routing table to display\n")
6304
6305/* old command */
6306DEFUN (show_ipv6_bgp_route,
6307 show_ipv6_bgp_route_cmd,
6308 "show ipv6 bgp X:X::X:X",
6309 SHOW_STR
6310 IP_STR
6311 BGP_STR
6312 "Network in the BGP routing table to display\n")
6313{
6314 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6315}
6316
6317DEFUN (show_bgp_prefix,
6318 show_bgp_prefix_cmd,
6319 "show bgp X:X::X:X/M",
6320 SHOW_STR
6321 BGP_STR
6322 "IPv6 prefix <network>/<length>\n")
6323{
6324 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6325}
6326
6327ALIAS (show_bgp_prefix,
6328 show_bgp_ipv6_prefix_cmd,
6329 "show bgp ipv6 X:X::X:X/M",
6330 SHOW_STR
6331 BGP_STR
6332 "Address family\n"
6333 "IPv6 prefix <network>/<length>\n")
6334
6335/* old command */
6336DEFUN (show_ipv6_bgp_prefix,
6337 show_ipv6_bgp_prefix_cmd,
6338 "show ipv6 bgp X:X::X:X/M",
6339 SHOW_STR
6340 IP_STR
6341 BGP_STR
6342 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6343{
6344 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6345}
6346
paulbb46e942003-10-24 19:02:03 +00006347DEFUN (show_bgp_view,
6348 show_bgp_view_cmd,
6349 "show bgp view WORD",
6350 SHOW_STR
6351 BGP_STR
6352 "BGP view\n"
6353 "View name\n")
6354{
6355 struct bgp *bgp;
6356
6357 /* BGP structure lookup. */
6358 bgp = bgp_lookup_by_name (argv[0]);
6359 if (bgp == NULL)
6360 {
6361 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6362 return CMD_WARNING;
6363 }
6364
ajs5a646652004-11-05 01:25:55 +00006365 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006366}
6367
6368ALIAS (show_bgp_view,
6369 show_bgp_view_ipv6_cmd,
6370 "show bgp view WORD ipv6",
6371 SHOW_STR
6372 BGP_STR
6373 "BGP view\n"
6374 "View name\n"
6375 "Address family\n")
6376
6377DEFUN (show_bgp_view_route,
6378 show_bgp_view_route_cmd,
6379 "show bgp view WORD X:X::X:X",
6380 SHOW_STR
6381 BGP_STR
6382 "BGP view\n"
6383 "View name\n"
6384 "Network in the BGP routing table to display\n")
6385{
6386 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6387}
6388
6389ALIAS (show_bgp_view_route,
6390 show_bgp_view_ipv6_route_cmd,
6391 "show bgp view WORD ipv6 X:X::X:X",
6392 SHOW_STR
6393 BGP_STR
6394 "BGP view\n"
6395 "View name\n"
6396 "Address family\n"
6397 "Network in the BGP routing table to display\n")
6398
6399DEFUN (show_bgp_view_prefix,
6400 show_bgp_view_prefix_cmd,
6401 "show bgp view WORD X:X::X:X/M",
6402 SHOW_STR
6403 BGP_STR
6404 "BGP view\n"
6405 "View name\n"
6406 "IPv6 prefix <network>/<length>\n")
6407{
6408 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6409}
6410
6411ALIAS (show_bgp_view_prefix,
6412 show_bgp_view_ipv6_prefix_cmd,
6413 "show bgp view WORD ipv6 X:X::X:X/M",
6414 SHOW_STR
6415 BGP_STR
6416 "BGP view\n"
6417 "View name\n"
6418 "Address family\n"
6419 "IPv6 prefix <network>/<length>\n")
6420
paul718e3742002-12-13 20:15:29 +00006421/* old command */
6422DEFUN (show_ipv6_mbgp,
6423 show_ipv6_mbgp_cmd,
6424 "show ipv6 mbgp",
6425 SHOW_STR
6426 IP_STR
6427 MBGP_STR)
6428{
ajs5a646652004-11-05 01:25:55 +00006429 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6430 NULL);
paul718e3742002-12-13 20:15:29 +00006431}
6432
6433/* old command */
6434DEFUN (show_ipv6_mbgp_route,
6435 show_ipv6_mbgp_route_cmd,
6436 "show ipv6 mbgp X:X::X:X",
6437 SHOW_STR
6438 IP_STR
6439 MBGP_STR
6440 "Network in the MBGP routing table to display\n")
6441{
6442 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6443}
6444
6445/* old command */
6446DEFUN (show_ipv6_mbgp_prefix,
6447 show_ipv6_mbgp_prefix_cmd,
6448 "show ipv6 mbgp X:X::X:X/M",
6449 SHOW_STR
6450 IP_STR
6451 MBGP_STR
6452 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6453{
6454 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6455}
6456#endif
6457
paul718e3742002-12-13 20:15:29 +00006458
paul94f2b392005-06-28 12:44:16 +00006459static int
paulfd79ac92004-10-13 05:06:08 +00006460bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006461 safi_t safi, enum bgp_show_type type)
6462{
6463 int i;
6464 struct buffer *b;
6465 char *regstr;
6466 int first;
6467 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006468 int rc;
paul718e3742002-12-13 20:15:29 +00006469
6470 first = 0;
6471 b = buffer_new (1024);
6472 for (i = 0; i < argc; i++)
6473 {
6474 if (first)
6475 buffer_putc (b, ' ');
6476 else
6477 {
6478 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6479 continue;
6480 first = 1;
6481 }
6482
6483 buffer_putstr (b, argv[i]);
6484 }
6485 buffer_putc (b, '\0');
6486
6487 regstr = buffer_getstr (b);
6488 buffer_free (b);
6489
6490 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006491 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006492 if (! regex)
6493 {
6494 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6495 VTY_NEWLINE);
6496 return CMD_WARNING;
6497 }
6498
ajs5a646652004-11-05 01:25:55 +00006499 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6500 bgp_regex_free (regex);
6501 return rc;
paul718e3742002-12-13 20:15:29 +00006502}
6503
6504DEFUN (show_ip_bgp_regexp,
6505 show_ip_bgp_regexp_cmd,
6506 "show ip bgp regexp .LINE",
6507 SHOW_STR
6508 IP_STR
6509 BGP_STR
6510 "Display routes matching the AS path regular expression\n"
6511 "A regular-expression to match the BGP AS paths\n")
6512{
6513 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6514 bgp_show_type_regexp);
6515}
6516
6517DEFUN (show_ip_bgp_flap_regexp,
6518 show_ip_bgp_flap_regexp_cmd,
6519 "show ip bgp flap-statistics regexp .LINE",
6520 SHOW_STR
6521 IP_STR
6522 BGP_STR
6523 "Display flap statistics of routes\n"
6524 "Display routes matching the AS path regular expression\n"
6525 "A regular-expression to match the BGP AS paths\n")
6526{
6527 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6528 bgp_show_type_flap_regexp);
6529}
6530
6531DEFUN (show_ip_bgp_ipv4_regexp,
6532 show_ip_bgp_ipv4_regexp_cmd,
6533 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6534 SHOW_STR
6535 IP_STR
6536 BGP_STR
6537 "Address family\n"
6538 "Address Family modifier\n"
6539 "Address Family modifier\n"
6540 "Display routes matching the AS path regular expression\n"
6541 "A regular-expression to match the BGP AS paths\n")
6542{
6543 if (strncmp (argv[0], "m", 1) == 0)
6544 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6545 bgp_show_type_regexp);
6546
6547 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6548 bgp_show_type_regexp);
6549}
6550
6551#ifdef HAVE_IPV6
6552DEFUN (show_bgp_regexp,
6553 show_bgp_regexp_cmd,
6554 "show bgp regexp .LINE",
6555 SHOW_STR
6556 BGP_STR
6557 "Display routes matching the AS path regular expression\n"
6558 "A regular-expression to match the BGP AS paths\n")
6559{
6560 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6561 bgp_show_type_regexp);
6562}
6563
6564ALIAS (show_bgp_regexp,
6565 show_bgp_ipv6_regexp_cmd,
6566 "show bgp ipv6 regexp .LINE",
6567 SHOW_STR
6568 BGP_STR
6569 "Address family\n"
6570 "Display routes matching the AS path regular expression\n"
6571 "A regular-expression to match the BGP AS paths\n")
6572
6573/* old command */
6574DEFUN (show_ipv6_bgp_regexp,
6575 show_ipv6_bgp_regexp_cmd,
6576 "show ipv6 bgp regexp .LINE",
6577 SHOW_STR
6578 IP_STR
6579 BGP_STR
6580 "Display routes matching the AS path regular expression\n"
6581 "A regular-expression to match the BGP AS paths\n")
6582{
6583 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6584 bgp_show_type_regexp);
6585}
6586
6587/* old command */
6588DEFUN (show_ipv6_mbgp_regexp,
6589 show_ipv6_mbgp_regexp_cmd,
6590 "show ipv6 mbgp regexp .LINE",
6591 SHOW_STR
6592 IP_STR
6593 BGP_STR
6594 "Display routes matching the AS path regular expression\n"
6595 "A regular-expression to match the MBGP AS paths\n")
6596{
6597 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6598 bgp_show_type_regexp);
6599}
6600#endif /* HAVE_IPV6 */
6601
paul94f2b392005-06-28 12:44:16 +00006602static int
paulfd79ac92004-10-13 05:06:08 +00006603bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006604 safi_t safi, enum bgp_show_type type)
6605{
6606 struct prefix_list *plist;
6607
6608 plist = prefix_list_lookup (afi, prefix_list_str);
6609 if (plist == NULL)
6610 {
6611 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6612 prefix_list_str, VTY_NEWLINE);
6613 return CMD_WARNING;
6614 }
6615
ajs5a646652004-11-05 01:25:55 +00006616 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006617}
6618
6619DEFUN (show_ip_bgp_prefix_list,
6620 show_ip_bgp_prefix_list_cmd,
6621 "show ip bgp prefix-list WORD",
6622 SHOW_STR
6623 IP_STR
6624 BGP_STR
6625 "Display routes conforming to the prefix-list\n"
6626 "IP prefix-list name\n")
6627{
6628 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6629 bgp_show_type_prefix_list);
6630}
6631
6632DEFUN (show_ip_bgp_flap_prefix_list,
6633 show_ip_bgp_flap_prefix_list_cmd,
6634 "show ip bgp flap-statistics prefix-list WORD",
6635 SHOW_STR
6636 IP_STR
6637 BGP_STR
6638 "Display flap statistics of routes\n"
6639 "Display routes conforming to the prefix-list\n"
6640 "IP prefix-list name\n")
6641{
6642 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6643 bgp_show_type_flap_prefix_list);
6644}
6645
6646DEFUN (show_ip_bgp_ipv4_prefix_list,
6647 show_ip_bgp_ipv4_prefix_list_cmd,
6648 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6649 SHOW_STR
6650 IP_STR
6651 BGP_STR
6652 "Address family\n"
6653 "Address Family modifier\n"
6654 "Address Family modifier\n"
6655 "Display routes conforming to the prefix-list\n"
6656 "IP prefix-list name\n")
6657{
6658 if (strncmp (argv[0], "m", 1) == 0)
6659 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6660 bgp_show_type_prefix_list);
6661
6662 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6663 bgp_show_type_prefix_list);
6664}
6665
6666#ifdef HAVE_IPV6
6667DEFUN (show_bgp_prefix_list,
6668 show_bgp_prefix_list_cmd,
6669 "show bgp prefix-list WORD",
6670 SHOW_STR
6671 BGP_STR
6672 "Display routes conforming to the prefix-list\n"
6673 "IPv6 prefix-list name\n")
6674{
6675 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6676 bgp_show_type_prefix_list);
6677}
6678
6679ALIAS (show_bgp_prefix_list,
6680 show_bgp_ipv6_prefix_list_cmd,
6681 "show bgp ipv6 prefix-list WORD",
6682 SHOW_STR
6683 BGP_STR
6684 "Address family\n"
6685 "Display routes conforming to the prefix-list\n"
6686 "IPv6 prefix-list name\n")
6687
6688/* old command */
6689DEFUN (show_ipv6_bgp_prefix_list,
6690 show_ipv6_bgp_prefix_list_cmd,
6691 "show ipv6 bgp prefix-list WORD",
6692 SHOW_STR
6693 IPV6_STR
6694 BGP_STR
6695 "Display routes matching the prefix-list\n"
6696 "IPv6 prefix-list name\n")
6697{
6698 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6699 bgp_show_type_prefix_list);
6700}
6701
6702/* old command */
6703DEFUN (show_ipv6_mbgp_prefix_list,
6704 show_ipv6_mbgp_prefix_list_cmd,
6705 "show ipv6 mbgp prefix-list WORD",
6706 SHOW_STR
6707 IPV6_STR
6708 MBGP_STR
6709 "Display routes matching the prefix-list\n"
6710 "IPv6 prefix-list name\n")
6711{
6712 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6713 bgp_show_type_prefix_list);
6714}
6715#endif /* HAVE_IPV6 */
6716
paul94f2b392005-06-28 12:44:16 +00006717static int
paulfd79ac92004-10-13 05:06:08 +00006718bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006719 safi_t safi, enum bgp_show_type type)
6720{
6721 struct as_list *as_list;
6722
6723 as_list = as_list_lookup (filter);
6724 if (as_list == NULL)
6725 {
6726 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6727 return CMD_WARNING;
6728 }
6729
ajs5a646652004-11-05 01:25:55 +00006730 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006731}
6732
6733DEFUN (show_ip_bgp_filter_list,
6734 show_ip_bgp_filter_list_cmd,
6735 "show ip bgp filter-list WORD",
6736 SHOW_STR
6737 IP_STR
6738 BGP_STR
6739 "Display routes conforming to the filter-list\n"
6740 "Regular expression access list name\n")
6741{
6742 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6743 bgp_show_type_filter_list);
6744}
6745
6746DEFUN (show_ip_bgp_flap_filter_list,
6747 show_ip_bgp_flap_filter_list_cmd,
6748 "show ip bgp flap-statistics filter-list WORD",
6749 SHOW_STR
6750 IP_STR
6751 BGP_STR
6752 "Display flap statistics of routes\n"
6753 "Display routes conforming to the filter-list\n"
6754 "Regular expression access list name\n")
6755{
6756 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6757 bgp_show_type_flap_filter_list);
6758}
6759
6760DEFUN (show_ip_bgp_ipv4_filter_list,
6761 show_ip_bgp_ipv4_filter_list_cmd,
6762 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6763 SHOW_STR
6764 IP_STR
6765 BGP_STR
6766 "Address family\n"
6767 "Address Family modifier\n"
6768 "Address Family modifier\n"
6769 "Display routes conforming to the filter-list\n"
6770 "Regular expression access list name\n")
6771{
6772 if (strncmp (argv[0], "m", 1) == 0)
6773 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6774 bgp_show_type_filter_list);
6775
6776 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6777 bgp_show_type_filter_list);
6778}
6779
6780#ifdef HAVE_IPV6
6781DEFUN (show_bgp_filter_list,
6782 show_bgp_filter_list_cmd,
6783 "show bgp filter-list WORD",
6784 SHOW_STR
6785 BGP_STR
6786 "Display routes conforming to the filter-list\n"
6787 "Regular expression access list name\n")
6788{
6789 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6790 bgp_show_type_filter_list);
6791}
6792
6793ALIAS (show_bgp_filter_list,
6794 show_bgp_ipv6_filter_list_cmd,
6795 "show bgp ipv6 filter-list WORD",
6796 SHOW_STR
6797 BGP_STR
6798 "Address family\n"
6799 "Display routes conforming to the filter-list\n"
6800 "Regular expression access list name\n")
6801
6802/* old command */
6803DEFUN (show_ipv6_bgp_filter_list,
6804 show_ipv6_bgp_filter_list_cmd,
6805 "show ipv6 bgp filter-list WORD",
6806 SHOW_STR
6807 IPV6_STR
6808 BGP_STR
6809 "Display routes conforming to the filter-list\n"
6810 "Regular expression access list name\n")
6811{
6812 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6813 bgp_show_type_filter_list);
6814}
6815
6816/* old command */
6817DEFUN (show_ipv6_mbgp_filter_list,
6818 show_ipv6_mbgp_filter_list_cmd,
6819 "show ipv6 mbgp filter-list WORD",
6820 SHOW_STR
6821 IPV6_STR
6822 MBGP_STR
6823 "Display routes conforming to the filter-list\n"
6824 "Regular expression access list name\n")
6825{
6826 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6827 bgp_show_type_filter_list);
6828}
6829#endif /* HAVE_IPV6 */
6830
paul94f2b392005-06-28 12:44:16 +00006831static int
paulfd79ac92004-10-13 05:06:08 +00006832bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006833 safi_t safi, enum bgp_show_type type)
6834{
6835 struct route_map *rmap;
6836
6837 rmap = route_map_lookup_by_name (rmap_str);
6838 if (! rmap)
6839 {
6840 vty_out (vty, "%% %s is not a valid route-map name%s",
6841 rmap_str, VTY_NEWLINE);
6842 return CMD_WARNING;
6843 }
6844
ajs5a646652004-11-05 01:25:55 +00006845 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006846}
6847
6848DEFUN (show_ip_bgp_route_map,
6849 show_ip_bgp_route_map_cmd,
6850 "show ip bgp route-map WORD",
6851 SHOW_STR
6852 IP_STR
6853 BGP_STR
6854 "Display routes matching the route-map\n"
6855 "A route-map to match on\n")
6856{
6857 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6858 bgp_show_type_route_map);
6859}
6860
6861DEFUN (show_ip_bgp_flap_route_map,
6862 show_ip_bgp_flap_route_map_cmd,
6863 "show ip bgp flap-statistics route-map WORD",
6864 SHOW_STR
6865 IP_STR
6866 BGP_STR
6867 "Display flap statistics of routes\n"
6868 "Display routes matching the route-map\n"
6869 "A route-map to match on\n")
6870{
6871 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6872 bgp_show_type_flap_route_map);
6873}
6874
6875DEFUN (show_ip_bgp_ipv4_route_map,
6876 show_ip_bgp_ipv4_route_map_cmd,
6877 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6878 SHOW_STR
6879 IP_STR
6880 BGP_STR
6881 "Address family\n"
6882 "Address Family modifier\n"
6883 "Address Family modifier\n"
6884 "Display routes matching the route-map\n"
6885 "A route-map to match on\n")
6886{
6887 if (strncmp (argv[0], "m", 1) == 0)
6888 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6889 bgp_show_type_route_map);
6890
6891 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6892 bgp_show_type_route_map);
6893}
6894
6895DEFUN (show_bgp_route_map,
6896 show_bgp_route_map_cmd,
6897 "show bgp route-map WORD",
6898 SHOW_STR
6899 BGP_STR
6900 "Display routes matching the route-map\n"
6901 "A route-map to match on\n")
6902{
6903 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6904 bgp_show_type_route_map);
6905}
6906
6907ALIAS (show_bgp_route_map,
6908 show_bgp_ipv6_route_map_cmd,
6909 "show bgp ipv6 route-map WORD",
6910 SHOW_STR
6911 BGP_STR
6912 "Address family\n"
6913 "Display routes matching the route-map\n"
6914 "A route-map to match on\n")
6915
6916DEFUN (show_ip_bgp_cidr_only,
6917 show_ip_bgp_cidr_only_cmd,
6918 "show ip bgp cidr-only",
6919 SHOW_STR
6920 IP_STR
6921 BGP_STR
6922 "Display only routes with non-natural netmasks\n")
6923{
6924 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006925 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006926}
6927
6928DEFUN (show_ip_bgp_flap_cidr_only,
6929 show_ip_bgp_flap_cidr_only_cmd,
6930 "show ip bgp flap-statistics cidr-only",
6931 SHOW_STR
6932 IP_STR
6933 BGP_STR
6934 "Display flap statistics of routes\n"
6935 "Display only routes with non-natural netmasks\n")
6936{
6937 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006938 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006939}
6940
6941DEFUN (show_ip_bgp_ipv4_cidr_only,
6942 show_ip_bgp_ipv4_cidr_only_cmd,
6943 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6944 SHOW_STR
6945 IP_STR
6946 BGP_STR
6947 "Address family\n"
6948 "Address Family modifier\n"
6949 "Address Family modifier\n"
6950 "Display only routes with non-natural netmasks\n")
6951{
6952 if (strncmp (argv[0], "m", 1) == 0)
6953 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006954 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006955
6956 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006957 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006958}
6959
6960DEFUN (show_ip_bgp_community_all,
6961 show_ip_bgp_community_all_cmd,
6962 "show ip bgp community",
6963 SHOW_STR
6964 IP_STR
6965 BGP_STR
6966 "Display routes matching the communities\n")
6967{
6968 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006969 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006970}
6971
6972DEFUN (show_ip_bgp_ipv4_community_all,
6973 show_ip_bgp_ipv4_community_all_cmd,
6974 "show ip bgp ipv4 (unicast|multicast) community",
6975 SHOW_STR
6976 IP_STR
6977 BGP_STR
6978 "Address family\n"
6979 "Address Family modifier\n"
6980 "Address Family modifier\n"
6981 "Display routes matching the communities\n")
6982{
6983 if (strncmp (argv[0], "m", 1) == 0)
6984 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006985 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006986
6987 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006988 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006989}
6990
6991#ifdef HAVE_IPV6
6992DEFUN (show_bgp_community_all,
6993 show_bgp_community_all_cmd,
6994 "show bgp community",
6995 SHOW_STR
6996 BGP_STR
6997 "Display routes matching the communities\n")
6998{
6999 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007000 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007001}
7002
7003ALIAS (show_bgp_community_all,
7004 show_bgp_ipv6_community_all_cmd,
7005 "show bgp ipv6 community",
7006 SHOW_STR
7007 BGP_STR
7008 "Address family\n"
7009 "Display routes matching the communities\n")
7010
7011/* old command */
7012DEFUN (show_ipv6_bgp_community_all,
7013 show_ipv6_bgp_community_all_cmd,
7014 "show ipv6 bgp community",
7015 SHOW_STR
7016 IPV6_STR
7017 BGP_STR
7018 "Display routes matching the communities\n")
7019{
7020 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007021 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007022}
7023
7024/* old command */
7025DEFUN (show_ipv6_mbgp_community_all,
7026 show_ipv6_mbgp_community_all_cmd,
7027 "show ipv6 mbgp community",
7028 SHOW_STR
7029 IPV6_STR
7030 MBGP_STR
7031 "Display routes matching the communities\n")
7032{
7033 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007034 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007035}
7036#endif /* HAVE_IPV6 */
7037
paul94f2b392005-06-28 12:44:16 +00007038static int
paulfd79ac92004-10-13 05:06:08 +00007039bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7040 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007041{
7042 struct community *com;
7043 struct buffer *b;
7044 int i;
7045 char *str;
7046 int first = 0;
7047
7048 b = buffer_new (1024);
7049 for (i = 0; i < argc; i++)
7050 {
7051 if (first)
7052 buffer_putc (b, ' ');
7053 else
7054 {
7055 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7056 continue;
7057 first = 1;
7058 }
7059
7060 buffer_putstr (b, argv[i]);
7061 }
7062 buffer_putc (b, '\0');
7063
7064 str = buffer_getstr (b);
7065 buffer_free (b);
7066
7067 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007068 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007069 if (! com)
7070 {
7071 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7072 return CMD_WARNING;
7073 }
7074
ajs5a646652004-11-05 01:25:55 +00007075 return bgp_show (vty, NULL, afi, safi,
7076 (exact ? bgp_show_type_community_exact :
7077 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007078}
7079
7080DEFUN (show_ip_bgp_community,
7081 show_ip_bgp_community_cmd,
7082 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7083 SHOW_STR
7084 IP_STR
7085 BGP_STR
7086 "Display routes matching the communities\n"
7087 "community number\n"
7088 "Do not send outside local AS (well-known community)\n"
7089 "Do not advertise to any peer (well-known community)\n"
7090 "Do not export to next AS (well-known community)\n")
7091{
7092 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7093}
7094
7095ALIAS (show_ip_bgp_community,
7096 show_ip_bgp_community2_cmd,
7097 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7098 SHOW_STR
7099 IP_STR
7100 BGP_STR
7101 "Display routes matching the communities\n"
7102 "community number\n"
7103 "Do not send outside local AS (well-known community)\n"
7104 "Do not advertise to any peer (well-known community)\n"
7105 "Do not export to next AS (well-known community)\n"
7106 "community number\n"
7107 "Do not send outside local AS (well-known community)\n"
7108 "Do not advertise to any peer (well-known community)\n"
7109 "Do not export to next AS (well-known community)\n")
7110
7111ALIAS (show_ip_bgp_community,
7112 show_ip_bgp_community3_cmd,
7113 "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)",
7114 SHOW_STR
7115 IP_STR
7116 BGP_STR
7117 "Display routes matching the communities\n"
7118 "community number\n"
7119 "Do not send outside local AS (well-known community)\n"
7120 "Do not advertise to any peer (well-known community)\n"
7121 "Do not export to next AS (well-known community)\n"
7122 "community number\n"
7123 "Do not send outside local AS (well-known community)\n"
7124 "Do not advertise to any peer (well-known community)\n"
7125 "Do not export to next AS (well-known community)\n"
7126 "community number\n"
7127 "Do not send outside local AS (well-known community)\n"
7128 "Do not advertise to any peer (well-known community)\n"
7129 "Do not export to next AS (well-known community)\n")
7130
7131ALIAS (show_ip_bgp_community,
7132 show_ip_bgp_community4_cmd,
7133 "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)",
7134 SHOW_STR
7135 IP_STR
7136 BGP_STR
7137 "Display routes matching the communities\n"
7138 "community number\n"
7139 "Do not send outside local AS (well-known community)\n"
7140 "Do not advertise to any peer (well-known community)\n"
7141 "Do not export to next AS (well-known community)\n"
7142 "community number\n"
7143 "Do not send outside local AS (well-known community)\n"
7144 "Do not advertise to any peer (well-known community)\n"
7145 "Do not export to next AS (well-known community)\n"
7146 "community number\n"
7147 "Do not send outside local AS (well-known community)\n"
7148 "Do not advertise to any peer (well-known community)\n"
7149 "Do not export to next AS (well-known community)\n"
7150 "community number\n"
7151 "Do not send outside local AS (well-known community)\n"
7152 "Do not advertise to any peer (well-known community)\n"
7153 "Do not export to next AS (well-known community)\n")
7154
7155DEFUN (show_ip_bgp_ipv4_community,
7156 show_ip_bgp_ipv4_community_cmd,
7157 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7158 SHOW_STR
7159 IP_STR
7160 BGP_STR
7161 "Address family\n"
7162 "Address Family modifier\n"
7163 "Address Family modifier\n"
7164 "Display routes matching the communities\n"
7165 "community number\n"
7166 "Do not send outside local AS (well-known community)\n"
7167 "Do not advertise to any peer (well-known community)\n"
7168 "Do not export to next AS (well-known community)\n")
7169{
7170 if (strncmp (argv[0], "m", 1) == 0)
7171 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7172
7173 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7174}
7175
7176ALIAS (show_ip_bgp_ipv4_community,
7177 show_ip_bgp_ipv4_community2_cmd,
7178 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7179 SHOW_STR
7180 IP_STR
7181 BGP_STR
7182 "Address family\n"
7183 "Address Family modifier\n"
7184 "Address Family modifier\n"
7185 "Display routes matching the communities\n"
7186 "community number\n"
7187 "Do not send outside local AS (well-known community)\n"
7188 "Do not advertise to any peer (well-known community)\n"
7189 "Do not export to next AS (well-known community)\n"
7190 "community number\n"
7191 "Do not send outside local AS (well-known community)\n"
7192 "Do not advertise to any peer (well-known community)\n"
7193 "Do not export to next AS (well-known community)\n")
7194
7195ALIAS (show_ip_bgp_ipv4_community,
7196 show_ip_bgp_ipv4_community3_cmd,
7197 "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)",
7198 SHOW_STR
7199 IP_STR
7200 BGP_STR
7201 "Address family\n"
7202 "Address Family modifier\n"
7203 "Address Family modifier\n"
7204 "Display routes matching the communities\n"
7205 "community number\n"
7206 "Do not send outside local AS (well-known community)\n"
7207 "Do not advertise to any peer (well-known community)\n"
7208 "Do not export to next AS (well-known community)\n"
7209 "community number\n"
7210 "Do not send outside local AS (well-known community)\n"
7211 "Do not advertise to any peer (well-known community)\n"
7212 "Do not export to next AS (well-known community)\n"
7213 "community number\n"
7214 "Do not send outside local AS (well-known community)\n"
7215 "Do not advertise to any peer (well-known community)\n"
7216 "Do not export to next AS (well-known community)\n")
7217
7218ALIAS (show_ip_bgp_ipv4_community,
7219 show_ip_bgp_ipv4_community4_cmd,
7220 "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)",
7221 SHOW_STR
7222 IP_STR
7223 BGP_STR
7224 "Address family\n"
7225 "Address Family modifier\n"
7226 "Address Family modifier\n"
7227 "Display routes matching the communities\n"
7228 "community number\n"
7229 "Do not send outside local AS (well-known community)\n"
7230 "Do not advertise to any peer (well-known community)\n"
7231 "Do not export to next AS (well-known community)\n"
7232 "community number\n"
7233 "Do not send outside local AS (well-known community)\n"
7234 "Do not advertise to any peer (well-known community)\n"
7235 "Do not export to next AS (well-known community)\n"
7236 "community number\n"
7237 "Do not send outside local AS (well-known community)\n"
7238 "Do not advertise to any peer (well-known community)\n"
7239 "Do not export to next AS (well-known community)\n"
7240 "community number\n"
7241 "Do not send outside local AS (well-known community)\n"
7242 "Do not advertise to any peer (well-known community)\n"
7243 "Do not export to next AS (well-known community)\n")
7244
7245DEFUN (show_ip_bgp_community_exact,
7246 show_ip_bgp_community_exact_cmd,
7247 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7248 SHOW_STR
7249 IP_STR
7250 BGP_STR
7251 "Display routes matching the communities\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{
7258 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7259}
7260
7261ALIAS (show_ip_bgp_community_exact,
7262 show_ip_bgp_community2_exact_cmd,
7263 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7264 SHOW_STR
7265 IP_STR
7266 BGP_STR
7267 "Display routes matching the communities\n"
7268 "community number\n"
7269 "Do not send outside local AS (well-known community)\n"
7270 "Do not advertise to any peer (well-known community)\n"
7271 "Do not export to next AS (well-known community)\n"
7272 "community number\n"
7273 "Do not send outside local AS (well-known community)\n"
7274 "Do not advertise to any peer (well-known community)\n"
7275 "Do not export to next AS (well-known community)\n"
7276 "Exact match of the communities")
7277
7278ALIAS (show_ip_bgp_community_exact,
7279 show_ip_bgp_community3_exact_cmd,
7280 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7281 SHOW_STR
7282 IP_STR
7283 BGP_STR
7284 "Display routes matching the communities\n"
7285 "community number\n"
7286 "Do not send outside local AS (well-known community)\n"
7287 "Do not advertise to any peer (well-known community)\n"
7288 "Do not export to next AS (well-known community)\n"
7289 "community number\n"
7290 "Do not send outside local AS (well-known community)\n"
7291 "Do not advertise to any peer (well-known community)\n"
7292 "Do not export to next AS (well-known community)\n"
7293 "community number\n"
7294 "Do not send outside local AS (well-known community)\n"
7295 "Do not advertise to any peer (well-known community)\n"
7296 "Do not export to next AS (well-known community)\n"
7297 "Exact match of the communities")
7298
7299ALIAS (show_ip_bgp_community_exact,
7300 show_ip_bgp_community4_exact_cmd,
7301 "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",
7302 SHOW_STR
7303 IP_STR
7304 BGP_STR
7305 "Display routes matching the communities\n"
7306 "community number\n"
7307 "Do not send outside local AS (well-known community)\n"
7308 "Do not advertise to any peer (well-known community)\n"
7309 "Do not export to next AS (well-known community)\n"
7310 "community number\n"
7311 "Do not send outside local AS (well-known community)\n"
7312 "Do not advertise to any peer (well-known community)\n"
7313 "Do not export to next AS (well-known community)\n"
7314 "community number\n"
7315 "Do not send outside local AS (well-known community)\n"
7316 "Do not advertise to any peer (well-known community)\n"
7317 "Do not export to next AS (well-known community)\n"
7318 "community number\n"
7319 "Do not send outside local AS (well-known community)\n"
7320 "Do not advertise to any peer (well-known community)\n"
7321 "Do not export to next AS (well-known community)\n"
7322 "Exact match of the communities")
7323
7324DEFUN (show_ip_bgp_ipv4_community_exact,
7325 show_ip_bgp_ipv4_community_exact_cmd,
7326 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7327 SHOW_STR
7328 IP_STR
7329 BGP_STR
7330 "Address family\n"
7331 "Address Family modifier\n"
7332 "Address Family modifier\n"
7333 "Display routes matching the communities\n"
7334 "community number\n"
7335 "Do not send outside local AS (well-known community)\n"
7336 "Do not advertise to any peer (well-known community)\n"
7337 "Do not export to next AS (well-known community)\n"
7338 "Exact match of the communities")
7339{
7340 if (strncmp (argv[0], "m", 1) == 0)
7341 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7342
7343 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7344}
7345
7346ALIAS (show_ip_bgp_ipv4_community_exact,
7347 show_ip_bgp_ipv4_community2_exact_cmd,
7348 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7349 SHOW_STR
7350 IP_STR
7351 BGP_STR
7352 "Address family\n"
7353 "Address Family modifier\n"
7354 "Address Family modifier\n"
7355 "Display routes matching the communities\n"
7356 "community number\n"
7357 "Do not send outside local AS (well-known community)\n"
7358 "Do not advertise to any peer (well-known community)\n"
7359 "Do not export to next AS (well-known community)\n"
7360 "community number\n"
7361 "Do not send outside local AS (well-known community)\n"
7362 "Do not advertise to any peer (well-known community)\n"
7363 "Do not export to next AS (well-known community)\n"
7364 "Exact match of the communities")
7365
7366ALIAS (show_ip_bgp_ipv4_community_exact,
7367 show_ip_bgp_ipv4_community3_exact_cmd,
7368 "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",
7369 SHOW_STR
7370 IP_STR
7371 BGP_STR
7372 "Address family\n"
7373 "Address Family modifier\n"
7374 "Address Family modifier\n"
7375 "Display routes matching the communities\n"
7376 "community number\n"
7377 "Do not send outside local AS (well-known community)\n"
7378 "Do not advertise to any peer (well-known community)\n"
7379 "Do not export to next AS (well-known community)\n"
7380 "community number\n"
7381 "Do not send outside local AS (well-known community)\n"
7382 "Do not advertise to any peer (well-known community)\n"
7383 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7389
7390ALIAS (show_ip_bgp_ipv4_community_exact,
7391 show_ip_bgp_ipv4_community4_exact_cmd,
7392 "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",
7393 SHOW_STR
7394 IP_STR
7395 BGP_STR
7396 "Address family\n"
7397 "Address Family modifier\n"
7398 "Address Family modifier\n"
7399 "Display routes matching the communities\n"
7400 "community number\n"
7401 "Do not send outside local AS (well-known community)\n"
7402 "Do not advertise to any peer (well-known community)\n"
7403 "Do not export to next AS (well-known community)\n"
7404 "community number\n"
7405 "Do not send outside local AS (well-known community)\n"
7406 "Do not advertise to any peer (well-known community)\n"
7407 "Do not export to next AS (well-known community)\n"
7408 "community number\n"
7409 "Do not send outside local AS (well-known community)\n"
7410 "Do not advertise to any peer (well-known community)\n"
7411 "Do not export to next AS (well-known community)\n"
7412 "community number\n"
7413 "Do not send outside local AS (well-known community)\n"
7414 "Do not advertise to any peer (well-known community)\n"
7415 "Do not export to next AS (well-known community)\n"
7416 "Exact match of the communities")
7417
7418#ifdef HAVE_IPV6
7419DEFUN (show_bgp_community,
7420 show_bgp_community_cmd,
7421 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7422 SHOW_STR
7423 BGP_STR
7424 "Display routes matching the communities\n"
7425 "community number\n"
7426 "Do not send outside local AS (well-known community)\n"
7427 "Do not advertise to any peer (well-known community)\n"
7428 "Do not export to next AS (well-known community)\n")
7429{
7430 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7431}
7432
7433ALIAS (show_bgp_community,
7434 show_bgp_ipv6_community_cmd,
7435 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7436 SHOW_STR
7437 BGP_STR
7438 "Address family\n"
7439 "Display routes matching the communities\n"
7440 "community number\n"
7441 "Do not send outside local AS (well-known community)\n"
7442 "Do not advertise to any peer (well-known community)\n"
7443 "Do not export to next AS (well-known community)\n")
7444
7445ALIAS (show_bgp_community,
7446 show_bgp_community2_cmd,
7447 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7448 SHOW_STR
7449 BGP_STR
7450 "Display routes matching the communities\n"
7451 "community number\n"
7452 "Do not send outside local AS (well-known community)\n"
7453 "Do not advertise to any peer (well-known community)\n"
7454 "Do not export to next AS (well-known community)\n"
7455 "community number\n"
7456 "Do not send outside local AS (well-known community)\n"
7457 "Do not advertise to any peer (well-known community)\n"
7458 "Do not export to next AS (well-known community)\n")
7459
7460ALIAS (show_bgp_community,
7461 show_bgp_ipv6_community2_cmd,
7462 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7463 SHOW_STR
7464 BGP_STR
7465 "Address family\n"
7466 "Display routes matching the communities\n"
7467 "community number\n"
7468 "Do not send outside local AS (well-known community)\n"
7469 "Do not advertise to any peer (well-known community)\n"
7470 "Do not export to next AS (well-known community)\n"
7471 "community number\n"
7472 "Do not send outside local AS (well-known community)\n"
7473 "Do not advertise to any peer (well-known community)\n"
7474 "Do not export to next AS (well-known community)\n")
7475
7476ALIAS (show_bgp_community,
7477 show_bgp_community3_cmd,
7478 "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)",
7479 SHOW_STR
7480 BGP_STR
7481 "Display routes matching the communities\n"
7482 "community number\n"
7483 "Do not send outside local AS (well-known community)\n"
7484 "Do not advertise to any peer (well-known community)\n"
7485 "Do not export to next AS (well-known community)\n"
7486 "community number\n"
7487 "Do not send outside local AS (well-known community)\n"
7488 "Do not advertise to any peer (well-known community)\n"
7489 "Do not export to next AS (well-known community)\n"
7490 "community number\n"
7491 "Do not send outside local AS (well-known community)\n"
7492 "Do not advertise to any peer (well-known community)\n"
7493 "Do not export to next AS (well-known community)\n")
7494
7495ALIAS (show_bgp_community,
7496 show_bgp_ipv6_community3_cmd,
7497 "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)",
7498 SHOW_STR
7499 BGP_STR
7500 "Address family\n"
7501 "Display routes matching the communities\n"
7502 "community number\n"
7503 "Do not send outside local AS (well-known community)\n"
7504 "Do not advertise to any peer (well-known community)\n"
7505 "Do not export to next AS (well-known community)\n"
7506 "community number\n"
7507 "Do not send outside local AS (well-known community)\n"
7508 "Do not advertise to any peer (well-known community)\n"
7509 "Do not export to next AS (well-known community)\n"
7510 "community number\n"
7511 "Do not send outside local AS (well-known community)\n"
7512 "Do not advertise to any peer (well-known community)\n"
7513 "Do not export to next AS (well-known community)\n")
7514
7515ALIAS (show_bgp_community,
7516 show_bgp_community4_cmd,
7517 "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)",
7518 SHOW_STR
7519 BGP_STR
7520 "Display routes matching the communities\n"
7521 "community number\n"
7522 "Do not send outside local AS (well-known community)\n"
7523 "Do not advertise to any peer (well-known community)\n"
7524 "Do not export to next AS (well-known community)\n"
7525 "community number\n"
7526 "Do not send outside local AS (well-known community)\n"
7527 "Do not advertise to any peer (well-known community)\n"
7528 "Do not export to next AS (well-known community)\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 "community number\n"
7534 "Do not send outside local AS (well-known community)\n"
7535 "Do not advertise to any peer (well-known community)\n"
7536 "Do not export to next AS (well-known community)\n")
7537
7538ALIAS (show_bgp_community,
7539 show_bgp_ipv6_community4_cmd,
7540 "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)",
7541 SHOW_STR
7542 BGP_STR
7543 "Address family\n"
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 "community number\n"
7554 "Do not send outside local AS (well-known community)\n"
7555 "Do not advertise to any peer (well-known community)\n"
7556 "Do not export to next AS (well-known community)\n"
7557 "community number\n"
7558 "Do not send outside local AS (well-known community)\n"
7559 "Do not advertise to any peer (well-known community)\n"
7560 "Do not export to next AS (well-known community)\n")
7561
7562/* old command */
7563DEFUN (show_ipv6_bgp_community,
7564 show_ipv6_bgp_community_cmd,
7565 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7566 SHOW_STR
7567 IPV6_STR
7568 BGP_STR
7569 "Display routes matching the communities\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 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7576}
7577
7578/* old command */
7579ALIAS (show_ipv6_bgp_community,
7580 show_ipv6_bgp_community2_cmd,
7581 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7582 SHOW_STR
7583 IPV6_STR
7584 BGP_STR
7585 "Display routes matching the communities\n"
7586 "community number\n"
7587 "Do not send outside local AS (well-known community)\n"
7588 "Do not advertise to any peer (well-known community)\n"
7589 "Do not export to next AS (well-known community)\n"
7590 "community number\n"
7591 "Do not send outside local AS (well-known community)\n"
7592 "Do not advertise to any peer (well-known community)\n"
7593 "Do not export to next AS (well-known community)\n")
7594
7595/* old command */
7596ALIAS (show_ipv6_bgp_community,
7597 show_ipv6_bgp_community3_cmd,
7598 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7599 SHOW_STR
7600 IPV6_STR
7601 BGP_STR
7602 "Display routes matching the communities\n"
7603 "community number\n"
7604 "Do not send outside local AS (well-known community)\n"
7605 "Do not advertise to any peer (well-known community)\n"
7606 "Do not export to next AS (well-known community)\n"
7607 "community number\n"
7608 "Do not send outside local AS (well-known community)\n"
7609 "Do not advertise to any peer (well-known community)\n"
7610 "Do not export to next AS (well-known community)\n"
7611 "community number\n"
7612 "Do not send outside local AS (well-known community)\n"
7613 "Do not advertise to any peer (well-known community)\n"
7614 "Do not export to next AS (well-known community)\n")
7615
7616/* old command */
7617ALIAS (show_ipv6_bgp_community,
7618 show_ipv6_bgp_community4_cmd,
7619 "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)",
7620 SHOW_STR
7621 IPV6_STR
7622 BGP_STR
7623 "Display routes matching the communities\n"
7624 "community number\n"
7625 "Do not send outside local AS (well-known community)\n"
7626 "Do not advertise to any peer (well-known community)\n"
7627 "Do not export to next AS (well-known community)\n"
7628 "community number\n"
7629 "Do not send outside local AS (well-known community)\n"
7630 "Do not advertise to any peer (well-known community)\n"
7631 "Do not export to next AS (well-known community)\n"
7632 "community number\n"
7633 "Do not send outside local AS (well-known community)\n"
7634 "Do not advertise to any peer (well-known community)\n"
7635 "Do not export to next AS (well-known community)\n"
7636 "community number\n"
7637 "Do not send outside local AS (well-known community)\n"
7638 "Do not advertise to any peer (well-known community)\n"
7639 "Do not export to next AS (well-known community)\n")
7640
7641DEFUN (show_bgp_community_exact,
7642 show_bgp_community_exact_cmd,
7643 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7644 SHOW_STR
7645 BGP_STR
7646 "Display routes matching the communities\n"
7647 "community number\n"
7648 "Do not send outside local AS (well-known community)\n"
7649 "Do not advertise to any peer (well-known community)\n"
7650 "Do not export to next AS (well-known community)\n"
7651 "Exact match of the communities")
7652{
7653 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7654}
7655
7656ALIAS (show_bgp_community_exact,
7657 show_bgp_ipv6_community_exact_cmd,
7658 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7659 SHOW_STR
7660 BGP_STR
7661 "Address family\n"
7662 "Display routes matching the communities\n"
7663 "community number\n"
7664 "Do not send outside local AS (well-known community)\n"
7665 "Do not advertise to any peer (well-known community)\n"
7666 "Do not export to next AS (well-known community)\n"
7667 "Exact match of the communities")
7668
7669ALIAS (show_bgp_community_exact,
7670 show_bgp_community2_exact_cmd,
7671 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7672 SHOW_STR
7673 BGP_STR
7674 "Display routes matching the communities\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 "community number\n"
7680 "Do not send outside local AS (well-known community)\n"
7681 "Do not advertise to any peer (well-known community)\n"
7682 "Do not export to next AS (well-known community)\n"
7683 "Exact match of the communities")
7684
7685ALIAS (show_bgp_community_exact,
7686 show_bgp_ipv6_community2_exact_cmd,
7687 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7688 SHOW_STR
7689 BGP_STR
7690 "Address family\n"
7691 "Display routes matching the communities\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_community3_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) 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 "Exact match of the communities")
7721
7722ALIAS (show_bgp_community_exact,
7723 show_bgp_ipv6_community3_exact_cmd,
7724 "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",
7725 SHOW_STR
7726 BGP_STR
7727 "Address family\n"
7728 "Display routes matching the communities\n"
7729 "community number\n"
7730 "Do not send outside local AS (well-known community)\n"
7731 "Do not advertise to any peer (well-known community)\n"
7732 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7742
7743ALIAS (show_bgp_community_exact,
7744 show_bgp_community4_exact_cmd,
7745 "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",
7746 SHOW_STR
7747 BGP_STR
7748 "Display routes matching the communities\n"
7749 "community number\n"
7750 "Do not send outside local AS (well-known community)\n"
7751 "Do not advertise to any peer (well-known community)\n"
7752 "Do not export to next AS (well-known community)\n"
7753 "community number\n"
7754 "Do not send outside local AS (well-known community)\n"
7755 "Do not advertise to any peer (well-known community)\n"
7756 "Do not export to next AS (well-known community)\n"
7757 "community number\n"
7758 "Do not send outside local AS (well-known community)\n"
7759 "Do not advertise to any peer (well-known community)\n"
7760 "Do not export to next AS (well-known community)\n"
7761 "community number\n"
7762 "Do not send outside local AS (well-known community)\n"
7763 "Do not advertise to any peer (well-known community)\n"
7764 "Do not export to next AS (well-known community)\n"
7765 "Exact match of the communities")
7766
7767ALIAS (show_bgp_community_exact,
7768 show_bgp_ipv6_community4_exact_cmd,
7769 "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",
7770 SHOW_STR
7771 BGP_STR
7772 "Address family\n"
7773 "Display routes matching the communities\n"
7774 "community number\n"
7775 "Do not send outside local AS (well-known community)\n"
7776 "Do not advertise to any peer (well-known community)\n"
7777 "Do not export to next AS (well-known community)\n"
7778 "community number\n"
7779 "Do not send outside local AS (well-known community)\n"
7780 "Do not advertise to any peer (well-known community)\n"
7781 "Do not export to next AS (well-known community)\n"
7782 "community number\n"
7783 "Do not send outside local AS (well-known community)\n"
7784 "Do not advertise to any peer (well-known community)\n"
7785 "Do not export to next AS (well-known community)\n"
7786 "community number\n"
7787 "Do not send outside local AS (well-known community)\n"
7788 "Do not advertise to any peer (well-known community)\n"
7789 "Do not export to next AS (well-known community)\n"
7790 "Exact match of the communities")
7791
7792/* old command */
7793DEFUN (show_ipv6_bgp_community_exact,
7794 show_ipv6_bgp_community_exact_cmd,
7795 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7796 SHOW_STR
7797 IPV6_STR
7798 BGP_STR
7799 "Display routes matching the communities\n"
7800 "community number\n"
7801 "Do not send outside local AS (well-known community)\n"
7802 "Do not advertise to any peer (well-known community)\n"
7803 "Do not export to next AS (well-known community)\n"
7804 "Exact match of the communities")
7805{
7806 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7807}
7808
7809/* old command */
7810ALIAS (show_ipv6_bgp_community_exact,
7811 show_ipv6_bgp_community2_exact_cmd,
7812 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7813 SHOW_STR
7814 IPV6_STR
7815 BGP_STR
7816 "Display routes matching the communities\n"
7817 "community number\n"
7818 "Do not send outside local AS (well-known community)\n"
7819 "Do not advertise to any peer (well-known community)\n"
7820 "Do not export to next AS (well-known community)\n"
7821 "community number\n"
7822 "Do not send outside local AS (well-known community)\n"
7823 "Do not advertise to any peer (well-known community)\n"
7824 "Do not export to next AS (well-known community)\n"
7825 "Exact match of the communities")
7826
7827/* old command */
7828ALIAS (show_ipv6_bgp_community_exact,
7829 show_ipv6_bgp_community3_exact_cmd,
7830 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7831 SHOW_STR
7832 IPV6_STR
7833 BGP_STR
7834 "Display routes matching the communities\n"
7835 "community number\n"
7836 "Do not send outside local AS (well-known community)\n"
7837 "Do not advertise to any peer (well-known community)\n"
7838 "Do not export to next AS (well-known community)\n"
7839 "community number\n"
7840 "Do not send outside local AS (well-known community)\n"
7841 "Do not advertise to any peer (well-known community)\n"
7842 "Do not export to next AS (well-known community)\n"
7843 "community number\n"
7844 "Do not send outside local AS (well-known community)\n"
7845 "Do not advertise to any peer (well-known community)\n"
7846 "Do not export to next AS (well-known community)\n"
7847 "Exact match of the communities")
7848
7849/* old command */
7850ALIAS (show_ipv6_bgp_community_exact,
7851 show_ipv6_bgp_community4_exact_cmd,
7852 "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",
7853 SHOW_STR
7854 IPV6_STR
7855 BGP_STR
7856 "Display routes matching the communities\n"
7857 "community number\n"
7858 "Do not send outside local AS (well-known community)\n"
7859 "Do not advertise to any peer (well-known community)\n"
7860 "Do not export to next AS (well-known community)\n"
7861 "community number\n"
7862 "Do not send outside local AS (well-known community)\n"
7863 "Do not advertise to any peer (well-known community)\n"
7864 "Do not export to next AS (well-known community)\n"
7865 "community number\n"
7866 "Do not send outside local AS (well-known community)\n"
7867 "Do not advertise to any peer (well-known community)\n"
7868 "Do not export to next AS (well-known community)\n"
7869 "community number\n"
7870 "Do not send outside local AS (well-known community)\n"
7871 "Do not advertise to any peer (well-known community)\n"
7872 "Do not export to next AS (well-known community)\n"
7873 "Exact match of the communities")
7874
7875/* old command */
7876DEFUN (show_ipv6_mbgp_community,
7877 show_ipv6_mbgp_community_cmd,
7878 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7879 SHOW_STR
7880 IPV6_STR
7881 MBGP_STR
7882 "Display routes matching the communities\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 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7889}
7890
7891/* old command */
7892ALIAS (show_ipv6_mbgp_community,
7893 show_ipv6_mbgp_community2_cmd,
7894 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7895 SHOW_STR
7896 IPV6_STR
7897 MBGP_STR
7898 "Display routes matching the communities\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n"
7903 "community number\n"
7904 "Do not send outside local AS (well-known community)\n"
7905 "Do not advertise to any peer (well-known community)\n"
7906 "Do not export to next AS (well-known community)\n")
7907
7908/* old command */
7909ALIAS (show_ipv6_mbgp_community,
7910 show_ipv6_mbgp_community3_cmd,
7911 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7912 SHOW_STR
7913 IPV6_STR
7914 MBGP_STR
7915 "Display routes matching the communities\n"
7916 "community number\n"
7917 "Do not send outside local AS (well-known community)\n"
7918 "Do not advertise to any peer (well-known community)\n"
7919 "Do not export to next AS (well-known community)\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n")
7928
7929/* old command */
7930ALIAS (show_ipv6_mbgp_community,
7931 show_ipv6_mbgp_community4_cmd,
7932 "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)",
7933 SHOW_STR
7934 IPV6_STR
7935 MBGP_STR
7936 "Display routes matching the communities\n"
7937 "community number\n"
7938 "Do not send outside local AS (well-known community)\n"
7939 "Do not advertise to any peer (well-known community)\n"
7940 "Do not export to next AS (well-known community)\n"
7941 "community number\n"
7942 "Do not send outside local AS (well-known community)\n"
7943 "Do not advertise to any peer (well-known community)\n"
7944 "Do not export to next AS (well-known community)\n"
7945 "community number\n"
7946 "Do not send outside local AS (well-known community)\n"
7947 "Do not advertise to any peer (well-known community)\n"
7948 "Do not export to next AS (well-known community)\n"
7949 "community number\n"
7950 "Do not send outside local AS (well-known community)\n"
7951 "Do not advertise to any peer (well-known community)\n"
7952 "Do not export to next AS (well-known community)\n")
7953
7954/* old command */
7955DEFUN (show_ipv6_mbgp_community_exact,
7956 show_ipv6_mbgp_community_exact_cmd,
7957 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7958 SHOW_STR
7959 IPV6_STR
7960 MBGP_STR
7961 "Display routes matching the communities\n"
7962 "community number\n"
7963 "Do not send outside local AS (well-known community)\n"
7964 "Do not advertise to any peer (well-known community)\n"
7965 "Do not export to next AS (well-known community)\n"
7966 "Exact match of the communities")
7967{
7968 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7969}
7970
7971/* old command */
7972ALIAS (show_ipv6_mbgp_community_exact,
7973 show_ipv6_mbgp_community2_exact_cmd,
7974 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7975 SHOW_STR
7976 IPV6_STR
7977 MBGP_STR
7978 "Display routes matching the communities\n"
7979 "community number\n"
7980 "Do not send outside local AS (well-known community)\n"
7981 "Do not advertise to any peer (well-known community)\n"
7982 "Do not export to next AS (well-known community)\n"
7983 "community number\n"
7984 "Do not send outside local AS (well-known community)\n"
7985 "Do not advertise to any peer (well-known community)\n"
7986 "Do not export to next AS (well-known community)\n"
7987 "Exact match of the communities")
7988
7989/* old command */
7990ALIAS (show_ipv6_mbgp_community_exact,
7991 show_ipv6_mbgp_community3_exact_cmd,
7992 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7993 SHOW_STR
7994 IPV6_STR
7995 MBGP_STR
7996 "Display routes matching the communities\n"
7997 "community number\n"
7998 "Do not send outside local AS (well-known community)\n"
7999 "Do not advertise to any peer (well-known community)\n"
8000 "Do not export to next AS (well-known community)\n"
8001 "community number\n"
8002 "Do not send outside local AS (well-known community)\n"
8003 "Do not advertise to any peer (well-known community)\n"
8004 "Do not export to next AS (well-known community)\n"
8005 "community number\n"
8006 "Do not send outside local AS (well-known community)\n"
8007 "Do not advertise to any peer (well-known community)\n"
8008 "Do not export to next AS (well-known community)\n"
8009 "Exact match of the communities")
8010
8011/* old command */
8012ALIAS (show_ipv6_mbgp_community_exact,
8013 show_ipv6_mbgp_community4_exact_cmd,
8014 "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",
8015 SHOW_STR
8016 IPV6_STR
8017 MBGP_STR
8018 "Display routes matching the communities\n"
8019 "community number\n"
8020 "Do not send outside local AS (well-known community)\n"
8021 "Do not advertise to any peer (well-known community)\n"
8022 "Do not export to next AS (well-known community)\n"
8023 "community number\n"
8024 "Do not send outside local AS (well-known community)\n"
8025 "Do not advertise to any peer (well-known community)\n"
8026 "Do not export to next AS (well-known community)\n"
8027 "community number\n"
8028 "Do not send outside local AS (well-known community)\n"
8029 "Do not advertise to any peer (well-known community)\n"
8030 "Do not export to next AS (well-known community)\n"
8031 "community number\n"
8032 "Do not send outside local AS (well-known community)\n"
8033 "Do not advertise to any peer (well-known community)\n"
8034 "Do not export to next AS (well-known community)\n"
8035 "Exact match of the communities")
8036#endif /* HAVE_IPV6 */
8037
paul94f2b392005-06-28 12:44:16 +00008038static int
paulfd79ac92004-10-13 05:06:08 +00008039bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008040 u_int16_t afi, u_char safi)
8041{
8042 struct community_list *list;
8043
hassofee6e4e2005-02-02 16:29:31 +00008044 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008045 if (list == NULL)
8046 {
8047 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8048 VTY_NEWLINE);
8049 return CMD_WARNING;
8050 }
8051
ajs5a646652004-11-05 01:25:55 +00008052 return bgp_show (vty, NULL, afi, safi,
8053 (exact ? bgp_show_type_community_list_exact :
8054 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008055}
8056
8057DEFUN (show_ip_bgp_community_list,
8058 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008059 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008060 SHOW_STR
8061 IP_STR
8062 BGP_STR
8063 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008064 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008065 "community-list name\n")
8066{
8067 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8068}
8069
8070DEFUN (show_ip_bgp_ipv4_community_list,
8071 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008072 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008073 SHOW_STR
8074 IP_STR
8075 BGP_STR
8076 "Address family\n"
8077 "Address Family modifier\n"
8078 "Address Family modifier\n"
8079 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008080 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008081 "community-list name\n")
8082{
8083 if (strncmp (argv[0], "m", 1) == 0)
8084 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8085
8086 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8087}
8088
8089DEFUN (show_ip_bgp_community_list_exact,
8090 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008091 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008092 SHOW_STR
8093 IP_STR
8094 BGP_STR
8095 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008096 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008097 "community-list name\n"
8098 "Exact match of the communities\n")
8099{
8100 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8101}
8102
8103DEFUN (show_ip_bgp_ipv4_community_list_exact,
8104 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008105 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008106 SHOW_STR
8107 IP_STR
8108 BGP_STR
8109 "Address family\n"
8110 "Address Family modifier\n"
8111 "Address Family modifier\n"
8112 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008113 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008114 "community-list name\n"
8115 "Exact match of the communities\n")
8116{
8117 if (strncmp (argv[0], "m", 1) == 0)
8118 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8119
8120 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8121}
8122
8123#ifdef HAVE_IPV6
8124DEFUN (show_bgp_community_list,
8125 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008126 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008127 SHOW_STR
8128 BGP_STR
8129 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008130 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008131 "community-list name\n")
8132{
8133 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8134}
8135
8136ALIAS (show_bgp_community_list,
8137 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008138 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008139 SHOW_STR
8140 BGP_STR
8141 "Address family\n"
8142 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008143 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008144 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008145
8146/* old command */
8147DEFUN (show_ipv6_bgp_community_list,
8148 show_ipv6_bgp_community_list_cmd,
8149 "show ipv6 bgp community-list WORD",
8150 SHOW_STR
8151 IPV6_STR
8152 BGP_STR
8153 "Display routes matching the community-list\n"
8154 "community-list name\n")
8155{
8156 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8157}
8158
8159/* old command */
8160DEFUN (show_ipv6_mbgp_community_list,
8161 show_ipv6_mbgp_community_list_cmd,
8162 "show ipv6 mbgp community-list WORD",
8163 SHOW_STR
8164 IPV6_STR
8165 MBGP_STR
8166 "Display routes matching the community-list\n"
8167 "community-list name\n")
8168{
8169 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8170}
8171
8172DEFUN (show_bgp_community_list_exact,
8173 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008174 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008175 SHOW_STR
8176 BGP_STR
8177 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008178 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008179 "community-list name\n"
8180 "Exact match of the communities\n")
8181{
8182 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8183}
8184
8185ALIAS (show_bgp_community_list_exact,
8186 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008187 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008188 SHOW_STR
8189 BGP_STR
8190 "Address family\n"
8191 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008192 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008193 "community-list name\n"
8194 "Exact match of the communities\n")
8195
8196/* old command */
8197DEFUN (show_ipv6_bgp_community_list_exact,
8198 show_ipv6_bgp_community_list_exact_cmd,
8199 "show ipv6 bgp community-list WORD exact-match",
8200 SHOW_STR
8201 IPV6_STR
8202 BGP_STR
8203 "Display routes matching the community-list\n"
8204 "community-list name\n"
8205 "Exact match of the communities\n")
8206{
8207 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8208}
8209
8210/* old command */
8211DEFUN (show_ipv6_mbgp_community_list_exact,
8212 show_ipv6_mbgp_community_list_exact_cmd,
8213 "show ipv6 mbgp community-list WORD exact-match",
8214 SHOW_STR
8215 IPV6_STR
8216 MBGP_STR
8217 "Display routes matching the community-list\n"
8218 "community-list name\n"
8219 "Exact match of the communities\n")
8220{
8221 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8222}
8223#endif /* HAVE_IPV6 */
8224
paul94f2b392005-06-28 12:44:16 +00008225static int
paulfd79ac92004-10-13 05:06:08 +00008226bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008227 safi_t safi, enum bgp_show_type type)
8228{
8229 int ret;
8230 struct prefix *p;
8231
8232 p = prefix_new();
8233
8234 ret = str2prefix (prefix, p);
8235 if (! ret)
8236 {
8237 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8238 return CMD_WARNING;
8239 }
8240
ajs5a646652004-11-05 01:25:55 +00008241 ret = bgp_show (vty, NULL, afi, safi, type, p);
8242 prefix_free(p);
8243 return ret;
paul718e3742002-12-13 20:15:29 +00008244}
8245
8246DEFUN (show_ip_bgp_prefix_longer,
8247 show_ip_bgp_prefix_longer_cmd,
8248 "show ip bgp A.B.C.D/M longer-prefixes",
8249 SHOW_STR
8250 IP_STR
8251 BGP_STR
8252 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8253 "Display route and more specific routes\n")
8254{
8255 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8256 bgp_show_type_prefix_longer);
8257}
8258
8259DEFUN (show_ip_bgp_flap_prefix_longer,
8260 show_ip_bgp_flap_prefix_longer_cmd,
8261 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8262 SHOW_STR
8263 IP_STR
8264 BGP_STR
8265 "Display flap statistics of routes\n"
8266 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8267 "Display route and more specific routes\n")
8268{
8269 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8270 bgp_show_type_flap_prefix_longer);
8271}
8272
8273DEFUN (show_ip_bgp_ipv4_prefix_longer,
8274 show_ip_bgp_ipv4_prefix_longer_cmd,
8275 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8276 SHOW_STR
8277 IP_STR
8278 BGP_STR
8279 "Address family\n"
8280 "Address Family modifier\n"
8281 "Address Family modifier\n"
8282 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8283 "Display route and more specific routes\n")
8284{
8285 if (strncmp (argv[0], "m", 1) == 0)
8286 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8287 bgp_show_type_prefix_longer);
8288
8289 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8290 bgp_show_type_prefix_longer);
8291}
8292
8293DEFUN (show_ip_bgp_flap_address,
8294 show_ip_bgp_flap_address_cmd,
8295 "show ip bgp flap-statistics A.B.C.D",
8296 SHOW_STR
8297 IP_STR
8298 BGP_STR
8299 "Display flap statistics of routes\n"
8300 "Network in the BGP routing table to display\n")
8301{
8302 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8303 bgp_show_type_flap_address);
8304}
8305
8306DEFUN (show_ip_bgp_flap_prefix,
8307 show_ip_bgp_flap_prefix_cmd,
8308 "show ip bgp flap-statistics A.B.C.D/M",
8309 SHOW_STR
8310 IP_STR
8311 BGP_STR
8312 "Display flap statistics of routes\n"
8313 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8314{
8315 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8316 bgp_show_type_flap_prefix);
8317}
8318#ifdef HAVE_IPV6
8319DEFUN (show_bgp_prefix_longer,
8320 show_bgp_prefix_longer_cmd,
8321 "show bgp X:X::X:X/M longer-prefixes",
8322 SHOW_STR
8323 BGP_STR
8324 "IPv6 prefix <network>/<length>\n"
8325 "Display route and more specific routes\n")
8326{
8327 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8328 bgp_show_type_prefix_longer);
8329}
8330
8331ALIAS (show_bgp_prefix_longer,
8332 show_bgp_ipv6_prefix_longer_cmd,
8333 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8334 SHOW_STR
8335 BGP_STR
8336 "Address family\n"
8337 "IPv6 prefix <network>/<length>\n"
8338 "Display route and more specific routes\n")
8339
8340/* old command */
8341DEFUN (show_ipv6_bgp_prefix_longer,
8342 show_ipv6_bgp_prefix_longer_cmd,
8343 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8344 SHOW_STR
8345 IPV6_STR
8346 BGP_STR
8347 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8348 "Display route and more specific routes\n")
8349{
8350 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8351 bgp_show_type_prefix_longer);
8352}
8353
8354/* old command */
8355DEFUN (show_ipv6_mbgp_prefix_longer,
8356 show_ipv6_mbgp_prefix_longer_cmd,
8357 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8358 SHOW_STR
8359 IPV6_STR
8360 MBGP_STR
8361 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8362 "Display route and more specific routes\n")
8363{
8364 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8365 bgp_show_type_prefix_longer);
8366}
8367#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008368
paul94f2b392005-06-28 12:44:16 +00008369static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008370peer_lookup_in_view (struct vty *vty, const char *view_name,
8371 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008372{
8373 int ret;
8374 struct bgp *bgp;
8375 struct peer *peer;
8376 union sockunion su;
8377
8378 /* BGP structure lookup. */
8379 if (view_name)
8380 {
8381 bgp = bgp_lookup_by_name (view_name);
8382 if (! bgp)
8383 {
8384 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8385 return NULL;
8386 }
8387 }
paul5228ad22004-06-04 17:58:18 +00008388 else
paulbb46e942003-10-24 19:02:03 +00008389 {
8390 bgp = bgp_get_default ();
8391 if (! bgp)
8392 {
8393 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8394 return NULL;
8395 }
8396 }
8397
8398 /* Get peer sockunion. */
8399 ret = str2sockunion (ip_str, &su);
8400 if (ret < 0)
8401 {
8402 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8403 return NULL;
8404 }
8405
8406 /* Peer structure lookup. */
8407 peer = peer_lookup (bgp, &su);
8408 if (! peer)
8409 {
8410 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8411 return NULL;
8412 }
8413
8414 return peer;
8415}
Paul Jakma2815e612006-09-14 02:56:07 +00008416
8417enum bgp_stats
8418{
8419 BGP_STATS_MAXBITLEN = 0,
8420 BGP_STATS_RIB,
8421 BGP_STATS_PREFIXES,
8422 BGP_STATS_TOTPLEN,
8423 BGP_STATS_UNAGGREGATEABLE,
8424 BGP_STATS_MAX_AGGREGATEABLE,
8425 BGP_STATS_AGGREGATES,
8426 BGP_STATS_SPACE,
8427 BGP_STATS_ASPATH_COUNT,
8428 BGP_STATS_ASPATH_MAXHOPS,
8429 BGP_STATS_ASPATH_TOTHOPS,
8430 BGP_STATS_ASPATH_MAXSIZE,
8431 BGP_STATS_ASPATH_TOTSIZE,
8432 BGP_STATS_ASN_HIGHEST,
8433 BGP_STATS_MAX,
8434};
paulbb46e942003-10-24 19:02:03 +00008435
Paul Jakma2815e612006-09-14 02:56:07 +00008436static const char *table_stats_strs[] =
8437{
8438 [BGP_STATS_PREFIXES] = "Total Prefixes",
8439 [BGP_STATS_TOTPLEN] = "Average prefix length",
8440 [BGP_STATS_RIB] = "Total Advertisements",
8441 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8442 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8443 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8444 [BGP_STATS_SPACE] = "Address space advertised",
8445 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8446 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8447 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8448 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8449 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8450 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8451 [BGP_STATS_MAX] = NULL,
8452};
8453
8454struct bgp_table_stats
8455{
8456 struct bgp_table *table;
8457 unsigned long long counts[BGP_STATS_MAX];
8458};
8459
8460#if 0
8461#define TALLY_SIGFIG 100000
8462static unsigned long
8463ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8464{
8465 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8466 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8467 unsigned long ret = newtot / count;
8468
8469 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
8470 return ret + 1;
8471 else
8472 return ret;
8473}
8474#endif
8475
8476static int
8477bgp_table_stats_walker (struct thread *t)
8478{
8479 struct bgp_node *rn;
8480 struct bgp_node *top;
8481 struct bgp_table_stats *ts = THREAD_ARG (t);
8482 unsigned int space = 0;
8483
8484 top = bgp_table_top (ts->table);
8485
8486 switch (top->p.family)
8487 {
8488 case AF_INET:
8489 space = IPV4_MAX_BITLEN;
8490 break;
8491 case AF_INET6:
8492 space = IPV6_MAX_BITLEN;
8493 break;
8494 }
8495
8496 ts->counts[BGP_STATS_MAXBITLEN] = space;
8497
8498 for (rn = top; rn; rn = bgp_route_next (rn))
8499 {
8500 struct bgp_info *ri;
8501 struct bgp_node *prn = rn->parent;
8502 unsigned int rinum = 0;
8503
8504 if (rn == top)
8505 continue;
8506
8507 if (!rn->info)
8508 continue;
8509
8510 ts->counts[BGP_STATS_PREFIXES]++;
8511 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
8512
8513#if 0
8514 ts->counts[BGP_STATS_AVGPLEN]
8515 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
8516 ts->counts[BGP_STATS_AVGPLEN],
8517 rn->p.prefixlen);
8518#endif
8519
8520 /* check if the prefix is included by any other announcements */
8521 while (prn && !prn->info)
8522 prn = prn->parent;
8523
8524 if (prn == NULL || prn == top)
8525 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
8526 else if (prn->info)
8527 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
8528
8529 /* announced address space */
8530 if (space)
8531 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
8532
8533 for (ri = rn->info; ri; ri = ri->next)
8534 {
8535 rinum++;
8536 ts->counts[BGP_STATS_RIB]++;
8537
8538 if (ri->attr &&
8539 (CHECK_FLAG (ri->attr->flag,
8540 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
8541 ts->counts[BGP_STATS_AGGREGATES]++;
8542
8543 /* as-path stats */
8544 if (ri->attr && ri->attr->aspath)
8545 {
8546 unsigned int hops = aspath_count_hops (ri->attr->aspath);
8547 unsigned int size = aspath_size (ri->attr->aspath);
8548 as_t highest = aspath_highest (ri->attr->aspath);
8549
8550 ts->counts[BGP_STATS_ASPATH_COUNT]++;
8551
8552 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
8553 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
8554
8555 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
8556 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
8557
8558 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
8559 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
8560#if 0
8561 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
8562 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8563 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
8564 hops);
8565 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
8566 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8567 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
8568 size);
8569#endif
8570 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
8571 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
8572 }
8573 }
8574 }
8575 return 0;
8576}
8577
8578static int
8579bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
8580{
8581 struct bgp_table_stats ts;
8582 unsigned int i;
8583
8584 if (!bgp->rib[afi][safi])
8585 {
8586 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
8587 return CMD_WARNING;
8588 }
8589
8590 memset (&ts, 0, sizeof (ts));
8591 ts.table = bgp->rib[afi][safi];
8592 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
8593
8594 vty_out (vty, "BGP %s RIB statistics%s%s",
8595 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
8596
8597 for (i = 0; i < BGP_STATS_MAX; i++)
8598 {
8599 if (!table_stats_strs[i])
8600 continue;
8601
8602 switch (i)
8603 {
8604#if 0
8605 case BGP_STATS_ASPATH_AVGHOPS:
8606 case BGP_STATS_ASPATH_AVGSIZE:
8607 case BGP_STATS_AVGPLEN:
8608 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8609 vty_out (vty, "%12.2f",
8610 (float)ts.counts[i] / (float)TALLY_SIGFIG);
8611 break;
8612#endif
8613 case BGP_STATS_ASPATH_TOTHOPS:
8614 case BGP_STATS_ASPATH_TOTSIZE:
8615 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8616 vty_out (vty, "%12.2f",
8617 ts.counts[i] ?
8618 (float)ts.counts[i] /
8619 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
8620 : 0);
8621 break;
8622 case BGP_STATS_TOTPLEN:
8623 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8624 vty_out (vty, "%12.2f",
8625 ts.counts[i] ?
8626 (float)ts.counts[i] /
8627 (float)ts.counts[BGP_STATS_PREFIXES]
8628 : 0);
8629 break;
8630 case BGP_STATS_SPACE:
8631 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8632 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
8633 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
8634 break;
8635 vty_out (vty, "%30s: ", "\% announced ");
8636 vty_out (vty, "%12.2f%s",
8637 100 * (float)ts.counts[BGP_STATS_SPACE] /
8638 (float)((u_int64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
8639 VTY_NEWLINE);
8640 vty_out (vty, "%30s: ", "/8 equivalent ");
8641 vty_out (vty, "%12.2f%s",
8642 (float)ts.counts[BGP_STATS_SPACE] /
8643 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
8644 VTY_NEWLINE);
8645 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
8646 break;
8647 vty_out (vty, "%30s: ", "/24 equivalent ");
8648 vty_out (vty, "%12.2f",
8649 (float)ts.counts[BGP_STATS_SPACE] /
8650 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
8651 break;
8652 default:
8653 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8654 vty_out (vty, "%12llu", ts.counts[i]);
8655 }
8656
8657 vty_out (vty, "%s", VTY_NEWLINE);
8658 }
8659 return CMD_SUCCESS;
8660}
8661
8662static int
8663bgp_table_stats_vty (struct vty *vty, const char *name,
8664 const char *afi_str, const char *safi_str)
8665{
8666 struct bgp *bgp;
8667 afi_t afi;
8668 safi_t safi;
8669
8670 if (name)
8671 bgp = bgp_lookup_by_name (name);
8672 else
8673 bgp = bgp_get_default ();
8674
8675 if (!bgp)
8676 {
8677 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
8678 return CMD_WARNING;
8679 }
8680 if (strncmp (afi_str, "ipv", 3) == 0)
8681 {
8682 if (strncmp (afi_str, "ipv4", 4) == 0)
8683 afi = AFI_IP;
8684 else if (strncmp (afi_str, "ipv6", 4) == 0)
8685 afi = AFI_IP6;
8686 else
8687 {
8688 vty_out (vty, "%% Invalid address family %s%s",
8689 afi_str, VTY_NEWLINE);
8690 return CMD_WARNING;
8691 }
8692 if (strncmp (safi_str, "m", 1) == 0)
8693 safi = SAFI_MULTICAST;
8694 else if (strncmp (safi_str, "u", 1) == 0)
8695 safi = SAFI_UNICAST;
8696 else if (strncmp (safi_str, "vpnv4", 5) == 0)
8697 safi = BGP_SAFI_VPNV4;
8698 else if (strncmp (safi_str, "vpnv6", 6) == 0)
8699 safi = BGP_SAFI_VPNV6;
8700 else
8701 {
8702 vty_out (vty, "%% Invalid subsequent address family %s%s",
8703 safi_str, VTY_NEWLINE);
8704 return CMD_WARNING;
8705 }
8706 }
8707 else
8708 {
8709 vty_out (vty, "%% Invalid address family %s%s",
8710 afi_str, VTY_NEWLINE);
8711 return CMD_WARNING;
8712 }
8713
8714 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
8715 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
8716 {
8717 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
8718 afi_str, safi_str, VTY_NEWLINE);
8719 return CMD_WARNING;
8720 }
8721 return bgp_table_stats (vty, bgp, afi, safi);
8722}
8723
8724DEFUN (show_bgp_statistics,
8725 show_bgp_statistics_cmd,
8726 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
8727 SHOW_STR
8728 BGP_STR
8729 "Address family\n"
8730 "Address family\n"
8731 "Address Family modifier\n"
8732 "Address Family modifier\n"
8733 "BGP RIB advertisement statistics\n")
8734{
8735 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
8736}
8737
8738ALIAS (show_bgp_statistics,
8739 show_bgp_statistics_vpnv4_cmd,
8740 "show bgp (ipv4) (vpnv4) statistics",
8741 SHOW_STR
8742 BGP_STR
8743 "Address family\n"
8744 "Address Family modifier\n"
8745 "BGP RIB advertisement statistics\n")
8746
8747DEFUN (show_bgp_statistics_view,
8748 show_bgp_statistics_view_cmd,
8749 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
8750 SHOW_STR
8751 BGP_STR
8752 "BGP view\n"
8753 "Address family\n"
8754 "Address family\n"
8755 "Address Family modifier\n"
8756 "Address Family modifier\n"
8757 "BGP RIB advertisement statistics\n")
8758{
8759 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
8760}
8761
8762ALIAS (show_bgp_statistics_view,
8763 show_bgp_statistics_view_vpnv4_cmd,
8764 "show bgp view WORD (ipv4) (vpnv4) statistics",
8765 SHOW_STR
8766 BGP_STR
8767 "BGP view\n"
8768 "Address family\n"
8769 "Address Family modifier\n"
8770 "BGP RIB advertisement statistics\n")
8771
Paul Jakmaff7924f2006-09-04 01:10:36 +00008772enum bgp_pcounts
8773{
8774 PCOUNT_ADJ_IN = 0,
8775 PCOUNT_DAMPED,
8776 PCOUNT_REMOVED,
8777 PCOUNT_HISTORY,
8778 PCOUNT_STALE,
8779 PCOUNT_VALID,
8780 PCOUNT_ALL,
8781 PCOUNT_COUNTED,
8782 PCOUNT_PFCNT, /* the figure we display to users */
8783 PCOUNT_MAX,
8784};
8785
8786static const char *pcount_strs[] =
8787{
8788 [PCOUNT_ADJ_IN] = "Adj-in",
8789 [PCOUNT_DAMPED] = "Damped",
8790 [PCOUNT_REMOVED] = "Removed",
8791 [PCOUNT_HISTORY] = "History",
8792 [PCOUNT_STALE] = "Stale",
8793 [PCOUNT_VALID] = "Valid",
8794 [PCOUNT_ALL] = "All RIB",
8795 [PCOUNT_COUNTED] = "PfxCt counted",
8796 [PCOUNT_PFCNT] = "Useable",
8797 [PCOUNT_MAX] = NULL,
8798};
8799
Paul Jakma2815e612006-09-14 02:56:07 +00008800struct peer_pcounts
8801{
8802 unsigned int count[PCOUNT_MAX];
8803 const struct peer *peer;
8804 const struct bgp_table *table;
8805};
8806
Paul Jakmaff7924f2006-09-04 01:10:36 +00008807static int
Paul Jakma2815e612006-09-14 02:56:07 +00008808bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00008809{
8810 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00008811 struct peer_pcounts *pc = THREAD_ARG (t);
8812 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008813
Paul Jakma2815e612006-09-14 02:56:07 +00008814 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008815 {
8816 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00008817 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008818
8819 for (ain = rn->adj_in; ain; ain = ain->next)
8820 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00008821 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008822
Paul Jakmaff7924f2006-09-04 01:10:36 +00008823 for (ri = rn->info; ri; ri = ri->next)
8824 {
8825 char buf[SU_ADDRSTRLEN];
8826
8827 if (ri->peer != peer)
8828 continue;
8829
Paul Jakma2815e612006-09-14 02:56:07 +00008830 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008831
8832 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00008833 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008834 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00008835 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008836 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00008837 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008838 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00008839 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008840 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00008841 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00008842 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00008843 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008844
8845 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
8846 {
Paul Jakma2815e612006-09-14 02:56:07 +00008847 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00008848 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008849 plog_warn (peer->log,
8850 "%s [pcount] %s/%d is counted but flags 0x%x",
8851 peer->host,
8852 inet_ntop(rn->p.family, &rn->p.u.prefix,
8853 buf, SU_ADDRSTRLEN),
8854 rn->p.prefixlen,
8855 ri->flags);
8856 }
8857 else
8858 {
Paul Jakma1a392d42006-09-07 00:24:49 +00008859 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008860 plog_warn (peer->log,
8861 "%s [pcount] %s/%d not counted but flags 0x%x",
8862 peer->host,
8863 inet_ntop(rn->p.family, &rn->p.u.prefix,
8864 buf, SU_ADDRSTRLEN),
8865 rn->p.prefixlen,
8866 ri->flags);
8867 }
8868 }
8869 }
Paul Jakma2815e612006-09-14 02:56:07 +00008870 return 0;
8871}
Paul Jakmaff7924f2006-09-04 01:10:36 +00008872
Paul Jakma2815e612006-09-14 02:56:07 +00008873static int
8874bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
8875{
8876 struct peer_pcounts pcounts = { .peer = peer };
8877 unsigned int i;
8878
8879 if (!peer || !peer->bgp || !peer->afc[afi][safi]
8880 || !peer->bgp->rib[afi][safi])
8881 {
8882 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8883 return CMD_WARNING;
8884 }
8885
8886 memset (&pcounts, 0, sizeof(pcounts));
8887 pcounts.peer = peer;
8888 pcounts.table = peer->bgp->rib[afi][safi];
8889
8890 /* in-place call via thread subsystem so as to record execution time
8891 * stats for the thread-walk (i.e. ensure this can't be blamed on
8892 * on just vty_read()).
8893 */
8894 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
8895
Paul Jakmaff7924f2006-09-04 01:10:36 +00008896 vty_out (vty, "Prefix counts for %s, %s%s",
8897 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
8898 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
8899 vty_out (vty, "%sCounts from RIB table walk:%s%s",
8900 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8901
8902 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00008903 vty_out (vty, "%20s: %-10d%s",
8904 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00008905
Paul Jakma2815e612006-09-14 02:56:07 +00008906 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00008907 {
8908 vty_out (vty, "%s [pcount] PfxCt drift!%s",
8909 peer->host, VTY_NEWLINE);
8910 vty_out (vty, "Please report this bug, with the above command output%s",
8911 VTY_NEWLINE);
8912 }
8913
8914 return CMD_SUCCESS;
8915}
8916
8917DEFUN (show_ip_bgp_neighbor_prefix_counts,
8918 show_ip_bgp_neighbor_prefix_counts_cmd,
8919 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8920 SHOW_STR
8921 IP_STR
8922 BGP_STR
8923 "Detailed information on TCP and BGP neighbor connections\n"
8924 "Neighbor to display information about\n"
8925 "Neighbor to display information about\n"
8926 "Display detailed prefix count information\n")
8927{
8928 struct peer *peer;
8929
8930 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8931 if (! peer)
8932 return CMD_WARNING;
8933
8934 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
8935}
8936
8937DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
8938 show_bgp_ipv6_neighbor_prefix_counts_cmd,
8939 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8940 SHOW_STR
8941 BGP_STR
8942 "Address family\n"
8943 "Detailed information on TCP and BGP neighbor connections\n"
8944 "Neighbor to display information about\n"
8945 "Neighbor to display information about\n"
8946 "Display detailed prefix count information\n")
8947{
8948 struct peer *peer;
8949
8950 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8951 if (! peer)
8952 return CMD_WARNING;
8953
8954 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
8955}
8956
8957DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
8958 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
8959 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8960 SHOW_STR
8961 IP_STR
8962 BGP_STR
8963 "Address family\n"
8964 "Address Family modifier\n"
8965 "Address Family modifier\n"
8966 "Detailed information on TCP and BGP neighbor connections\n"
8967 "Neighbor to display information about\n"
8968 "Neighbor to display information about\n"
8969 "Display detailed prefix count information\n")
8970{
8971 struct peer *peer;
8972
8973 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8974 if (! peer)
8975 return CMD_WARNING;
8976
8977 if (strncmp (argv[0], "m", 1) == 0)
8978 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
8979
8980 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
8981}
8982
8983DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
8984 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
8985 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8986 SHOW_STR
8987 IP_STR
8988 BGP_STR
8989 "Address family\n"
8990 "Address Family modifier\n"
8991 "Address Family modifier\n"
8992 "Detailed information on TCP and BGP neighbor connections\n"
8993 "Neighbor to display information about\n"
8994 "Neighbor to display information about\n"
8995 "Display detailed prefix count information\n")
8996{
8997 struct peer *peer;
8998
8999 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9000 if (! peer)
9001 return CMD_WARNING;
9002
9003 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9004}
9005
9006
paul94f2b392005-06-28 12:44:16 +00009007static void
paul718e3742002-12-13 20:15:29 +00009008show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9009 int in)
9010{
9011 struct bgp_table *table;
9012 struct bgp_adj_in *ain;
9013 struct bgp_adj_out *adj;
9014 unsigned long output_count;
9015 struct bgp_node *rn;
9016 int header1 = 1;
9017 struct bgp *bgp;
9018 int header2 = 1;
9019
paulbb46e942003-10-24 19:02:03 +00009020 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009021
9022 if (! bgp)
9023 return;
9024
9025 table = bgp->rib[afi][safi];
9026
9027 output_count = 0;
9028
9029 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9030 PEER_STATUS_DEFAULT_ORIGINATE))
9031 {
9032 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 +00009033 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9034 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009035
9036 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9037 VTY_NEWLINE, VTY_NEWLINE);
9038 header1 = 0;
9039 }
9040
9041 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9042 if (in)
9043 {
9044 for (ain = rn->adj_in; ain; ain = ain->next)
9045 if (ain->peer == peer)
9046 {
9047 if (header1)
9048 {
9049 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 +00009050 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9051 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009052 header1 = 0;
9053 }
9054 if (header2)
9055 {
9056 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9057 header2 = 0;
9058 }
9059 if (ain->attr)
9060 {
9061 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9062 output_count++;
9063 }
9064 }
9065 }
9066 else
9067 {
9068 for (adj = rn->adj_out; adj; adj = adj->next)
9069 if (adj->peer == peer)
9070 {
9071 if (header1)
9072 {
9073 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 +00009074 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9075 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009076 header1 = 0;
9077 }
9078 if (header2)
9079 {
9080 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9081 header2 = 0;
9082 }
9083 if (adj->attr)
9084 {
9085 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9086 output_count++;
9087 }
9088 }
9089 }
9090
9091 if (output_count != 0)
9092 vty_out (vty, "%sTotal number of prefixes %ld%s",
9093 VTY_NEWLINE, output_count, VTY_NEWLINE);
9094}
9095
paul94f2b392005-06-28 12:44:16 +00009096static int
paulbb46e942003-10-24 19:02:03 +00009097peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9098{
paul718e3742002-12-13 20:15:29 +00009099 if (! peer || ! peer->afc[afi][safi])
9100 {
9101 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9102 return CMD_WARNING;
9103 }
9104
9105 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9106 {
9107 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9108 VTY_NEWLINE);
9109 return CMD_WARNING;
9110 }
9111
9112 show_adj_route (vty, peer, afi, safi, in);
9113
9114 return CMD_SUCCESS;
9115}
9116
9117DEFUN (show_ip_bgp_neighbor_advertised_route,
9118 show_ip_bgp_neighbor_advertised_route_cmd,
9119 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9120 SHOW_STR
9121 IP_STR
9122 BGP_STR
9123 "Detailed information on TCP and BGP neighbor connections\n"
9124 "Neighbor to display information about\n"
9125 "Neighbor to display information about\n"
9126 "Display the routes advertised to a BGP neighbor\n")
9127{
paulbb46e942003-10-24 19:02:03 +00009128 struct peer *peer;
9129
9130 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9131 if (! peer)
9132 return CMD_WARNING;
9133
9134 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009135}
9136
9137DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9138 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9139 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9140 SHOW_STR
9141 IP_STR
9142 BGP_STR
9143 "Address family\n"
9144 "Address Family modifier\n"
9145 "Address Family modifier\n"
9146 "Detailed information on TCP and BGP neighbor connections\n"
9147 "Neighbor to display information about\n"
9148 "Neighbor to display information about\n"
9149 "Display the routes advertised to a BGP neighbor\n")
9150{
paulbb46e942003-10-24 19:02:03 +00009151 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009152
paulbb46e942003-10-24 19:02:03 +00009153 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9154 if (! peer)
9155 return CMD_WARNING;
9156
9157 if (strncmp (argv[0], "m", 1) == 0)
9158 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9159
9160 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009161}
9162
9163#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009164DEFUN (show_bgp_view_neighbor_advertised_route,
9165 show_bgp_view_neighbor_advertised_route_cmd,
9166 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9167 SHOW_STR
9168 BGP_STR
9169 "BGP view\n"
9170 "View name\n"
9171 "Detailed information on TCP and BGP neighbor connections\n"
9172 "Neighbor to display information about\n"
9173 "Neighbor to display information about\n"
9174 "Display the routes advertised to a BGP neighbor\n")
9175{
9176 struct peer *peer;
9177
9178 if (argc == 2)
9179 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9180 else
9181 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9182
9183 if (! peer)
9184 return CMD_WARNING;
9185
9186 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9187}
9188
9189ALIAS (show_bgp_view_neighbor_advertised_route,
9190 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9191 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9192 SHOW_STR
9193 BGP_STR
9194 "BGP view\n"
9195 "View name\n"
9196 "Address family\n"
9197 "Detailed information on TCP and BGP neighbor connections\n"
9198 "Neighbor to display information about\n"
9199 "Neighbor to display information about\n"
9200 "Display the routes advertised to a BGP neighbor\n")
9201
9202DEFUN (show_bgp_view_neighbor_received_routes,
9203 show_bgp_view_neighbor_received_routes_cmd,
9204 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9205 SHOW_STR
9206 BGP_STR
9207 "BGP view\n"
9208 "View name\n"
9209 "Detailed information on TCP and BGP neighbor connections\n"
9210 "Neighbor to display information about\n"
9211 "Neighbor to display information about\n"
9212 "Display the received routes from neighbor\n")
9213{
9214 struct peer *peer;
9215
9216 if (argc == 2)
9217 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9218 else
9219 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9220
9221 if (! peer)
9222 return CMD_WARNING;
9223
9224 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9225}
9226
9227ALIAS (show_bgp_view_neighbor_received_routes,
9228 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9229 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9230 SHOW_STR
9231 BGP_STR
9232 "BGP view\n"
9233 "View name\n"
9234 "Address family\n"
9235 "Detailed information on TCP and BGP neighbor connections\n"
9236 "Neighbor to display information about\n"
9237 "Neighbor to display information about\n"
9238 "Display the received routes from neighbor\n")
9239
9240ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009241 show_bgp_neighbor_advertised_route_cmd,
9242 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9243 SHOW_STR
9244 BGP_STR
9245 "Detailed information on TCP and BGP neighbor connections\n"
9246 "Neighbor to display information about\n"
9247 "Neighbor to display information about\n"
9248 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009249
9250ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009251 show_bgp_ipv6_neighbor_advertised_route_cmd,
9252 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9253 SHOW_STR
9254 BGP_STR
9255 "Address family\n"
9256 "Detailed information on TCP and BGP neighbor connections\n"
9257 "Neighbor to display information about\n"
9258 "Neighbor to display information about\n"
9259 "Display the routes advertised to a BGP neighbor\n")
9260
9261/* old command */
paulbb46e942003-10-24 19:02:03 +00009262ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009263 ipv6_bgp_neighbor_advertised_route_cmd,
9264 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9265 SHOW_STR
9266 IPV6_STR
9267 BGP_STR
9268 "Detailed information on TCP and BGP neighbor connections\n"
9269 "Neighbor to display information about\n"
9270 "Neighbor to display information about\n"
9271 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009272
paul718e3742002-12-13 20:15:29 +00009273/* old command */
9274DEFUN (ipv6_mbgp_neighbor_advertised_route,
9275 ipv6_mbgp_neighbor_advertised_route_cmd,
9276 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9277 SHOW_STR
9278 IPV6_STR
9279 MBGP_STR
9280 "Detailed information on TCP and BGP neighbor connections\n"
9281 "Neighbor to display information about\n"
9282 "Neighbor to display information about\n"
9283 "Display the routes advertised to a BGP neighbor\n")
9284{
paulbb46e942003-10-24 19:02:03 +00009285 struct peer *peer;
9286
9287 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9288 if (! peer)
9289 return CMD_WARNING;
9290
9291 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009292}
9293#endif /* HAVE_IPV6 */
9294
9295DEFUN (show_ip_bgp_neighbor_received_routes,
9296 show_ip_bgp_neighbor_received_routes_cmd,
9297 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9298 SHOW_STR
9299 IP_STR
9300 BGP_STR
9301 "Detailed information on TCP and BGP neighbor connections\n"
9302 "Neighbor to display information about\n"
9303 "Neighbor to display information about\n"
9304 "Display the received routes from neighbor\n")
9305{
paulbb46e942003-10-24 19:02:03 +00009306 struct peer *peer;
9307
9308 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9309 if (! peer)
9310 return CMD_WARNING;
9311
9312 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009313}
9314
9315DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9316 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9317 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9318 SHOW_STR
9319 IP_STR
9320 BGP_STR
9321 "Address family\n"
9322 "Address Family modifier\n"
9323 "Address Family modifier\n"
9324 "Detailed information on TCP and BGP neighbor connections\n"
9325 "Neighbor to display information about\n"
9326 "Neighbor to display information about\n"
9327 "Display the received routes from neighbor\n")
9328{
paulbb46e942003-10-24 19:02:03 +00009329 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009330
paulbb46e942003-10-24 19:02:03 +00009331 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9332 if (! peer)
9333 return CMD_WARNING;
9334
9335 if (strncmp (argv[0], "m", 1) == 0)
9336 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9337
9338 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009339}
9340
9341DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9342 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9343 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9344 SHOW_STR
9345 IP_STR
9346 BGP_STR
9347 "Detailed information on TCP and BGP neighbor connections\n"
9348 "Neighbor to display information about\n"
9349 "Neighbor to display information about\n"
9350 "Display information received from a BGP neighbor\n"
9351 "Display the prefixlist filter\n")
9352{
9353 char name[BUFSIZ];
9354 union sockunion *su;
9355 struct peer *peer;
9356 int count;
9357
9358 su = sockunion_str2su (argv[0]);
9359 if (su == NULL)
9360 return CMD_WARNING;
9361
9362 peer = peer_lookup (NULL, su);
9363 if (! peer)
9364 return CMD_WARNING;
9365
9366 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9367 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9368 if (count)
9369 {
9370 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9371 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9372 }
9373
9374 return CMD_SUCCESS;
9375}
9376
9377DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9378 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9379 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9380 SHOW_STR
9381 IP_STR
9382 BGP_STR
9383 "Address family\n"
9384 "Address Family modifier\n"
9385 "Address Family modifier\n"
9386 "Detailed information on TCP and BGP neighbor connections\n"
9387 "Neighbor to display information about\n"
9388 "Neighbor to display information about\n"
9389 "Display information received from a BGP neighbor\n"
9390 "Display the prefixlist filter\n")
9391{
9392 char name[BUFSIZ];
9393 union sockunion *su;
9394 struct peer *peer;
9395 int count;
9396
9397 su = sockunion_str2su (argv[1]);
9398 if (su == NULL)
9399 return CMD_WARNING;
9400
9401 peer = peer_lookup (NULL, su);
9402 if (! peer)
9403 return CMD_WARNING;
9404
9405 if (strncmp (argv[0], "m", 1) == 0)
9406 {
9407 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9408 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9409 if (count)
9410 {
9411 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9412 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9413 }
9414 }
9415 else
9416 {
9417 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9418 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9419 if (count)
9420 {
9421 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9422 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9423 }
9424 }
9425
9426 return CMD_SUCCESS;
9427}
9428
9429
9430#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009431ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009432 show_bgp_neighbor_received_routes_cmd,
9433 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9434 SHOW_STR
9435 BGP_STR
9436 "Detailed information on TCP and BGP neighbor connections\n"
9437 "Neighbor to display information about\n"
9438 "Neighbor to display information about\n"
9439 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009440
paulbb46e942003-10-24 19:02:03 +00009441ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009442 show_bgp_ipv6_neighbor_received_routes_cmd,
9443 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9444 SHOW_STR
9445 BGP_STR
9446 "Address family\n"
9447 "Detailed information on TCP and BGP neighbor connections\n"
9448 "Neighbor to display information about\n"
9449 "Neighbor to display information about\n"
9450 "Display the received routes from neighbor\n")
9451
9452DEFUN (show_bgp_neighbor_received_prefix_filter,
9453 show_bgp_neighbor_received_prefix_filter_cmd,
9454 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9455 SHOW_STR
9456 BGP_STR
9457 "Detailed information on TCP and BGP neighbor connections\n"
9458 "Neighbor to display information about\n"
9459 "Neighbor to display information about\n"
9460 "Display information received from a BGP neighbor\n"
9461 "Display the prefixlist filter\n")
9462{
9463 char name[BUFSIZ];
9464 union sockunion *su;
9465 struct peer *peer;
9466 int count;
9467
9468 su = sockunion_str2su (argv[0]);
9469 if (su == NULL)
9470 return CMD_WARNING;
9471
9472 peer = peer_lookup (NULL, su);
9473 if (! peer)
9474 return CMD_WARNING;
9475
9476 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9477 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9478 if (count)
9479 {
9480 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9481 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9482 }
9483
9484 return CMD_SUCCESS;
9485}
9486
9487ALIAS (show_bgp_neighbor_received_prefix_filter,
9488 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
9489 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9490 SHOW_STR
9491 BGP_STR
9492 "Address family\n"
9493 "Detailed information on TCP and BGP neighbor connections\n"
9494 "Neighbor to display information about\n"
9495 "Neighbor to display information about\n"
9496 "Display information received from a BGP neighbor\n"
9497 "Display the prefixlist filter\n")
9498
9499/* old command */
paulbb46e942003-10-24 19:02:03 +00009500ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009501 ipv6_bgp_neighbor_received_routes_cmd,
9502 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9503 SHOW_STR
9504 IPV6_STR
9505 BGP_STR
9506 "Detailed information on TCP and BGP neighbor connections\n"
9507 "Neighbor to display information about\n"
9508 "Neighbor to display information about\n"
9509 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009510
9511/* old command */
9512DEFUN (ipv6_mbgp_neighbor_received_routes,
9513 ipv6_mbgp_neighbor_received_routes_cmd,
9514 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9515 SHOW_STR
9516 IPV6_STR
9517 MBGP_STR
9518 "Detailed information on TCP and BGP neighbor connections\n"
9519 "Neighbor to display information about\n"
9520 "Neighbor to display information about\n"
9521 "Display the received routes from neighbor\n")
9522{
paulbb46e942003-10-24 19:02:03 +00009523 struct peer *peer;
9524
9525 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9526 if (! peer)
9527 return CMD_WARNING;
9528
9529 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00009530}
paulbb46e942003-10-24 19:02:03 +00009531
9532DEFUN (show_bgp_view_neighbor_received_prefix_filter,
9533 show_bgp_view_neighbor_received_prefix_filter_cmd,
9534 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9535 SHOW_STR
9536 BGP_STR
9537 "BGP view\n"
9538 "View name\n"
9539 "Detailed information on TCP and BGP neighbor connections\n"
9540 "Neighbor to display information about\n"
9541 "Neighbor to display information about\n"
9542 "Display information received from a BGP neighbor\n"
9543 "Display the prefixlist filter\n")
9544{
9545 char name[BUFSIZ];
9546 union sockunion *su;
9547 struct peer *peer;
9548 struct bgp *bgp;
9549 int count;
9550
9551 /* BGP structure lookup. */
9552 bgp = bgp_lookup_by_name (argv[0]);
9553 if (bgp == NULL)
9554 {
9555 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9556 return CMD_WARNING;
9557 }
9558
9559 su = sockunion_str2su (argv[1]);
9560 if (su == NULL)
9561 return CMD_WARNING;
9562
9563 peer = peer_lookup (bgp, su);
9564 if (! peer)
9565 return CMD_WARNING;
9566
9567 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9568 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9569 if (count)
9570 {
9571 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9572 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9573 }
9574
9575 return CMD_SUCCESS;
9576}
9577
9578ALIAS (show_bgp_view_neighbor_received_prefix_filter,
9579 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
9580 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9581 SHOW_STR
9582 BGP_STR
9583 "BGP view\n"
9584 "View name\n"
9585 "Address family\n"
9586 "Detailed information on TCP and BGP neighbor connections\n"
9587 "Neighbor to display information about\n"
9588 "Neighbor to display information about\n"
9589 "Display information received from a BGP neighbor\n"
9590 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00009591#endif /* HAVE_IPV6 */
9592
paul94f2b392005-06-28 12:44:16 +00009593static int
paulbb46e942003-10-24 19:02:03 +00009594bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009595 safi_t safi, enum bgp_show_type type)
9596{
paul718e3742002-12-13 20:15:29 +00009597 if (! peer || ! peer->afc[afi][safi])
9598 {
9599 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009600 return CMD_WARNING;
9601 }
9602
ajs5a646652004-11-05 01:25:55 +00009603 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00009604}
9605
9606DEFUN (show_ip_bgp_neighbor_routes,
9607 show_ip_bgp_neighbor_routes_cmd,
9608 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
9609 SHOW_STR
9610 IP_STR
9611 BGP_STR
9612 "Detailed information on TCP and BGP neighbor connections\n"
9613 "Neighbor to display information about\n"
9614 "Neighbor to display information about\n"
9615 "Display routes learned from neighbor\n")
9616{
paulbb46e942003-10-24 19:02:03 +00009617 struct peer *peer;
9618
9619 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9620 if (! peer)
9621 return CMD_WARNING;
9622
9623 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009624 bgp_show_type_neighbor);
9625}
9626
9627DEFUN (show_ip_bgp_neighbor_flap,
9628 show_ip_bgp_neighbor_flap_cmd,
9629 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9630 SHOW_STR
9631 IP_STR
9632 BGP_STR
9633 "Detailed information on TCP and BGP neighbor connections\n"
9634 "Neighbor to display information about\n"
9635 "Neighbor to display information about\n"
9636 "Display flap statistics of the routes learned from neighbor\n")
9637{
paulbb46e942003-10-24 19:02:03 +00009638 struct peer *peer;
9639
9640 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9641 if (! peer)
9642 return CMD_WARNING;
9643
9644 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009645 bgp_show_type_flap_neighbor);
9646}
9647
9648DEFUN (show_ip_bgp_neighbor_damp,
9649 show_ip_bgp_neighbor_damp_cmd,
9650 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9651 SHOW_STR
9652 IP_STR
9653 BGP_STR
9654 "Detailed information on TCP and BGP neighbor connections\n"
9655 "Neighbor to display information about\n"
9656 "Neighbor to display information about\n"
9657 "Display the dampened routes received from neighbor\n")
9658{
paulbb46e942003-10-24 19:02:03 +00009659 struct peer *peer;
9660
9661 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9662 if (! peer)
9663 return CMD_WARNING;
9664
9665 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009666 bgp_show_type_damp_neighbor);
9667}
9668
9669DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9670 show_ip_bgp_ipv4_neighbor_routes_cmd,
9671 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9672 SHOW_STR
9673 IP_STR
9674 BGP_STR
9675 "Address family\n"
9676 "Address Family modifier\n"
9677 "Address Family modifier\n"
9678 "Detailed information on TCP and BGP neighbor connections\n"
9679 "Neighbor to display information about\n"
9680 "Neighbor to display information about\n"
9681 "Display routes learned from neighbor\n")
9682{
paulbb46e942003-10-24 19:02:03 +00009683 struct peer *peer;
9684
9685 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9686 if (! peer)
9687 return CMD_WARNING;
9688
paul718e3742002-12-13 20:15:29 +00009689 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009690 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009691 bgp_show_type_neighbor);
9692
paulbb46e942003-10-24 19:02:03 +00009693 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009694 bgp_show_type_neighbor);
9695}
paulbb46e942003-10-24 19:02:03 +00009696
paulfee0f4c2004-09-13 05:12:46 +00009697DEFUN (show_ip_bgp_view_rsclient,
9698 show_ip_bgp_view_rsclient_cmd,
9699 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9700 SHOW_STR
9701 IP_STR
9702 BGP_STR
9703 "BGP view\n"
9704 "BGP view name\n"
9705 "Information about Route Server Client\n"
9706 NEIGHBOR_ADDR_STR)
9707{
9708 struct bgp_table *table;
9709 struct peer *peer;
9710
9711 if (argc == 2)
9712 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9713 else
9714 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9715
9716 if (! peer)
9717 return CMD_WARNING;
9718
9719 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9720 {
9721 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9722 VTY_NEWLINE);
9723 return CMD_WARNING;
9724 }
9725
9726 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9727 PEER_FLAG_RSERVER_CLIENT))
9728 {
9729 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9730 VTY_NEWLINE);
9731 return CMD_WARNING;
9732 }
9733
9734 table = peer->rib[AFI_IP][SAFI_UNICAST];
9735
ajs5a646652004-11-05 01:25:55 +00009736 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009737}
9738
9739ALIAS (show_ip_bgp_view_rsclient,
9740 show_ip_bgp_rsclient_cmd,
9741 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9742 SHOW_STR
9743 IP_STR
9744 BGP_STR
9745 "Information about Route Server Client\n"
9746 NEIGHBOR_ADDR_STR)
9747
9748DEFUN (show_ip_bgp_view_rsclient_route,
9749 show_ip_bgp_view_rsclient_route_cmd,
9750 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9751 SHOW_STR
9752 IP_STR
9753 BGP_STR
9754 "BGP view\n"
9755 "BGP view name\n"
9756 "Information about Route Server Client\n"
9757 NEIGHBOR_ADDR_STR
9758 "Network in the BGP routing table to display\n")
9759{
9760 struct bgp *bgp;
9761 struct peer *peer;
9762
9763 /* BGP structure lookup. */
9764 if (argc == 3)
9765 {
9766 bgp = bgp_lookup_by_name (argv[0]);
9767 if (bgp == NULL)
9768 {
9769 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9770 return CMD_WARNING;
9771 }
9772 }
9773 else
9774 {
9775 bgp = bgp_get_default ();
9776 if (bgp == NULL)
9777 {
9778 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9779 return CMD_WARNING;
9780 }
9781 }
9782
9783 if (argc == 3)
9784 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9785 else
9786 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9787
9788 if (! peer)
9789 return CMD_WARNING;
9790
9791 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9792 {
9793 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9794 VTY_NEWLINE);
9795 return CMD_WARNING;
9796}
9797
9798 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9799 PEER_FLAG_RSERVER_CLIENT))
9800 {
9801 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9802 VTY_NEWLINE);
9803 return CMD_WARNING;
9804 }
9805
9806 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9807 (argc == 3) ? argv[2] : argv[1],
9808 AFI_IP, SAFI_UNICAST, NULL, 0);
9809}
9810
9811ALIAS (show_ip_bgp_view_rsclient_route,
9812 show_ip_bgp_rsclient_route_cmd,
9813 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9814 SHOW_STR
9815 IP_STR
9816 BGP_STR
9817 "Information about Route Server Client\n"
9818 NEIGHBOR_ADDR_STR
9819 "Network in the BGP routing table to display\n")
9820
9821DEFUN (show_ip_bgp_view_rsclient_prefix,
9822 show_ip_bgp_view_rsclient_prefix_cmd,
9823 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9824 SHOW_STR
9825 IP_STR
9826 BGP_STR
9827 "BGP view\n"
9828 "BGP view name\n"
9829 "Information about Route Server Client\n"
9830 NEIGHBOR_ADDR_STR
9831 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9832{
9833 struct bgp *bgp;
9834 struct peer *peer;
9835
9836 /* BGP structure lookup. */
9837 if (argc == 3)
9838 {
9839 bgp = bgp_lookup_by_name (argv[0]);
9840 if (bgp == NULL)
9841 {
9842 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9843 return CMD_WARNING;
9844 }
9845 }
9846 else
9847 {
9848 bgp = bgp_get_default ();
9849 if (bgp == NULL)
9850 {
9851 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9852 return CMD_WARNING;
9853 }
9854 }
9855
9856 if (argc == 3)
9857 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9858 else
9859 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9860
9861 if (! peer)
9862 return CMD_WARNING;
9863
9864 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9865 {
9866 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9867 VTY_NEWLINE);
9868 return CMD_WARNING;
9869}
9870
9871 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9872 PEER_FLAG_RSERVER_CLIENT))
9873{
9874 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9875 VTY_NEWLINE);
9876 return CMD_WARNING;
9877 }
9878
9879 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9880 (argc == 3) ? argv[2] : argv[1],
9881 AFI_IP, SAFI_UNICAST, NULL, 1);
9882}
9883
9884ALIAS (show_ip_bgp_view_rsclient_prefix,
9885 show_ip_bgp_rsclient_prefix_cmd,
9886 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9887 SHOW_STR
9888 IP_STR
9889 BGP_STR
9890 "Information about Route Server Client\n"
9891 NEIGHBOR_ADDR_STR
9892 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9893
9894
paul718e3742002-12-13 20:15:29 +00009895#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009896DEFUN (show_bgp_view_neighbor_routes,
9897 show_bgp_view_neighbor_routes_cmd,
9898 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9899 SHOW_STR
9900 BGP_STR
9901 "BGP view\n"
9902 "BGP view name\n"
9903 "Detailed information on TCP and BGP neighbor connections\n"
9904 "Neighbor to display information about\n"
9905 "Neighbor to display information about\n"
9906 "Display routes learned from neighbor\n")
9907{
9908 struct peer *peer;
9909
9910 if (argc == 2)
9911 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9912 else
9913 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9914
9915 if (! peer)
9916 return CMD_WARNING;
9917
9918 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9919 bgp_show_type_neighbor);
9920}
9921
9922ALIAS (show_bgp_view_neighbor_routes,
9923 show_bgp_view_ipv6_neighbor_routes_cmd,
9924 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9925 SHOW_STR
9926 BGP_STR
9927 "BGP view\n"
9928 "BGP view name\n"
9929 "Address family\n"
9930 "Detailed information on TCP and BGP neighbor connections\n"
9931 "Neighbor to display information about\n"
9932 "Neighbor to display information about\n"
9933 "Display routes learned from neighbor\n")
9934
9935DEFUN (show_bgp_view_neighbor_damp,
9936 show_bgp_view_neighbor_damp_cmd,
9937 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9938 SHOW_STR
9939 BGP_STR
9940 "BGP view\n"
9941 "BGP view name\n"
9942 "Detailed information on TCP and BGP neighbor connections\n"
9943 "Neighbor to display information about\n"
9944 "Neighbor to display information about\n"
9945 "Display the dampened routes received from neighbor\n")
9946{
9947 struct peer *peer;
9948
9949 if (argc == 2)
9950 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9951 else
9952 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9953
9954 if (! peer)
9955 return CMD_WARNING;
9956
9957 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9958 bgp_show_type_damp_neighbor);
9959}
9960
9961ALIAS (show_bgp_view_neighbor_damp,
9962 show_bgp_view_ipv6_neighbor_damp_cmd,
9963 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9964 SHOW_STR
9965 BGP_STR
9966 "BGP view\n"
9967 "BGP view name\n"
9968 "Address family\n"
9969 "Detailed information on TCP and BGP neighbor connections\n"
9970 "Neighbor to display information about\n"
9971 "Neighbor to display information about\n"
9972 "Display the dampened routes received from neighbor\n")
9973
9974DEFUN (show_bgp_view_neighbor_flap,
9975 show_bgp_view_neighbor_flap_cmd,
9976 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9977 SHOW_STR
9978 BGP_STR
9979 "BGP view\n"
9980 "BGP view name\n"
9981 "Detailed information on TCP and BGP neighbor connections\n"
9982 "Neighbor to display information about\n"
9983 "Neighbor to display information about\n"
9984 "Display flap statistics of the routes learned from neighbor\n")
9985{
9986 struct peer *peer;
9987
9988 if (argc == 2)
9989 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9990 else
9991 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9992
9993 if (! peer)
9994 return CMD_WARNING;
9995
9996 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9997 bgp_show_type_flap_neighbor);
9998}
9999
10000ALIAS (show_bgp_view_neighbor_flap,
10001 show_bgp_view_ipv6_neighbor_flap_cmd,
10002 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10003 SHOW_STR
10004 BGP_STR
10005 "BGP view\n"
10006 "BGP view name\n"
10007 "Address family\n"
10008 "Detailed information on TCP and BGP neighbor connections\n"
10009 "Neighbor to display information about\n"
10010 "Neighbor to display information about\n"
10011 "Display flap statistics of the routes learned from neighbor\n")
10012
10013ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010014 show_bgp_neighbor_routes_cmd,
10015 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10016 SHOW_STR
10017 BGP_STR
10018 "Detailed information on TCP and BGP neighbor connections\n"
10019 "Neighbor to display information about\n"
10020 "Neighbor to display information about\n"
10021 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010022
paulbb46e942003-10-24 19:02:03 +000010023
10024ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010025 show_bgp_ipv6_neighbor_routes_cmd,
10026 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10027 SHOW_STR
10028 BGP_STR
10029 "Address family\n"
10030 "Detailed information on TCP and BGP neighbor connections\n"
10031 "Neighbor to display information about\n"
10032 "Neighbor to display information about\n"
10033 "Display routes learned from neighbor\n")
10034
10035/* old command */
paulbb46e942003-10-24 19:02:03 +000010036ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010037 ipv6_bgp_neighbor_routes_cmd,
10038 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10039 SHOW_STR
10040 IPV6_STR
10041 BGP_STR
10042 "Detailed information on TCP and BGP neighbor connections\n"
10043 "Neighbor to display information about\n"
10044 "Neighbor to display information about\n"
10045 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010046
10047/* old command */
10048DEFUN (ipv6_mbgp_neighbor_routes,
10049 ipv6_mbgp_neighbor_routes_cmd,
10050 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10051 SHOW_STR
10052 IPV6_STR
10053 MBGP_STR
10054 "Detailed information on TCP and BGP neighbor connections\n"
10055 "Neighbor to display information about\n"
10056 "Neighbor to display information about\n"
10057 "Display routes learned from neighbor\n")
10058{
paulbb46e942003-10-24 19:02:03 +000010059 struct peer *peer;
10060
10061 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10062 if (! peer)
10063 return CMD_WARNING;
10064
10065 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010066 bgp_show_type_neighbor);
10067}
paulbb46e942003-10-24 19:02:03 +000010068
10069ALIAS (show_bgp_view_neighbor_flap,
10070 show_bgp_neighbor_flap_cmd,
10071 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10072 SHOW_STR
10073 BGP_STR
10074 "Detailed information on TCP and BGP neighbor connections\n"
10075 "Neighbor to display information about\n"
10076 "Neighbor to display information about\n"
10077 "Display flap statistics of the routes learned from neighbor\n")
10078
10079ALIAS (show_bgp_view_neighbor_flap,
10080 show_bgp_ipv6_neighbor_flap_cmd,
10081 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10082 SHOW_STR
10083 BGP_STR
10084 "Address family\n"
10085 "Detailed information on TCP and BGP neighbor connections\n"
10086 "Neighbor to display information about\n"
10087 "Neighbor to display information about\n"
10088 "Display flap statistics of the routes learned from neighbor\n")
10089
10090ALIAS (show_bgp_view_neighbor_damp,
10091 show_bgp_neighbor_damp_cmd,
10092 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10093 SHOW_STR
10094 BGP_STR
10095 "Detailed information on TCP and BGP neighbor connections\n"
10096 "Neighbor to display information about\n"
10097 "Neighbor to display information about\n"
10098 "Display the dampened routes received from neighbor\n")
10099
10100ALIAS (show_bgp_view_neighbor_damp,
10101 show_bgp_ipv6_neighbor_damp_cmd,
10102 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10103 SHOW_STR
10104 BGP_STR
10105 "Address family\n"
10106 "Detailed information on TCP and BGP neighbor connections\n"
10107 "Neighbor to display information about\n"
10108 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010109 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010110
10111DEFUN (show_bgp_view_rsclient,
10112 show_bgp_view_rsclient_cmd,
10113 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10114 SHOW_STR
10115 BGP_STR
10116 "BGP view\n"
10117 "BGP view name\n"
10118 "Information about Route Server Client\n"
10119 NEIGHBOR_ADDR_STR)
10120{
10121 struct bgp_table *table;
10122 struct peer *peer;
10123
10124 if (argc == 2)
10125 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10126 else
10127 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10128
10129 if (! peer)
10130 return CMD_WARNING;
10131
10132 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10133 {
10134 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10135 VTY_NEWLINE);
10136 return CMD_WARNING;
10137 }
10138
10139 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10140 PEER_FLAG_RSERVER_CLIENT))
10141 {
10142 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10143 VTY_NEWLINE);
10144 return CMD_WARNING;
10145 }
10146
10147 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10148
ajs5a646652004-11-05 01:25:55 +000010149 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010150}
10151
10152ALIAS (show_bgp_view_rsclient,
10153 show_bgp_rsclient_cmd,
10154 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10155 SHOW_STR
10156 BGP_STR
10157 "Information about Route Server Client\n"
10158 NEIGHBOR_ADDR_STR)
10159
10160DEFUN (show_bgp_view_rsclient_route,
10161 show_bgp_view_rsclient_route_cmd,
10162 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10163 SHOW_STR
10164 BGP_STR
10165 "BGP view\n"
10166 "BGP view name\n"
10167 "Information about Route Server Client\n"
10168 NEIGHBOR_ADDR_STR
10169 "Network in the BGP routing table to display\n")
10170{
10171 struct bgp *bgp;
10172 struct peer *peer;
10173
10174 /* BGP structure lookup. */
10175 if (argc == 3)
10176 {
10177 bgp = bgp_lookup_by_name (argv[0]);
10178 if (bgp == NULL)
10179 {
10180 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10181 return CMD_WARNING;
10182 }
10183 }
10184 else
10185 {
10186 bgp = bgp_get_default ();
10187 if (bgp == NULL)
10188 {
10189 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10190 return CMD_WARNING;
10191 }
10192 }
10193
10194 if (argc == 3)
10195 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10196 else
10197 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10198
10199 if (! peer)
10200 return CMD_WARNING;
10201
10202 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10203 {
10204 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10205 VTY_NEWLINE);
10206 return CMD_WARNING;
10207 }
10208
10209 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10210 PEER_FLAG_RSERVER_CLIENT))
10211 {
10212 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10213 VTY_NEWLINE);
10214 return CMD_WARNING;
10215 }
10216
10217 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10218 (argc == 3) ? argv[2] : argv[1],
10219 AFI_IP6, SAFI_UNICAST, NULL, 0);
10220}
10221
10222ALIAS (show_bgp_view_rsclient_route,
10223 show_bgp_rsclient_route_cmd,
10224 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10225 SHOW_STR
10226 BGP_STR
10227 "Information about Route Server Client\n"
10228 NEIGHBOR_ADDR_STR
10229 "Network in the BGP routing table to display\n")
10230
10231DEFUN (show_bgp_view_rsclient_prefix,
10232 show_bgp_view_rsclient_prefix_cmd,
10233 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10234 SHOW_STR
10235 BGP_STR
10236 "BGP view\n"
10237 "BGP view name\n"
10238 "Information about Route Server Client\n"
10239 NEIGHBOR_ADDR_STR
10240 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10241{
10242 struct bgp *bgp;
10243 struct peer *peer;
10244
10245 /* BGP structure lookup. */
10246 if (argc == 3)
10247 {
10248 bgp = bgp_lookup_by_name (argv[0]);
10249 if (bgp == NULL)
10250 {
10251 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10252 return CMD_WARNING;
10253 }
10254 }
10255 else
10256 {
10257 bgp = bgp_get_default ();
10258 if (bgp == NULL)
10259 {
10260 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10261 return CMD_WARNING;
10262 }
10263 }
10264
10265 if (argc == 3)
10266 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10267 else
10268 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10269
10270 if (! peer)
10271 return CMD_WARNING;
10272
10273 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10274 {
10275 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10276 VTY_NEWLINE);
10277 return CMD_WARNING;
10278 }
10279
10280 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10281 PEER_FLAG_RSERVER_CLIENT))
10282 {
10283 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10284 VTY_NEWLINE);
10285 return CMD_WARNING;
10286 }
10287
10288 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10289 (argc == 3) ? argv[2] : argv[1],
10290 AFI_IP6, SAFI_UNICAST, NULL, 1);
10291}
10292
10293ALIAS (show_bgp_view_rsclient_prefix,
10294 show_bgp_rsclient_prefix_cmd,
10295 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10296 SHOW_STR
10297 BGP_STR
10298 "Information about Route Server Client\n"
10299 NEIGHBOR_ADDR_STR
10300 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10301
paul718e3742002-12-13 20:15:29 +000010302#endif /* HAVE_IPV6 */
10303
10304struct bgp_table *bgp_distance_table;
10305
10306struct bgp_distance
10307{
10308 /* Distance value for the IP source prefix. */
10309 u_char distance;
10310
10311 /* Name of the access-list to be matched. */
10312 char *access_list;
10313};
10314
paul94f2b392005-06-28 12:44:16 +000010315static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +000010316bgp_distance_new ()
10317{
10318 struct bgp_distance *new;
10319 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
10320 memset (new, 0, sizeof (struct bgp_distance));
10321 return new;
10322}
10323
paul94f2b392005-06-28 12:44:16 +000010324static void
paul718e3742002-12-13 20:15:29 +000010325bgp_distance_free (struct bgp_distance *bdistance)
10326{
10327 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10328}
10329
paul94f2b392005-06-28 12:44:16 +000010330static int
paulfd79ac92004-10-13 05:06:08 +000010331bgp_distance_set (struct vty *vty, const char *distance_str,
10332 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010333{
10334 int ret;
10335 struct prefix_ipv4 p;
10336 u_char distance;
10337 struct bgp_node *rn;
10338 struct bgp_distance *bdistance;
10339
10340 ret = str2prefix_ipv4 (ip_str, &p);
10341 if (ret == 0)
10342 {
10343 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10344 return CMD_WARNING;
10345 }
10346
10347 distance = atoi (distance_str);
10348
10349 /* Get BGP distance node. */
10350 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10351 if (rn->info)
10352 {
10353 bdistance = rn->info;
10354 bgp_unlock_node (rn);
10355 }
10356 else
10357 {
10358 bdistance = bgp_distance_new ();
10359 rn->info = bdistance;
10360 }
10361
10362 /* Set distance value. */
10363 bdistance->distance = distance;
10364
10365 /* Reset access-list configuration. */
10366 if (bdistance->access_list)
10367 {
10368 free (bdistance->access_list);
10369 bdistance->access_list = NULL;
10370 }
10371 if (access_list_str)
10372 bdistance->access_list = strdup (access_list_str);
10373
10374 return CMD_SUCCESS;
10375}
10376
paul94f2b392005-06-28 12:44:16 +000010377static int
paulfd79ac92004-10-13 05:06:08 +000010378bgp_distance_unset (struct vty *vty, const char *distance_str,
10379 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010380{
10381 int ret;
10382 struct prefix_ipv4 p;
10383 u_char distance;
10384 struct bgp_node *rn;
10385 struct bgp_distance *bdistance;
10386
10387 ret = str2prefix_ipv4 (ip_str, &p);
10388 if (ret == 0)
10389 {
10390 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10391 return CMD_WARNING;
10392 }
10393
10394 distance = atoi (distance_str);
10395
10396 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10397 if (! rn)
10398 {
10399 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10400 return CMD_WARNING;
10401 }
10402
10403 bdistance = rn->info;
10404
10405 if (bdistance->access_list)
10406 free (bdistance->access_list);
10407 bgp_distance_free (bdistance);
10408
10409 rn->info = NULL;
10410 bgp_unlock_node (rn);
10411 bgp_unlock_node (rn);
10412
10413 return CMD_SUCCESS;
10414}
10415
paul94f2b392005-06-28 12:44:16 +000010416static void
paul718e3742002-12-13 20:15:29 +000010417bgp_distance_reset ()
10418{
10419 struct bgp_node *rn;
10420 struct bgp_distance *bdistance;
10421
10422 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10423 if ((bdistance = rn->info) != NULL)
10424 {
10425 if (bdistance->access_list)
10426 free (bdistance->access_list);
10427 bgp_distance_free (bdistance);
10428 rn->info = NULL;
10429 bgp_unlock_node (rn);
10430 }
10431}
10432
10433/* Apply BGP information to distance method. */
10434u_char
10435bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10436{
10437 struct bgp_node *rn;
10438 struct prefix_ipv4 q;
10439 struct peer *peer;
10440 struct bgp_distance *bdistance;
10441 struct access_list *alist;
10442 struct bgp_static *bgp_static;
10443
10444 if (! bgp)
10445 return 0;
10446
10447 if (p->family != AF_INET)
10448 return 0;
10449
10450 peer = rinfo->peer;
10451
10452 if (peer->su.sa.sa_family != AF_INET)
10453 return 0;
10454
10455 memset (&q, 0, sizeof (struct prefix_ipv4));
10456 q.family = AF_INET;
10457 q.prefix = peer->su.sin.sin_addr;
10458 q.prefixlen = IPV4_MAX_BITLEN;
10459
10460 /* Check source address. */
10461 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10462 if (rn)
10463 {
10464 bdistance = rn->info;
10465 bgp_unlock_node (rn);
10466
10467 if (bdistance->access_list)
10468 {
10469 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10470 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10471 return bdistance->distance;
10472 }
10473 else
10474 return bdistance->distance;
10475 }
10476
10477 /* Backdoor check. */
10478 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10479 if (rn)
10480 {
10481 bgp_static = rn->info;
10482 bgp_unlock_node (rn);
10483
10484 if (bgp_static->backdoor)
10485 {
10486 if (bgp->distance_local)
10487 return bgp->distance_local;
10488 else
10489 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10490 }
10491 }
10492
10493 if (peer_sort (peer) == BGP_PEER_EBGP)
10494 {
10495 if (bgp->distance_ebgp)
10496 return bgp->distance_ebgp;
10497 return ZEBRA_EBGP_DISTANCE_DEFAULT;
10498 }
10499 else
10500 {
10501 if (bgp->distance_ibgp)
10502 return bgp->distance_ibgp;
10503 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10504 }
10505}
10506
10507DEFUN (bgp_distance,
10508 bgp_distance_cmd,
10509 "distance bgp <1-255> <1-255> <1-255>",
10510 "Define an administrative distance\n"
10511 "BGP distance\n"
10512 "Distance for routes external to the AS\n"
10513 "Distance for routes internal to the AS\n"
10514 "Distance for local routes\n")
10515{
10516 struct bgp *bgp;
10517
10518 bgp = vty->index;
10519
10520 bgp->distance_ebgp = atoi (argv[0]);
10521 bgp->distance_ibgp = atoi (argv[1]);
10522 bgp->distance_local = atoi (argv[2]);
10523 return CMD_SUCCESS;
10524}
10525
10526DEFUN (no_bgp_distance,
10527 no_bgp_distance_cmd,
10528 "no distance bgp <1-255> <1-255> <1-255>",
10529 NO_STR
10530 "Define an administrative distance\n"
10531 "BGP distance\n"
10532 "Distance for routes external to the AS\n"
10533 "Distance for routes internal to the AS\n"
10534 "Distance for local routes\n")
10535{
10536 struct bgp *bgp;
10537
10538 bgp = vty->index;
10539
10540 bgp->distance_ebgp= 0;
10541 bgp->distance_ibgp = 0;
10542 bgp->distance_local = 0;
10543 return CMD_SUCCESS;
10544}
10545
10546ALIAS (no_bgp_distance,
10547 no_bgp_distance2_cmd,
10548 "no distance bgp",
10549 NO_STR
10550 "Define an administrative distance\n"
10551 "BGP distance\n")
10552
10553DEFUN (bgp_distance_source,
10554 bgp_distance_source_cmd,
10555 "distance <1-255> A.B.C.D/M",
10556 "Define an administrative distance\n"
10557 "Administrative distance\n"
10558 "IP source prefix\n")
10559{
10560 bgp_distance_set (vty, argv[0], argv[1], NULL);
10561 return CMD_SUCCESS;
10562}
10563
10564DEFUN (no_bgp_distance_source,
10565 no_bgp_distance_source_cmd,
10566 "no distance <1-255> A.B.C.D/M",
10567 NO_STR
10568 "Define an administrative distance\n"
10569 "Administrative distance\n"
10570 "IP source prefix\n")
10571{
10572 bgp_distance_unset (vty, argv[0], argv[1], NULL);
10573 return CMD_SUCCESS;
10574}
10575
10576DEFUN (bgp_distance_source_access_list,
10577 bgp_distance_source_access_list_cmd,
10578 "distance <1-255> A.B.C.D/M WORD",
10579 "Define an administrative distance\n"
10580 "Administrative distance\n"
10581 "IP source prefix\n"
10582 "Access list name\n")
10583{
10584 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
10585 return CMD_SUCCESS;
10586}
10587
10588DEFUN (no_bgp_distance_source_access_list,
10589 no_bgp_distance_source_access_list_cmd,
10590 "no distance <1-255> A.B.C.D/M WORD",
10591 NO_STR
10592 "Define an administrative distance\n"
10593 "Administrative distance\n"
10594 "IP source prefix\n"
10595 "Access list name\n")
10596{
10597 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
10598 return CMD_SUCCESS;
10599}
10600
10601DEFUN (bgp_damp_set,
10602 bgp_damp_set_cmd,
10603 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10604 "BGP Specific commands\n"
10605 "Enable route-flap dampening\n"
10606 "Half-life time for the penalty\n"
10607 "Value to start reusing a route\n"
10608 "Value to start suppressing a route\n"
10609 "Maximum duration to suppress a stable route\n")
10610{
10611 struct bgp *bgp;
10612 int half = DEFAULT_HALF_LIFE * 60;
10613 int reuse = DEFAULT_REUSE;
10614 int suppress = DEFAULT_SUPPRESS;
10615 int max = 4 * half;
10616
10617 if (argc == 4)
10618 {
10619 half = atoi (argv[0]) * 60;
10620 reuse = atoi (argv[1]);
10621 suppress = atoi (argv[2]);
10622 max = atoi (argv[3]) * 60;
10623 }
10624 else if (argc == 1)
10625 {
10626 half = atoi (argv[0]) * 60;
10627 max = 4 * half;
10628 }
10629
10630 bgp = vty->index;
10631 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10632 half, reuse, suppress, max);
10633}
10634
10635ALIAS (bgp_damp_set,
10636 bgp_damp_set2_cmd,
10637 "bgp dampening <1-45>",
10638 "BGP Specific commands\n"
10639 "Enable route-flap dampening\n"
10640 "Half-life time for the penalty\n")
10641
10642ALIAS (bgp_damp_set,
10643 bgp_damp_set3_cmd,
10644 "bgp dampening",
10645 "BGP Specific commands\n"
10646 "Enable route-flap dampening\n")
10647
10648DEFUN (bgp_damp_unset,
10649 bgp_damp_unset_cmd,
10650 "no bgp dampening",
10651 NO_STR
10652 "BGP Specific commands\n"
10653 "Enable route-flap dampening\n")
10654{
10655 struct bgp *bgp;
10656
10657 bgp = vty->index;
10658 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10659}
10660
10661ALIAS (bgp_damp_unset,
10662 bgp_damp_unset2_cmd,
10663 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10664 NO_STR
10665 "BGP Specific commands\n"
10666 "Enable route-flap dampening\n"
10667 "Half-life time for the penalty\n"
10668 "Value to start reusing a route\n"
10669 "Value to start suppressing a route\n"
10670 "Maximum duration to suppress a stable route\n")
10671
10672DEFUN (show_ip_bgp_dampened_paths,
10673 show_ip_bgp_dampened_paths_cmd,
10674 "show ip bgp dampened-paths",
10675 SHOW_STR
10676 IP_STR
10677 BGP_STR
10678 "Display paths suppressed due to dampening\n")
10679{
ajs5a646652004-11-05 01:25:55 +000010680 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10681 NULL);
paul718e3742002-12-13 20:15:29 +000010682}
10683
10684DEFUN (show_ip_bgp_flap_statistics,
10685 show_ip_bgp_flap_statistics_cmd,
10686 "show ip bgp flap-statistics",
10687 SHOW_STR
10688 IP_STR
10689 BGP_STR
10690 "Display flap statistics of routes\n")
10691{
ajs5a646652004-11-05 01:25:55 +000010692 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10693 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010694}
10695
10696/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010697static int
paulfd79ac92004-10-13 05:06:08 +000010698bgp_clear_damp_route (struct vty *vty, const char *view_name,
10699 const char *ip_str, afi_t afi, safi_t safi,
10700 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010701{
10702 int ret;
10703 struct prefix match;
10704 struct bgp_node *rn;
10705 struct bgp_node *rm;
10706 struct bgp_info *ri;
10707 struct bgp_info *ri_temp;
10708 struct bgp *bgp;
10709 struct bgp_table *table;
10710
10711 /* BGP structure lookup. */
10712 if (view_name)
10713 {
10714 bgp = bgp_lookup_by_name (view_name);
10715 if (bgp == NULL)
10716 {
10717 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10718 return CMD_WARNING;
10719 }
10720 }
10721 else
10722 {
10723 bgp = bgp_get_default ();
10724 if (bgp == NULL)
10725 {
10726 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10727 return CMD_WARNING;
10728 }
10729 }
10730
10731 /* Check IP address argument. */
10732 ret = str2prefix (ip_str, &match);
10733 if (! ret)
10734 {
10735 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10736 return CMD_WARNING;
10737 }
10738
10739 match.family = afi2family (afi);
10740
10741 if (safi == SAFI_MPLS_VPN)
10742 {
10743 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10744 {
10745 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10746 continue;
10747
10748 if ((table = rn->info) != NULL)
10749 if ((rm = bgp_node_match (table, &match)) != NULL)
10750 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10751 {
10752 ri = rm->info;
10753 while (ri)
10754 {
10755 if (ri->damp_info)
10756 {
10757 ri_temp = ri->next;
10758 bgp_damp_info_free (ri->damp_info, 1);
10759 ri = ri_temp;
10760 }
10761 else
10762 ri = ri->next;
10763 }
10764 }
10765 }
10766 }
10767 else
10768 {
10769 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10770 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10771 {
10772 ri = rn->info;
10773 while (ri)
10774 {
10775 if (ri->damp_info)
10776 {
10777 ri_temp = ri->next;
10778 bgp_damp_info_free (ri->damp_info, 1);
10779 ri = ri_temp;
10780 }
10781 else
10782 ri = ri->next;
10783 }
10784 }
10785 }
10786
10787 return CMD_SUCCESS;
10788}
10789
10790DEFUN (clear_ip_bgp_dampening,
10791 clear_ip_bgp_dampening_cmd,
10792 "clear ip bgp dampening",
10793 CLEAR_STR
10794 IP_STR
10795 BGP_STR
10796 "Clear route flap dampening information\n")
10797{
10798 bgp_damp_info_clean ();
10799 return CMD_SUCCESS;
10800}
10801
10802DEFUN (clear_ip_bgp_dampening_prefix,
10803 clear_ip_bgp_dampening_prefix_cmd,
10804 "clear ip bgp dampening A.B.C.D/M",
10805 CLEAR_STR
10806 IP_STR
10807 BGP_STR
10808 "Clear route flap dampening information\n"
10809 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10810{
10811 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10812 SAFI_UNICAST, NULL, 1);
10813}
10814
10815DEFUN (clear_ip_bgp_dampening_address,
10816 clear_ip_bgp_dampening_address_cmd,
10817 "clear ip bgp dampening A.B.C.D",
10818 CLEAR_STR
10819 IP_STR
10820 BGP_STR
10821 "Clear route flap dampening information\n"
10822 "Network to clear damping information\n")
10823{
10824 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10825 SAFI_UNICAST, NULL, 0);
10826}
10827
10828DEFUN (clear_ip_bgp_dampening_address_mask,
10829 clear_ip_bgp_dampening_address_mask_cmd,
10830 "clear ip bgp dampening A.B.C.D A.B.C.D",
10831 CLEAR_STR
10832 IP_STR
10833 BGP_STR
10834 "Clear route flap dampening information\n"
10835 "Network to clear damping information\n"
10836 "Network mask\n")
10837{
10838 int ret;
10839 char prefix_str[BUFSIZ];
10840
10841 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10842 if (! ret)
10843 {
10844 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10845 return CMD_WARNING;
10846 }
10847
10848 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10849 SAFI_UNICAST, NULL, 0);
10850}
10851
paul94f2b392005-06-28 12:44:16 +000010852static int
paul718e3742002-12-13 20:15:29 +000010853bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10854 afi_t afi, safi_t safi, int *write)
10855{
10856 struct bgp_node *prn;
10857 struct bgp_node *rn;
10858 struct bgp_table *table;
10859 struct prefix *p;
10860 struct prefix_rd *prd;
10861 struct bgp_static *bgp_static;
10862 u_int32_t label;
10863 char buf[SU_ADDRSTRLEN];
10864 char rdbuf[RD_ADDRSTRLEN];
10865
10866 /* Network configuration. */
10867 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10868 if ((table = prn->info) != NULL)
10869 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10870 if ((bgp_static = rn->info) != NULL)
10871 {
10872 p = &rn->p;
10873 prd = (struct prefix_rd *) &prn->p;
10874
10875 /* "address-family" display. */
10876 bgp_config_write_family_header (vty, afi, safi, write);
10877
10878 /* "network" configuration display. */
10879 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10880 label = decode_label (bgp_static->tag);
10881
10882 vty_out (vty, " network %s/%d rd %s tag %d",
10883 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10884 p->prefixlen,
10885 rdbuf, label);
10886 vty_out (vty, "%s", VTY_NEWLINE);
10887 }
10888 return 0;
10889}
10890
10891/* Configuration of static route announcement and aggregate
10892 information. */
10893int
10894bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10895 afi_t afi, safi_t safi, int *write)
10896{
10897 struct bgp_node *rn;
10898 struct prefix *p;
10899 struct bgp_static *bgp_static;
10900 struct bgp_aggregate *bgp_aggregate;
10901 char buf[SU_ADDRSTRLEN];
10902
10903 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10904 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10905
10906 /* Network configuration. */
10907 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10908 if ((bgp_static = rn->info) != NULL)
10909 {
10910 p = &rn->p;
10911
10912 /* "address-family" display. */
10913 bgp_config_write_family_header (vty, afi, safi, write);
10914
10915 /* "network" configuration display. */
10916 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10917 {
10918 u_int32_t destination;
10919 struct in_addr netmask;
10920
10921 destination = ntohl (p->u.prefix4.s_addr);
10922 masklen2ip (p->prefixlen, &netmask);
10923 vty_out (vty, " network %s",
10924 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10925
10926 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10927 || (IN_CLASSB (destination) && p->prefixlen == 16)
10928 || (IN_CLASSA (destination) && p->prefixlen == 8)
10929 || p->u.prefix4.s_addr == 0)
10930 {
10931 /* Natural mask is not display. */
10932 }
10933 else
10934 vty_out (vty, " mask %s", inet_ntoa (netmask));
10935 }
10936 else
10937 {
10938 vty_out (vty, " network %s/%d",
10939 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10940 p->prefixlen);
10941 }
10942
10943 if (bgp_static->rmap.name)
10944 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10945 else if (bgp_static->backdoor)
10946 vty_out (vty, " backdoor");
10947
10948 vty_out (vty, "%s", VTY_NEWLINE);
10949 }
10950
10951 /* Aggregate-address configuration. */
10952 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10953 if ((bgp_aggregate = rn->info) != NULL)
10954 {
10955 p = &rn->p;
10956
10957 /* "address-family" display. */
10958 bgp_config_write_family_header (vty, afi, safi, write);
10959
10960 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10961 {
10962 struct in_addr netmask;
10963
10964 masklen2ip (p->prefixlen, &netmask);
10965 vty_out (vty, " aggregate-address %s %s",
10966 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10967 inet_ntoa (netmask));
10968 }
10969 else
10970 {
10971 vty_out (vty, " aggregate-address %s/%d",
10972 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10973 p->prefixlen);
10974 }
10975
10976 if (bgp_aggregate->as_set)
10977 vty_out (vty, " as-set");
10978
10979 if (bgp_aggregate->summary_only)
10980 vty_out (vty, " summary-only");
10981
10982 vty_out (vty, "%s", VTY_NEWLINE);
10983 }
10984
10985 return 0;
10986}
10987
10988int
10989bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10990{
10991 struct bgp_node *rn;
10992 struct bgp_distance *bdistance;
10993
10994 /* Distance configuration. */
10995 if (bgp->distance_ebgp
10996 && bgp->distance_ibgp
10997 && bgp->distance_local
10998 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10999 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11000 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11001 vty_out (vty, " distance bgp %d %d %d%s",
11002 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11003 VTY_NEWLINE);
11004
11005 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11006 if ((bdistance = rn->info) != NULL)
11007 {
11008 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11009 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11010 bdistance->access_list ? bdistance->access_list : "",
11011 VTY_NEWLINE);
11012 }
11013
11014 return 0;
11015}
11016
11017/* Allocate routing table structure and install commands. */
11018void
11019bgp_route_init ()
11020{
11021 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011022 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011023
11024 /* IPv4 BGP commands. */
11025 install_element (BGP_NODE, &bgp_network_cmd);
11026 install_element (BGP_NODE, &bgp_network_mask_cmd);
11027 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11028 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11029 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11030 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11031 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11032 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11033 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
11034 install_element (BGP_NODE, &no_bgp_network_cmd);
11035 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11036 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11037 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11038 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11039 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11040 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11041 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11042 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
11043
11044 install_element (BGP_NODE, &aggregate_address_cmd);
11045 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11046 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11047 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11048 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11049 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11050 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11051 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11052 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11053 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11054 install_element (BGP_NODE, &no_aggregate_address_cmd);
11055 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11056 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11057 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11058 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11059 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11060 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11061 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11062 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11063 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11064
11065 /* IPv4 unicast configuration. */
11066 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11067 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11068 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11069 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11070 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11071 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
11072 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11073 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11074 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11075 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11076 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11077 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11078 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11079 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11080 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11081 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11082 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11083 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11084 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11085 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11086 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11087 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11088 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11089 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11090 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11091 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11092 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11093 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11094 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11095 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11096 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11097 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11098
11099 /* IPv4 multicast configuration. */
11100 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11101 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11102 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11103 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11104 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11105 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
11106 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11107 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11108 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11109 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11110 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11111 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11112 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11113 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11114 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11115 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11116 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11117 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11118 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11119 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11120 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11121 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11122 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11123 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11124 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11125 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11126 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11127 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11128 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11129 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11130 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11131 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11132
11133 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11134 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11135 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11136 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11137 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11138 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11139 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11140 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11141 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11142 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11143 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11144 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11145 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11146 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11147 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11148 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11149 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11150 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11151 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11152 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11153 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11154 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11155 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11156 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11157 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11158 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11159 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11160 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11161 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11162 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11163 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11164 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11165 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11166 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11167 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11168 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11169 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11170 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11171 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11172 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11173 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11174 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11175 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11176 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11177 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11178 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11179 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11180 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11181 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11182 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11183 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11184 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11185 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11186 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11187 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11188 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11189 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11190 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11191 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11192 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11193 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11194 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11195 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11196 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11197 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11198 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11199 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011200 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11201 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11202 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11203 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11204 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11205 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011206
11207 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11208 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11209 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11210 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11211 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11212 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11213 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11214 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11215 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11216 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11217 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11218 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11219 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11220 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11221 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11222 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11223 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11224 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11225 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11226 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11227 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11228 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11229 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11230 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11231 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11232 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11233 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11234 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11235 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11236 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11237 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11238 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11239 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11240 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11241 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11242 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11243 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11244 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11245 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11246 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11247 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11248 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11249 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11250 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11251 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11252 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11253 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11254 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11255 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11256 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11257 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11258 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11259 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11260 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11261 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11262 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11263 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11264 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11265 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11266 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11267 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11268 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11269 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11270 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11271 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11272 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11273 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011274 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11275 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11276 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11277 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11278 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11279 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011280
11281 /* BGP dampening clear commands */
11282 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11283 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11284 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11285 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11286
Paul Jakmaff7924f2006-09-04 01:10:36 +000011287 /* prefix count */
11288 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11289 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11290 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011291#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011292 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11293
paul718e3742002-12-13 20:15:29 +000011294 /* New config IPv6 BGP commands. */
11295 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11296 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
11297 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11298 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
11299
11300 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11301 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11302 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11303 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11304
11305 /* Old config IPv6 BGP commands. */
11306 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11307 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11308
11309 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11310 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11311 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11312 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11313
11314 install_element (VIEW_NODE, &show_bgp_cmd);
11315 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11316 install_element (VIEW_NODE, &show_bgp_route_cmd);
11317 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11318 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11319 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11320 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11321 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11322 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11323 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11324 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11325 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11326 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11327 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11328 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11329 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11330 install_element (VIEW_NODE, &show_bgp_community_cmd);
11331 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11332 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11333 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11334 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11335 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11336 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11337 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11338 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11339 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11340 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11341 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11342 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11343 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11344 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11345 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11346 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11347 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11348 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11349 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11350 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11351 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11352 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11353 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11354 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11355 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11356 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11357 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11358 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11359 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011360 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11361 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11362 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11363 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011364 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11365 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11366 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011367 install_element (VIEW_NODE, &show_bgp_view_cmd);
11368 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11369 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11370 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11371 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11372 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11373 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11374 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11375 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11376 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11377 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11378 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11379 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11380 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11381 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11382 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11383 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11384 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011385 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11386 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11387 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011388
11389 install_element (ENABLE_NODE, &show_bgp_cmd);
11390 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11391 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11392 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11393 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11394 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11395 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11396 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11397 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11398 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11399 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11400 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11401 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11402 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11403 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11404 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11405 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11406 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11407 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11408 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11409 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11410 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11411 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
11412 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
11413 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
11414 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
11415 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
11416 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
11417 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
11418 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
11419 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
11420 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
11421 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
11422 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
11423 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
11424 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11425 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
11426 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11427 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
11428 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11429 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
11430 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11431 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
11432 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11433 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11434 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011435 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
11436 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11437 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
11438 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011439 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
11440 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
11441 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011442 install_element (ENABLE_NODE, &show_bgp_view_cmd);
11443 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
11444 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
11445 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
11446 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
11447 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
11448 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11449 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11450 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11451 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11452 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
11453 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11454 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11455 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11456 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
11457 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11458 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
11459 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011460 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
11461 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
11462 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000011463
11464 /* Statistics */
11465 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
11466 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
11467 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
11468 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
11469
paul718e3742002-12-13 20:15:29 +000011470 /* old command */
11471 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
11472 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
11473 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
11474 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
11475 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
11476 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
11477 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
11478 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
11479 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
11480 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
11481 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
11482 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
11483 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
11484 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
11485 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
11486 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
11487 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11488 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11489 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
11490 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
11491 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
11492 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
11493 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11494 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
11495 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
11496 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
11497 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
11498 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
11499 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
11500 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
11501 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11502 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11503 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11504 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
11505 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11506 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000011507
paul718e3742002-12-13 20:15:29 +000011508 /* old command */
11509 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
11510 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
11511 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
11512 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
11513 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
11514 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
11515 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
11516 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
11517 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
11518 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
11519 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
11520 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
11521 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
11522 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
11523 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
11524 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
11525 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11526 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11527 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
11528 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
11529 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
11530 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
11531 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11532 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
11533 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
11534 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
11535 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
11536 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
11537 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
11538 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
11539 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11540 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11541 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11542 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
11543 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11544 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
11545
11546 /* old command */
11547 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11548 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11549 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11550 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11551
11552 /* old command */
11553 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11554 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11555 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11556 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11557
11558 /* old command */
11559 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
11560 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
11561 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11562 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11563#endif /* HAVE_IPV6 */
11564
11565 install_element (BGP_NODE, &bgp_distance_cmd);
11566 install_element (BGP_NODE, &no_bgp_distance_cmd);
11567 install_element (BGP_NODE, &no_bgp_distance2_cmd);
11568 install_element (BGP_NODE, &bgp_distance_source_cmd);
11569 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
11570 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
11571 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
11572
11573 install_element (BGP_NODE, &bgp_damp_set_cmd);
11574 install_element (BGP_NODE, &bgp_damp_set2_cmd);
11575 install_element (BGP_NODE, &bgp_damp_set3_cmd);
11576 install_element (BGP_NODE, &bgp_damp_unset_cmd);
11577 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
11578 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
11579 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
11580 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
11581 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
11582 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
11583}