blob: 2ce2ef4d81cfd8d31f28db1def0304da29bc38cf [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
2530 UNSET_FLAG (peer->sflags, PEER_STATUS_CLEARING);
2531 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002532
2533 /* Tickle FSM to start moving again */
2534 BGP_EVENT_ADD (peer, BGP_Start);
paul200df112005-06-01 11:17:05 +00002535}
2536
2537static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002538bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002539{
Paul Jakma64e580a2006-02-21 01:09:01 +00002540#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2541 char wname[CLEAR_QUEUE_NAME_LEN];
2542
2543 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2544#undef CLEAR_QUEUE_NAME_LEN
2545
2546 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002547 {
2548 zlog_err ("%s: Failed to allocate work queue", __func__);
2549 exit (1);
2550 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002551 peer->clear_node_queue->spec.hold = 10;
2552 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2553 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2554 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2555 peer->clear_node_queue->spec.max_retries = 0;
2556
2557 /* we only 'lock' this peer reference when the queue is actually active */
2558 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002559}
2560
paul718e3742002-12-13 20:15:29 +00002561static void
2562bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002563 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002564{
2565 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002566
paul718e3742002-12-13 20:15:29 +00002567 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002568 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002569
hasso6cf159b2005-03-21 10:28:14 +00002570 /* If still no table => afi/safi isn't configured at all or smth. */
2571 if (! table)
2572 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002573
2574 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2575 {
2576 if (rn->info == NULL)
2577 continue;
2578
2579 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2580 work_queue_add (peer->clear_node_queue, rn);
2581 }
2582 return;
2583}
2584
2585void
2586bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2587{
2588 struct bgp_node *rn;
2589 struct bgp_table *table;
2590 struct peer *rsclient;
2591 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002592
Paul Jakma64e580a2006-02-21 01:09:01 +00002593 if (peer->clear_node_queue == NULL)
2594 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002595
Paul Jakma64e580a2006-02-21 01:09:01 +00002596 /* bgp_fsm.c will not bring CLEARING sessions out of Idle this
2597 * protects against peers which flap faster than we can we clear,
2598 * which could lead to:
2599 *
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 Jakma64e580a2006-02-21 01:09:01 +00002607 if (!CHECK_FLAG (peer->sflags, PEER_STATUS_CLEARING))
2608 {
2609 SET_FLAG (peer->sflags, PEER_STATUS_CLEARING);
2610 peer_lock (peer); /* bgp_clear_node_complete */
2611 }
paul200df112005-06-01 11:17:05 +00002612
paul718e3742002-12-13 20:15:29 +00002613 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002614 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002615 else
2616 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2617 rn = bgp_route_next (rn))
2618 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002619 bgp_clear_route_table (peer, afi, safi, table, NULL);
2620
paul1eb8ef22005-04-07 07:30:20 +00002621 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002622 {
2623 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2624 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2625 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002626
2627 /* If no routes were cleared, nothing was added to workqueue, run the
2628 * completion function now.
2629 */
2630 if (!peer->clear_node_queue->thread)
2631 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002632}
2633
2634void
2635bgp_clear_route_all (struct peer *peer)
2636{
2637 afi_t afi;
2638 safi_t safi;
2639
2640 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2641 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2642 bgp_clear_route (peer, afi, safi);
2643}
2644
2645void
2646bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2647{
2648 struct bgp_table *table;
2649 struct bgp_node *rn;
2650 struct bgp_adj_in *ain;
2651
2652 table = peer->bgp->rib[afi][safi];
2653
2654 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2655 for (ain = rn->adj_in; ain ; ain = ain->next)
2656 if (ain->peer == peer)
2657 {
2658 bgp_adj_in_remove (rn, ain);
2659 bgp_unlock_node (rn);
2660 break;
2661 }
2662}
hasso93406d82005-02-02 14:40:33 +00002663
2664void
2665bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2666{
2667 struct bgp_node *rn;
2668 struct bgp_info *ri;
2669 struct bgp_table *table;
2670
2671 table = peer->bgp->rib[afi][safi];
2672
2673 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2674 {
2675 for (ri = rn->info; ri; ri = ri->next)
2676 if (ri->peer == peer)
2677 {
2678 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2679 bgp_rib_remove (rn, ri, peer, afi, safi);
2680 break;
2681 }
2682 }
2683}
paul718e3742002-12-13 20:15:29 +00002684
2685/* Delete all kernel routes. */
2686void
paul545acaf2004-04-20 15:13:15 +00002687bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002688{
2689 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002690 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002691 struct bgp_node *rn;
2692 struct bgp_table *table;
2693 struct bgp_info *ri;
2694
paul1eb8ef22005-04-07 07:30:20 +00002695 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002696 {
2697 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2698
2699 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2700 for (ri = rn->info; ri; ri = ri->next)
2701 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2702 && ri->type == ZEBRA_ROUTE_BGP
2703 && ri->sub_type == BGP_ROUTE_NORMAL)
2704 bgp_zebra_withdraw (&rn->p, ri);
2705
2706 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2707
2708 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2709 for (ri = rn->info; ri; ri = ri->next)
2710 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2711 && ri->type == ZEBRA_ROUTE_BGP
2712 && ri->sub_type == BGP_ROUTE_NORMAL)
2713 bgp_zebra_withdraw (&rn->p, ri);
2714 }
2715}
2716
2717void
2718bgp_reset ()
2719{
2720 vty_reset ();
2721 bgp_zclient_reset ();
2722 access_list_reset ();
2723 prefix_list_reset ();
2724}
2725
2726/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2727 value. */
2728int
2729bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2730{
2731 u_char *pnt;
2732 u_char *lim;
2733 struct prefix p;
2734 int psize;
2735 int ret;
2736
2737 /* Check peer status. */
2738 if (peer->status != Established)
2739 return 0;
2740
2741 pnt = packet->nlri;
2742 lim = pnt + packet->length;
2743
2744 for (; pnt < lim; pnt += psize)
2745 {
2746 /* Clear prefix structure. */
2747 memset (&p, 0, sizeof (struct prefix));
2748
2749 /* Fetch prefix length. */
2750 p.prefixlen = *pnt++;
2751 p.family = afi2family (packet->afi);
2752
2753 /* Already checked in nlri_sanity_check(). We do double check
2754 here. */
2755 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2756 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2757 return -1;
2758
2759 /* Packet size overflow check. */
2760 psize = PSIZE (p.prefixlen);
2761
2762 /* When packet overflow occur return immediately. */
2763 if (pnt + psize > lim)
2764 return -1;
2765
2766 /* Fetch prefix from NLRI packet. */
2767 memcpy (&p.u.prefix, pnt, psize);
2768
2769 /* Check address. */
2770 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2771 {
2772 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2773 {
paulf5ba3872004-07-09 12:11:31 +00002774 /*
2775 * From draft-ietf-idr-bgp4-22, Section 6.3:
2776 * If a BGP router receives an UPDATE message with a
2777 * semantically incorrect NLRI field, in which a prefix is
2778 * semantically incorrect (eg. an unexpected multicast IP
2779 * address), it should ignore the prefix.
2780 */
paul718e3742002-12-13 20:15:29 +00002781 zlog (peer->log, LOG_ERR,
2782 "IPv4 unicast NLRI is multicast address %s",
2783 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002784
paul718e3742002-12-13 20:15:29 +00002785 return -1;
2786 }
2787 }
2788
2789#ifdef HAVE_IPV6
2790 /* Check address. */
2791 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2792 {
2793 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2794 {
2795 char buf[BUFSIZ];
2796
2797 zlog (peer->log, LOG_WARNING,
2798 "IPv6 link-local NLRI received %s ignore this NLRI",
2799 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2800
2801 continue;
2802 }
2803 }
2804#endif /* HAVE_IPV6 */
2805
2806 /* Normal process. */
2807 if (attr)
2808 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2809 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2810 else
2811 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2812 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2813
2814 /* Address family configuration mismatch or maximum-prefix count
2815 overflow. */
2816 if (ret < 0)
2817 return -1;
2818 }
2819
2820 /* Packet length consistency check. */
2821 if (pnt != lim)
2822 return -1;
2823
2824 return 0;
2825}
2826
2827/* NLRI encode syntax check routine. */
2828int
2829bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2830 bgp_size_t length)
2831{
2832 u_char *end;
2833 u_char prefixlen;
2834 int psize;
2835
2836 end = pnt + length;
2837
2838 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2839 syntactic validity. If the field is syntactically incorrect,
2840 then the Error Subcode is set to Invalid Network Field. */
2841
2842 while (pnt < end)
2843 {
2844 prefixlen = *pnt++;
2845
2846 /* Prefix length check. */
2847 if ((afi == AFI_IP && prefixlen > 32)
2848 || (afi == AFI_IP6 && prefixlen > 128))
2849 {
2850 plog_err (peer->log,
2851 "%s [Error] Update packet error (wrong prefix length %d)",
2852 peer->host, prefixlen);
2853 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2854 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2855 return -1;
2856 }
2857
2858 /* Packet size overflow check. */
2859 psize = PSIZE (prefixlen);
2860
2861 if (pnt + psize > end)
2862 {
2863 plog_err (peer->log,
2864 "%s [Error] Update packet error"
2865 " (prefix data overflow prefix size is %d)",
2866 peer->host, psize);
2867 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2868 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2869 return -1;
2870 }
2871
2872 pnt += psize;
2873 }
2874
2875 /* Packet length consistency check. */
2876 if (pnt != end)
2877 {
2878 plog_err (peer->log,
2879 "%s [Error] Update packet error"
2880 " (prefix length mismatch with total length)",
2881 peer->host);
2882 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2883 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2884 return -1;
2885 }
2886 return 0;
2887}
2888
paul94f2b392005-06-28 12:44:16 +00002889static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002890bgp_static_new ()
2891{
2892 struct bgp_static *new;
2893 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2894 memset (new, 0, sizeof (struct bgp_static));
2895 return new;
2896}
2897
paul94f2b392005-06-28 12:44:16 +00002898static void
paul718e3742002-12-13 20:15:29 +00002899bgp_static_free (struct bgp_static *bgp_static)
2900{
2901 if (bgp_static->rmap.name)
2902 free (bgp_static->rmap.name);
2903 XFREE (MTYPE_BGP_STATIC, bgp_static);
2904}
2905
paul94f2b392005-06-28 12:44:16 +00002906static void
paulfee0f4c2004-09-13 05:12:46 +00002907bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2908 struct prefix *p, afi_t afi, safi_t safi)
2909{
2910 struct bgp_node *rn;
2911 struct bgp_info *ri;
2912
2913 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2914
2915 /* Check selected route and self inserted route. */
2916 for (ri = rn->info; ri; ri = ri->next)
2917 if (ri->peer == bgp->peer_self
2918 && ri->type == ZEBRA_ROUTE_BGP
2919 && ri->sub_type == BGP_ROUTE_STATIC)
2920 break;
2921
2922 /* Withdraw static BGP route from routing table. */
2923 if (ri)
2924 {
paulfee0f4c2004-09-13 05:12:46 +00002925 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00002926 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002927 }
2928
2929 /* Unlock bgp_node_lookup. */
2930 bgp_unlock_node (rn);
2931}
2932
paul94f2b392005-06-28 12:44:16 +00002933static void
paulfee0f4c2004-09-13 05:12:46 +00002934bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2935 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2936{
2937 struct bgp_node *rn;
2938 struct bgp_info *ri;
2939 struct bgp_info *new;
2940 struct bgp_info info;
2941 struct attr new_attr;
2942 struct attr *attr_new;
2943 struct attr attr;
2944 struct bgp *bgp;
2945 int ret;
2946 char buf[SU_ADDRSTRLEN];
2947
2948 bgp = rsclient->bgp;
2949
Paul Jakma06e110f2006-05-12 23:29:22 +00002950 assert (bgp_static);
2951 if (!bgp_static)
2952 return;
2953
paulfee0f4c2004-09-13 05:12:46 +00002954 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2955
2956 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00002957
2958 attr.nexthop = bgp_static->igpnexthop;
2959 attr.med = bgp_static->igpmetric;
2960 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paulfee0f4c2004-09-13 05:12:46 +00002961
2962 new_attr = attr;
2963
2964 /* Apply network route-map for export to this rsclient. */
2965 if (bgp_static->rmap.name)
2966 {
2967 info.peer = rsclient;
2968 info.attr = &new_attr;
2969
2970 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2971 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2972
2973 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2974
2975 rsclient->rmap_type = 0;
2976
2977 if (ret == RMAP_DENYMATCH)
2978 {
2979 /* Free uninterned attribute. */
2980 bgp_attr_flush (&new_attr);
2981
2982 /* Unintern original. */
2983 aspath_unintern (attr.aspath);
2984 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2985
2986 return;
2987 }
2988 attr_new = bgp_attr_intern (&new_attr);
2989 }
2990 else
2991 attr_new = bgp_attr_intern (&attr);
2992
2993 new_attr = *attr_new;
2994
2995 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2996
2997 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2998{
2999 /* This BGP update is filtered. Log the reason then update BGP entry. */
3000 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003001 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003002 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3003 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3004 p->prefixlen, rsclient->host);
3005
3006 bgp->peer_self->rmap_type = 0;
3007
3008 bgp_attr_unintern (attr_new);
3009 aspath_unintern (attr.aspath);
3010
3011 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3012
3013 return;
3014 }
3015
3016 bgp->peer_self->rmap_type = 0;
3017
3018 bgp_attr_unintern (attr_new);
3019 attr_new = bgp_attr_intern (&new_attr);
3020
3021 for (ri = rn->info; ri; ri = ri->next)
3022 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3023 && ri->sub_type == BGP_ROUTE_STATIC)
3024 break;
3025
3026 if (ri)
3027 {
3028 if (attrhash_cmp (ri->attr, attr_new))
3029 {
3030 bgp_unlock_node (rn);
3031 bgp_attr_unintern (attr_new);
3032 aspath_unintern (attr.aspath);
3033 return;
3034 }
3035 else
3036 {
3037 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003038 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003039
3040 /* Rewrite BGP route information. */
3041 bgp_attr_unintern (ri->attr);
3042 ri->attr = attr_new;
3043 ri->uptime = time (NULL);
3044
3045 /* Process change. */
3046 bgp_process (bgp, rn, afi, safi);
3047 bgp_unlock_node (rn);
3048 aspath_unintern (attr.aspath);
3049 return;
3050 }
3051}
3052
3053 /* Make new BGP info. */
3054 new = bgp_info_new ();
3055 new->type = ZEBRA_ROUTE_BGP;
3056 new->sub_type = BGP_ROUTE_STATIC;
3057 new->peer = bgp->peer_self;
3058 SET_FLAG (new->flags, BGP_INFO_VALID);
3059 new->attr = attr_new;
3060 new->uptime = time (NULL);
3061
3062 /* Register new BGP information. */
3063 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003064
3065 /* route_node_get lock */
3066 bgp_unlock_node (rn);
3067
paulfee0f4c2004-09-13 05:12:46 +00003068 /* Process change. */
3069 bgp_process (bgp, rn, afi, safi);
3070
3071 /* Unintern original. */
3072 aspath_unintern (attr.aspath);
3073}
3074
paul94f2b392005-06-28 12:44:16 +00003075static void
paulfee0f4c2004-09-13 05:12:46 +00003076bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003077 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3078{
3079 struct bgp_node *rn;
3080 struct bgp_info *ri;
3081 struct bgp_info *new;
3082 struct bgp_info info;
3083 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003084 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003085 struct attr *attr_new;
3086 int ret;
3087
Paul Jakmadd8103a2006-05-12 23:27:30 +00003088 assert (bgp_static);
3089 if (!bgp_static)
3090 return;
3091
paulfee0f4c2004-09-13 05:12:46 +00003092 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003093
3094 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003095
3096 attr.nexthop = bgp_static->igpnexthop;
3097 attr.med = bgp_static->igpmetric;
3098 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003099
3100 /* Apply route-map. */
3101 if (bgp_static->rmap.name)
3102 {
paul286e1e72003-08-08 00:24:31 +00003103 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003104 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003105 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003106
paulfee0f4c2004-09-13 05:12:46 +00003107 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3108
paul718e3742002-12-13 20:15:29 +00003109 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003110
paulfee0f4c2004-09-13 05:12:46 +00003111 bgp->peer_self->rmap_type = 0;
3112
paul718e3742002-12-13 20:15:29 +00003113 if (ret == RMAP_DENYMATCH)
3114 {
3115 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003116 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003117
3118 /* Unintern original. */
3119 aspath_unintern (attr.aspath);
3120 bgp_static_withdraw (bgp, p, afi, safi);
3121 return;
3122 }
paul286e1e72003-08-08 00:24:31 +00003123 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003124 }
paul286e1e72003-08-08 00:24:31 +00003125 else
3126 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003127
3128 for (ri = rn->info; ri; ri = ri->next)
3129 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3130 && ri->sub_type == BGP_ROUTE_STATIC)
3131 break;
3132
3133 if (ri)
3134 {
3135 if (attrhash_cmp (ri->attr, attr_new))
3136 {
3137 bgp_unlock_node (rn);
3138 bgp_attr_unintern (attr_new);
3139 aspath_unintern (attr.aspath);
3140 return;
3141 }
3142 else
3143 {
3144 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003145 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003146
3147 /* Rewrite BGP route information. */
3148 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3149 bgp_attr_unintern (ri->attr);
3150 ri->attr = attr_new;
3151 ri->uptime = time (NULL);
3152
3153 /* Process change. */
3154 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3155 bgp_process (bgp, rn, afi, safi);
3156 bgp_unlock_node (rn);
3157 aspath_unintern (attr.aspath);
3158 return;
3159 }
3160 }
3161
3162 /* Make new BGP info. */
3163 new = bgp_info_new ();
3164 new->type = ZEBRA_ROUTE_BGP;
3165 new->sub_type = BGP_ROUTE_STATIC;
3166 new->peer = bgp->peer_self;
3167 SET_FLAG (new->flags, BGP_INFO_VALID);
3168 new->attr = attr_new;
3169 new->uptime = time (NULL);
3170
3171 /* Aggregate address increment. */
3172 bgp_aggregate_increment (bgp, p, new, afi, safi);
3173
3174 /* Register new BGP information. */
3175 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003176
3177 /* route_node_get lock */
3178 bgp_unlock_node (rn);
3179
paul718e3742002-12-13 20:15:29 +00003180 /* Process change. */
3181 bgp_process (bgp, rn, afi, safi);
3182
3183 /* Unintern original. */
3184 aspath_unintern (attr.aspath);
3185}
3186
3187void
paulfee0f4c2004-09-13 05:12:46 +00003188bgp_static_update (struct bgp *bgp, struct prefix *p,
3189 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3190{
3191 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003192 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003193
3194 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3195
paul1eb8ef22005-04-07 07:30:20 +00003196 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003197 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003198 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3199 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003200 }
3201}
3202
paul94f2b392005-06-28 12:44:16 +00003203static void
paul718e3742002-12-13 20:15:29 +00003204bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3205 u_char safi, struct prefix_rd *prd, u_char *tag)
3206{
3207 struct bgp_node *rn;
3208 struct bgp_info *new;
3209
paulfee0f4c2004-09-13 05:12:46 +00003210 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003211
3212 /* Make new BGP info. */
3213 new = bgp_info_new ();
3214 new->type = ZEBRA_ROUTE_BGP;
3215 new->sub_type = BGP_ROUTE_STATIC;
3216 new->peer = bgp->peer_self;
3217 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3218 SET_FLAG (new->flags, BGP_INFO_VALID);
3219 new->uptime = time (NULL);
3220 memcpy (new->tag, tag, 3);
3221
3222 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003223 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003224
3225 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003226 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003227
paul200df112005-06-01 11:17:05 +00003228 /* route_node_get lock */
3229 bgp_unlock_node (rn);
3230
paul718e3742002-12-13 20:15:29 +00003231 /* Process change. */
3232 bgp_process (bgp, rn, afi, safi);
3233}
3234
3235void
3236bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3237 safi_t safi)
3238{
3239 struct bgp_node *rn;
3240 struct bgp_info *ri;
3241
paulfee0f4c2004-09-13 05:12:46 +00003242 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003243
3244 /* Check selected route and self inserted route. */
3245 for (ri = rn->info; ri; ri = ri->next)
3246 if (ri->peer == bgp->peer_self
3247 && ri->type == ZEBRA_ROUTE_BGP
3248 && ri->sub_type == BGP_ROUTE_STATIC)
3249 break;
3250
3251 /* Withdraw static BGP route from routing table. */
3252 if (ri)
3253 {
3254 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003255 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003256 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003257 }
3258
3259 /* Unlock bgp_node_lookup. */
3260 bgp_unlock_node (rn);
3261}
3262
3263void
paulfee0f4c2004-09-13 05:12:46 +00003264bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3265{
3266 struct bgp_static *bgp_static;
3267 struct bgp *bgp;
3268 struct bgp_node *rn;
3269 struct prefix *p;
3270
3271 bgp = rsclient->bgp;
3272
3273 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3274 if ((bgp_static = rn->info) != NULL)
3275 {
3276 p = &rn->p;
3277
3278 bgp_static_update_rsclient (rsclient, p, bgp_static,
3279 afi, safi);
3280 }
3281}
3282
paul94f2b392005-06-28 12:44:16 +00003283static void
paul718e3742002-12-13 20:15:29 +00003284bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3285 u_char safi, struct prefix_rd *prd, u_char *tag)
3286{
3287 struct bgp_node *rn;
3288 struct bgp_info *ri;
3289
paulfee0f4c2004-09-13 05:12:46 +00003290 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003291
3292 /* Check selected route and self inserted route. */
3293 for (ri = rn->info; ri; ri = ri->next)
3294 if (ri->peer == bgp->peer_self
3295 && ri->type == ZEBRA_ROUTE_BGP
3296 && ri->sub_type == BGP_ROUTE_STATIC)
3297 break;
3298
3299 /* Withdraw static BGP route from routing table. */
3300 if (ri)
3301 {
3302 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003303 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003304 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003305 }
3306
3307 /* Unlock bgp_node_lookup. */
3308 bgp_unlock_node (rn);
3309}
3310
3311/* Configure static BGP network. When user don't run zebra, static
3312 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003313static int
paulfd79ac92004-10-13 05:06:08 +00003314bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3315 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003316{
3317 int ret;
3318 struct prefix p;
3319 struct bgp_static *bgp_static;
3320 struct bgp_node *rn;
3321 int need_update = 0;
3322
3323 /* Convert IP prefix string to struct prefix. */
3324 ret = str2prefix (ip_str, &p);
3325 if (! ret)
3326 {
3327 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3328 return CMD_WARNING;
3329 }
3330#ifdef HAVE_IPV6
3331 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3332 {
3333 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3334 VTY_NEWLINE);
3335 return CMD_WARNING;
3336 }
3337#endif /* HAVE_IPV6 */
3338
3339 apply_mask (&p);
3340
3341 /* Set BGP static route configuration. */
3342 rn = bgp_node_get (bgp->route[afi][safi], &p);
3343
3344 if (rn->info)
3345 {
3346 /* Configuration change. */
3347 bgp_static = rn->info;
3348
3349 /* Check previous routes are installed into BGP. */
3350 if (! bgp_static->backdoor && bgp_static->valid)
3351 need_update = 1;
3352
3353 bgp_static->backdoor = backdoor;
3354 if (rmap)
3355 {
3356 if (bgp_static->rmap.name)
3357 free (bgp_static->rmap.name);
3358 bgp_static->rmap.name = strdup (rmap);
3359 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3360 }
3361 else
3362 {
3363 if (bgp_static->rmap.name)
3364 free (bgp_static->rmap.name);
3365 bgp_static->rmap.name = NULL;
3366 bgp_static->rmap.map = NULL;
3367 bgp_static->valid = 0;
3368 }
3369 bgp_unlock_node (rn);
3370 }
3371 else
3372 {
3373 /* New configuration. */
3374 bgp_static = bgp_static_new ();
3375 bgp_static->backdoor = backdoor;
3376 bgp_static->valid = 0;
3377 bgp_static->igpmetric = 0;
3378 bgp_static->igpnexthop.s_addr = 0;
3379 if (rmap)
3380 {
3381 if (bgp_static->rmap.name)
3382 free (bgp_static->rmap.name);
3383 bgp_static->rmap.name = strdup (rmap);
3384 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3385 }
3386 rn->info = bgp_static;
3387 }
3388
3389 /* If BGP scan is not enabled, we should install this route here. */
3390 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3391 {
3392 bgp_static->valid = 1;
3393
3394 if (need_update)
3395 bgp_static_withdraw (bgp, &p, afi, safi);
3396
3397 if (! bgp_static->backdoor)
3398 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3399 }
3400
3401 return CMD_SUCCESS;
3402}
3403
3404/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003405static int
paulfd79ac92004-10-13 05:06:08 +00003406bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003407 u_int16_t afi, u_char safi)
3408{
3409 int ret;
3410 struct prefix p;
3411 struct bgp_static *bgp_static;
3412 struct bgp_node *rn;
3413
3414 /* Convert IP prefix string to struct prefix. */
3415 ret = str2prefix (ip_str, &p);
3416 if (! ret)
3417 {
3418 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3419 return CMD_WARNING;
3420 }
3421#ifdef HAVE_IPV6
3422 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3423 {
3424 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3425 VTY_NEWLINE);
3426 return CMD_WARNING;
3427 }
3428#endif /* HAVE_IPV6 */
3429
3430 apply_mask (&p);
3431
3432 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3433 if (! rn)
3434 {
3435 vty_out (vty, "%% Can't find specified static route configuration.%s",
3436 VTY_NEWLINE);
3437 return CMD_WARNING;
3438 }
3439
3440 bgp_static = rn->info;
3441
3442 /* Update BGP RIB. */
3443 if (! bgp_static->backdoor)
3444 bgp_static_withdraw (bgp, &p, afi, safi);
3445
3446 /* Clear configuration. */
3447 bgp_static_free (bgp_static);
3448 rn->info = NULL;
3449 bgp_unlock_node (rn);
3450 bgp_unlock_node (rn);
3451
3452 return CMD_SUCCESS;
3453}
3454
3455/* Called from bgp_delete(). Delete all static routes from the BGP
3456 instance. */
3457void
3458bgp_static_delete (struct bgp *bgp)
3459{
3460 afi_t afi;
3461 safi_t safi;
3462 struct bgp_node *rn;
3463 struct bgp_node *rm;
3464 struct bgp_table *table;
3465 struct bgp_static *bgp_static;
3466
3467 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3468 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3469 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3470 if (rn->info != NULL)
3471 {
3472 if (safi == SAFI_MPLS_VPN)
3473 {
3474 table = rn->info;
3475
3476 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3477 {
3478 bgp_static = rn->info;
3479 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3480 AFI_IP, SAFI_MPLS_VPN,
3481 (struct prefix_rd *)&rn->p,
3482 bgp_static->tag);
3483 bgp_static_free (bgp_static);
3484 rn->info = NULL;
3485 bgp_unlock_node (rn);
3486 }
3487 }
3488 else
3489 {
3490 bgp_static = rn->info;
3491 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3492 bgp_static_free (bgp_static);
3493 rn->info = NULL;
3494 bgp_unlock_node (rn);
3495 }
3496 }
3497}
3498
3499int
paulfd79ac92004-10-13 05:06:08 +00003500bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3501 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003502{
3503 int ret;
3504 struct prefix p;
3505 struct prefix_rd prd;
3506 struct bgp *bgp;
3507 struct bgp_node *prn;
3508 struct bgp_node *rn;
3509 struct bgp_table *table;
3510 struct bgp_static *bgp_static;
3511 u_char tag[3];
3512
3513 bgp = vty->index;
3514
3515 ret = str2prefix (ip_str, &p);
3516 if (! ret)
3517 {
3518 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3519 return CMD_WARNING;
3520 }
3521 apply_mask (&p);
3522
3523 ret = str2prefix_rd (rd_str, &prd);
3524 if (! ret)
3525 {
3526 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3527 return CMD_WARNING;
3528 }
3529
3530 ret = str2tag (tag_str, tag);
3531 if (! ret)
3532 {
3533 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3534 return CMD_WARNING;
3535 }
3536
3537 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3538 (struct prefix *)&prd);
3539 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003540 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003541 else
3542 bgp_unlock_node (prn);
3543 table = prn->info;
3544
3545 rn = bgp_node_get (table, &p);
3546
3547 if (rn->info)
3548 {
3549 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3550 bgp_unlock_node (rn);
3551 }
3552 else
3553 {
3554 /* New configuration. */
3555 bgp_static = bgp_static_new ();
3556 bgp_static->valid = 1;
3557 memcpy (bgp_static->tag, tag, 3);
3558 rn->info = bgp_static;
3559
3560 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3561 }
3562
3563 return CMD_SUCCESS;
3564}
3565
3566/* Configure static BGP network. */
3567int
paulfd79ac92004-10-13 05:06:08 +00003568bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3569 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003570{
3571 int ret;
3572 struct bgp *bgp;
3573 struct prefix p;
3574 struct prefix_rd prd;
3575 struct bgp_node *prn;
3576 struct bgp_node *rn;
3577 struct bgp_table *table;
3578 struct bgp_static *bgp_static;
3579 u_char tag[3];
3580
3581 bgp = vty->index;
3582
3583 /* Convert IP prefix string to struct prefix. */
3584 ret = str2prefix (ip_str, &p);
3585 if (! ret)
3586 {
3587 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3588 return CMD_WARNING;
3589 }
3590 apply_mask (&p);
3591
3592 ret = str2prefix_rd (rd_str, &prd);
3593 if (! ret)
3594 {
3595 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3596 return CMD_WARNING;
3597 }
3598
3599 ret = str2tag (tag_str, tag);
3600 if (! ret)
3601 {
3602 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3603 return CMD_WARNING;
3604 }
3605
3606 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3607 (struct prefix *)&prd);
3608 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003609 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003610 else
3611 bgp_unlock_node (prn);
3612 table = prn->info;
3613
3614 rn = bgp_node_lookup (table, &p);
3615
3616 if (rn)
3617 {
3618 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3619
3620 bgp_static = rn->info;
3621 bgp_static_free (bgp_static);
3622 rn->info = NULL;
3623 bgp_unlock_node (rn);
3624 bgp_unlock_node (rn);
3625 }
3626 else
3627 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3628
3629 return CMD_SUCCESS;
3630}
3631
3632DEFUN (bgp_network,
3633 bgp_network_cmd,
3634 "network A.B.C.D/M",
3635 "Specify a network to announce via BGP\n"
3636 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3637{
3638 return bgp_static_set (vty, vty->index, argv[0],
3639 AFI_IP, bgp_node_safi (vty), NULL, 0);
3640}
3641
3642DEFUN (bgp_network_route_map,
3643 bgp_network_route_map_cmd,
3644 "network A.B.C.D/M route-map WORD",
3645 "Specify a network to announce via BGP\n"
3646 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3647 "Route-map to modify the attributes\n"
3648 "Name of the route map\n")
3649{
3650 return bgp_static_set (vty, vty->index, argv[0],
3651 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3652}
3653
3654DEFUN (bgp_network_backdoor,
3655 bgp_network_backdoor_cmd,
3656 "network A.B.C.D/M backdoor",
3657 "Specify a network to announce via BGP\n"
3658 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3659 "Specify a BGP backdoor route\n")
3660{
3661 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3662}
3663
3664DEFUN (bgp_network_mask,
3665 bgp_network_mask_cmd,
3666 "network A.B.C.D mask A.B.C.D",
3667 "Specify a network to announce via BGP\n"
3668 "Network number\n"
3669 "Network mask\n"
3670 "Network mask\n")
3671{
3672 int ret;
3673 char prefix_str[BUFSIZ];
3674
3675 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3676 if (! ret)
3677 {
3678 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3679 return CMD_WARNING;
3680 }
3681
3682 return bgp_static_set (vty, vty->index, prefix_str,
3683 AFI_IP, bgp_node_safi (vty), NULL, 0);
3684}
3685
3686DEFUN (bgp_network_mask_route_map,
3687 bgp_network_mask_route_map_cmd,
3688 "network A.B.C.D mask A.B.C.D route-map WORD",
3689 "Specify a network to announce via BGP\n"
3690 "Network number\n"
3691 "Network mask\n"
3692 "Network mask\n"
3693 "Route-map to modify the attributes\n"
3694 "Name of the route map\n")
3695{
3696 int ret;
3697 char prefix_str[BUFSIZ];
3698
3699 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3700 if (! ret)
3701 {
3702 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3703 return CMD_WARNING;
3704 }
3705
3706 return bgp_static_set (vty, vty->index, prefix_str,
3707 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3708}
3709
3710DEFUN (bgp_network_mask_backdoor,
3711 bgp_network_mask_backdoor_cmd,
3712 "network A.B.C.D mask A.B.C.D backdoor",
3713 "Specify a network to announce via BGP\n"
3714 "Network number\n"
3715 "Network mask\n"
3716 "Network mask\n"
3717 "Specify a BGP backdoor route\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, AFI_IP, SAFI_UNICAST, NULL, 1);
3730}
3731
3732DEFUN (bgp_network_mask_natural,
3733 bgp_network_mask_natural_cmd,
3734 "network A.B.C.D",
3735 "Specify a network to announce via BGP\n"
3736 "Network number\n")
3737{
3738 int ret;
3739 char prefix_str[BUFSIZ];
3740
3741 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3742 if (! ret)
3743 {
3744 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3745 return CMD_WARNING;
3746 }
3747
3748 return bgp_static_set (vty, vty->index, prefix_str,
3749 AFI_IP, bgp_node_safi (vty), NULL, 0);
3750}
3751
3752DEFUN (bgp_network_mask_natural_route_map,
3753 bgp_network_mask_natural_route_map_cmd,
3754 "network A.B.C.D route-map WORD",
3755 "Specify a network to announce via BGP\n"
3756 "Network number\n"
3757 "Route-map to modify the attributes\n"
3758 "Name of the route map\n")
3759{
3760 int ret;
3761 char prefix_str[BUFSIZ];
3762
3763 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3764 if (! ret)
3765 {
3766 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3767 return CMD_WARNING;
3768 }
3769
3770 return bgp_static_set (vty, vty->index, prefix_str,
3771 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3772}
3773
3774DEFUN (bgp_network_mask_natural_backdoor,
3775 bgp_network_mask_natural_backdoor_cmd,
3776 "network A.B.C.D backdoor",
3777 "Specify a network to announce via BGP\n"
3778 "Network number\n"
3779 "Specify a BGP backdoor route\n")
3780{
3781 int ret;
3782 char prefix_str[BUFSIZ];
3783
3784 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3785 if (! ret)
3786 {
3787 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3788 return CMD_WARNING;
3789 }
3790
3791 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3792}
3793
3794DEFUN (no_bgp_network,
3795 no_bgp_network_cmd,
3796 "no network A.B.C.D/M",
3797 NO_STR
3798 "Specify a network to announce via BGP\n"
3799 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3800{
3801 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3802 bgp_node_safi (vty));
3803}
3804
3805ALIAS (no_bgp_network,
3806 no_bgp_network_route_map_cmd,
3807 "no network A.B.C.D/M route-map WORD",
3808 NO_STR
3809 "Specify a network to announce via BGP\n"
3810 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3811 "Route-map to modify the attributes\n"
3812 "Name of the route map\n")
3813
3814ALIAS (no_bgp_network,
3815 no_bgp_network_backdoor_cmd,
3816 "no network A.B.C.D/M backdoor",
3817 NO_STR
3818 "Specify a network to announce via BGP\n"
3819 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3820 "Specify a BGP backdoor route\n")
3821
3822DEFUN (no_bgp_network_mask,
3823 no_bgp_network_mask_cmd,
3824 "no network A.B.C.D mask A.B.C.D",
3825 NO_STR
3826 "Specify a network to announce via BGP\n"
3827 "Network number\n"
3828 "Network mask\n"
3829 "Network mask\n")
3830{
3831 int ret;
3832 char prefix_str[BUFSIZ];
3833
3834 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3835 if (! ret)
3836 {
3837 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3838 return CMD_WARNING;
3839 }
3840
3841 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3842 bgp_node_safi (vty));
3843}
3844
3845ALIAS (no_bgp_network_mask,
3846 no_bgp_network_mask_route_map_cmd,
3847 "no network A.B.C.D mask A.B.C.D route-map WORD",
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 "Route-map to modify the attributes\n"
3854 "Name of the route map\n")
3855
3856ALIAS (no_bgp_network_mask,
3857 no_bgp_network_mask_backdoor_cmd,
3858 "no network A.B.C.D mask A.B.C.D backdoor",
3859 NO_STR
3860 "Specify a network to announce via BGP\n"
3861 "Network number\n"
3862 "Network mask\n"
3863 "Network mask\n"
3864 "Specify a BGP backdoor route\n")
3865
3866DEFUN (no_bgp_network_mask_natural,
3867 no_bgp_network_mask_natural_cmd,
3868 "no network A.B.C.D",
3869 NO_STR
3870 "Specify a network to announce via BGP\n"
3871 "Network number\n")
3872{
3873 int ret;
3874 char prefix_str[BUFSIZ];
3875
3876 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3877 if (! ret)
3878 {
3879 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3880 return CMD_WARNING;
3881 }
3882
3883 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3884 bgp_node_safi (vty));
3885}
3886
3887ALIAS (no_bgp_network_mask_natural,
3888 no_bgp_network_mask_natural_route_map_cmd,
3889 "no network A.B.C.D route-map WORD",
3890 NO_STR
3891 "Specify a network to announce via BGP\n"
3892 "Network number\n"
3893 "Route-map to modify the attributes\n"
3894 "Name of the route map\n")
3895
3896ALIAS (no_bgp_network_mask_natural,
3897 no_bgp_network_mask_natural_backdoor_cmd,
3898 "no network A.B.C.D backdoor",
3899 NO_STR
3900 "Specify a network to announce via BGP\n"
3901 "Network number\n"
3902 "Specify a BGP backdoor route\n")
3903
3904#ifdef HAVE_IPV6
3905DEFUN (ipv6_bgp_network,
3906 ipv6_bgp_network_cmd,
3907 "network X:X::X:X/M",
3908 "Specify a network to announce via BGP\n"
3909 "IPv6 prefix <network>/<length>\n")
3910{
3911 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3912}
3913
3914DEFUN (ipv6_bgp_network_route_map,
3915 ipv6_bgp_network_route_map_cmd,
3916 "network X:X::X:X/M route-map WORD",
3917 "Specify a network to announce via BGP\n"
3918 "IPv6 prefix <network>/<length>\n"
3919 "Route-map to modify the attributes\n"
3920 "Name of the route map\n")
3921{
3922 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3923 bgp_node_safi (vty), argv[1], 0);
3924}
3925
3926DEFUN (no_ipv6_bgp_network,
3927 no_ipv6_bgp_network_cmd,
3928 "no network X:X::X:X/M",
3929 NO_STR
3930 "Specify a network to announce via BGP\n"
3931 "IPv6 prefix <network>/<length>\n")
3932{
3933 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3934}
3935
3936ALIAS (no_ipv6_bgp_network,
3937 no_ipv6_bgp_network_route_map_cmd,
3938 "no network X:X::X:X/M route-map WORD",
3939 NO_STR
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
3945ALIAS (ipv6_bgp_network,
3946 old_ipv6_bgp_network_cmd,
3947 "ipv6 bgp network X:X::X:X/M",
3948 IPV6_STR
3949 BGP_STR
3950 "Specify a network to announce via BGP\n"
3951 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3952
3953ALIAS (no_ipv6_bgp_network,
3954 old_no_ipv6_bgp_network_cmd,
3955 "no ipv6 bgp network X:X::X:X/M",
3956 NO_STR
3957 IPV6_STR
3958 BGP_STR
3959 "Specify a network to announce via BGP\n"
3960 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3961#endif /* HAVE_IPV6 */
3962
3963/* Aggreagete address:
3964
3965 advertise-map Set condition to advertise attribute
3966 as-set Generate AS set path information
3967 attribute-map Set attributes of aggregate
3968 route-map Set parameters of aggregate
3969 summary-only Filter more specific routes from updates
3970 suppress-map Conditionally filter more specific routes from updates
3971 <cr>
3972 */
3973struct bgp_aggregate
3974{
3975 /* Summary-only flag. */
3976 u_char summary_only;
3977
3978 /* AS set generation. */
3979 u_char as_set;
3980
3981 /* Route-map for aggregated route. */
3982 struct route_map *map;
3983
3984 /* Suppress-count. */
3985 unsigned long count;
3986
3987 /* SAFI configuration. */
3988 safi_t safi;
3989};
3990
paul94f2b392005-06-28 12:44:16 +00003991static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00003992bgp_aggregate_new ()
3993{
3994 struct bgp_aggregate *new;
3995 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3996 memset (new, 0, sizeof (struct bgp_aggregate));
3997 return new;
3998}
3999
paul94f2b392005-06-28 12:44:16 +00004000static void
paul718e3742002-12-13 20:15:29 +00004001bgp_aggregate_free (struct bgp_aggregate *aggregate)
4002{
4003 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4004}
4005
paul94f2b392005-06-28 12:44:16 +00004006static void
paul718e3742002-12-13 20:15:29 +00004007bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4008 afi_t afi, safi_t safi, struct bgp_info *del,
4009 struct bgp_aggregate *aggregate)
4010{
4011 struct bgp_table *table;
4012 struct bgp_node *top;
4013 struct bgp_node *rn;
4014 u_char origin;
4015 struct aspath *aspath = NULL;
4016 struct aspath *asmerge = NULL;
4017 struct community *community = NULL;
4018 struct community *commerge = NULL;
4019 struct in_addr nexthop;
4020 u_int32_t med = 0;
4021 struct bgp_info *ri;
4022 struct bgp_info *new;
4023 int first = 1;
4024 unsigned long match = 0;
4025
4026 /* Record adding route's nexthop and med. */
4027 if (rinew)
4028 {
4029 nexthop = rinew->attr->nexthop;
4030 med = rinew->attr->med;
4031 }
4032
4033 /* ORIGIN attribute: If at least one route among routes that are
4034 aggregated has ORIGIN with the value INCOMPLETE, then the
4035 aggregated route must have the ORIGIN attribute with the value
4036 INCOMPLETE. Otherwise, if at least one route among routes that
4037 are aggregated has ORIGIN with the value EGP, then the aggregated
4038 route must have the origin attribute with the value EGP. In all
4039 other case the value of the ORIGIN attribute of the aggregated
4040 route is INTERNAL. */
4041 origin = BGP_ORIGIN_IGP;
4042
4043 table = bgp->rib[afi][safi];
4044
4045 top = bgp_node_get (table, p);
4046 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4047 if (rn->p.prefixlen > p->prefixlen)
4048 {
4049 match = 0;
4050
4051 for (ri = rn->info; ri; ri = ri->next)
4052 {
4053 if (BGP_INFO_HOLDDOWN (ri))
4054 continue;
4055
4056 if (del && ri == del)
4057 continue;
4058
4059 if (! rinew && first)
4060 {
4061 nexthop = ri->attr->nexthop;
4062 med = ri->attr->med;
4063 first = 0;
4064 }
4065
4066#ifdef AGGREGATE_NEXTHOP_CHECK
4067 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4068 || ri->attr->med != med)
4069 {
4070 if (aspath)
4071 aspath_free (aspath);
4072 if (community)
4073 community_free (community);
4074 bgp_unlock_node (rn);
4075 bgp_unlock_node (top);
4076 return;
4077 }
4078#endif /* AGGREGATE_NEXTHOP_CHECK */
4079
4080 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4081 {
4082 if (aggregate->summary_only)
4083 {
4084 ri->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004085 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004086 match++;
4087 }
4088
4089 aggregate->count++;
4090
4091 if (aggregate->as_set)
4092 {
4093 if (origin < ri->attr->origin)
4094 origin = ri->attr->origin;
4095
4096 if (aspath)
4097 {
4098 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4099 aspath_free (aspath);
4100 aspath = asmerge;
4101 }
4102 else
4103 aspath = aspath_dup (ri->attr->aspath);
4104
4105 if (ri->attr->community)
4106 {
4107 if (community)
4108 {
4109 commerge = community_merge (community,
4110 ri->attr->community);
4111 community = community_uniq_sort (commerge);
4112 community_free (commerge);
4113 }
4114 else
4115 community = community_dup (ri->attr->community);
4116 }
4117 }
4118 }
4119 }
4120 if (match)
4121 bgp_process (bgp, rn, afi, safi);
4122 }
4123 bgp_unlock_node (top);
4124
4125 if (rinew)
4126 {
4127 aggregate->count++;
4128
4129 if (aggregate->summary_only)
4130 rinew->suppress++;
4131
4132 if (aggregate->as_set)
4133 {
4134 if (origin < rinew->attr->origin)
4135 origin = rinew->attr->origin;
4136
4137 if (aspath)
4138 {
4139 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4140 aspath_free (aspath);
4141 aspath = asmerge;
4142 }
4143 else
4144 aspath = aspath_dup (rinew->attr->aspath);
4145
4146 if (rinew->attr->community)
4147 {
4148 if (community)
4149 {
4150 commerge = community_merge (community,
4151 rinew->attr->community);
4152 community = community_uniq_sort (commerge);
4153 community_free (commerge);
4154 }
4155 else
4156 community = community_dup (rinew->attr->community);
4157 }
4158 }
4159 }
4160
4161 if (aggregate->count > 0)
4162 {
4163 rn = bgp_node_get (table, p);
4164 new = bgp_info_new ();
4165 new->type = ZEBRA_ROUTE_BGP;
4166 new->sub_type = BGP_ROUTE_AGGREGATE;
4167 new->peer = bgp->peer_self;
4168 SET_FLAG (new->flags, BGP_INFO_VALID);
4169 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4170 new->uptime = time (NULL);
4171
4172 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004173 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004174 bgp_process (bgp, rn, afi, safi);
4175 }
4176 else
4177 {
4178 if (aspath)
4179 aspath_free (aspath);
4180 if (community)
4181 community_free (community);
4182 }
4183}
4184
4185void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4186 struct bgp_aggregate *);
4187
4188void
4189bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4190 struct bgp_info *ri, afi_t afi, safi_t safi)
4191{
4192 struct bgp_node *child;
4193 struct bgp_node *rn;
4194 struct bgp_aggregate *aggregate;
4195
4196 /* MPLS-VPN aggregation is not yet supported. */
4197 if (safi == SAFI_MPLS_VPN)
4198 return;
4199
4200 if (p->prefixlen == 0)
4201 return;
4202
4203 if (BGP_INFO_HOLDDOWN (ri))
4204 return;
4205
4206 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4207
4208 /* Aggregate address configuration check. */
4209 for (rn = child; rn; rn = rn->parent)
4210 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4211 {
4212 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004213 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004214 }
4215 bgp_unlock_node (child);
4216}
4217
4218void
4219bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4220 struct bgp_info *del, afi_t afi, safi_t safi)
4221{
4222 struct bgp_node *child;
4223 struct bgp_node *rn;
4224 struct bgp_aggregate *aggregate;
4225
4226 /* MPLS-VPN aggregation is not yet supported. */
4227 if (safi == SAFI_MPLS_VPN)
4228 return;
4229
4230 if (p->prefixlen == 0)
4231 return;
4232
4233 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4234
4235 /* Aggregate address configuration check. */
4236 for (rn = child; rn; rn = rn->parent)
4237 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4238 {
4239 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004240 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004241 }
4242 bgp_unlock_node (child);
4243}
4244
paul94f2b392005-06-28 12:44:16 +00004245static void
paul718e3742002-12-13 20:15:29 +00004246bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4247 struct bgp_aggregate *aggregate)
4248{
4249 struct bgp_table *table;
4250 struct bgp_node *top;
4251 struct bgp_node *rn;
4252 struct bgp_info *new;
4253 struct bgp_info *ri;
4254 unsigned long match;
4255 u_char origin = BGP_ORIGIN_IGP;
4256 struct aspath *aspath = NULL;
4257 struct aspath *asmerge = NULL;
4258 struct community *community = NULL;
4259 struct community *commerge = NULL;
4260
4261 table = bgp->rib[afi][safi];
4262
4263 /* Sanity check. */
4264 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4265 return;
4266 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4267 return;
4268
4269 /* If routes exists below this node, generate aggregate routes. */
4270 top = bgp_node_get (table, p);
4271 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4272 if (rn->p.prefixlen > p->prefixlen)
4273 {
4274 match = 0;
4275
4276 for (ri = rn->info; ri; ri = ri->next)
4277 {
4278 if (BGP_INFO_HOLDDOWN (ri))
4279 continue;
4280
4281 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4282 {
4283 /* summary-only aggregate route suppress aggregated
4284 route announcement. */
4285 if (aggregate->summary_only)
4286 {
4287 ri->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004288 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004289 match++;
4290 }
4291 /* as-set aggregate route generate origin, as path,
4292 community aggregation. */
4293 if (aggregate->as_set)
4294 {
4295 if (origin < ri->attr->origin)
4296 origin = ri->attr->origin;
4297
4298 if (aspath)
4299 {
4300 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4301 aspath_free (aspath);
4302 aspath = asmerge;
4303 }
4304 else
4305 aspath = aspath_dup (ri->attr->aspath);
4306
4307 if (ri->attr->community)
4308 {
4309 if (community)
4310 {
4311 commerge = community_merge (community,
4312 ri->attr->community);
4313 community = community_uniq_sort (commerge);
4314 community_free (commerge);
4315 }
4316 else
4317 community = community_dup (ri->attr->community);
4318 }
4319 }
4320 aggregate->count++;
4321 }
4322 }
4323
4324 /* If this node is suppressed, process the change. */
4325 if (match)
4326 bgp_process (bgp, rn, afi, safi);
4327 }
4328 bgp_unlock_node (top);
4329
4330 /* Add aggregate route to BGP table. */
4331 if (aggregate->count)
4332 {
4333 rn = bgp_node_get (table, p);
4334
4335 new = bgp_info_new ();
4336 new->type = ZEBRA_ROUTE_BGP;
4337 new->sub_type = BGP_ROUTE_AGGREGATE;
4338 new->peer = bgp->peer_self;
4339 SET_FLAG (new->flags, BGP_INFO_VALID);
4340 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4341 new->uptime = time (NULL);
4342
4343 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004344 bgp_unlock_node (rn);
4345
paul718e3742002-12-13 20:15:29 +00004346 /* Process change. */
4347 bgp_process (bgp, rn, afi, safi);
4348 }
4349}
4350
4351void
4352bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4353 safi_t safi, struct bgp_aggregate *aggregate)
4354{
4355 struct bgp_table *table;
4356 struct bgp_node *top;
4357 struct bgp_node *rn;
4358 struct bgp_info *ri;
4359 unsigned long match;
4360
4361 table = bgp->rib[afi][safi];
4362
4363 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4364 return;
4365 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4366 return;
4367
4368 /* If routes exists below this node, generate aggregate routes. */
4369 top = bgp_node_get (table, p);
4370 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4371 if (rn->p.prefixlen > p->prefixlen)
4372 {
4373 match = 0;
4374
4375 for (ri = rn->info; ri; ri = ri->next)
4376 {
4377 if (BGP_INFO_HOLDDOWN (ri))
4378 continue;
4379
4380 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4381 {
4382 if (aggregate->summary_only)
4383 {
4384 ri->suppress--;
4385
4386 if (ri->suppress == 0)
4387 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004388 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004389 match++;
4390 }
4391 }
4392 aggregate->count--;
4393 }
4394 }
4395
4396 /* If this node is suppressed, process the change. */
4397 if (match)
4398 bgp_process (bgp, rn, afi, safi);
4399 }
4400 bgp_unlock_node (top);
4401
4402 /* Delete aggregate route from BGP table. */
4403 rn = bgp_node_get (table, p);
4404
4405 for (ri = rn->info; ri; ri = ri->next)
4406 if (ri->peer == bgp->peer_self
4407 && ri->type == ZEBRA_ROUTE_BGP
4408 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4409 break;
4410
4411 /* Withdraw static BGP route from routing table. */
4412 if (ri)
4413 {
paul718e3742002-12-13 20:15:29 +00004414 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004415 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004416 }
4417
4418 /* Unlock bgp_node_lookup. */
4419 bgp_unlock_node (rn);
4420}
4421
4422/* Aggregate route attribute. */
4423#define AGGREGATE_SUMMARY_ONLY 1
4424#define AGGREGATE_AS_SET 1
4425
paul94f2b392005-06-28 12:44:16 +00004426static int
paulfd79ac92004-10-13 05:06:08 +00004427bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4428 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004429 u_char summary_only, u_char as_set)
4430{
4431 int ret;
4432 struct prefix p;
4433 struct bgp_node *rn;
4434 struct bgp *bgp;
4435 struct bgp_aggregate *aggregate;
4436
4437 /* Convert string to prefix structure. */
4438 ret = str2prefix (prefix_str, &p);
4439 if (!ret)
4440 {
4441 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4442 return CMD_WARNING;
4443 }
4444 apply_mask (&p);
4445
4446 /* Get BGP structure. */
4447 bgp = vty->index;
4448
4449 /* Old configuration check. */
4450 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4451
4452 if (rn->info)
4453 {
4454 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4455 bgp_unlock_node (rn);
4456 return CMD_WARNING;
4457 }
4458
4459 /* Make aggregate address structure. */
4460 aggregate = bgp_aggregate_new ();
4461 aggregate->summary_only = summary_only;
4462 aggregate->as_set = as_set;
4463 aggregate->safi = safi;
4464 rn->info = aggregate;
4465
4466 /* Aggregate address insert into BGP routing table. */
4467 if (safi & SAFI_UNICAST)
4468 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4469 if (safi & SAFI_MULTICAST)
4470 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4471
4472 return CMD_SUCCESS;
4473}
4474
paul94f2b392005-06-28 12:44:16 +00004475static int
paulfd79ac92004-10-13 05:06:08 +00004476bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4477 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004478{
4479 int ret;
4480 struct prefix p;
4481 struct bgp_node *rn;
4482 struct bgp *bgp;
4483 struct bgp_aggregate *aggregate;
4484
4485 /* Convert string to prefix structure. */
4486 ret = str2prefix (prefix_str, &p);
4487 if (!ret)
4488 {
4489 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4490 return CMD_WARNING;
4491 }
4492 apply_mask (&p);
4493
4494 /* Get BGP structure. */
4495 bgp = vty->index;
4496
4497 /* Old configuration check. */
4498 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4499 if (! rn)
4500 {
4501 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4502 VTY_NEWLINE);
4503 return CMD_WARNING;
4504 }
4505
4506 aggregate = rn->info;
4507 if (aggregate->safi & SAFI_UNICAST)
4508 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4509 if (aggregate->safi & SAFI_MULTICAST)
4510 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4511
4512 /* Unlock aggregate address configuration. */
4513 rn->info = NULL;
4514 bgp_aggregate_free (aggregate);
4515 bgp_unlock_node (rn);
4516 bgp_unlock_node (rn);
4517
4518 return CMD_SUCCESS;
4519}
4520
4521DEFUN (aggregate_address,
4522 aggregate_address_cmd,
4523 "aggregate-address A.B.C.D/M",
4524 "Configure BGP aggregate entries\n"
4525 "Aggregate prefix\n")
4526{
4527 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4528}
4529
4530DEFUN (aggregate_address_mask,
4531 aggregate_address_mask_cmd,
4532 "aggregate-address A.B.C.D A.B.C.D",
4533 "Configure BGP aggregate entries\n"
4534 "Aggregate address\n"
4535 "Aggregate mask\n")
4536{
4537 int ret;
4538 char prefix_str[BUFSIZ];
4539
4540 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4541
4542 if (! ret)
4543 {
4544 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4545 return CMD_WARNING;
4546 }
4547
4548 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4549 0, 0);
4550}
4551
4552DEFUN (aggregate_address_summary_only,
4553 aggregate_address_summary_only_cmd,
4554 "aggregate-address A.B.C.D/M summary-only",
4555 "Configure BGP aggregate entries\n"
4556 "Aggregate prefix\n"
4557 "Filter more specific routes from updates\n")
4558{
4559 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4560 AGGREGATE_SUMMARY_ONLY, 0);
4561}
4562
4563DEFUN (aggregate_address_mask_summary_only,
4564 aggregate_address_mask_summary_only_cmd,
4565 "aggregate-address A.B.C.D A.B.C.D summary-only",
4566 "Configure BGP aggregate entries\n"
4567 "Aggregate address\n"
4568 "Aggregate mask\n"
4569 "Filter more specific routes from updates\n")
4570{
4571 int ret;
4572 char prefix_str[BUFSIZ];
4573
4574 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4575
4576 if (! ret)
4577 {
4578 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4579 return CMD_WARNING;
4580 }
4581
4582 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4583 AGGREGATE_SUMMARY_ONLY, 0);
4584}
4585
4586DEFUN (aggregate_address_as_set,
4587 aggregate_address_as_set_cmd,
4588 "aggregate-address A.B.C.D/M as-set",
4589 "Configure BGP aggregate entries\n"
4590 "Aggregate prefix\n"
4591 "Generate AS set path information\n")
4592{
4593 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4594 0, AGGREGATE_AS_SET);
4595}
4596
4597DEFUN (aggregate_address_mask_as_set,
4598 aggregate_address_mask_as_set_cmd,
4599 "aggregate-address A.B.C.D A.B.C.D as-set",
4600 "Configure BGP aggregate entries\n"
4601 "Aggregate address\n"
4602 "Aggregate mask\n"
4603 "Generate AS set path information\n")
4604{
4605 int ret;
4606 char prefix_str[BUFSIZ];
4607
4608 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4609
4610 if (! ret)
4611 {
4612 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4613 return CMD_WARNING;
4614 }
4615
4616 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4617 0, AGGREGATE_AS_SET);
4618}
4619
4620
4621DEFUN (aggregate_address_as_set_summary,
4622 aggregate_address_as_set_summary_cmd,
4623 "aggregate-address A.B.C.D/M as-set summary-only",
4624 "Configure BGP aggregate entries\n"
4625 "Aggregate prefix\n"
4626 "Generate AS set path information\n"
4627 "Filter more specific routes from updates\n")
4628{
4629 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4630 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4631}
4632
4633ALIAS (aggregate_address_as_set_summary,
4634 aggregate_address_summary_as_set_cmd,
4635 "aggregate-address A.B.C.D/M summary-only as-set",
4636 "Configure BGP aggregate entries\n"
4637 "Aggregate prefix\n"
4638 "Filter more specific routes from updates\n"
4639 "Generate AS set path information\n")
4640
4641DEFUN (aggregate_address_mask_as_set_summary,
4642 aggregate_address_mask_as_set_summary_cmd,
4643 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4644 "Configure BGP aggregate entries\n"
4645 "Aggregate address\n"
4646 "Aggregate mask\n"
4647 "Generate AS set path information\n"
4648 "Filter more specific routes from updates\n")
4649{
4650 int ret;
4651 char prefix_str[BUFSIZ];
4652
4653 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4654
4655 if (! ret)
4656 {
4657 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4658 return CMD_WARNING;
4659 }
4660
4661 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4662 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4663}
4664
4665ALIAS (aggregate_address_mask_as_set_summary,
4666 aggregate_address_mask_summary_as_set_cmd,
4667 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4668 "Configure BGP aggregate entries\n"
4669 "Aggregate address\n"
4670 "Aggregate mask\n"
4671 "Filter more specific routes from updates\n"
4672 "Generate AS set path information\n")
4673
4674DEFUN (no_aggregate_address,
4675 no_aggregate_address_cmd,
4676 "no aggregate-address A.B.C.D/M",
4677 NO_STR
4678 "Configure BGP aggregate entries\n"
4679 "Aggregate prefix\n")
4680{
4681 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4682}
4683
4684ALIAS (no_aggregate_address,
4685 no_aggregate_address_summary_only_cmd,
4686 "no aggregate-address A.B.C.D/M summary-only",
4687 NO_STR
4688 "Configure BGP aggregate entries\n"
4689 "Aggregate prefix\n"
4690 "Filter more specific routes from updates\n")
4691
4692ALIAS (no_aggregate_address,
4693 no_aggregate_address_as_set_cmd,
4694 "no aggregate-address A.B.C.D/M as-set",
4695 NO_STR
4696 "Configure BGP aggregate entries\n"
4697 "Aggregate prefix\n"
4698 "Generate AS set path information\n")
4699
4700ALIAS (no_aggregate_address,
4701 no_aggregate_address_as_set_summary_cmd,
4702 "no aggregate-address A.B.C.D/M as-set summary-only",
4703 NO_STR
4704 "Configure BGP aggregate entries\n"
4705 "Aggregate prefix\n"
4706 "Generate AS set path information\n"
4707 "Filter more specific routes from updates\n")
4708
4709ALIAS (no_aggregate_address,
4710 no_aggregate_address_summary_as_set_cmd,
4711 "no aggregate-address A.B.C.D/M summary-only as-set",
4712 NO_STR
4713 "Configure BGP aggregate entries\n"
4714 "Aggregate prefix\n"
4715 "Filter more specific routes from updates\n"
4716 "Generate AS set path information\n")
4717
4718DEFUN (no_aggregate_address_mask,
4719 no_aggregate_address_mask_cmd,
4720 "no aggregate-address A.B.C.D A.B.C.D",
4721 NO_STR
4722 "Configure BGP aggregate entries\n"
4723 "Aggregate address\n"
4724 "Aggregate mask\n")
4725{
4726 int ret;
4727 char prefix_str[BUFSIZ];
4728
4729 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4730
4731 if (! ret)
4732 {
4733 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4734 return CMD_WARNING;
4735 }
4736
4737 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4738}
4739
4740ALIAS (no_aggregate_address_mask,
4741 no_aggregate_address_mask_summary_only_cmd,
4742 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4743 NO_STR
4744 "Configure BGP aggregate entries\n"
4745 "Aggregate address\n"
4746 "Aggregate mask\n"
4747 "Filter more specific routes from updates\n")
4748
4749ALIAS (no_aggregate_address_mask,
4750 no_aggregate_address_mask_as_set_cmd,
4751 "no aggregate-address A.B.C.D A.B.C.D as-set",
4752 NO_STR
4753 "Configure BGP aggregate entries\n"
4754 "Aggregate address\n"
4755 "Aggregate mask\n"
4756 "Generate AS set path information\n")
4757
4758ALIAS (no_aggregate_address_mask,
4759 no_aggregate_address_mask_as_set_summary_cmd,
4760 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4761 NO_STR
4762 "Configure BGP aggregate entries\n"
4763 "Aggregate address\n"
4764 "Aggregate mask\n"
4765 "Generate AS set path information\n"
4766 "Filter more specific routes from updates\n")
4767
4768ALIAS (no_aggregate_address_mask,
4769 no_aggregate_address_mask_summary_as_set_cmd,
4770 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4771 NO_STR
4772 "Configure BGP aggregate entries\n"
4773 "Aggregate address\n"
4774 "Aggregate mask\n"
4775 "Filter more specific routes from updates\n"
4776 "Generate AS set path information\n")
4777
4778#ifdef HAVE_IPV6
4779DEFUN (ipv6_aggregate_address,
4780 ipv6_aggregate_address_cmd,
4781 "aggregate-address X:X::X:X/M",
4782 "Configure BGP aggregate entries\n"
4783 "Aggregate prefix\n")
4784{
4785 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4786}
4787
4788DEFUN (ipv6_aggregate_address_summary_only,
4789 ipv6_aggregate_address_summary_only_cmd,
4790 "aggregate-address X:X::X:X/M summary-only",
4791 "Configure BGP aggregate entries\n"
4792 "Aggregate prefix\n"
4793 "Filter more specific routes from updates\n")
4794{
4795 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4796 AGGREGATE_SUMMARY_ONLY, 0);
4797}
4798
4799DEFUN (no_ipv6_aggregate_address,
4800 no_ipv6_aggregate_address_cmd,
4801 "no aggregate-address X:X::X:X/M",
4802 NO_STR
4803 "Configure BGP aggregate entries\n"
4804 "Aggregate prefix\n")
4805{
4806 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4807}
4808
4809DEFUN (no_ipv6_aggregate_address_summary_only,
4810 no_ipv6_aggregate_address_summary_only_cmd,
4811 "no aggregate-address X:X::X:X/M summary-only",
4812 NO_STR
4813 "Configure BGP aggregate entries\n"
4814 "Aggregate prefix\n"
4815 "Filter more specific routes from updates\n")
4816{
4817 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4818}
4819
4820ALIAS (ipv6_aggregate_address,
4821 old_ipv6_aggregate_address_cmd,
4822 "ipv6 bgp aggregate-address X:X::X:X/M",
4823 IPV6_STR
4824 BGP_STR
4825 "Configure BGP aggregate entries\n"
4826 "Aggregate prefix\n")
4827
4828ALIAS (ipv6_aggregate_address_summary_only,
4829 old_ipv6_aggregate_address_summary_only_cmd,
4830 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4831 IPV6_STR
4832 BGP_STR
4833 "Configure BGP aggregate entries\n"
4834 "Aggregate prefix\n"
4835 "Filter more specific routes from updates\n")
4836
4837ALIAS (no_ipv6_aggregate_address,
4838 old_no_ipv6_aggregate_address_cmd,
4839 "no ipv6 bgp aggregate-address X:X::X:X/M",
4840 NO_STR
4841 IPV6_STR
4842 BGP_STR
4843 "Configure BGP aggregate entries\n"
4844 "Aggregate prefix\n")
4845
4846ALIAS (no_ipv6_aggregate_address_summary_only,
4847 old_no_ipv6_aggregate_address_summary_only_cmd,
4848 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4849 NO_STR
4850 IPV6_STR
4851 BGP_STR
4852 "Configure BGP aggregate entries\n"
4853 "Aggregate prefix\n"
4854 "Filter more specific routes from updates\n")
4855#endif /* HAVE_IPV6 */
4856
4857/* Redistribute route treatment. */
4858void
4859bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4860 u_int32_t metric, u_char type)
4861{
4862 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004863 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004864 struct bgp_info *new;
4865 struct bgp_info *bi;
4866 struct bgp_info info;
4867 struct bgp_node *bn;
4868 struct attr attr;
4869 struct attr attr_new;
4870 struct attr *new_attr;
4871 afi_t afi;
4872 int ret;
4873
4874 /* Make default attribute. */
4875 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4876 if (nexthop)
4877 attr.nexthop = *nexthop;
4878
4879 attr.med = metric;
4880 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4881
paul1eb8ef22005-04-07 07:30:20 +00004882 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004883 {
4884 afi = family2afi (p->family);
4885
4886 if (bgp->redist[afi][type])
4887 {
4888 /* Copy attribute for modification. */
4889 attr_new = attr;
4890
4891 if (bgp->redist_metric_flag[afi][type])
4892 attr_new.med = bgp->redist_metric[afi][type];
4893
4894 /* Apply route-map. */
4895 if (bgp->rmap[afi][type].map)
4896 {
4897 info.peer = bgp->peer_self;
4898 info.attr = &attr_new;
4899
paulfee0f4c2004-09-13 05:12:46 +00004900 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4901
paul718e3742002-12-13 20:15:29 +00004902 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4903 &info);
paulfee0f4c2004-09-13 05:12:46 +00004904
4905 bgp->peer_self->rmap_type = 0;
4906
paul718e3742002-12-13 20:15:29 +00004907 if (ret == RMAP_DENYMATCH)
4908 {
4909 /* Free uninterned attribute. */
4910 bgp_attr_flush (&attr_new);
4911
4912 /* Unintern original. */
4913 aspath_unintern (attr.aspath);
4914 bgp_redistribute_delete (p, type);
4915 return;
4916 }
4917 }
4918
paulfee0f4c2004-09-13 05:12:46 +00004919 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004920 new_attr = bgp_attr_intern (&attr_new);
4921
4922 for (bi = bn->info; bi; bi = bi->next)
4923 if (bi->peer == bgp->peer_self
4924 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4925 break;
4926
4927 if (bi)
4928 {
4929 if (attrhash_cmp (bi->attr, new_attr))
4930 {
4931 bgp_attr_unintern (new_attr);
4932 aspath_unintern (attr.aspath);
4933 bgp_unlock_node (bn);
4934 return;
4935 }
4936 else
4937 {
4938 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00004939 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004940
4941 /* Rewrite BGP route information. */
4942 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4943 bgp_attr_unintern (bi->attr);
4944 bi->attr = new_attr;
4945 bi->uptime = time (NULL);
4946
4947 /* Process change. */
4948 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4949 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4950 bgp_unlock_node (bn);
4951 aspath_unintern (attr.aspath);
4952 return;
4953 }
4954 }
4955
4956 new = bgp_info_new ();
4957 new->type = type;
4958 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4959 new->peer = bgp->peer_self;
4960 SET_FLAG (new->flags, BGP_INFO_VALID);
4961 new->attr = new_attr;
4962 new->uptime = time (NULL);
4963
4964 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4965 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004966 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004967 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4968 }
4969 }
4970
4971 /* Unintern original. */
4972 aspath_unintern (attr.aspath);
4973}
4974
4975void
4976bgp_redistribute_delete (struct prefix *p, u_char type)
4977{
4978 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004979 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004980 afi_t afi;
4981 struct bgp_node *rn;
4982 struct bgp_info *ri;
4983
paul1eb8ef22005-04-07 07:30:20 +00004984 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004985 {
4986 afi = family2afi (p->family);
4987
4988 if (bgp->redist[afi][type])
4989 {
paulfee0f4c2004-09-13 05:12:46 +00004990 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004991
4992 for (ri = rn->info; ri; ri = ri->next)
4993 if (ri->peer == bgp->peer_self
4994 && ri->type == type)
4995 break;
4996
4997 if (ri)
4998 {
4999 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005000 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005001 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005002 }
5003 bgp_unlock_node (rn);
5004 }
5005 }
5006}
5007
5008/* Withdraw specified route type's route. */
5009void
5010bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5011{
5012 struct bgp_node *rn;
5013 struct bgp_info *ri;
5014 struct bgp_table *table;
5015
5016 table = bgp->rib[afi][SAFI_UNICAST];
5017
5018 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5019 {
5020 for (ri = rn->info; ri; ri = ri->next)
5021 if (ri->peer == bgp->peer_self
5022 && ri->type == type)
5023 break;
5024
5025 if (ri)
5026 {
5027 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005028 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005029 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005030 }
5031 }
5032}
5033
5034/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005035static void
paul718e3742002-12-13 20:15:29 +00005036route_vty_out_route (struct prefix *p, struct vty *vty)
5037{
5038 int len;
5039 u_int32_t destination;
5040 char buf[BUFSIZ];
5041
5042 if (p->family == AF_INET)
5043 {
5044 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5045 destination = ntohl (p->u.prefix4.s_addr);
5046
5047 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5048 || (IN_CLASSB (destination) && p->prefixlen == 16)
5049 || (IN_CLASSA (destination) && p->prefixlen == 8)
5050 || p->u.prefix4.s_addr == 0)
5051 {
5052 /* When mask is natural, mask is not displayed. */
5053 }
5054 else
5055 len += vty_out (vty, "/%d", p->prefixlen);
5056 }
5057 else
5058 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5059 p->prefixlen);
5060
5061 len = 17 - len;
5062 if (len < 1)
5063 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5064 else
5065 vty_out (vty, "%*s", len, " ");
5066}
5067
paul718e3742002-12-13 20:15:29 +00005068enum bgp_display_type
5069{
5070 normal_list,
5071};
5072
paulb40d9392005-08-22 22:34:41 +00005073/* Print the short form route status for a bgp_info */
5074static void
5075route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005076{
paulb40d9392005-08-22 22:34:41 +00005077 /* Route status display. */
5078 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5079 vty_out (vty, "R");
5080 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005081 vty_out (vty, "S");
5082 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005083 vty_out (vty, "s");
5084 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5085 vty_out (vty, "*");
5086 else
5087 vty_out (vty, " ");
5088
5089 /* Selected */
5090 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5091 vty_out (vty, "h");
5092 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5093 vty_out (vty, "d");
5094 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5095 vty_out (vty, ">");
5096 else
5097 vty_out (vty, " ");
5098
5099 /* Internal route. */
5100 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5101 vty_out (vty, "i");
5102 else
paulb40d9392005-08-22 22:34:41 +00005103 vty_out (vty, " ");
5104}
5105
5106/* called from terminal list command */
5107void
5108route_vty_out (struct vty *vty, struct prefix *p,
5109 struct bgp_info *binfo, int display, safi_t safi)
5110{
5111 struct attr *attr;
5112
5113 /* short status lead text */
5114 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005115
5116 /* print prefix and mask */
5117 if (! display)
5118 route_vty_out_route (p, vty);
5119 else
5120 vty_out (vty, "%*s", 17, " ");
5121
5122 /* Print attribute */
5123 attr = binfo->attr;
5124 if (attr)
5125 {
5126 if (p->family == AF_INET)
5127 {
5128 if (safi == SAFI_MPLS_VPN)
5129 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5130 else
5131 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5132 }
5133#ifdef HAVE_IPV6
5134 else if (p->family == AF_INET6)
5135 {
5136 int len;
5137 char buf[BUFSIZ];
5138
5139 len = vty_out (vty, "%s",
5140 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5141 len = 16 - len;
5142 if (len < 1)
5143 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5144 else
5145 vty_out (vty, "%*s", len, " ");
5146 }
5147#endif /* HAVE_IPV6 */
5148
5149 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5150 vty_out (vty, "%10d", attr->med);
5151 else
5152 vty_out (vty, " ");
5153
5154 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5155 vty_out (vty, "%7d", attr->local_pref);
5156 else
5157 vty_out (vty, " ");
5158
5159 vty_out (vty, "%7u ",attr->weight);
5160
Paul Jakmab2518c12006-05-12 23:48:40 +00005161 /* Print aspath */
5162 if (attr->aspath)
5163 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005164
Paul Jakmab2518c12006-05-12 23:48:40 +00005165 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005166 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005167 }
paul718e3742002-12-13 20:15:29 +00005168 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005169}
5170
5171/* called from terminal list command */
5172void
5173route_vty_out_tmp (struct vty *vty, struct prefix *p,
5174 struct attr *attr, safi_t safi)
5175{
5176 /* Route status display. */
5177 vty_out (vty, "*");
5178 vty_out (vty, ">");
5179 vty_out (vty, " ");
5180
5181 /* print prefix and mask */
5182 route_vty_out_route (p, vty);
5183
5184 /* Print attribute */
5185 if (attr)
5186 {
5187 if (p->family == AF_INET)
5188 {
5189 if (safi == SAFI_MPLS_VPN)
5190 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5191 else
5192 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5193 }
5194#ifdef HAVE_IPV6
5195 else if (p->family == AF_INET6)
5196 {
5197 int len;
5198 char buf[BUFSIZ];
5199
5200 len = vty_out (vty, "%s",
5201 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5202 len = 16 - len;
5203 if (len < 1)
5204 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5205 else
5206 vty_out (vty, "%*s", len, " ");
5207 }
5208#endif /* HAVE_IPV6 */
5209
5210 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5211 vty_out (vty, "%10d", attr->med);
5212 else
5213 vty_out (vty, " ");
5214
5215 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5216 vty_out (vty, "%7d", attr->local_pref);
5217 else
5218 vty_out (vty, " ");
5219
5220 vty_out (vty, "%7d ",attr->weight);
5221
Paul Jakmab2518c12006-05-12 23:48:40 +00005222 /* Print aspath */
5223 if (attr->aspath)
5224 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005225
Paul Jakmab2518c12006-05-12 23:48:40 +00005226 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005227 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005228 }
paul718e3742002-12-13 20:15:29 +00005229
5230 vty_out (vty, "%s", VTY_NEWLINE);
5231}
5232
ajs5a646652004-11-05 01:25:55 +00005233void
paul718e3742002-12-13 20:15:29 +00005234route_vty_out_tag (struct vty *vty, struct prefix *p,
5235 struct bgp_info *binfo, int display, safi_t safi)
5236{
5237 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005238 u_int32_t label = 0;
5239
paulb40d9392005-08-22 22:34:41 +00005240 /* short status lead text */
5241 route_vty_short_status_out (vty, binfo);
5242
paul718e3742002-12-13 20:15:29 +00005243 /* print prefix and mask */
5244 if (! display)
5245 route_vty_out_route (p, vty);
5246 else
5247 vty_out (vty, "%*s", 17, " ");
5248
5249 /* Print attribute */
5250 attr = binfo->attr;
5251 if (attr)
5252 {
5253 if (p->family == AF_INET)
5254 {
5255 if (safi == SAFI_MPLS_VPN)
5256 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5257 else
5258 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5259 }
5260#ifdef HAVE_IPV6
5261 else if (p->family == AF_INET6)
5262 {
5263 char buf[BUFSIZ];
5264 char buf1[BUFSIZ];
5265 if (attr->mp_nexthop_len == 16)
5266 vty_out (vty, "%s",
5267 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5268 else if (attr->mp_nexthop_len == 32)
5269 vty_out (vty, "%s(%s)",
5270 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5271 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5272
5273 }
5274#endif /* HAVE_IPV6 */
5275 }
5276
5277 label = decode_label (binfo->tag);
5278
5279 vty_out (vty, "notag/%d", label);
5280
5281 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005282}
5283
5284/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005285static void
paul718e3742002-12-13 20:15:29 +00005286damp_route_vty_out (struct vty *vty, struct prefix *p,
5287 struct bgp_info *binfo, int display, safi_t safi)
5288{
5289 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005290 int len;
5291
paulb40d9392005-08-22 22:34:41 +00005292 /* short status lead text */
5293 route_vty_short_status_out (vty, binfo);
5294
paul718e3742002-12-13 20:15:29 +00005295 /* print prefix and mask */
5296 if (! display)
5297 route_vty_out_route (p, vty);
5298 else
5299 vty_out (vty, "%*s", 17, " ");
5300
5301 len = vty_out (vty, "%s", binfo->peer->host);
5302 len = 17 - len;
5303 if (len < 1)
5304 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5305 else
5306 vty_out (vty, "%*s", len, " ");
5307
5308 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5309
5310 /* Print attribute */
5311 attr = binfo->attr;
5312 if (attr)
5313 {
5314 /* Print aspath */
5315 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005316 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005317
5318 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005319 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005320 }
5321 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005322}
5323
5324#define BGP_UPTIME_LEN 25
5325
5326/* flap route */
ajs5a646652004-11-05 01:25:55 +00005327static void
paul718e3742002-12-13 20:15:29 +00005328flap_route_vty_out (struct vty *vty, struct prefix *p,
5329 struct bgp_info *binfo, int display, safi_t safi)
5330{
5331 struct attr *attr;
5332 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005333 char timebuf[BGP_UPTIME_LEN];
5334 int len;
5335
paul718e3742002-12-13 20:15:29 +00005336 bdi = binfo->damp_info;
5337
paulb40d9392005-08-22 22:34:41 +00005338 /* short status lead text */
5339 route_vty_short_status_out (vty, binfo);
5340
paul718e3742002-12-13 20:15:29 +00005341 /* print prefix and mask */
5342 if (! display)
5343 route_vty_out_route (p, vty);
5344 else
5345 vty_out (vty, "%*s", 17, " ");
5346
5347 len = vty_out (vty, "%s", binfo->peer->host);
5348 len = 16 - len;
5349 if (len < 1)
5350 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5351 else
5352 vty_out (vty, "%*s", len, " ");
5353
5354 len = vty_out (vty, "%d", bdi->flap);
5355 len = 5 - len;
5356 if (len < 1)
5357 vty_out (vty, " ");
5358 else
5359 vty_out (vty, "%*s ", len, " ");
5360
5361 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5362 timebuf, BGP_UPTIME_LEN));
5363
5364 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5365 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5366 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5367 else
5368 vty_out (vty, "%*s ", 8, " ");
5369
5370 /* Print attribute */
5371 attr = binfo->attr;
5372 if (attr)
5373 {
5374 /* Print aspath */
5375 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005376 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005377
5378 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005379 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005380 }
5381 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005382}
5383
paul94f2b392005-06-28 12:44:16 +00005384static void
paul718e3742002-12-13 20:15:29 +00005385route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5386 struct bgp_info *binfo, afi_t afi, safi_t safi)
5387{
5388 char buf[INET6_ADDRSTRLEN];
5389 char buf1[BUFSIZ];
5390 struct attr *attr;
5391 int sockunion_vty_out (struct vty *, union sockunion *);
5392
5393 attr = binfo->attr;
5394
5395 if (attr)
5396 {
5397 /* Line1 display AS-path, Aggregator */
5398 if (attr->aspath)
5399 {
5400 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005401 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005402 vty_out (vty, "Local");
5403 else
Paul Jakmab2518c12006-05-12 23:48:40 +00005404 aspath_print_vty (vty, "%s", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005405 }
5406
paulb40d9392005-08-22 22:34:41 +00005407 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5408 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005409 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5410 vty_out (vty, ", (stale)");
5411 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5412 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5413 inet_ntoa (attr->aggregator_addr));
5414 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5415 vty_out (vty, ", (Received from a RR-client)");
5416 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5417 vty_out (vty, ", (Received from a RS-client)");
5418 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5419 vty_out (vty, ", (history entry)");
5420 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5421 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005422 vty_out (vty, "%s", VTY_NEWLINE);
5423
5424 /* Line2 display Next-hop, Neighbor, Router-id */
5425 if (p->family == AF_INET)
5426 {
5427 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5428 inet_ntoa (attr->mp_nexthop_global_in) :
5429 inet_ntoa (attr->nexthop));
5430 }
5431#ifdef HAVE_IPV6
5432 else
5433 {
5434 vty_out (vty, " %s",
5435 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5436 buf, INET6_ADDRSTRLEN));
5437 }
5438#endif /* HAVE_IPV6 */
5439
5440 if (binfo->peer == bgp->peer_self)
5441 {
5442 vty_out (vty, " from %s ",
5443 p->family == AF_INET ? "0.0.0.0" : "::");
5444 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5445 }
5446 else
5447 {
5448 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5449 vty_out (vty, " (inaccessible)");
5450 else if (binfo->igpmetric)
5451 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005452 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005453 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5454 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5455 else
5456 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5457 }
5458 vty_out (vty, "%s", VTY_NEWLINE);
5459
5460#ifdef HAVE_IPV6
5461 /* display nexthop local */
5462 if (attr->mp_nexthop_len == 32)
5463 {
5464 vty_out (vty, " (%s)%s",
5465 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5466 buf, INET6_ADDRSTRLEN),
5467 VTY_NEWLINE);
5468 }
5469#endif /* HAVE_IPV6 */
5470
5471 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5472 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5473
5474 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5475 vty_out (vty, ", metric %d", attr->med);
5476
5477 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5478 vty_out (vty, ", localpref %d", attr->local_pref);
5479 else
5480 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5481
5482 if (attr->weight != 0)
5483 vty_out (vty, ", weight %d", attr->weight);
5484
5485 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5486 vty_out (vty, ", valid");
5487
5488 if (binfo->peer != bgp->peer_self)
5489 {
5490 if (binfo->peer->as == binfo->peer->local_as)
5491 vty_out (vty, ", internal");
5492 else
5493 vty_out (vty, ", %s",
5494 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5495 }
5496 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5497 vty_out (vty, ", aggregated, local");
5498 else if (binfo->type != ZEBRA_ROUTE_BGP)
5499 vty_out (vty, ", sourced");
5500 else
5501 vty_out (vty, ", sourced, local");
5502
5503 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5504 vty_out (vty, ", atomic-aggregate");
5505
5506 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5507 vty_out (vty, ", best");
5508
5509 vty_out (vty, "%s", VTY_NEWLINE);
5510
5511 /* Line 4 display Community */
5512 if (attr->community)
5513 vty_out (vty, " Community: %s%s", attr->community->str,
5514 VTY_NEWLINE);
5515
5516 /* Line 5 display Extended-community */
5517 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5518 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5519 VTY_NEWLINE);
5520
5521 /* Line 6 display Originator, Cluster-id */
5522 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5523 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5524 {
5525 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5526 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5527
5528 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5529 {
5530 int i;
5531 vty_out (vty, ", Cluster list: ");
5532 for (i = 0; i < attr->cluster->length / 4; i++)
5533 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5534 }
5535 vty_out (vty, "%s", VTY_NEWLINE);
5536 }
5537
5538 if (binfo->damp_info)
5539 bgp_damp_info_vty (vty, binfo);
5540
5541 /* Line 7 display Uptime */
5542 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5543 }
5544 vty_out (vty, "%s", VTY_NEWLINE);
5545}
5546
paulb40d9392005-08-22 22:34:41 +00005547#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 +00005548#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005549#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5550#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5551#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5552
5553enum bgp_show_type
5554{
5555 bgp_show_type_normal,
5556 bgp_show_type_regexp,
5557 bgp_show_type_prefix_list,
5558 bgp_show_type_filter_list,
5559 bgp_show_type_route_map,
5560 bgp_show_type_neighbor,
5561 bgp_show_type_cidr_only,
5562 bgp_show_type_prefix_longer,
5563 bgp_show_type_community_all,
5564 bgp_show_type_community,
5565 bgp_show_type_community_exact,
5566 bgp_show_type_community_list,
5567 bgp_show_type_community_list_exact,
5568 bgp_show_type_flap_statistics,
5569 bgp_show_type_flap_address,
5570 bgp_show_type_flap_prefix,
5571 bgp_show_type_flap_cidr_only,
5572 bgp_show_type_flap_regexp,
5573 bgp_show_type_flap_filter_list,
5574 bgp_show_type_flap_prefix_list,
5575 bgp_show_type_flap_prefix_longer,
5576 bgp_show_type_flap_route_map,
5577 bgp_show_type_flap_neighbor,
5578 bgp_show_type_dampend_paths,
5579 bgp_show_type_damp_neighbor
5580};
5581
ajs5a646652004-11-05 01:25:55 +00005582static int
paulfee0f4c2004-09-13 05:12:46 +00005583bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005584 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005585{
paul718e3742002-12-13 20:15:29 +00005586 struct bgp_info *ri;
5587 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005588 int header = 1;
paul718e3742002-12-13 20:15:29 +00005589 int display;
ajs5a646652004-11-05 01:25:55 +00005590 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005591
5592 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005593 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005594
paul718e3742002-12-13 20:15:29 +00005595 /* Start processing of routes. */
5596 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5597 if (rn->info != NULL)
5598 {
5599 display = 0;
5600
5601 for (ri = rn->info; ri; ri = ri->next)
5602 {
ajs5a646652004-11-05 01:25:55 +00005603 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005604 || type == bgp_show_type_flap_address
5605 || type == bgp_show_type_flap_prefix
5606 || type == bgp_show_type_flap_cidr_only
5607 || type == bgp_show_type_flap_regexp
5608 || type == bgp_show_type_flap_filter_list
5609 || type == bgp_show_type_flap_prefix_list
5610 || type == bgp_show_type_flap_prefix_longer
5611 || type == bgp_show_type_flap_route_map
5612 || type == bgp_show_type_flap_neighbor
5613 || type == bgp_show_type_dampend_paths
5614 || type == bgp_show_type_damp_neighbor)
5615 {
5616 if (! ri->damp_info)
5617 continue;
5618 }
5619 if (type == bgp_show_type_regexp
5620 || type == bgp_show_type_flap_regexp)
5621 {
ajs5a646652004-11-05 01:25:55 +00005622 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005623
5624 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5625 continue;
5626 }
5627 if (type == bgp_show_type_prefix_list
5628 || type == bgp_show_type_flap_prefix_list)
5629 {
ajs5a646652004-11-05 01:25:55 +00005630 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005631
5632 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5633 continue;
5634 }
5635 if (type == bgp_show_type_filter_list
5636 || type == bgp_show_type_flap_filter_list)
5637 {
ajs5a646652004-11-05 01:25:55 +00005638 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005639
5640 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5641 continue;
5642 }
5643 if (type == bgp_show_type_route_map
5644 || type == bgp_show_type_flap_route_map)
5645 {
ajs5a646652004-11-05 01:25:55 +00005646 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005647 struct bgp_info binfo;
5648 struct attr dummy_attr;
5649 int ret;
5650
5651 dummy_attr = *ri->attr;
5652 binfo.peer = ri->peer;
5653 binfo.attr = &dummy_attr;
5654
5655 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5656
5657 if (ret == RMAP_DENYMATCH)
5658 continue;
5659 }
5660 if (type == bgp_show_type_neighbor
5661 || type == bgp_show_type_flap_neighbor
5662 || type == bgp_show_type_damp_neighbor)
5663 {
ajs5a646652004-11-05 01:25:55 +00005664 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005665
5666 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5667 continue;
5668 }
5669 if (type == bgp_show_type_cidr_only
5670 || type == bgp_show_type_flap_cidr_only)
5671 {
5672 u_int32_t destination;
5673
5674 destination = ntohl (rn->p.u.prefix4.s_addr);
5675 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5676 continue;
5677 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5678 continue;
5679 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5680 continue;
5681 }
5682 if (type == bgp_show_type_prefix_longer
5683 || type == bgp_show_type_flap_prefix_longer)
5684 {
ajs5a646652004-11-05 01:25:55 +00005685 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005686
5687 if (! prefix_match (p, &rn->p))
5688 continue;
5689 }
5690 if (type == bgp_show_type_community_all)
5691 {
5692 if (! ri->attr->community)
5693 continue;
5694 }
5695 if (type == bgp_show_type_community)
5696 {
ajs5a646652004-11-05 01:25:55 +00005697 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005698
5699 if (! ri->attr->community ||
5700 ! community_match (ri->attr->community, com))
5701 continue;
5702 }
5703 if (type == bgp_show_type_community_exact)
5704 {
ajs5a646652004-11-05 01:25:55 +00005705 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005706
5707 if (! ri->attr->community ||
5708 ! community_cmp (ri->attr->community, com))
5709 continue;
5710 }
5711 if (type == bgp_show_type_community_list)
5712 {
ajs5a646652004-11-05 01:25:55 +00005713 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005714
5715 if (! community_list_match (ri->attr->community, list))
5716 continue;
5717 }
5718 if (type == bgp_show_type_community_list_exact)
5719 {
ajs5a646652004-11-05 01:25:55 +00005720 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005721
5722 if (! community_list_exact_match (ri->attr->community, list))
5723 continue;
5724 }
5725 if (type == bgp_show_type_flap_address
5726 || type == bgp_show_type_flap_prefix)
5727 {
ajs5a646652004-11-05 01:25:55 +00005728 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005729
5730 if (! prefix_match (&rn->p, p))
5731 continue;
5732
5733 if (type == bgp_show_type_flap_prefix)
5734 if (p->prefixlen != rn->p.prefixlen)
5735 continue;
5736 }
5737 if (type == bgp_show_type_dampend_paths
5738 || type == bgp_show_type_damp_neighbor)
5739 {
5740 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5741 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5742 continue;
5743 }
5744
5745 if (header)
5746 {
hasso93406d82005-02-02 14:40:33 +00005747 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5748 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5749 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005750 if (type == bgp_show_type_dampend_paths
5751 || type == bgp_show_type_damp_neighbor)
5752 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5753 else if (type == bgp_show_type_flap_statistics
5754 || type == bgp_show_type_flap_address
5755 || type == bgp_show_type_flap_prefix
5756 || type == bgp_show_type_flap_cidr_only
5757 || type == bgp_show_type_flap_regexp
5758 || type == bgp_show_type_flap_filter_list
5759 || type == bgp_show_type_flap_prefix_list
5760 || type == bgp_show_type_flap_prefix_longer
5761 || type == bgp_show_type_flap_route_map
5762 || type == bgp_show_type_flap_neighbor)
5763 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5764 else
5765 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005766 header = 0;
5767 }
5768
5769 if (type == bgp_show_type_dampend_paths
5770 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005771 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005772 else if (type == bgp_show_type_flap_statistics
5773 || type == bgp_show_type_flap_address
5774 || type == bgp_show_type_flap_prefix
5775 || type == bgp_show_type_flap_cidr_only
5776 || type == bgp_show_type_flap_regexp
5777 || type == bgp_show_type_flap_filter_list
5778 || type == bgp_show_type_flap_prefix_list
5779 || type == bgp_show_type_flap_prefix_longer
5780 || type == bgp_show_type_flap_route_map
5781 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005782 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005783 else
ajs5a646652004-11-05 01:25:55 +00005784 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005785 display++;
5786 }
5787 if (display)
ajs5a646652004-11-05 01:25:55 +00005788 output_count++;
paul718e3742002-12-13 20:15:29 +00005789 }
5790
5791 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005792 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005793 {
5794 if (type == bgp_show_type_normal)
5795 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5796 }
5797 else
5798 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005799 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005800
5801 return CMD_SUCCESS;
5802}
5803
ajs5a646652004-11-05 01:25:55 +00005804static int
paulfee0f4c2004-09-13 05:12:46 +00005805bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005806 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005807{
5808 struct bgp_table *table;
5809
5810 if (bgp == NULL) {
5811 bgp = bgp_get_default ();
5812 }
5813
5814 if (bgp == NULL)
5815 {
5816 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5817 return CMD_WARNING;
5818 }
5819
5820
5821 table = bgp->rib[afi][safi];
5822
ajs5a646652004-11-05 01:25:55 +00005823 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005824}
5825
paul718e3742002-12-13 20:15:29 +00005826/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005827static void
paul718e3742002-12-13 20:15:29 +00005828route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5829 struct bgp_node *rn,
5830 struct prefix_rd *prd, afi_t afi, safi_t safi)
5831{
5832 struct bgp_info *ri;
5833 struct prefix *p;
5834 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005835 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005836 char buf1[INET6_ADDRSTRLEN];
5837 char buf2[INET6_ADDRSTRLEN];
5838 int count = 0;
5839 int best = 0;
5840 int suppress = 0;
5841 int no_export = 0;
5842 int no_advertise = 0;
5843 int local_as = 0;
5844 int first = 0;
5845
5846 p = &rn->p;
5847 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5848 (safi == SAFI_MPLS_VPN ?
5849 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5850 safi == SAFI_MPLS_VPN ? ":" : "",
5851 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5852 p->prefixlen, VTY_NEWLINE);
5853
5854 for (ri = rn->info; ri; ri = ri->next)
5855 {
5856 count++;
5857 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5858 {
5859 best = count;
5860 if (ri->suppress)
5861 suppress = 1;
5862 if (ri->attr->community != NULL)
5863 {
5864 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5865 no_advertise = 1;
5866 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5867 no_export = 1;
5868 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5869 local_as = 1;
5870 }
5871 }
5872 }
5873
5874 vty_out (vty, "Paths: (%d available", count);
5875 if (best)
5876 {
5877 vty_out (vty, ", best #%d", best);
5878 if (safi == SAFI_UNICAST)
5879 vty_out (vty, ", table Default-IP-Routing-Table");
5880 }
5881 else
5882 vty_out (vty, ", no best path");
5883 if (no_advertise)
5884 vty_out (vty, ", not advertised to any peer");
5885 else if (no_export)
5886 vty_out (vty, ", not advertised to EBGP peer");
5887 else if (local_as)
5888 vty_out (vty, ", not advertised outside local AS");
5889 if (suppress)
5890 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5891 vty_out (vty, ")%s", VTY_NEWLINE);
5892
5893 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005894 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005895 {
5896 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5897 {
5898 if (! first)
5899 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5900 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5901 first = 1;
5902 }
5903 }
5904 if (! first)
5905 vty_out (vty, " Not advertised to any peer");
5906 vty_out (vty, "%s", VTY_NEWLINE);
5907}
5908
5909/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005910static int
paulfee0f4c2004-09-13 05:12:46 +00005911bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005912 struct bgp_table *rib, const char *ip_str,
5913 afi_t afi, safi_t safi, struct prefix_rd *prd,
5914 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005915{
5916 int ret;
5917 int header;
5918 int display = 0;
5919 struct prefix match;
5920 struct bgp_node *rn;
5921 struct bgp_node *rm;
5922 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005923 struct bgp_table *table;
5924
paul718e3742002-12-13 20:15:29 +00005925 /* Check IP address argument. */
5926 ret = str2prefix (ip_str, &match);
5927 if (! ret)
5928 {
5929 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5930 return CMD_WARNING;
5931 }
5932
5933 match.family = afi2family (afi);
5934
5935 if (safi == SAFI_MPLS_VPN)
5936 {
paulfee0f4c2004-09-13 05:12:46 +00005937 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005938 {
5939 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5940 continue;
5941
5942 if ((table = rn->info) != NULL)
5943 {
5944 header = 1;
5945
5946 if ((rm = bgp_node_match (table, &match)) != NULL)
5947 {
5948 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5949 continue;
5950
5951 for (ri = rm->info; ri; ri = ri->next)
5952 {
5953 if (header)
5954 {
5955 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5956 AFI_IP, SAFI_MPLS_VPN);
5957
5958 header = 0;
5959 }
5960 display++;
5961 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5962 }
5963 }
5964 }
5965 }
5966 }
5967 else
5968 {
5969 header = 1;
5970
paulfee0f4c2004-09-13 05:12:46 +00005971 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005972 {
5973 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5974 {
5975 for (ri = rn->info; ri; ri = ri->next)
5976 {
5977 if (header)
5978 {
5979 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5980 header = 0;
5981 }
5982 display++;
5983 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5984 }
5985 }
5986 }
5987 }
5988
5989 if (! display)
5990 {
5991 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5992 return CMD_WARNING;
5993 }
5994
5995 return CMD_SUCCESS;
5996}
5997
paulfee0f4c2004-09-13 05:12:46 +00005998/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00005999static int
paulfd79ac92004-10-13 05:06:08 +00006000bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006001 afi_t afi, safi_t safi, struct prefix_rd *prd,
6002 int prefix_check)
6003{
6004 struct bgp *bgp;
6005
6006 /* BGP structure lookup. */
6007 if (view_name)
6008 {
6009 bgp = bgp_lookup_by_name (view_name);
6010 if (bgp == NULL)
6011 {
6012 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6013 return CMD_WARNING;
6014 }
6015 }
6016 else
6017 {
6018 bgp = bgp_get_default ();
6019 if (bgp == NULL)
6020 {
6021 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6022 return CMD_WARNING;
6023 }
6024 }
6025
6026 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6027 afi, safi, prd, prefix_check);
6028}
6029
paul718e3742002-12-13 20:15:29 +00006030/* BGP route print out function. */
6031DEFUN (show_ip_bgp,
6032 show_ip_bgp_cmd,
6033 "show ip bgp",
6034 SHOW_STR
6035 IP_STR
6036 BGP_STR)
6037{
ajs5a646652004-11-05 01:25:55 +00006038 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006039}
6040
6041DEFUN (show_ip_bgp_ipv4,
6042 show_ip_bgp_ipv4_cmd,
6043 "show ip bgp ipv4 (unicast|multicast)",
6044 SHOW_STR
6045 IP_STR
6046 BGP_STR
6047 "Address family\n"
6048 "Address Family modifier\n"
6049 "Address Family modifier\n")
6050{
6051 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006052 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6053 NULL);
paul718e3742002-12-13 20:15:29 +00006054
ajs5a646652004-11-05 01:25:55 +00006055 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006056}
6057
6058DEFUN (show_ip_bgp_route,
6059 show_ip_bgp_route_cmd,
6060 "show ip bgp A.B.C.D",
6061 SHOW_STR
6062 IP_STR
6063 BGP_STR
6064 "Network in the BGP routing table to display\n")
6065{
6066 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6067}
6068
6069DEFUN (show_ip_bgp_ipv4_route,
6070 show_ip_bgp_ipv4_route_cmd,
6071 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6072 SHOW_STR
6073 IP_STR
6074 BGP_STR
6075 "Address family\n"
6076 "Address Family modifier\n"
6077 "Address Family modifier\n"
6078 "Network in the BGP routing table to display\n")
6079{
6080 if (strncmp (argv[0], "m", 1) == 0)
6081 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6082
6083 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6084}
6085
6086DEFUN (show_ip_bgp_vpnv4_all_route,
6087 show_ip_bgp_vpnv4_all_route_cmd,
6088 "show ip bgp vpnv4 all A.B.C.D",
6089 SHOW_STR
6090 IP_STR
6091 BGP_STR
6092 "Display VPNv4 NLRI specific information\n"
6093 "Display information about all VPNv4 NLRIs\n"
6094 "Network in the BGP routing table to display\n")
6095{
6096 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6097}
6098
6099DEFUN (show_ip_bgp_vpnv4_rd_route,
6100 show_ip_bgp_vpnv4_rd_route_cmd,
6101 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6102 SHOW_STR
6103 IP_STR
6104 BGP_STR
6105 "Display VPNv4 NLRI specific information\n"
6106 "Display information for a route distinguisher\n"
6107 "VPN Route Distinguisher\n"
6108 "Network in the BGP routing table to display\n")
6109{
6110 int ret;
6111 struct prefix_rd prd;
6112
6113 ret = str2prefix_rd (argv[0], &prd);
6114 if (! ret)
6115 {
6116 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6117 return CMD_WARNING;
6118 }
6119 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6120}
6121
6122DEFUN (show_ip_bgp_prefix,
6123 show_ip_bgp_prefix_cmd,
6124 "show ip bgp A.B.C.D/M",
6125 SHOW_STR
6126 IP_STR
6127 BGP_STR
6128 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6129{
6130 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6131}
6132
6133DEFUN (show_ip_bgp_ipv4_prefix,
6134 show_ip_bgp_ipv4_prefix_cmd,
6135 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6136 SHOW_STR
6137 IP_STR
6138 BGP_STR
6139 "Address family\n"
6140 "Address Family modifier\n"
6141 "Address Family modifier\n"
6142 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6143{
6144 if (strncmp (argv[0], "m", 1) == 0)
6145 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6146
6147 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6148}
6149
6150DEFUN (show_ip_bgp_vpnv4_all_prefix,
6151 show_ip_bgp_vpnv4_all_prefix_cmd,
6152 "show ip bgp vpnv4 all A.B.C.D/M",
6153 SHOW_STR
6154 IP_STR
6155 BGP_STR
6156 "Display VPNv4 NLRI specific information\n"
6157 "Display information about all VPNv4 NLRIs\n"
6158 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6159{
6160 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6161}
6162
6163DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6164 show_ip_bgp_vpnv4_rd_prefix_cmd,
6165 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6166 SHOW_STR
6167 IP_STR
6168 BGP_STR
6169 "Display VPNv4 NLRI specific information\n"
6170 "Display information for a route distinguisher\n"
6171 "VPN Route Distinguisher\n"
6172 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6173{
6174 int ret;
6175 struct prefix_rd prd;
6176
6177 ret = str2prefix_rd (argv[0], &prd);
6178 if (! ret)
6179 {
6180 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6181 return CMD_WARNING;
6182 }
6183 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6184}
6185
6186DEFUN (show_ip_bgp_view,
6187 show_ip_bgp_view_cmd,
6188 "show ip bgp view WORD",
6189 SHOW_STR
6190 IP_STR
6191 BGP_STR
6192 "BGP view\n"
6193 "BGP view name\n")
6194{
paulbb46e942003-10-24 19:02:03 +00006195 struct bgp *bgp;
6196
6197 /* BGP structure lookup. */
6198 bgp = bgp_lookup_by_name (argv[0]);
6199 if (bgp == NULL)
6200 {
6201 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6202 return CMD_WARNING;
6203 }
6204
ajs5a646652004-11-05 01:25:55 +00006205 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006206}
6207
6208DEFUN (show_ip_bgp_view_route,
6209 show_ip_bgp_view_route_cmd,
6210 "show ip bgp view WORD A.B.C.D",
6211 SHOW_STR
6212 IP_STR
6213 BGP_STR
6214 "BGP view\n"
6215 "BGP view name\n"
6216 "Network in the BGP routing table to display\n")
6217{
6218 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6219}
6220
6221DEFUN (show_ip_bgp_view_prefix,
6222 show_ip_bgp_view_prefix_cmd,
6223 "show ip bgp view WORD A.B.C.D/M",
6224 SHOW_STR
6225 IP_STR
6226 BGP_STR
6227 "BGP view\n"
6228 "BGP view name\n"
6229 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6230{
6231 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6232}
6233
6234#ifdef HAVE_IPV6
6235DEFUN (show_bgp,
6236 show_bgp_cmd,
6237 "show bgp",
6238 SHOW_STR
6239 BGP_STR)
6240{
ajs5a646652004-11-05 01:25:55 +00006241 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6242 NULL);
paul718e3742002-12-13 20:15:29 +00006243}
6244
6245ALIAS (show_bgp,
6246 show_bgp_ipv6_cmd,
6247 "show bgp ipv6",
6248 SHOW_STR
6249 BGP_STR
6250 "Address family\n")
6251
6252/* old command */
6253DEFUN (show_ipv6_bgp,
6254 show_ipv6_bgp_cmd,
6255 "show ipv6 bgp",
6256 SHOW_STR
6257 IP_STR
6258 BGP_STR)
6259{
ajs5a646652004-11-05 01:25:55 +00006260 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6261 NULL);
paul718e3742002-12-13 20:15:29 +00006262}
6263
6264DEFUN (show_bgp_route,
6265 show_bgp_route_cmd,
6266 "show bgp X:X::X:X",
6267 SHOW_STR
6268 BGP_STR
6269 "Network in the BGP routing table to display\n")
6270{
6271 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6272}
6273
6274ALIAS (show_bgp_route,
6275 show_bgp_ipv6_route_cmd,
6276 "show bgp ipv6 X:X::X:X",
6277 SHOW_STR
6278 BGP_STR
6279 "Address family\n"
6280 "Network in the BGP routing table to display\n")
6281
6282/* old command */
6283DEFUN (show_ipv6_bgp_route,
6284 show_ipv6_bgp_route_cmd,
6285 "show ipv6 bgp X:X::X:X",
6286 SHOW_STR
6287 IP_STR
6288 BGP_STR
6289 "Network in the BGP routing table to display\n")
6290{
6291 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6292}
6293
6294DEFUN (show_bgp_prefix,
6295 show_bgp_prefix_cmd,
6296 "show bgp X:X::X:X/M",
6297 SHOW_STR
6298 BGP_STR
6299 "IPv6 prefix <network>/<length>\n")
6300{
6301 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6302}
6303
6304ALIAS (show_bgp_prefix,
6305 show_bgp_ipv6_prefix_cmd,
6306 "show bgp ipv6 X:X::X:X/M",
6307 SHOW_STR
6308 BGP_STR
6309 "Address family\n"
6310 "IPv6 prefix <network>/<length>\n")
6311
6312/* old command */
6313DEFUN (show_ipv6_bgp_prefix,
6314 show_ipv6_bgp_prefix_cmd,
6315 "show ipv6 bgp X:X::X:X/M",
6316 SHOW_STR
6317 IP_STR
6318 BGP_STR
6319 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6320{
6321 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6322}
6323
paulbb46e942003-10-24 19:02:03 +00006324DEFUN (show_bgp_view,
6325 show_bgp_view_cmd,
6326 "show bgp view WORD",
6327 SHOW_STR
6328 BGP_STR
6329 "BGP view\n"
6330 "View name\n")
6331{
6332 struct bgp *bgp;
6333
6334 /* BGP structure lookup. */
6335 bgp = bgp_lookup_by_name (argv[0]);
6336 if (bgp == NULL)
6337 {
6338 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6339 return CMD_WARNING;
6340 }
6341
ajs5a646652004-11-05 01:25:55 +00006342 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006343}
6344
6345ALIAS (show_bgp_view,
6346 show_bgp_view_ipv6_cmd,
6347 "show bgp view WORD ipv6",
6348 SHOW_STR
6349 BGP_STR
6350 "BGP view\n"
6351 "View name\n"
6352 "Address family\n")
6353
6354DEFUN (show_bgp_view_route,
6355 show_bgp_view_route_cmd,
6356 "show bgp view WORD X:X::X:X",
6357 SHOW_STR
6358 BGP_STR
6359 "BGP view\n"
6360 "View name\n"
6361 "Network in the BGP routing table to display\n")
6362{
6363 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6364}
6365
6366ALIAS (show_bgp_view_route,
6367 show_bgp_view_ipv6_route_cmd,
6368 "show bgp view WORD ipv6 X:X::X:X",
6369 SHOW_STR
6370 BGP_STR
6371 "BGP view\n"
6372 "View name\n"
6373 "Address family\n"
6374 "Network in the BGP routing table to display\n")
6375
6376DEFUN (show_bgp_view_prefix,
6377 show_bgp_view_prefix_cmd,
6378 "show bgp view WORD X:X::X:X/M",
6379 SHOW_STR
6380 BGP_STR
6381 "BGP view\n"
6382 "View name\n"
6383 "IPv6 prefix <network>/<length>\n")
6384{
6385 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6386}
6387
6388ALIAS (show_bgp_view_prefix,
6389 show_bgp_view_ipv6_prefix_cmd,
6390 "show bgp view WORD ipv6 X:X::X:X/M",
6391 SHOW_STR
6392 BGP_STR
6393 "BGP view\n"
6394 "View name\n"
6395 "Address family\n"
6396 "IPv6 prefix <network>/<length>\n")
6397
paul718e3742002-12-13 20:15:29 +00006398/* old command */
6399DEFUN (show_ipv6_mbgp,
6400 show_ipv6_mbgp_cmd,
6401 "show ipv6 mbgp",
6402 SHOW_STR
6403 IP_STR
6404 MBGP_STR)
6405{
ajs5a646652004-11-05 01:25:55 +00006406 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6407 NULL);
paul718e3742002-12-13 20:15:29 +00006408}
6409
6410/* old command */
6411DEFUN (show_ipv6_mbgp_route,
6412 show_ipv6_mbgp_route_cmd,
6413 "show ipv6 mbgp X:X::X:X",
6414 SHOW_STR
6415 IP_STR
6416 MBGP_STR
6417 "Network in the MBGP routing table to display\n")
6418{
6419 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6420}
6421
6422/* old command */
6423DEFUN (show_ipv6_mbgp_prefix,
6424 show_ipv6_mbgp_prefix_cmd,
6425 "show ipv6 mbgp X:X::X:X/M",
6426 SHOW_STR
6427 IP_STR
6428 MBGP_STR
6429 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6430{
6431 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6432}
6433#endif
6434
paul718e3742002-12-13 20:15:29 +00006435
paul94f2b392005-06-28 12:44:16 +00006436static int
paulfd79ac92004-10-13 05:06:08 +00006437bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006438 safi_t safi, enum bgp_show_type type)
6439{
6440 int i;
6441 struct buffer *b;
6442 char *regstr;
6443 int first;
6444 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006445 int rc;
paul718e3742002-12-13 20:15:29 +00006446
6447 first = 0;
6448 b = buffer_new (1024);
6449 for (i = 0; i < argc; i++)
6450 {
6451 if (first)
6452 buffer_putc (b, ' ');
6453 else
6454 {
6455 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6456 continue;
6457 first = 1;
6458 }
6459
6460 buffer_putstr (b, argv[i]);
6461 }
6462 buffer_putc (b, '\0');
6463
6464 regstr = buffer_getstr (b);
6465 buffer_free (b);
6466
6467 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006468 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006469 if (! regex)
6470 {
6471 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6472 VTY_NEWLINE);
6473 return CMD_WARNING;
6474 }
6475
ajs5a646652004-11-05 01:25:55 +00006476 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6477 bgp_regex_free (regex);
6478 return rc;
paul718e3742002-12-13 20:15:29 +00006479}
6480
6481DEFUN (show_ip_bgp_regexp,
6482 show_ip_bgp_regexp_cmd,
6483 "show ip bgp regexp .LINE",
6484 SHOW_STR
6485 IP_STR
6486 BGP_STR
6487 "Display routes matching the AS path regular expression\n"
6488 "A regular-expression to match the BGP AS paths\n")
6489{
6490 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6491 bgp_show_type_regexp);
6492}
6493
6494DEFUN (show_ip_bgp_flap_regexp,
6495 show_ip_bgp_flap_regexp_cmd,
6496 "show ip bgp flap-statistics regexp .LINE",
6497 SHOW_STR
6498 IP_STR
6499 BGP_STR
6500 "Display flap statistics of routes\n"
6501 "Display routes matching the AS path regular expression\n"
6502 "A regular-expression to match the BGP AS paths\n")
6503{
6504 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6505 bgp_show_type_flap_regexp);
6506}
6507
6508DEFUN (show_ip_bgp_ipv4_regexp,
6509 show_ip_bgp_ipv4_regexp_cmd,
6510 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6511 SHOW_STR
6512 IP_STR
6513 BGP_STR
6514 "Address family\n"
6515 "Address Family modifier\n"
6516 "Address Family modifier\n"
6517 "Display routes matching the AS path regular expression\n"
6518 "A regular-expression to match the BGP AS paths\n")
6519{
6520 if (strncmp (argv[0], "m", 1) == 0)
6521 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6522 bgp_show_type_regexp);
6523
6524 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6525 bgp_show_type_regexp);
6526}
6527
6528#ifdef HAVE_IPV6
6529DEFUN (show_bgp_regexp,
6530 show_bgp_regexp_cmd,
6531 "show bgp regexp .LINE",
6532 SHOW_STR
6533 BGP_STR
6534 "Display routes matching the AS path regular expression\n"
6535 "A regular-expression to match the BGP AS paths\n")
6536{
6537 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6538 bgp_show_type_regexp);
6539}
6540
6541ALIAS (show_bgp_regexp,
6542 show_bgp_ipv6_regexp_cmd,
6543 "show bgp ipv6 regexp .LINE",
6544 SHOW_STR
6545 BGP_STR
6546 "Address family\n"
6547 "Display routes matching the AS path regular expression\n"
6548 "A regular-expression to match the BGP AS paths\n")
6549
6550/* old command */
6551DEFUN (show_ipv6_bgp_regexp,
6552 show_ipv6_bgp_regexp_cmd,
6553 "show ipv6 bgp regexp .LINE",
6554 SHOW_STR
6555 IP_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
6564/* old command */
6565DEFUN (show_ipv6_mbgp_regexp,
6566 show_ipv6_mbgp_regexp_cmd,
6567 "show ipv6 mbgp regexp .LINE",
6568 SHOW_STR
6569 IP_STR
6570 BGP_STR
6571 "Display routes matching the AS path regular expression\n"
6572 "A regular-expression to match the MBGP AS paths\n")
6573{
6574 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6575 bgp_show_type_regexp);
6576}
6577#endif /* HAVE_IPV6 */
6578
paul94f2b392005-06-28 12:44:16 +00006579static int
paulfd79ac92004-10-13 05:06:08 +00006580bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006581 safi_t safi, enum bgp_show_type type)
6582{
6583 struct prefix_list *plist;
6584
6585 plist = prefix_list_lookup (afi, prefix_list_str);
6586 if (plist == NULL)
6587 {
6588 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6589 prefix_list_str, VTY_NEWLINE);
6590 return CMD_WARNING;
6591 }
6592
ajs5a646652004-11-05 01:25:55 +00006593 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006594}
6595
6596DEFUN (show_ip_bgp_prefix_list,
6597 show_ip_bgp_prefix_list_cmd,
6598 "show ip bgp prefix-list WORD",
6599 SHOW_STR
6600 IP_STR
6601 BGP_STR
6602 "Display routes conforming to the prefix-list\n"
6603 "IP prefix-list name\n")
6604{
6605 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6606 bgp_show_type_prefix_list);
6607}
6608
6609DEFUN (show_ip_bgp_flap_prefix_list,
6610 show_ip_bgp_flap_prefix_list_cmd,
6611 "show ip bgp flap-statistics prefix-list WORD",
6612 SHOW_STR
6613 IP_STR
6614 BGP_STR
6615 "Display flap statistics of routes\n"
6616 "Display routes conforming to the prefix-list\n"
6617 "IP prefix-list name\n")
6618{
6619 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6620 bgp_show_type_flap_prefix_list);
6621}
6622
6623DEFUN (show_ip_bgp_ipv4_prefix_list,
6624 show_ip_bgp_ipv4_prefix_list_cmd,
6625 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6626 SHOW_STR
6627 IP_STR
6628 BGP_STR
6629 "Address family\n"
6630 "Address Family modifier\n"
6631 "Address Family modifier\n"
6632 "Display routes conforming to the prefix-list\n"
6633 "IP prefix-list name\n")
6634{
6635 if (strncmp (argv[0], "m", 1) == 0)
6636 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6637 bgp_show_type_prefix_list);
6638
6639 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6640 bgp_show_type_prefix_list);
6641}
6642
6643#ifdef HAVE_IPV6
6644DEFUN (show_bgp_prefix_list,
6645 show_bgp_prefix_list_cmd,
6646 "show bgp prefix-list WORD",
6647 SHOW_STR
6648 BGP_STR
6649 "Display routes conforming to the prefix-list\n"
6650 "IPv6 prefix-list name\n")
6651{
6652 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6653 bgp_show_type_prefix_list);
6654}
6655
6656ALIAS (show_bgp_prefix_list,
6657 show_bgp_ipv6_prefix_list_cmd,
6658 "show bgp ipv6 prefix-list WORD",
6659 SHOW_STR
6660 BGP_STR
6661 "Address family\n"
6662 "Display routes conforming to the prefix-list\n"
6663 "IPv6 prefix-list name\n")
6664
6665/* old command */
6666DEFUN (show_ipv6_bgp_prefix_list,
6667 show_ipv6_bgp_prefix_list_cmd,
6668 "show ipv6 bgp prefix-list WORD",
6669 SHOW_STR
6670 IPV6_STR
6671 BGP_STR
6672 "Display routes matching 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
6679/* old command */
6680DEFUN (show_ipv6_mbgp_prefix_list,
6681 show_ipv6_mbgp_prefix_list_cmd,
6682 "show ipv6 mbgp prefix-list WORD",
6683 SHOW_STR
6684 IPV6_STR
6685 MBGP_STR
6686 "Display routes matching the prefix-list\n"
6687 "IPv6 prefix-list name\n")
6688{
6689 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6690 bgp_show_type_prefix_list);
6691}
6692#endif /* HAVE_IPV6 */
6693
paul94f2b392005-06-28 12:44:16 +00006694static int
paulfd79ac92004-10-13 05:06:08 +00006695bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006696 safi_t safi, enum bgp_show_type type)
6697{
6698 struct as_list *as_list;
6699
6700 as_list = as_list_lookup (filter);
6701 if (as_list == NULL)
6702 {
6703 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6704 return CMD_WARNING;
6705 }
6706
ajs5a646652004-11-05 01:25:55 +00006707 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006708}
6709
6710DEFUN (show_ip_bgp_filter_list,
6711 show_ip_bgp_filter_list_cmd,
6712 "show ip bgp filter-list WORD",
6713 SHOW_STR
6714 IP_STR
6715 BGP_STR
6716 "Display routes conforming to the filter-list\n"
6717 "Regular expression access list name\n")
6718{
6719 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6720 bgp_show_type_filter_list);
6721}
6722
6723DEFUN (show_ip_bgp_flap_filter_list,
6724 show_ip_bgp_flap_filter_list_cmd,
6725 "show ip bgp flap-statistics filter-list WORD",
6726 SHOW_STR
6727 IP_STR
6728 BGP_STR
6729 "Display flap statistics of routes\n"
6730 "Display routes conforming to the filter-list\n"
6731 "Regular expression access list name\n")
6732{
6733 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6734 bgp_show_type_flap_filter_list);
6735}
6736
6737DEFUN (show_ip_bgp_ipv4_filter_list,
6738 show_ip_bgp_ipv4_filter_list_cmd,
6739 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6740 SHOW_STR
6741 IP_STR
6742 BGP_STR
6743 "Address family\n"
6744 "Address Family modifier\n"
6745 "Address Family modifier\n"
6746 "Display routes conforming to the filter-list\n"
6747 "Regular expression access list name\n")
6748{
6749 if (strncmp (argv[0], "m", 1) == 0)
6750 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6751 bgp_show_type_filter_list);
6752
6753 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6754 bgp_show_type_filter_list);
6755}
6756
6757#ifdef HAVE_IPV6
6758DEFUN (show_bgp_filter_list,
6759 show_bgp_filter_list_cmd,
6760 "show bgp filter-list WORD",
6761 SHOW_STR
6762 BGP_STR
6763 "Display routes conforming to the filter-list\n"
6764 "Regular expression access list name\n")
6765{
6766 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6767 bgp_show_type_filter_list);
6768}
6769
6770ALIAS (show_bgp_filter_list,
6771 show_bgp_ipv6_filter_list_cmd,
6772 "show bgp ipv6 filter-list WORD",
6773 SHOW_STR
6774 BGP_STR
6775 "Address family\n"
6776 "Display routes conforming to the filter-list\n"
6777 "Regular expression access list name\n")
6778
6779/* old command */
6780DEFUN (show_ipv6_bgp_filter_list,
6781 show_ipv6_bgp_filter_list_cmd,
6782 "show ipv6 bgp filter-list WORD",
6783 SHOW_STR
6784 IPV6_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
6793/* old command */
6794DEFUN (show_ipv6_mbgp_filter_list,
6795 show_ipv6_mbgp_filter_list_cmd,
6796 "show ipv6 mbgp filter-list WORD",
6797 SHOW_STR
6798 IPV6_STR
6799 MBGP_STR
6800 "Display routes conforming to the filter-list\n"
6801 "Regular expression access list name\n")
6802{
6803 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6804 bgp_show_type_filter_list);
6805}
6806#endif /* HAVE_IPV6 */
6807
paul94f2b392005-06-28 12:44:16 +00006808static int
paulfd79ac92004-10-13 05:06:08 +00006809bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006810 safi_t safi, enum bgp_show_type type)
6811{
6812 struct route_map *rmap;
6813
6814 rmap = route_map_lookup_by_name (rmap_str);
6815 if (! rmap)
6816 {
6817 vty_out (vty, "%% %s is not a valid route-map name%s",
6818 rmap_str, VTY_NEWLINE);
6819 return CMD_WARNING;
6820 }
6821
ajs5a646652004-11-05 01:25:55 +00006822 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006823}
6824
6825DEFUN (show_ip_bgp_route_map,
6826 show_ip_bgp_route_map_cmd,
6827 "show ip bgp route-map WORD",
6828 SHOW_STR
6829 IP_STR
6830 BGP_STR
6831 "Display routes matching the route-map\n"
6832 "A route-map to match on\n")
6833{
6834 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6835 bgp_show_type_route_map);
6836}
6837
6838DEFUN (show_ip_bgp_flap_route_map,
6839 show_ip_bgp_flap_route_map_cmd,
6840 "show ip bgp flap-statistics route-map WORD",
6841 SHOW_STR
6842 IP_STR
6843 BGP_STR
6844 "Display flap statistics of routes\n"
6845 "Display routes matching the route-map\n"
6846 "A route-map to match on\n")
6847{
6848 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6849 bgp_show_type_flap_route_map);
6850}
6851
6852DEFUN (show_ip_bgp_ipv4_route_map,
6853 show_ip_bgp_ipv4_route_map_cmd,
6854 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6855 SHOW_STR
6856 IP_STR
6857 BGP_STR
6858 "Address family\n"
6859 "Address Family modifier\n"
6860 "Address Family modifier\n"
6861 "Display routes matching the route-map\n"
6862 "A route-map to match on\n")
6863{
6864 if (strncmp (argv[0], "m", 1) == 0)
6865 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6866 bgp_show_type_route_map);
6867
6868 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6869 bgp_show_type_route_map);
6870}
6871
6872DEFUN (show_bgp_route_map,
6873 show_bgp_route_map_cmd,
6874 "show bgp route-map WORD",
6875 SHOW_STR
6876 BGP_STR
6877 "Display routes matching the route-map\n"
6878 "A route-map to match on\n")
6879{
6880 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6881 bgp_show_type_route_map);
6882}
6883
6884ALIAS (show_bgp_route_map,
6885 show_bgp_ipv6_route_map_cmd,
6886 "show bgp ipv6 route-map WORD",
6887 SHOW_STR
6888 BGP_STR
6889 "Address family\n"
6890 "Display routes matching the route-map\n"
6891 "A route-map to match on\n")
6892
6893DEFUN (show_ip_bgp_cidr_only,
6894 show_ip_bgp_cidr_only_cmd,
6895 "show ip bgp cidr-only",
6896 SHOW_STR
6897 IP_STR
6898 BGP_STR
6899 "Display only routes with non-natural netmasks\n")
6900{
6901 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006902 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006903}
6904
6905DEFUN (show_ip_bgp_flap_cidr_only,
6906 show_ip_bgp_flap_cidr_only_cmd,
6907 "show ip bgp flap-statistics cidr-only",
6908 SHOW_STR
6909 IP_STR
6910 BGP_STR
6911 "Display flap statistics of routes\n"
6912 "Display only routes with non-natural netmasks\n")
6913{
6914 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006915 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006916}
6917
6918DEFUN (show_ip_bgp_ipv4_cidr_only,
6919 show_ip_bgp_ipv4_cidr_only_cmd,
6920 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6921 SHOW_STR
6922 IP_STR
6923 BGP_STR
6924 "Address family\n"
6925 "Address Family modifier\n"
6926 "Address Family modifier\n"
6927 "Display only routes with non-natural netmasks\n")
6928{
6929 if (strncmp (argv[0], "m", 1) == 0)
6930 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006931 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006932
6933 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006934 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006935}
6936
6937DEFUN (show_ip_bgp_community_all,
6938 show_ip_bgp_community_all_cmd,
6939 "show ip bgp community",
6940 SHOW_STR
6941 IP_STR
6942 BGP_STR
6943 "Display routes matching the communities\n")
6944{
6945 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006946 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006947}
6948
6949DEFUN (show_ip_bgp_ipv4_community_all,
6950 show_ip_bgp_ipv4_community_all_cmd,
6951 "show ip bgp ipv4 (unicast|multicast) community",
6952 SHOW_STR
6953 IP_STR
6954 BGP_STR
6955 "Address family\n"
6956 "Address Family modifier\n"
6957 "Address Family modifier\n"
6958 "Display routes matching the communities\n")
6959{
6960 if (strncmp (argv[0], "m", 1) == 0)
6961 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006962 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006963
6964 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006965 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006966}
6967
6968#ifdef HAVE_IPV6
6969DEFUN (show_bgp_community_all,
6970 show_bgp_community_all_cmd,
6971 "show bgp community",
6972 SHOW_STR
6973 BGP_STR
6974 "Display routes matching the communities\n")
6975{
6976 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006977 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006978}
6979
6980ALIAS (show_bgp_community_all,
6981 show_bgp_ipv6_community_all_cmd,
6982 "show bgp ipv6 community",
6983 SHOW_STR
6984 BGP_STR
6985 "Address family\n"
6986 "Display routes matching the communities\n")
6987
6988/* old command */
6989DEFUN (show_ipv6_bgp_community_all,
6990 show_ipv6_bgp_community_all_cmd,
6991 "show ipv6 bgp community",
6992 SHOW_STR
6993 IPV6_STR
6994 BGP_STR
6995 "Display routes matching the communities\n")
6996{
6997 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006998 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006999}
7000
7001/* old command */
7002DEFUN (show_ipv6_mbgp_community_all,
7003 show_ipv6_mbgp_community_all_cmd,
7004 "show ipv6 mbgp community",
7005 SHOW_STR
7006 IPV6_STR
7007 MBGP_STR
7008 "Display routes matching the communities\n")
7009{
7010 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007011 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007012}
7013#endif /* HAVE_IPV6 */
7014
paul94f2b392005-06-28 12:44:16 +00007015static int
paulfd79ac92004-10-13 05:06:08 +00007016bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7017 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007018{
7019 struct community *com;
7020 struct buffer *b;
7021 int i;
7022 char *str;
7023 int first = 0;
7024
7025 b = buffer_new (1024);
7026 for (i = 0; i < argc; i++)
7027 {
7028 if (first)
7029 buffer_putc (b, ' ');
7030 else
7031 {
7032 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7033 continue;
7034 first = 1;
7035 }
7036
7037 buffer_putstr (b, argv[i]);
7038 }
7039 buffer_putc (b, '\0');
7040
7041 str = buffer_getstr (b);
7042 buffer_free (b);
7043
7044 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007045 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007046 if (! com)
7047 {
7048 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7049 return CMD_WARNING;
7050 }
7051
ajs5a646652004-11-05 01:25:55 +00007052 return bgp_show (vty, NULL, afi, safi,
7053 (exact ? bgp_show_type_community_exact :
7054 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007055}
7056
7057DEFUN (show_ip_bgp_community,
7058 show_ip_bgp_community_cmd,
7059 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7060 SHOW_STR
7061 IP_STR
7062 BGP_STR
7063 "Display routes matching the communities\n"
7064 "community number\n"
7065 "Do not send outside local AS (well-known community)\n"
7066 "Do not advertise to any peer (well-known community)\n"
7067 "Do not export to next AS (well-known community)\n")
7068{
7069 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7070}
7071
7072ALIAS (show_ip_bgp_community,
7073 show_ip_bgp_community2_cmd,
7074 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7075 SHOW_STR
7076 IP_STR
7077 BGP_STR
7078 "Display routes matching the communities\n"
7079 "community number\n"
7080 "Do not send outside local AS (well-known community)\n"
7081 "Do not advertise to any peer (well-known community)\n"
7082 "Do not export to next AS (well-known community)\n"
7083 "community number\n"
7084 "Do not send outside local AS (well-known community)\n"
7085 "Do not advertise to any peer (well-known community)\n"
7086 "Do not export to next AS (well-known community)\n")
7087
7088ALIAS (show_ip_bgp_community,
7089 show_ip_bgp_community3_cmd,
7090 "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)",
7091 SHOW_STR
7092 IP_STR
7093 BGP_STR
7094 "Display routes matching the communities\n"
7095 "community number\n"
7096 "Do not send outside local AS (well-known community)\n"
7097 "Do not advertise to any peer (well-known community)\n"
7098 "Do not export to next AS (well-known community)\n"
7099 "community number\n"
7100 "Do not send outside local AS (well-known community)\n"
7101 "Do not advertise to any peer (well-known community)\n"
7102 "Do not export to next AS (well-known community)\n"
7103 "community number\n"
7104 "Do not send outside local AS (well-known community)\n"
7105 "Do not advertise to any peer (well-known community)\n"
7106 "Do not export to next AS (well-known community)\n")
7107
7108ALIAS (show_ip_bgp_community,
7109 show_ip_bgp_community4_cmd,
7110 "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)",
7111 SHOW_STR
7112 IP_STR
7113 BGP_STR
7114 "Display routes matching the communities\n"
7115 "community number\n"
7116 "Do not send outside local AS (well-known community)\n"
7117 "Do not advertise to any peer (well-known community)\n"
7118 "Do not export to next AS (well-known community)\n"
7119 "community number\n"
7120 "Do not send outside local AS (well-known community)\n"
7121 "Do not advertise to any peer (well-known community)\n"
7122 "Do not export to next AS (well-known community)\n"
7123 "community number\n"
7124 "Do not send outside local AS (well-known community)\n"
7125 "Do not advertise to any peer (well-known community)\n"
7126 "Do not export to next AS (well-known community)\n"
7127 "community number\n"
7128 "Do not send outside local AS (well-known community)\n"
7129 "Do not advertise to any peer (well-known community)\n"
7130 "Do not export to next AS (well-known community)\n")
7131
7132DEFUN (show_ip_bgp_ipv4_community,
7133 show_ip_bgp_ipv4_community_cmd,
7134 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7135 SHOW_STR
7136 IP_STR
7137 BGP_STR
7138 "Address family\n"
7139 "Address Family modifier\n"
7140 "Address Family modifier\n"
7141 "Display routes matching the communities\n"
7142 "community number\n"
7143 "Do not send outside local AS (well-known community)\n"
7144 "Do not advertise to any peer (well-known community)\n"
7145 "Do not export to next AS (well-known community)\n")
7146{
7147 if (strncmp (argv[0], "m", 1) == 0)
7148 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7149
7150 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7151}
7152
7153ALIAS (show_ip_bgp_ipv4_community,
7154 show_ip_bgp_ipv4_community2_cmd,
7155 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7156 SHOW_STR
7157 IP_STR
7158 BGP_STR
7159 "Address family\n"
7160 "Address Family modifier\n"
7161 "Address Family modifier\n"
7162 "Display routes matching the communities\n"
7163 "community number\n"
7164 "Do not send outside local AS (well-known community)\n"
7165 "Do not advertise to any peer (well-known community)\n"
7166 "Do not export to next AS (well-known community)\n"
7167 "community number\n"
7168 "Do not send outside local AS (well-known community)\n"
7169 "Do not advertise to any peer (well-known community)\n"
7170 "Do not export to next AS (well-known community)\n")
7171
7172ALIAS (show_ip_bgp_ipv4_community,
7173 show_ip_bgp_ipv4_community3_cmd,
7174 "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)",
7175 SHOW_STR
7176 IP_STR
7177 BGP_STR
7178 "Address family\n"
7179 "Address Family modifier\n"
7180 "Address Family modifier\n"
7181 "Display routes matching the communities\n"
7182 "community number\n"
7183 "Do not send outside local AS (well-known community)\n"
7184 "Do not advertise to any peer (well-known community)\n"
7185 "Do not export to next AS (well-known community)\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_community4_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) (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 "community number\n"
7218 "Do not send outside local AS (well-known community)\n"
7219 "Do not advertise to any peer (well-known community)\n"
7220 "Do not export to next AS (well-known community)\n")
7221
7222DEFUN (show_ip_bgp_community_exact,
7223 show_ip_bgp_community_exact_cmd,
7224 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7225 SHOW_STR
7226 IP_STR
7227 BGP_STR
7228 "Display routes matching the communities\n"
7229 "community number\n"
7230 "Do not send outside local AS (well-known community)\n"
7231 "Do not advertise to any peer (well-known community)\n"
7232 "Do not export to next AS (well-known community)\n"
7233 "Exact match of the communities")
7234{
7235 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7236}
7237
7238ALIAS (show_ip_bgp_community_exact,
7239 show_ip_bgp_community2_exact_cmd,
7240 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7241 SHOW_STR
7242 IP_STR
7243 BGP_STR
7244 "Display routes matching the communities\n"
7245 "community number\n"
7246 "Do not send outside local AS (well-known community)\n"
7247 "Do not advertise to any peer (well-known community)\n"
7248 "Do not export to next AS (well-known community)\n"
7249 "community number\n"
7250 "Do not send outside local AS (well-known community)\n"
7251 "Do not advertise to any peer (well-known community)\n"
7252 "Do not export to next AS (well-known community)\n"
7253 "Exact match of the communities")
7254
7255ALIAS (show_ip_bgp_community_exact,
7256 show_ip_bgp_community3_exact_cmd,
7257 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7258 SHOW_STR
7259 IP_STR
7260 BGP_STR
7261 "Display routes matching the communities\n"
7262 "community number\n"
7263 "Do not send outside local AS (well-known community)\n"
7264 "Do not advertise to any peer (well-known community)\n"
7265 "Do not export to next AS (well-known community)\n"
7266 "community number\n"
7267 "Do not send outside local AS (well-known community)\n"
7268 "Do not advertise to any peer (well-known community)\n"
7269 "Do not export to next AS (well-known community)\n"
7270 "community number\n"
7271 "Do not send outside local AS (well-known community)\n"
7272 "Do not advertise to any peer (well-known community)\n"
7273 "Do not export to next AS (well-known community)\n"
7274 "Exact match of the communities")
7275
7276ALIAS (show_ip_bgp_community_exact,
7277 show_ip_bgp_community4_exact_cmd,
7278 "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",
7279 SHOW_STR
7280 IP_STR
7281 BGP_STR
7282 "Display routes matching the communities\n"
7283 "community number\n"
7284 "Do not send outside local AS (well-known community)\n"
7285 "Do not advertise to any peer (well-known community)\n"
7286 "Do not export to next AS (well-known community)\n"
7287 "community number\n"
7288 "Do not send outside local AS (well-known community)\n"
7289 "Do not advertise to any peer (well-known community)\n"
7290 "Do not export to next AS (well-known community)\n"
7291 "community number\n"
7292 "Do not send outside local AS (well-known community)\n"
7293 "Do not advertise to any peer (well-known community)\n"
7294 "Do not export to next AS (well-known community)\n"
7295 "community number\n"
7296 "Do not send outside local AS (well-known community)\n"
7297 "Do not advertise to any peer (well-known community)\n"
7298 "Do not export to next AS (well-known community)\n"
7299 "Exact match of the communities")
7300
7301DEFUN (show_ip_bgp_ipv4_community_exact,
7302 show_ip_bgp_ipv4_community_exact_cmd,
7303 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7304 SHOW_STR
7305 IP_STR
7306 BGP_STR
7307 "Address family\n"
7308 "Address Family modifier\n"
7309 "Address Family modifier\n"
7310 "Display routes matching the communities\n"
7311 "community number\n"
7312 "Do not send outside local AS (well-known community)\n"
7313 "Do not advertise to any peer (well-known community)\n"
7314 "Do not export to next AS (well-known community)\n"
7315 "Exact match of the communities")
7316{
7317 if (strncmp (argv[0], "m", 1) == 0)
7318 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7319
7320 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7321}
7322
7323ALIAS (show_ip_bgp_ipv4_community_exact,
7324 show_ip_bgp_ipv4_community2_exact_cmd,
7325 "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",
7326 SHOW_STR
7327 IP_STR
7328 BGP_STR
7329 "Address family\n"
7330 "Address Family modifier\n"
7331 "Address Family modifier\n"
7332 "Display routes matching the communities\n"
7333 "community number\n"
7334 "Do not send outside local AS (well-known community)\n"
7335 "Do not advertise to any peer (well-known community)\n"
7336 "Do not export to next AS (well-known community)\n"
7337 "community number\n"
7338 "Do not send outside local AS (well-known community)\n"
7339 "Do not advertise to any peer (well-known community)\n"
7340 "Do not export to next AS (well-known community)\n"
7341 "Exact match of the communities")
7342
7343ALIAS (show_ip_bgp_ipv4_community_exact,
7344 show_ip_bgp_ipv4_community3_exact_cmd,
7345 "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",
7346 SHOW_STR
7347 IP_STR
7348 BGP_STR
7349 "Address family\n"
7350 "Address Family modifier\n"
7351 "Address Family modifier\n"
7352 "Display routes matching the communities\n"
7353 "community number\n"
7354 "Do not send outside local AS (well-known community)\n"
7355 "Do not advertise to any peer (well-known community)\n"
7356 "Do not export to next AS (well-known community)\n"
7357 "community number\n"
7358 "Do not send outside local AS (well-known community)\n"
7359 "Do not advertise to any peer (well-known community)\n"
7360 "Do not export to next AS (well-known community)\n"
7361 "community number\n"
7362 "Do not send outside local AS (well-known community)\n"
7363 "Do not advertise to any peer (well-known community)\n"
7364 "Do not export to next AS (well-known community)\n"
7365 "Exact match of the communities")
7366
7367ALIAS (show_ip_bgp_ipv4_community_exact,
7368 show_ip_bgp_ipv4_community4_exact_cmd,
7369 "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",
7370 SHOW_STR
7371 IP_STR
7372 BGP_STR
7373 "Address family\n"
7374 "Address Family modifier\n"
7375 "Address Family modifier\n"
7376 "Display routes matching the communities\n"
7377 "community number\n"
7378 "Do not send outside local AS (well-known community)\n"
7379 "Do not advertise to any peer (well-known community)\n"
7380 "Do not export to next AS (well-known community)\n"
7381 "community number\n"
7382 "Do not send outside local AS (well-known community)\n"
7383 "Do not advertise to any peer (well-known community)\n"
7384 "Do not export to next AS (well-known community)\n"
7385 "community number\n"
7386 "Do not send outside local AS (well-known community)\n"
7387 "Do not advertise to any peer (well-known community)\n"
7388 "Do not export to next AS (well-known community)\n"
7389 "community number\n"
7390 "Do not send outside local AS (well-known community)\n"
7391 "Do not advertise to any peer (well-known community)\n"
7392 "Do not export to next AS (well-known community)\n"
7393 "Exact match of the communities")
7394
7395#ifdef HAVE_IPV6
7396DEFUN (show_bgp_community,
7397 show_bgp_community_cmd,
7398 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7399 SHOW_STR
7400 BGP_STR
7401 "Display routes matching the communities\n"
7402 "community number\n"
7403 "Do not send outside local AS (well-known community)\n"
7404 "Do not advertise to any peer (well-known community)\n"
7405 "Do not export to next AS (well-known community)\n")
7406{
7407 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7408}
7409
7410ALIAS (show_bgp_community,
7411 show_bgp_ipv6_community_cmd,
7412 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7413 SHOW_STR
7414 BGP_STR
7415 "Address family\n"
7416 "Display routes matching the communities\n"
7417 "community number\n"
7418 "Do not send outside local AS (well-known community)\n"
7419 "Do not advertise to any peer (well-known community)\n"
7420 "Do not export to next AS (well-known community)\n")
7421
7422ALIAS (show_bgp_community,
7423 show_bgp_community2_cmd,
7424 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7425 SHOW_STR
7426 BGP_STR
7427 "Display routes matching the communities\n"
7428 "community number\n"
7429 "Do not send outside local AS (well-known community)\n"
7430 "Do not advertise to any peer (well-known community)\n"
7431 "Do not export to next AS (well-known community)\n"
7432 "community number\n"
7433 "Do not send outside local AS (well-known community)\n"
7434 "Do not advertise to any peer (well-known community)\n"
7435 "Do not export to next AS (well-known community)\n")
7436
7437ALIAS (show_bgp_community,
7438 show_bgp_ipv6_community2_cmd,
7439 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7440 SHOW_STR
7441 BGP_STR
7442 "Address family\n"
7443 "Display routes matching the communities\n"
7444 "community number\n"
7445 "Do not send outside local AS (well-known community)\n"
7446 "Do not advertise to any peer (well-known community)\n"
7447 "Do not export to next AS (well-known community)\n"
7448 "community number\n"
7449 "Do not send outside local AS (well-known community)\n"
7450 "Do not advertise to any peer (well-known community)\n"
7451 "Do not export to next AS (well-known community)\n")
7452
7453ALIAS (show_bgp_community,
7454 show_bgp_community3_cmd,
7455 "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)",
7456 SHOW_STR
7457 BGP_STR
7458 "Display routes matching the communities\n"
7459 "community number\n"
7460 "Do not send outside local AS (well-known community)\n"
7461 "Do not advertise to any peer (well-known community)\n"
7462 "Do not export to next AS (well-known community)\n"
7463 "community number\n"
7464 "Do not send outside local AS (well-known community)\n"
7465 "Do not advertise to any peer (well-known community)\n"
7466 "Do not export to next AS (well-known community)\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
7472ALIAS (show_bgp_community,
7473 show_bgp_ipv6_community3_cmd,
7474 "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)",
7475 SHOW_STR
7476 BGP_STR
7477 "Address family\n"
7478 "Display routes matching the communities\n"
7479 "community number\n"
7480 "Do not send outside local AS (well-known community)\n"
7481 "Do not advertise to any peer (well-known community)\n"
7482 "Do not export to next AS (well-known community)\n"
7483 "community number\n"
7484 "Do not send outside local AS (well-known community)\n"
7485 "Do not advertise to any peer (well-known community)\n"
7486 "Do not export to next AS (well-known community)\n"
7487 "community number\n"
7488 "Do not send outside local AS (well-known community)\n"
7489 "Do not advertise to any peer (well-known community)\n"
7490 "Do not export to next AS (well-known community)\n")
7491
7492ALIAS (show_bgp_community,
7493 show_bgp_community4_cmd,
7494 "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)",
7495 SHOW_STR
7496 BGP_STR
7497 "Display routes matching the communities\n"
7498 "community number\n"
7499 "Do not send outside local AS (well-known community)\n"
7500 "Do not advertise to any peer (well-known community)\n"
7501 "Do not export to next AS (well-known community)\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_ipv6_community4_cmd,
7517 "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)",
7518 SHOW_STR
7519 BGP_STR
7520 "Address family\n"
7521 "Display routes matching the communities\n"
7522 "community number\n"
7523 "Do not send outside local AS (well-known community)\n"
7524 "Do not advertise to any peer (well-known community)\n"
7525 "Do not export to next AS (well-known community)\n"
7526 "community number\n"
7527 "Do not send outside local AS (well-known community)\n"
7528 "Do not advertise to any peer (well-known community)\n"
7529 "Do not export to next AS (well-known community)\n"
7530 "community number\n"
7531 "Do not send outside local AS (well-known community)\n"
7532 "Do not advertise to any peer (well-known community)\n"
7533 "Do not export to next AS (well-known community)\n"
7534 "community number\n"
7535 "Do not send outside local AS (well-known community)\n"
7536 "Do not advertise to any peer (well-known community)\n"
7537 "Do not export to next AS (well-known community)\n")
7538
7539/* old command */
7540DEFUN (show_ipv6_bgp_community,
7541 show_ipv6_bgp_community_cmd,
7542 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7543 SHOW_STR
7544 IPV6_STR
7545 BGP_STR
7546 "Display routes matching the communities\n"
7547 "community number\n"
7548 "Do not send outside local AS (well-known community)\n"
7549 "Do not advertise to any peer (well-known community)\n"
7550 "Do not export to next AS (well-known community)\n")
7551{
7552 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7553}
7554
7555/* old command */
7556ALIAS (show_ipv6_bgp_community,
7557 show_ipv6_bgp_community2_cmd,
7558 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7559 SHOW_STR
7560 IPV6_STR
7561 BGP_STR
7562 "Display routes matching the communities\n"
7563 "community number\n"
7564 "Do not send outside local AS (well-known community)\n"
7565 "Do not advertise to any peer (well-known community)\n"
7566 "Do not export to next AS (well-known community)\n"
7567 "community number\n"
7568 "Do not send outside local AS (well-known community)\n"
7569 "Do not advertise to any peer (well-known community)\n"
7570 "Do not export to next AS (well-known community)\n")
7571
7572/* old command */
7573ALIAS (show_ipv6_bgp_community,
7574 show_ipv6_bgp_community3_cmd,
7575 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7576 SHOW_STR
7577 IPV6_STR
7578 BGP_STR
7579 "Display routes matching the communities\n"
7580 "community number\n"
7581 "Do not send outside local AS (well-known community)\n"
7582 "Do not advertise to any peer (well-known community)\n"
7583 "Do not export to next AS (well-known community)\n"
7584 "community number\n"
7585 "Do not send outside local AS (well-known community)\n"
7586 "Do not advertise to any peer (well-known community)\n"
7587 "Do not export to next AS (well-known community)\n"
7588 "community number\n"
7589 "Do not send outside local AS (well-known community)\n"
7590 "Do not advertise to any peer (well-known community)\n"
7591 "Do not export to next AS (well-known community)\n")
7592
7593/* old command */
7594ALIAS (show_ipv6_bgp_community,
7595 show_ipv6_bgp_community4_cmd,
7596 "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)",
7597 SHOW_STR
7598 IPV6_STR
7599 BGP_STR
7600 "Display routes matching the communities\n"
7601 "community number\n"
7602 "Do not send outside local AS (well-known community)\n"
7603 "Do not advertise to any peer (well-known community)\n"
7604 "Do not export to next AS (well-known community)\n"
7605 "community number\n"
7606 "Do not send outside local AS (well-known community)\n"
7607 "Do not advertise to any peer (well-known community)\n"
7608 "Do not export to next AS (well-known community)\n"
7609 "community number\n"
7610 "Do not send outside local AS (well-known community)\n"
7611 "Do not advertise to any peer (well-known community)\n"
7612 "Do not export to next AS (well-known community)\n"
7613 "community number\n"
7614 "Do not send outside local AS (well-known community)\n"
7615 "Do not advertise to any peer (well-known community)\n"
7616 "Do not export to next AS (well-known community)\n")
7617
7618DEFUN (show_bgp_community_exact,
7619 show_bgp_community_exact_cmd,
7620 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7621 SHOW_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 "Exact match of the communities")
7629{
7630 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7631}
7632
7633ALIAS (show_bgp_community_exact,
7634 show_bgp_ipv6_community_exact_cmd,
7635 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7636 SHOW_STR
7637 BGP_STR
7638 "Address family\n"
7639 "Display routes matching the communities\n"
7640 "community number\n"
7641 "Do not send outside local AS (well-known community)\n"
7642 "Do not advertise to any peer (well-known community)\n"
7643 "Do not export to next AS (well-known community)\n"
7644 "Exact match of the communities")
7645
7646ALIAS (show_bgp_community_exact,
7647 show_bgp_community2_exact_cmd,
7648 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7649 SHOW_STR
7650 BGP_STR
7651 "Display routes matching the communities\n"
7652 "community number\n"
7653 "Do not send outside local AS (well-known community)\n"
7654 "Do not advertise to any peer (well-known community)\n"
7655 "Do not export to next AS (well-known community)\n"
7656 "community number\n"
7657 "Do not send outside local AS (well-known community)\n"
7658 "Do not advertise to any peer (well-known community)\n"
7659 "Do not export to next AS (well-known community)\n"
7660 "Exact match of the communities")
7661
7662ALIAS (show_bgp_community_exact,
7663 show_bgp_ipv6_community2_exact_cmd,
7664 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7665 SHOW_STR
7666 BGP_STR
7667 "Address family\n"
7668 "Display routes matching the communities\n"
7669 "community number\n"
7670 "Do not send outside local AS (well-known community)\n"
7671 "Do not advertise to any peer (well-known community)\n"
7672 "Do not export to next AS (well-known community)\n"
7673 "community number\n"
7674 "Do not send outside local AS (well-known community)\n"
7675 "Do not advertise to any peer (well-known community)\n"
7676 "Do not export to next AS (well-known community)\n"
7677 "Exact match of the communities")
7678
7679ALIAS (show_bgp_community_exact,
7680 show_bgp_community3_exact_cmd,
7681 "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",
7682 SHOW_STR
7683 BGP_STR
7684 "Display routes matching the communities\n"
7685 "community number\n"
7686 "Do not send outside local AS (well-known community)\n"
7687 "Do not advertise to any peer (well-known community)\n"
7688 "Do not export to next AS (well-known community)\n"
7689 "community number\n"
7690 "Do not send outside local AS (well-known community)\n"
7691 "Do not advertise to any peer (well-known community)\n"
7692 "Do not export to next AS (well-known community)\n"
7693 "community number\n"
7694 "Do not send outside local AS (well-known community)\n"
7695 "Do not advertise to any peer (well-known community)\n"
7696 "Do not export to next AS (well-known community)\n"
7697 "Exact match of the communities")
7698
7699ALIAS (show_bgp_community_exact,
7700 show_bgp_ipv6_community3_exact_cmd,
7701 "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",
7702 SHOW_STR
7703 BGP_STR
7704 "Address family\n"
7705 "Display routes matching the communities\n"
7706 "community number\n"
7707 "Do not send outside local AS (well-known community)\n"
7708 "Do not advertise to any peer (well-known community)\n"
7709 "Do not export to next AS (well-known community)\n"
7710 "community number\n"
7711 "Do not send outside local AS (well-known community)\n"
7712 "Do not advertise to any peer (well-known community)\n"
7713 "Do not export to next AS (well-known community)\n"
7714 "community number\n"
7715 "Do not send outside local AS (well-known community)\n"
7716 "Do not advertise to any peer (well-known community)\n"
7717 "Do not export to next AS (well-known community)\n"
7718 "Exact match of the communities")
7719
7720ALIAS (show_bgp_community_exact,
7721 show_bgp_community4_exact_cmd,
7722 "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",
7723 SHOW_STR
7724 BGP_STR
7725 "Display routes matching the communities\n"
7726 "community number\n"
7727 "Do not send outside local AS (well-known community)\n"
7728 "Do not advertise to any peer (well-known community)\n"
7729 "Do not export to next AS (well-known community)\n"
7730 "community number\n"
7731 "Do not send outside local AS (well-known community)\n"
7732 "Do not advertise to any peer (well-known community)\n"
7733 "Do not export to next AS (well-known community)\n"
7734 "community number\n"
7735 "Do not send outside local AS (well-known community)\n"
7736 "Do not advertise to any peer (well-known community)\n"
7737 "Do not export to next AS (well-known community)\n"
7738 "community number\n"
7739 "Do not send outside local AS (well-known community)\n"
7740 "Do not advertise to any peer (well-known community)\n"
7741 "Do not export to next AS (well-known community)\n"
7742 "Exact match of the communities")
7743
7744ALIAS (show_bgp_community_exact,
7745 show_bgp_ipv6_community4_exact_cmd,
7746 "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",
7747 SHOW_STR
7748 BGP_STR
7749 "Address family\n"
7750 "Display routes matching the communities\n"
7751 "community number\n"
7752 "Do not send outside local AS (well-known community)\n"
7753 "Do not advertise to any peer (well-known community)\n"
7754 "Do not export to next AS (well-known community)\n"
7755 "community number\n"
7756 "Do not send outside local AS (well-known community)\n"
7757 "Do not advertise to any peer (well-known community)\n"
7758 "Do not export to next AS (well-known community)\n"
7759 "community number\n"
7760 "Do not send outside local AS (well-known community)\n"
7761 "Do not advertise to any peer (well-known community)\n"
7762 "Do not export to next AS (well-known community)\n"
7763 "community number\n"
7764 "Do not send outside local AS (well-known community)\n"
7765 "Do not advertise to any peer (well-known community)\n"
7766 "Do not export to next AS (well-known community)\n"
7767 "Exact match of the communities")
7768
7769/* old command */
7770DEFUN (show_ipv6_bgp_community_exact,
7771 show_ipv6_bgp_community_exact_cmd,
7772 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7773 SHOW_STR
7774 IPV6_STR
7775 BGP_STR
7776 "Display routes matching the communities\n"
7777 "community number\n"
7778 "Do not send outside local AS (well-known community)\n"
7779 "Do not advertise to any peer (well-known community)\n"
7780 "Do not export to next AS (well-known community)\n"
7781 "Exact match of the communities")
7782{
7783 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7784}
7785
7786/* old command */
7787ALIAS (show_ipv6_bgp_community_exact,
7788 show_ipv6_bgp_community2_exact_cmd,
7789 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7790 SHOW_STR
7791 IPV6_STR
7792 BGP_STR
7793 "Display routes matching the communities\n"
7794 "community number\n"
7795 "Do not send outside local AS (well-known community)\n"
7796 "Do not advertise to any peer (well-known community)\n"
7797 "Do not export to next AS (well-known community)\n"
7798 "community number\n"
7799 "Do not send outside local AS (well-known community)\n"
7800 "Do not advertise to any peer (well-known community)\n"
7801 "Do not export to next AS (well-known community)\n"
7802 "Exact match of the communities")
7803
7804/* old command */
7805ALIAS (show_ipv6_bgp_community_exact,
7806 show_ipv6_bgp_community3_exact_cmd,
7807 "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",
7808 SHOW_STR
7809 IPV6_STR
7810 BGP_STR
7811 "Display routes matching the communities\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n"
7824 "Exact match of the communities")
7825
7826/* old command */
7827ALIAS (show_ipv6_bgp_community_exact,
7828 show_ipv6_bgp_community4_exact_cmd,
7829 "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",
7830 SHOW_STR
7831 IPV6_STR
7832 BGP_STR
7833 "Display routes matching the communities\n"
7834 "community number\n"
7835 "Do not send outside local AS (well-known community)\n"
7836 "Do not advertise to any peer (well-known community)\n"
7837 "Do not export to next AS (well-known community)\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n"
7842 "community number\n"
7843 "Do not send outside local AS (well-known community)\n"
7844 "Do not advertise to any peer (well-known community)\n"
7845 "Do not export to next AS (well-known community)\n"
7846 "community number\n"
7847 "Do not send outside local AS (well-known community)\n"
7848 "Do not advertise to any peer (well-known community)\n"
7849 "Do not export to next AS (well-known community)\n"
7850 "Exact match of the communities")
7851
7852/* old command */
7853DEFUN (show_ipv6_mbgp_community,
7854 show_ipv6_mbgp_community_cmd,
7855 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7856 SHOW_STR
7857 IPV6_STR
7858 MBGP_STR
7859 "Display routes matching the communities\n"
7860 "community number\n"
7861 "Do not send outside local AS (well-known community)\n"
7862 "Do not advertise to any peer (well-known community)\n"
7863 "Do not export to next AS (well-known community)\n")
7864{
7865 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7866}
7867
7868/* old command */
7869ALIAS (show_ipv6_mbgp_community,
7870 show_ipv6_mbgp_community2_cmd,
7871 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7872 SHOW_STR
7873 IPV6_STR
7874 MBGP_STR
7875 "Display routes matching the communities\n"
7876 "community number\n"
7877 "Do not send outside local AS (well-known community)\n"
7878 "Do not advertise to any peer (well-known community)\n"
7879 "Do not export to next AS (well-known community)\n"
7880 "community number\n"
7881 "Do not send outside local AS (well-known community)\n"
7882 "Do not advertise to any peer (well-known community)\n"
7883 "Do not export to next AS (well-known community)\n")
7884
7885/* old command */
7886ALIAS (show_ipv6_mbgp_community,
7887 show_ipv6_mbgp_community3_cmd,
7888 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7889 SHOW_STR
7890 IPV6_STR
7891 MBGP_STR
7892 "Display routes matching the communities\n"
7893 "community number\n"
7894 "Do not send outside local AS (well-known community)\n"
7895 "Do not advertise to any peer (well-known community)\n"
7896 "Do not export to next AS (well-known community)\n"
7897 "community number\n"
7898 "Do not send outside local AS (well-known community)\n"
7899 "Do not advertise to any peer (well-known community)\n"
7900 "Do not export to next AS (well-known community)\n"
7901 "community number\n"
7902 "Do not send outside local AS (well-known community)\n"
7903 "Do not advertise to any peer (well-known community)\n"
7904 "Do not export to next AS (well-known community)\n")
7905
7906/* old command */
7907ALIAS (show_ipv6_mbgp_community,
7908 show_ipv6_mbgp_community4_cmd,
7909 "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)",
7910 SHOW_STR
7911 IPV6_STR
7912 MBGP_STR
7913 "Display routes matching the communities\n"
7914 "community number\n"
7915 "Do not send outside local AS (well-known community)\n"
7916 "Do not advertise to any peer (well-known community)\n"
7917 "Do not export to next AS (well-known community)\n"
7918 "community number\n"
7919 "Do not send outside local AS (well-known community)\n"
7920 "Do not advertise to any peer (well-known community)\n"
7921 "Do not export to next AS (well-known community)\n"
7922 "community number\n"
7923 "Do not send outside local AS (well-known community)\n"
7924 "Do not advertise to any peer (well-known community)\n"
7925 "Do not export to next AS (well-known community)\n"
7926 "community number\n"
7927 "Do not send outside local AS (well-known community)\n"
7928 "Do not advertise to any peer (well-known community)\n"
7929 "Do not export to next AS (well-known community)\n")
7930
7931/* old command */
7932DEFUN (show_ipv6_mbgp_community_exact,
7933 show_ipv6_mbgp_community_exact_cmd,
7934 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7935 SHOW_STR
7936 IPV6_STR
7937 MBGP_STR
7938 "Display routes matching the communities\n"
7939 "community number\n"
7940 "Do not send outside local AS (well-known community)\n"
7941 "Do not advertise to any peer (well-known community)\n"
7942 "Do not export to next AS (well-known community)\n"
7943 "Exact match of the communities")
7944{
7945 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7946}
7947
7948/* old command */
7949ALIAS (show_ipv6_mbgp_community_exact,
7950 show_ipv6_mbgp_community2_exact_cmd,
7951 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7952 SHOW_STR
7953 IPV6_STR
7954 MBGP_STR
7955 "Display routes matching the communities\n"
7956 "community number\n"
7957 "Do not send outside local AS (well-known community)\n"
7958 "Do not advertise to any peer (well-known community)\n"
7959 "Do not export to next AS (well-known community)\n"
7960 "community number\n"
7961 "Do not send outside local AS (well-known community)\n"
7962 "Do not advertise to any peer (well-known community)\n"
7963 "Do not export to next AS (well-known community)\n"
7964 "Exact match of the communities")
7965
7966/* old command */
7967ALIAS (show_ipv6_mbgp_community_exact,
7968 show_ipv6_mbgp_community3_exact_cmd,
7969 "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",
7970 SHOW_STR
7971 IPV6_STR
7972 MBGP_STR
7973 "Display routes matching the communities\n"
7974 "community number\n"
7975 "Do not send outside local AS (well-known community)\n"
7976 "Do not advertise to any peer (well-known community)\n"
7977 "Do not export to next AS (well-known community)\n"
7978 "community number\n"
7979 "Do not send outside local AS (well-known community)\n"
7980 "Do not advertise to any peer (well-known community)\n"
7981 "Do not export to next AS (well-known community)\n"
7982 "community number\n"
7983 "Do not send outside local AS (well-known community)\n"
7984 "Do not advertise to any peer (well-known community)\n"
7985 "Do not export to next AS (well-known community)\n"
7986 "Exact match of the communities")
7987
7988/* old command */
7989ALIAS (show_ipv6_mbgp_community_exact,
7990 show_ipv6_mbgp_community4_exact_cmd,
7991 "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",
7992 SHOW_STR
7993 IPV6_STR
7994 MBGP_STR
7995 "Display routes matching the communities\n"
7996 "community number\n"
7997 "Do not send outside local AS (well-known community)\n"
7998 "Do not advertise to any peer (well-known community)\n"
7999 "Do not export to next AS (well-known community)\n"
8000 "community number\n"
8001 "Do not send outside local AS (well-known community)\n"
8002 "Do not advertise to any peer (well-known community)\n"
8003 "Do not export to next AS (well-known community)\n"
8004 "community number\n"
8005 "Do not send outside local AS (well-known community)\n"
8006 "Do not advertise to any peer (well-known community)\n"
8007 "Do not export to next AS (well-known community)\n"
8008 "community number\n"
8009 "Do not send outside local AS (well-known community)\n"
8010 "Do not advertise to any peer (well-known community)\n"
8011 "Do not export to next AS (well-known community)\n"
8012 "Exact match of the communities")
8013#endif /* HAVE_IPV6 */
8014
paul94f2b392005-06-28 12:44:16 +00008015static int
paulfd79ac92004-10-13 05:06:08 +00008016bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008017 u_int16_t afi, u_char safi)
8018{
8019 struct community_list *list;
8020
hassofee6e4e2005-02-02 16:29:31 +00008021 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008022 if (list == NULL)
8023 {
8024 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8025 VTY_NEWLINE);
8026 return CMD_WARNING;
8027 }
8028
ajs5a646652004-11-05 01:25:55 +00008029 return bgp_show (vty, NULL, afi, safi,
8030 (exact ? bgp_show_type_community_list_exact :
8031 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008032}
8033
8034DEFUN (show_ip_bgp_community_list,
8035 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008036 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008037 SHOW_STR
8038 IP_STR
8039 BGP_STR
8040 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008041 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008042 "community-list name\n")
8043{
8044 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8045}
8046
8047DEFUN (show_ip_bgp_ipv4_community_list,
8048 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008049 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008050 SHOW_STR
8051 IP_STR
8052 BGP_STR
8053 "Address family\n"
8054 "Address Family modifier\n"
8055 "Address Family modifier\n"
8056 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008057 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008058 "community-list name\n")
8059{
8060 if (strncmp (argv[0], "m", 1) == 0)
8061 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8062
8063 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8064}
8065
8066DEFUN (show_ip_bgp_community_list_exact,
8067 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008068 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008069 SHOW_STR
8070 IP_STR
8071 BGP_STR
8072 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008073 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008074 "community-list name\n"
8075 "Exact match of the communities\n")
8076{
8077 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8078}
8079
8080DEFUN (show_ip_bgp_ipv4_community_list_exact,
8081 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008082 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008083 SHOW_STR
8084 IP_STR
8085 BGP_STR
8086 "Address family\n"
8087 "Address Family modifier\n"
8088 "Address Family modifier\n"
8089 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008090 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008091 "community-list name\n"
8092 "Exact match of the communities\n")
8093{
8094 if (strncmp (argv[0], "m", 1) == 0)
8095 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8096
8097 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8098}
8099
8100#ifdef HAVE_IPV6
8101DEFUN (show_bgp_community_list,
8102 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008103 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008104 SHOW_STR
8105 BGP_STR
8106 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008107 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008108 "community-list name\n")
8109{
8110 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8111}
8112
8113ALIAS (show_bgp_community_list,
8114 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008115 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008116 SHOW_STR
8117 BGP_STR
8118 "Address family\n"
8119 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008120 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008121 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008122
8123/* old command */
8124DEFUN (show_ipv6_bgp_community_list,
8125 show_ipv6_bgp_community_list_cmd,
8126 "show ipv6 bgp community-list WORD",
8127 SHOW_STR
8128 IPV6_STR
8129 BGP_STR
8130 "Display routes matching the community-list\n"
8131 "community-list name\n")
8132{
8133 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8134}
8135
8136/* old command */
8137DEFUN (show_ipv6_mbgp_community_list,
8138 show_ipv6_mbgp_community_list_cmd,
8139 "show ipv6 mbgp community-list WORD",
8140 SHOW_STR
8141 IPV6_STR
8142 MBGP_STR
8143 "Display routes matching the community-list\n"
8144 "community-list name\n")
8145{
8146 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8147}
8148
8149DEFUN (show_bgp_community_list_exact,
8150 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008151 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008152 SHOW_STR
8153 BGP_STR
8154 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008155 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008156 "community-list name\n"
8157 "Exact match of the communities\n")
8158{
8159 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8160}
8161
8162ALIAS (show_bgp_community_list_exact,
8163 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008164 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008165 SHOW_STR
8166 BGP_STR
8167 "Address family\n"
8168 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008169 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008170 "community-list name\n"
8171 "Exact match of the communities\n")
8172
8173/* old command */
8174DEFUN (show_ipv6_bgp_community_list_exact,
8175 show_ipv6_bgp_community_list_exact_cmd,
8176 "show ipv6 bgp community-list WORD exact-match",
8177 SHOW_STR
8178 IPV6_STR
8179 BGP_STR
8180 "Display routes matching the community-list\n"
8181 "community-list name\n"
8182 "Exact match of the communities\n")
8183{
8184 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8185}
8186
8187/* old command */
8188DEFUN (show_ipv6_mbgp_community_list_exact,
8189 show_ipv6_mbgp_community_list_exact_cmd,
8190 "show ipv6 mbgp community-list WORD exact-match",
8191 SHOW_STR
8192 IPV6_STR
8193 MBGP_STR
8194 "Display routes matching the community-list\n"
8195 "community-list name\n"
8196 "Exact match of the communities\n")
8197{
8198 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8199}
8200#endif /* HAVE_IPV6 */
8201
paul94f2b392005-06-28 12:44:16 +00008202static int
paulfd79ac92004-10-13 05:06:08 +00008203bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008204 safi_t safi, enum bgp_show_type type)
8205{
8206 int ret;
8207 struct prefix *p;
8208
8209 p = prefix_new();
8210
8211 ret = str2prefix (prefix, p);
8212 if (! ret)
8213 {
8214 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8215 return CMD_WARNING;
8216 }
8217
ajs5a646652004-11-05 01:25:55 +00008218 ret = bgp_show (vty, NULL, afi, safi, type, p);
8219 prefix_free(p);
8220 return ret;
paul718e3742002-12-13 20:15:29 +00008221}
8222
8223DEFUN (show_ip_bgp_prefix_longer,
8224 show_ip_bgp_prefix_longer_cmd,
8225 "show ip bgp A.B.C.D/M longer-prefixes",
8226 SHOW_STR
8227 IP_STR
8228 BGP_STR
8229 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8230 "Display route and more specific routes\n")
8231{
8232 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8233 bgp_show_type_prefix_longer);
8234}
8235
8236DEFUN (show_ip_bgp_flap_prefix_longer,
8237 show_ip_bgp_flap_prefix_longer_cmd,
8238 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8239 SHOW_STR
8240 IP_STR
8241 BGP_STR
8242 "Display flap statistics of routes\n"
8243 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8244 "Display route and more specific routes\n")
8245{
8246 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8247 bgp_show_type_flap_prefix_longer);
8248}
8249
8250DEFUN (show_ip_bgp_ipv4_prefix_longer,
8251 show_ip_bgp_ipv4_prefix_longer_cmd,
8252 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8253 SHOW_STR
8254 IP_STR
8255 BGP_STR
8256 "Address family\n"
8257 "Address Family modifier\n"
8258 "Address Family modifier\n"
8259 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8260 "Display route and more specific routes\n")
8261{
8262 if (strncmp (argv[0], "m", 1) == 0)
8263 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8264 bgp_show_type_prefix_longer);
8265
8266 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8267 bgp_show_type_prefix_longer);
8268}
8269
8270DEFUN (show_ip_bgp_flap_address,
8271 show_ip_bgp_flap_address_cmd,
8272 "show ip bgp flap-statistics A.B.C.D",
8273 SHOW_STR
8274 IP_STR
8275 BGP_STR
8276 "Display flap statistics of routes\n"
8277 "Network in the BGP routing table to display\n")
8278{
8279 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8280 bgp_show_type_flap_address);
8281}
8282
8283DEFUN (show_ip_bgp_flap_prefix,
8284 show_ip_bgp_flap_prefix_cmd,
8285 "show ip bgp flap-statistics A.B.C.D/M",
8286 SHOW_STR
8287 IP_STR
8288 BGP_STR
8289 "Display flap statistics of routes\n"
8290 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8291{
8292 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8293 bgp_show_type_flap_prefix);
8294}
8295#ifdef HAVE_IPV6
8296DEFUN (show_bgp_prefix_longer,
8297 show_bgp_prefix_longer_cmd,
8298 "show bgp X:X::X:X/M longer-prefixes",
8299 SHOW_STR
8300 BGP_STR
8301 "IPv6 prefix <network>/<length>\n"
8302 "Display route and more specific routes\n")
8303{
8304 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8305 bgp_show_type_prefix_longer);
8306}
8307
8308ALIAS (show_bgp_prefix_longer,
8309 show_bgp_ipv6_prefix_longer_cmd,
8310 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8311 SHOW_STR
8312 BGP_STR
8313 "Address family\n"
8314 "IPv6 prefix <network>/<length>\n"
8315 "Display route and more specific routes\n")
8316
8317/* old command */
8318DEFUN (show_ipv6_bgp_prefix_longer,
8319 show_ipv6_bgp_prefix_longer_cmd,
8320 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8321 SHOW_STR
8322 IPV6_STR
8323 BGP_STR
8324 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\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
8331/* old command */
8332DEFUN (show_ipv6_mbgp_prefix_longer,
8333 show_ipv6_mbgp_prefix_longer_cmd,
8334 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8335 SHOW_STR
8336 IPV6_STR
8337 MBGP_STR
8338 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8339 "Display route and more specific routes\n")
8340{
8341 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8342 bgp_show_type_prefix_longer);
8343}
8344#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008345
paul94f2b392005-06-28 12:44:16 +00008346static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008347peer_lookup_in_view (struct vty *vty, const char *view_name,
8348 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008349{
8350 int ret;
8351 struct bgp *bgp;
8352 struct peer *peer;
8353 union sockunion su;
8354
8355 /* BGP structure lookup. */
8356 if (view_name)
8357 {
8358 bgp = bgp_lookup_by_name (view_name);
8359 if (! bgp)
8360 {
8361 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8362 return NULL;
8363 }
8364 }
paul5228ad22004-06-04 17:58:18 +00008365 else
paulbb46e942003-10-24 19:02:03 +00008366 {
8367 bgp = bgp_get_default ();
8368 if (! bgp)
8369 {
8370 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8371 return NULL;
8372 }
8373 }
8374
8375 /* Get peer sockunion. */
8376 ret = str2sockunion (ip_str, &su);
8377 if (ret < 0)
8378 {
8379 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8380 return NULL;
8381 }
8382
8383 /* Peer structure lookup. */
8384 peer = peer_lookup (bgp, &su);
8385 if (! peer)
8386 {
8387 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8388 return NULL;
8389 }
8390
8391 return peer;
8392}
Paul Jakma2815e612006-09-14 02:56:07 +00008393
8394enum bgp_stats
8395{
8396 BGP_STATS_MAXBITLEN = 0,
8397 BGP_STATS_RIB,
8398 BGP_STATS_PREFIXES,
8399 BGP_STATS_TOTPLEN,
8400 BGP_STATS_UNAGGREGATEABLE,
8401 BGP_STATS_MAX_AGGREGATEABLE,
8402 BGP_STATS_AGGREGATES,
8403 BGP_STATS_SPACE,
8404 BGP_STATS_ASPATH_COUNT,
8405 BGP_STATS_ASPATH_MAXHOPS,
8406 BGP_STATS_ASPATH_TOTHOPS,
8407 BGP_STATS_ASPATH_MAXSIZE,
8408 BGP_STATS_ASPATH_TOTSIZE,
8409 BGP_STATS_ASN_HIGHEST,
8410 BGP_STATS_MAX,
8411};
paulbb46e942003-10-24 19:02:03 +00008412
Paul Jakma2815e612006-09-14 02:56:07 +00008413static const char *table_stats_strs[] =
8414{
8415 [BGP_STATS_PREFIXES] = "Total Prefixes",
8416 [BGP_STATS_TOTPLEN] = "Average prefix length",
8417 [BGP_STATS_RIB] = "Total Advertisements",
8418 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8419 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8420 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8421 [BGP_STATS_SPACE] = "Address space advertised",
8422 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8423 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8424 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8425 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8426 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8427 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8428 [BGP_STATS_MAX] = NULL,
8429};
8430
8431struct bgp_table_stats
8432{
8433 struct bgp_table *table;
8434 unsigned long long counts[BGP_STATS_MAX];
8435};
8436
8437#if 0
8438#define TALLY_SIGFIG 100000
8439static unsigned long
8440ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8441{
8442 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8443 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8444 unsigned long ret = newtot / count;
8445
8446 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
8447 return ret + 1;
8448 else
8449 return ret;
8450}
8451#endif
8452
8453static int
8454bgp_table_stats_walker (struct thread *t)
8455{
8456 struct bgp_node *rn;
8457 struct bgp_node *top;
8458 struct bgp_table_stats *ts = THREAD_ARG (t);
8459 unsigned int space = 0;
8460
8461 top = bgp_table_top (ts->table);
8462
8463 switch (top->p.family)
8464 {
8465 case AF_INET:
8466 space = IPV4_MAX_BITLEN;
8467 break;
8468 case AF_INET6:
8469 space = IPV6_MAX_BITLEN;
8470 break;
8471 }
8472
8473 ts->counts[BGP_STATS_MAXBITLEN] = space;
8474
8475 for (rn = top; rn; rn = bgp_route_next (rn))
8476 {
8477 struct bgp_info *ri;
8478 struct bgp_node *prn = rn->parent;
8479 unsigned int rinum = 0;
8480
8481 if (rn == top)
8482 continue;
8483
8484 if (!rn->info)
8485 continue;
8486
8487 ts->counts[BGP_STATS_PREFIXES]++;
8488 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
8489
8490#if 0
8491 ts->counts[BGP_STATS_AVGPLEN]
8492 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
8493 ts->counts[BGP_STATS_AVGPLEN],
8494 rn->p.prefixlen);
8495#endif
8496
8497 /* check if the prefix is included by any other announcements */
8498 while (prn && !prn->info)
8499 prn = prn->parent;
8500
8501 if (prn == NULL || prn == top)
8502 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
8503 else if (prn->info)
8504 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
8505
8506 /* announced address space */
8507 if (space)
8508 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
8509
8510 for (ri = rn->info; ri; ri = ri->next)
8511 {
8512 rinum++;
8513 ts->counts[BGP_STATS_RIB]++;
8514
8515 if (ri->attr &&
8516 (CHECK_FLAG (ri->attr->flag,
8517 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
8518 ts->counts[BGP_STATS_AGGREGATES]++;
8519
8520 /* as-path stats */
8521 if (ri->attr && ri->attr->aspath)
8522 {
8523 unsigned int hops = aspath_count_hops (ri->attr->aspath);
8524 unsigned int size = aspath_size (ri->attr->aspath);
8525 as_t highest = aspath_highest (ri->attr->aspath);
8526
8527 ts->counts[BGP_STATS_ASPATH_COUNT]++;
8528
8529 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
8530 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
8531
8532 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
8533 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
8534
8535 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
8536 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
8537#if 0
8538 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
8539 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8540 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
8541 hops);
8542 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
8543 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8544 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
8545 size);
8546#endif
8547 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
8548 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
8549 }
8550 }
8551 }
8552 return 0;
8553}
8554
8555static int
8556bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
8557{
8558 struct bgp_table_stats ts;
8559 unsigned int i;
8560
8561 if (!bgp->rib[afi][safi])
8562 {
8563 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
8564 return CMD_WARNING;
8565 }
8566
8567 memset (&ts, 0, sizeof (ts));
8568 ts.table = bgp->rib[afi][safi];
8569 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
8570
8571 vty_out (vty, "BGP %s RIB statistics%s%s",
8572 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
8573
8574 for (i = 0; i < BGP_STATS_MAX; i++)
8575 {
8576 if (!table_stats_strs[i])
8577 continue;
8578
8579 switch (i)
8580 {
8581#if 0
8582 case BGP_STATS_ASPATH_AVGHOPS:
8583 case BGP_STATS_ASPATH_AVGSIZE:
8584 case BGP_STATS_AVGPLEN:
8585 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8586 vty_out (vty, "%12.2f",
8587 (float)ts.counts[i] / (float)TALLY_SIGFIG);
8588 break;
8589#endif
8590 case BGP_STATS_ASPATH_TOTHOPS:
8591 case BGP_STATS_ASPATH_TOTSIZE:
8592 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8593 vty_out (vty, "%12.2f",
8594 ts.counts[i] ?
8595 (float)ts.counts[i] /
8596 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
8597 : 0);
8598 break;
8599 case BGP_STATS_TOTPLEN:
8600 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8601 vty_out (vty, "%12.2f",
8602 ts.counts[i] ?
8603 (float)ts.counts[i] /
8604 (float)ts.counts[BGP_STATS_PREFIXES]
8605 : 0);
8606 break;
8607 case BGP_STATS_SPACE:
8608 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8609 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
8610 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
8611 break;
8612 vty_out (vty, "%30s: ", "\% announced ");
8613 vty_out (vty, "%12.2f%s",
8614 100 * (float)ts.counts[BGP_STATS_SPACE] /
8615 (float)((u_int64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
8616 VTY_NEWLINE);
8617 vty_out (vty, "%30s: ", "/8 equivalent ");
8618 vty_out (vty, "%12.2f%s",
8619 (float)ts.counts[BGP_STATS_SPACE] /
8620 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
8621 VTY_NEWLINE);
8622 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
8623 break;
8624 vty_out (vty, "%30s: ", "/24 equivalent ");
8625 vty_out (vty, "%12.2f",
8626 (float)ts.counts[BGP_STATS_SPACE] /
8627 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
8628 break;
8629 default:
8630 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8631 vty_out (vty, "%12llu", ts.counts[i]);
8632 }
8633
8634 vty_out (vty, "%s", VTY_NEWLINE);
8635 }
8636 return CMD_SUCCESS;
8637}
8638
8639static int
8640bgp_table_stats_vty (struct vty *vty, const char *name,
8641 const char *afi_str, const char *safi_str)
8642{
8643 struct bgp *bgp;
8644 afi_t afi;
8645 safi_t safi;
8646
8647 if (name)
8648 bgp = bgp_lookup_by_name (name);
8649 else
8650 bgp = bgp_get_default ();
8651
8652 if (!bgp)
8653 {
8654 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
8655 return CMD_WARNING;
8656 }
8657 if (strncmp (afi_str, "ipv", 3) == 0)
8658 {
8659 if (strncmp (afi_str, "ipv4", 4) == 0)
8660 afi = AFI_IP;
8661 else if (strncmp (afi_str, "ipv6", 4) == 0)
8662 afi = AFI_IP6;
8663 else
8664 {
8665 vty_out (vty, "%% Invalid address family %s%s",
8666 afi_str, VTY_NEWLINE);
8667 return CMD_WARNING;
8668 }
8669 if (strncmp (safi_str, "m", 1) == 0)
8670 safi = SAFI_MULTICAST;
8671 else if (strncmp (safi_str, "u", 1) == 0)
8672 safi = SAFI_UNICAST;
8673 else if (strncmp (safi_str, "vpnv4", 5) == 0)
8674 safi = BGP_SAFI_VPNV4;
8675 else if (strncmp (safi_str, "vpnv6", 6) == 0)
8676 safi = BGP_SAFI_VPNV6;
8677 else
8678 {
8679 vty_out (vty, "%% Invalid subsequent address family %s%s",
8680 safi_str, VTY_NEWLINE);
8681 return CMD_WARNING;
8682 }
8683 }
8684 else
8685 {
8686 vty_out (vty, "%% Invalid address family %s%s",
8687 afi_str, VTY_NEWLINE);
8688 return CMD_WARNING;
8689 }
8690
8691 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
8692 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
8693 {
8694 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
8695 afi_str, safi_str, VTY_NEWLINE);
8696 return CMD_WARNING;
8697 }
8698 return bgp_table_stats (vty, bgp, afi, safi);
8699}
8700
8701DEFUN (show_bgp_statistics,
8702 show_bgp_statistics_cmd,
8703 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
8704 SHOW_STR
8705 BGP_STR
8706 "Address family\n"
8707 "Address family\n"
8708 "Address Family modifier\n"
8709 "Address Family modifier\n"
8710 "BGP RIB advertisement statistics\n")
8711{
8712 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
8713}
8714
8715ALIAS (show_bgp_statistics,
8716 show_bgp_statistics_vpnv4_cmd,
8717 "show bgp (ipv4) (vpnv4) statistics",
8718 SHOW_STR
8719 BGP_STR
8720 "Address family\n"
8721 "Address Family modifier\n"
8722 "BGP RIB advertisement statistics\n")
8723
8724DEFUN (show_bgp_statistics_view,
8725 show_bgp_statistics_view_cmd,
8726 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
8727 SHOW_STR
8728 BGP_STR
8729 "BGP view\n"
8730 "Address family\n"
8731 "Address family\n"
8732 "Address Family modifier\n"
8733 "Address Family modifier\n"
8734 "BGP RIB advertisement statistics\n")
8735{
8736 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
8737}
8738
8739ALIAS (show_bgp_statistics_view,
8740 show_bgp_statistics_view_vpnv4_cmd,
8741 "show bgp view WORD (ipv4) (vpnv4) statistics",
8742 SHOW_STR
8743 BGP_STR
8744 "BGP view\n"
8745 "Address family\n"
8746 "Address Family modifier\n"
8747 "BGP RIB advertisement statistics\n")
8748
Paul Jakmaff7924f2006-09-04 01:10:36 +00008749enum bgp_pcounts
8750{
8751 PCOUNT_ADJ_IN = 0,
8752 PCOUNT_DAMPED,
8753 PCOUNT_REMOVED,
8754 PCOUNT_HISTORY,
8755 PCOUNT_STALE,
8756 PCOUNT_VALID,
8757 PCOUNT_ALL,
8758 PCOUNT_COUNTED,
8759 PCOUNT_PFCNT, /* the figure we display to users */
8760 PCOUNT_MAX,
8761};
8762
8763static const char *pcount_strs[] =
8764{
8765 [PCOUNT_ADJ_IN] = "Adj-in",
8766 [PCOUNT_DAMPED] = "Damped",
8767 [PCOUNT_REMOVED] = "Removed",
8768 [PCOUNT_HISTORY] = "History",
8769 [PCOUNT_STALE] = "Stale",
8770 [PCOUNT_VALID] = "Valid",
8771 [PCOUNT_ALL] = "All RIB",
8772 [PCOUNT_COUNTED] = "PfxCt counted",
8773 [PCOUNT_PFCNT] = "Useable",
8774 [PCOUNT_MAX] = NULL,
8775};
8776
Paul Jakma2815e612006-09-14 02:56:07 +00008777struct peer_pcounts
8778{
8779 unsigned int count[PCOUNT_MAX];
8780 const struct peer *peer;
8781 const struct bgp_table *table;
8782};
8783
Paul Jakmaff7924f2006-09-04 01:10:36 +00008784static int
Paul Jakma2815e612006-09-14 02:56:07 +00008785bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00008786{
8787 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00008788 struct peer_pcounts *pc = THREAD_ARG (t);
8789 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008790
Paul Jakma2815e612006-09-14 02:56:07 +00008791 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008792 {
8793 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00008794 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008795
8796 for (ain = rn->adj_in; ain; ain = ain->next)
8797 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00008798 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008799
Paul Jakmaff7924f2006-09-04 01:10:36 +00008800 for (ri = rn->info; ri; ri = ri->next)
8801 {
8802 char buf[SU_ADDRSTRLEN];
8803
8804 if (ri->peer != peer)
8805 continue;
8806
Paul Jakma2815e612006-09-14 02:56:07 +00008807 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008808
8809 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00008810 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008811 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00008812 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008813 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00008814 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008815 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00008816 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008817 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00008818 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00008819 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00008820 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008821
8822 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
8823 {
Paul Jakma2815e612006-09-14 02:56:07 +00008824 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00008825 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008826 plog_warn (peer->log,
8827 "%s [pcount] %s/%d is counted but flags 0x%x",
8828 peer->host,
8829 inet_ntop(rn->p.family, &rn->p.u.prefix,
8830 buf, SU_ADDRSTRLEN),
8831 rn->p.prefixlen,
8832 ri->flags);
8833 }
8834 else
8835 {
Paul Jakma1a392d42006-09-07 00:24:49 +00008836 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008837 plog_warn (peer->log,
8838 "%s [pcount] %s/%d not counted but flags 0x%x",
8839 peer->host,
8840 inet_ntop(rn->p.family, &rn->p.u.prefix,
8841 buf, SU_ADDRSTRLEN),
8842 rn->p.prefixlen,
8843 ri->flags);
8844 }
8845 }
8846 }
Paul Jakma2815e612006-09-14 02:56:07 +00008847 return 0;
8848}
Paul Jakmaff7924f2006-09-04 01:10:36 +00008849
Paul Jakma2815e612006-09-14 02:56:07 +00008850static int
8851bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
8852{
8853 struct peer_pcounts pcounts = { .peer = peer };
8854 unsigned int i;
8855
8856 if (!peer || !peer->bgp || !peer->afc[afi][safi]
8857 || !peer->bgp->rib[afi][safi])
8858 {
8859 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8860 return CMD_WARNING;
8861 }
8862
8863 memset (&pcounts, 0, sizeof(pcounts));
8864 pcounts.peer = peer;
8865 pcounts.table = peer->bgp->rib[afi][safi];
8866
8867 /* in-place call via thread subsystem so as to record execution time
8868 * stats for the thread-walk (i.e. ensure this can't be blamed on
8869 * on just vty_read()).
8870 */
8871 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
8872
Paul Jakmaff7924f2006-09-04 01:10:36 +00008873 vty_out (vty, "Prefix counts for %s, %s%s",
8874 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
8875 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
8876 vty_out (vty, "%sCounts from RIB table walk:%s%s",
8877 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8878
8879 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00008880 vty_out (vty, "%20s: %-10d%s",
8881 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00008882
Paul Jakma2815e612006-09-14 02:56:07 +00008883 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00008884 {
8885 vty_out (vty, "%s [pcount] PfxCt drift!%s",
8886 peer->host, VTY_NEWLINE);
8887 vty_out (vty, "Please report this bug, with the above command output%s",
8888 VTY_NEWLINE);
8889 }
8890
8891 return CMD_SUCCESS;
8892}
8893
8894DEFUN (show_ip_bgp_neighbor_prefix_counts,
8895 show_ip_bgp_neighbor_prefix_counts_cmd,
8896 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8897 SHOW_STR
8898 IP_STR
8899 BGP_STR
8900 "Detailed information on TCP and BGP neighbor connections\n"
8901 "Neighbor to display information about\n"
8902 "Neighbor to display information about\n"
8903 "Display detailed prefix count information\n")
8904{
8905 struct peer *peer;
8906
8907 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8908 if (! peer)
8909 return CMD_WARNING;
8910
8911 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
8912}
8913
8914DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
8915 show_bgp_ipv6_neighbor_prefix_counts_cmd,
8916 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8917 SHOW_STR
8918 BGP_STR
8919 "Address family\n"
8920 "Detailed information on TCP and BGP neighbor connections\n"
8921 "Neighbor to display information about\n"
8922 "Neighbor to display information about\n"
8923 "Display detailed prefix count information\n")
8924{
8925 struct peer *peer;
8926
8927 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8928 if (! peer)
8929 return CMD_WARNING;
8930
8931 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
8932}
8933
8934DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
8935 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
8936 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8937 SHOW_STR
8938 IP_STR
8939 BGP_STR
8940 "Address family\n"
8941 "Address Family modifier\n"
8942 "Address Family modifier\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[1]);
8951 if (! peer)
8952 return CMD_WARNING;
8953
8954 if (strncmp (argv[0], "m", 1) == 0)
8955 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
8956
8957 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
8958}
8959
8960DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
8961 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
8962 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8963 SHOW_STR
8964 IP_STR
8965 BGP_STR
8966 "Address family\n"
8967 "Address Family modifier\n"
8968 "Address Family modifier\n"
8969 "Detailed information on TCP and BGP neighbor connections\n"
8970 "Neighbor to display information about\n"
8971 "Neighbor to display information about\n"
8972 "Display detailed prefix count information\n")
8973{
8974 struct peer *peer;
8975
8976 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8977 if (! peer)
8978 return CMD_WARNING;
8979
8980 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
8981}
8982
8983
paul94f2b392005-06-28 12:44:16 +00008984static void
paul718e3742002-12-13 20:15:29 +00008985show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8986 int in)
8987{
8988 struct bgp_table *table;
8989 struct bgp_adj_in *ain;
8990 struct bgp_adj_out *adj;
8991 unsigned long output_count;
8992 struct bgp_node *rn;
8993 int header1 = 1;
8994 struct bgp *bgp;
8995 int header2 = 1;
8996
paulbb46e942003-10-24 19:02:03 +00008997 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008998
8999 if (! bgp)
9000 return;
9001
9002 table = bgp->rib[afi][safi];
9003
9004 output_count = 0;
9005
9006 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9007 PEER_STATUS_DEFAULT_ORIGINATE))
9008 {
9009 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 +00009010 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9011 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009012
9013 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9014 VTY_NEWLINE, VTY_NEWLINE);
9015 header1 = 0;
9016 }
9017
9018 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9019 if (in)
9020 {
9021 for (ain = rn->adj_in; ain; ain = ain->next)
9022 if (ain->peer == peer)
9023 {
9024 if (header1)
9025 {
9026 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 +00009027 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9028 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009029 header1 = 0;
9030 }
9031 if (header2)
9032 {
9033 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9034 header2 = 0;
9035 }
9036 if (ain->attr)
9037 {
9038 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9039 output_count++;
9040 }
9041 }
9042 }
9043 else
9044 {
9045 for (adj = rn->adj_out; adj; adj = adj->next)
9046 if (adj->peer == peer)
9047 {
9048 if (header1)
9049 {
9050 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 +00009051 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9052 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009053 header1 = 0;
9054 }
9055 if (header2)
9056 {
9057 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9058 header2 = 0;
9059 }
9060 if (adj->attr)
9061 {
9062 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9063 output_count++;
9064 }
9065 }
9066 }
9067
9068 if (output_count != 0)
9069 vty_out (vty, "%sTotal number of prefixes %ld%s",
9070 VTY_NEWLINE, output_count, VTY_NEWLINE);
9071}
9072
paul94f2b392005-06-28 12:44:16 +00009073static int
paulbb46e942003-10-24 19:02:03 +00009074peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9075{
paul718e3742002-12-13 20:15:29 +00009076 if (! peer || ! peer->afc[afi][safi])
9077 {
9078 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9079 return CMD_WARNING;
9080 }
9081
9082 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9083 {
9084 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9085 VTY_NEWLINE);
9086 return CMD_WARNING;
9087 }
9088
9089 show_adj_route (vty, peer, afi, safi, in);
9090
9091 return CMD_SUCCESS;
9092}
9093
9094DEFUN (show_ip_bgp_neighbor_advertised_route,
9095 show_ip_bgp_neighbor_advertised_route_cmd,
9096 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9097 SHOW_STR
9098 IP_STR
9099 BGP_STR
9100 "Detailed information on TCP and BGP neighbor connections\n"
9101 "Neighbor to display information about\n"
9102 "Neighbor to display information about\n"
9103 "Display the routes advertised to a BGP neighbor\n")
9104{
paulbb46e942003-10-24 19:02:03 +00009105 struct peer *peer;
9106
9107 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9108 if (! peer)
9109 return CMD_WARNING;
9110
9111 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009112}
9113
9114DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9115 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9116 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9117 SHOW_STR
9118 IP_STR
9119 BGP_STR
9120 "Address family\n"
9121 "Address Family modifier\n"
9122 "Address Family modifier\n"
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;
paul718e3742002-12-13 20:15:29 +00009129
paulbb46e942003-10-24 19:02:03 +00009130 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9131 if (! peer)
9132 return CMD_WARNING;
9133
9134 if (strncmp (argv[0], "m", 1) == 0)
9135 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9136
9137 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009138}
9139
9140#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009141DEFUN (show_bgp_view_neighbor_advertised_route,
9142 show_bgp_view_neighbor_advertised_route_cmd,
9143 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9144 SHOW_STR
9145 BGP_STR
9146 "BGP view\n"
9147 "View name\n"
9148 "Detailed information on TCP and BGP neighbor connections\n"
9149 "Neighbor to display information about\n"
9150 "Neighbor to display information about\n"
9151 "Display the routes advertised to a BGP neighbor\n")
9152{
9153 struct peer *peer;
9154
9155 if (argc == 2)
9156 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9157 else
9158 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9159
9160 if (! peer)
9161 return CMD_WARNING;
9162
9163 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9164}
9165
9166ALIAS (show_bgp_view_neighbor_advertised_route,
9167 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9168 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9169 SHOW_STR
9170 BGP_STR
9171 "BGP view\n"
9172 "View name\n"
9173 "Address family\n"
9174 "Detailed information on TCP and BGP neighbor connections\n"
9175 "Neighbor to display information about\n"
9176 "Neighbor to display information about\n"
9177 "Display the routes advertised to a BGP neighbor\n")
9178
9179DEFUN (show_bgp_view_neighbor_received_routes,
9180 show_bgp_view_neighbor_received_routes_cmd,
9181 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9182 SHOW_STR
9183 BGP_STR
9184 "BGP view\n"
9185 "View name\n"
9186 "Detailed information on TCP and BGP neighbor connections\n"
9187 "Neighbor to display information about\n"
9188 "Neighbor to display information about\n"
9189 "Display the received routes from neighbor\n")
9190{
9191 struct peer *peer;
9192
9193 if (argc == 2)
9194 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9195 else
9196 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9197
9198 if (! peer)
9199 return CMD_WARNING;
9200
9201 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9202}
9203
9204ALIAS (show_bgp_view_neighbor_received_routes,
9205 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9206 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9207 SHOW_STR
9208 BGP_STR
9209 "BGP view\n"
9210 "View name\n"
9211 "Address family\n"
9212 "Detailed information on TCP and BGP neighbor connections\n"
9213 "Neighbor to display information about\n"
9214 "Neighbor to display information about\n"
9215 "Display the received routes from neighbor\n")
9216
9217ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009218 show_bgp_neighbor_advertised_route_cmd,
9219 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9220 SHOW_STR
9221 BGP_STR
9222 "Detailed information on TCP and BGP neighbor connections\n"
9223 "Neighbor to display information about\n"
9224 "Neighbor to display information about\n"
9225 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009226
9227ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009228 show_bgp_ipv6_neighbor_advertised_route_cmd,
9229 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9230 SHOW_STR
9231 BGP_STR
9232 "Address family\n"
9233 "Detailed information on TCP and BGP neighbor connections\n"
9234 "Neighbor to display information about\n"
9235 "Neighbor to display information about\n"
9236 "Display the routes advertised to a BGP neighbor\n")
9237
9238/* old command */
paulbb46e942003-10-24 19:02:03 +00009239ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009240 ipv6_bgp_neighbor_advertised_route_cmd,
9241 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9242 SHOW_STR
9243 IPV6_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
paul718e3742002-12-13 20:15:29 +00009250/* old command */
9251DEFUN (ipv6_mbgp_neighbor_advertised_route,
9252 ipv6_mbgp_neighbor_advertised_route_cmd,
9253 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9254 SHOW_STR
9255 IPV6_STR
9256 MBGP_STR
9257 "Detailed information on TCP and BGP neighbor connections\n"
9258 "Neighbor to display information about\n"
9259 "Neighbor to display information about\n"
9260 "Display the routes advertised to a BGP neighbor\n")
9261{
paulbb46e942003-10-24 19:02:03 +00009262 struct peer *peer;
9263
9264 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9265 if (! peer)
9266 return CMD_WARNING;
9267
9268 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009269}
9270#endif /* HAVE_IPV6 */
9271
9272DEFUN (show_ip_bgp_neighbor_received_routes,
9273 show_ip_bgp_neighbor_received_routes_cmd,
9274 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9275 SHOW_STR
9276 IP_STR
9277 BGP_STR
9278 "Detailed information on TCP and BGP neighbor connections\n"
9279 "Neighbor to display information about\n"
9280 "Neighbor to display information about\n"
9281 "Display the received routes from neighbor\n")
9282{
paulbb46e942003-10-24 19:02:03 +00009283 struct peer *peer;
9284
9285 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9286 if (! peer)
9287 return CMD_WARNING;
9288
9289 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009290}
9291
9292DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9293 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9294 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9295 SHOW_STR
9296 IP_STR
9297 BGP_STR
9298 "Address family\n"
9299 "Address Family modifier\n"
9300 "Address Family modifier\n"
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;
paul718e3742002-12-13 20:15:29 +00009307
paulbb46e942003-10-24 19:02:03 +00009308 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9309 if (! peer)
9310 return CMD_WARNING;
9311
9312 if (strncmp (argv[0], "m", 1) == 0)
9313 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9314
9315 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009316}
9317
9318DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9319 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9320 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9321 SHOW_STR
9322 IP_STR
9323 BGP_STR
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 information received from a BGP neighbor\n"
9328 "Display the prefixlist filter\n")
9329{
9330 char name[BUFSIZ];
9331 union sockunion *su;
9332 struct peer *peer;
9333 int count;
9334
9335 su = sockunion_str2su (argv[0]);
9336 if (su == NULL)
9337 return CMD_WARNING;
9338
9339 peer = peer_lookup (NULL, su);
9340 if (! peer)
9341 return CMD_WARNING;
9342
9343 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9344 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9345 if (count)
9346 {
9347 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9348 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9349 }
9350
9351 return CMD_SUCCESS;
9352}
9353
9354DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9355 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9356 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9357 SHOW_STR
9358 IP_STR
9359 BGP_STR
9360 "Address family\n"
9361 "Address Family modifier\n"
9362 "Address Family modifier\n"
9363 "Detailed information on TCP and BGP neighbor connections\n"
9364 "Neighbor to display information about\n"
9365 "Neighbor to display information about\n"
9366 "Display information received from a BGP neighbor\n"
9367 "Display the prefixlist filter\n")
9368{
9369 char name[BUFSIZ];
9370 union sockunion *su;
9371 struct peer *peer;
9372 int count;
9373
9374 su = sockunion_str2su (argv[1]);
9375 if (su == NULL)
9376 return CMD_WARNING;
9377
9378 peer = peer_lookup (NULL, su);
9379 if (! peer)
9380 return CMD_WARNING;
9381
9382 if (strncmp (argv[0], "m", 1) == 0)
9383 {
9384 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9385 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9386 if (count)
9387 {
9388 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9389 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9390 }
9391 }
9392 else
9393 {
9394 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9395 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9396 if (count)
9397 {
9398 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9399 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9400 }
9401 }
9402
9403 return CMD_SUCCESS;
9404}
9405
9406
9407#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009408ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009409 show_bgp_neighbor_received_routes_cmd,
9410 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9411 SHOW_STR
9412 BGP_STR
9413 "Detailed information on TCP and BGP neighbor connections\n"
9414 "Neighbor to display information about\n"
9415 "Neighbor to display information about\n"
9416 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009417
paulbb46e942003-10-24 19:02:03 +00009418ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009419 show_bgp_ipv6_neighbor_received_routes_cmd,
9420 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9421 SHOW_STR
9422 BGP_STR
9423 "Address family\n"
9424 "Detailed information on TCP and BGP neighbor connections\n"
9425 "Neighbor to display information about\n"
9426 "Neighbor to display information about\n"
9427 "Display the received routes from neighbor\n")
9428
9429DEFUN (show_bgp_neighbor_received_prefix_filter,
9430 show_bgp_neighbor_received_prefix_filter_cmd,
9431 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9432 SHOW_STR
9433 BGP_STR
9434 "Detailed information on TCP and BGP neighbor connections\n"
9435 "Neighbor to display information about\n"
9436 "Neighbor to display information about\n"
9437 "Display information received from a BGP neighbor\n"
9438 "Display the prefixlist filter\n")
9439{
9440 char name[BUFSIZ];
9441 union sockunion *su;
9442 struct peer *peer;
9443 int count;
9444
9445 su = sockunion_str2su (argv[0]);
9446 if (su == NULL)
9447 return CMD_WARNING;
9448
9449 peer = peer_lookup (NULL, su);
9450 if (! peer)
9451 return CMD_WARNING;
9452
9453 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9454 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9455 if (count)
9456 {
9457 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9458 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9459 }
9460
9461 return CMD_SUCCESS;
9462}
9463
9464ALIAS (show_bgp_neighbor_received_prefix_filter,
9465 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
9466 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9467 SHOW_STR
9468 BGP_STR
9469 "Address family\n"
9470 "Detailed information on TCP and BGP neighbor connections\n"
9471 "Neighbor to display information about\n"
9472 "Neighbor to display information about\n"
9473 "Display information received from a BGP neighbor\n"
9474 "Display the prefixlist filter\n")
9475
9476/* old command */
paulbb46e942003-10-24 19:02:03 +00009477ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009478 ipv6_bgp_neighbor_received_routes_cmd,
9479 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9480 SHOW_STR
9481 IPV6_STR
9482 BGP_STR
9483 "Detailed information on TCP and BGP neighbor connections\n"
9484 "Neighbor to display information about\n"
9485 "Neighbor to display information about\n"
9486 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009487
9488/* old command */
9489DEFUN (ipv6_mbgp_neighbor_received_routes,
9490 ipv6_mbgp_neighbor_received_routes_cmd,
9491 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9492 SHOW_STR
9493 IPV6_STR
9494 MBGP_STR
9495 "Detailed information on TCP and BGP neighbor connections\n"
9496 "Neighbor to display information about\n"
9497 "Neighbor to display information about\n"
9498 "Display the received routes from neighbor\n")
9499{
paulbb46e942003-10-24 19:02:03 +00009500 struct peer *peer;
9501
9502 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9503 if (! peer)
9504 return CMD_WARNING;
9505
9506 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00009507}
paulbb46e942003-10-24 19:02:03 +00009508
9509DEFUN (show_bgp_view_neighbor_received_prefix_filter,
9510 show_bgp_view_neighbor_received_prefix_filter_cmd,
9511 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9512 SHOW_STR
9513 BGP_STR
9514 "BGP view\n"
9515 "View name\n"
9516 "Detailed information on TCP and BGP neighbor connections\n"
9517 "Neighbor to display information about\n"
9518 "Neighbor to display information about\n"
9519 "Display information received from a BGP neighbor\n"
9520 "Display the prefixlist filter\n")
9521{
9522 char name[BUFSIZ];
9523 union sockunion *su;
9524 struct peer *peer;
9525 struct bgp *bgp;
9526 int count;
9527
9528 /* BGP structure lookup. */
9529 bgp = bgp_lookup_by_name (argv[0]);
9530 if (bgp == NULL)
9531 {
9532 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9533 return CMD_WARNING;
9534 }
9535
9536 su = sockunion_str2su (argv[1]);
9537 if (su == NULL)
9538 return CMD_WARNING;
9539
9540 peer = peer_lookup (bgp, su);
9541 if (! peer)
9542 return CMD_WARNING;
9543
9544 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9545 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9546 if (count)
9547 {
9548 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9549 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9550 }
9551
9552 return CMD_SUCCESS;
9553}
9554
9555ALIAS (show_bgp_view_neighbor_received_prefix_filter,
9556 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
9557 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9558 SHOW_STR
9559 BGP_STR
9560 "BGP view\n"
9561 "View name\n"
9562 "Address family\n"
9563 "Detailed information on TCP and BGP neighbor connections\n"
9564 "Neighbor to display information about\n"
9565 "Neighbor to display information about\n"
9566 "Display information received from a BGP neighbor\n"
9567 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00009568#endif /* HAVE_IPV6 */
9569
paul94f2b392005-06-28 12:44:16 +00009570static int
paulbb46e942003-10-24 19:02:03 +00009571bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009572 safi_t safi, enum bgp_show_type type)
9573{
paul718e3742002-12-13 20:15:29 +00009574 if (! peer || ! peer->afc[afi][safi])
9575 {
9576 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009577 return CMD_WARNING;
9578 }
9579
ajs5a646652004-11-05 01:25:55 +00009580 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00009581}
9582
9583DEFUN (show_ip_bgp_neighbor_routes,
9584 show_ip_bgp_neighbor_routes_cmd,
9585 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
9586 SHOW_STR
9587 IP_STR
9588 BGP_STR
9589 "Detailed information on TCP and BGP neighbor connections\n"
9590 "Neighbor to display information about\n"
9591 "Neighbor to display information about\n"
9592 "Display routes learned from neighbor\n")
9593{
paulbb46e942003-10-24 19:02:03 +00009594 struct peer *peer;
9595
9596 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9597 if (! peer)
9598 return CMD_WARNING;
9599
9600 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009601 bgp_show_type_neighbor);
9602}
9603
9604DEFUN (show_ip_bgp_neighbor_flap,
9605 show_ip_bgp_neighbor_flap_cmd,
9606 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9607 SHOW_STR
9608 IP_STR
9609 BGP_STR
9610 "Detailed information on TCP and BGP neighbor connections\n"
9611 "Neighbor to display information about\n"
9612 "Neighbor to display information about\n"
9613 "Display flap statistics of the routes learned from neighbor\n")
9614{
paulbb46e942003-10-24 19:02:03 +00009615 struct peer *peer;
9616
9617 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9618 if (! peer)
9619 return CMD_WARNING;
9620
9621 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009622 bgp_show_type_flap_neighbor);
9623}
9624
9625DEFUN (show_ip_bgp_neighbor_damp,
9626 show_ip_bgp_neighbor_damp_cmd,
9627 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9628 SHOW_STR
9629 IP_STR
9630 BGP_STR
9631 "Detailed information on TCP and BGP neighbor connections\n"
9632 "Neighbor to display information about\n"
9633 "Neighbor to display information about\n"
9634 "Display the dampened routes received from neighbor\n")
9635{
paulbb46e942003-10-24 19:02:03 +00009636 struct peer *peer;
9637
9638 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9639 if (! peer)
9640 return CMD_WARNING;
9641
9642 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009643 bgp_show_type_damp_neighbor);
9644}
9645
9646DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9647 show_ip_bgp_ipv4_neighbor_routes_cmd,
9648 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9649 SHOW_STR
9650 IP_STR
9651 BGP_STR
9652 "Address family\n"
9653 "Address Family modifier\n"
9654 "Address Family modifier\n"
9655 "Detailed information on TCP and BGP neighbor connections\n"
9656 "Neighbor to display information about\n"
9657 "Neighbor to display information about\n"
9658 "Display routes learned from neighbor\n")
9659{
paulbb46e942003-10-24 19:02:03 +00009660 struct peer *peer;
9661
9662 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9663 if (! peer)
9664 return CMD_WARNING;
9665
paul718e3742002-12-13 20:15:29 +00009666 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009667 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009668 bgp_show_type_neighbor);
9669
paulbb46e942003-10-24 19:02:03 +00009670 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009671 bgp_show_type_neighbor);
9672}
paulbb46e942003-10-24 19:02:03 +00009673
paulfee0f4c2004-09-13 05:12:46 +00009674DEFUN (show_ip_bgp_view_rsclient,
9675 show_ip_bgp_view_rsclient_cmd,
9676 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9677 SHOW_STR
9678 IP_STR
9679 BGP_STR
9680 "BGP view\n"
9681 "BGP view name\n"
9682 "Information about Route Server Client\n"
9683 NEIGHBOR_ADDR_STR)
9684{
9685 struct bgp_table *table;
9686 struct peer *peer;
9687
9688 if (argc == 2)
9689 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9690 else
9691 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9692
9693 if (! peer)
9694 return CMD_WARNING;
9695
9696 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9697 {
9698 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9699 VTY_NEWLINE);
9700 return CMD_WARNING;
9701 }
9702
9703 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9704 PEER_FLAG_RSERVER_CLIENT))
9705 {
9706 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9707 VTY_NEWLINE);
9708 return CMD_WARNING;
9709 }
9710
9711 table = peer->rib[AFI_IP][SAFI_UNICAST];
9712
ajs5a646652004-11-05 01:25:55 +00009713 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009714}
9715
9716ALIAS (show_ip_bgp_view_rsclient,
9717 show_ip_bgp_rsclient_cmd,
9718 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9719 SHOW_STR
9720 IP_STR
9721 BGP_STR
9722 "Information about Route Server Client\n"
9723 NEIGHBOR_ADDR_STR)
9724
9725DEFUN (show_ip_bgp_view_rsclient_route,
9726 show_ip_bgp_view_rsclient_route_cmd,
9727 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9728 SHOW_STR
9729 IP_STR
9730 BGP_STR
9731 "BGP view\n"
9732 "BGP view name\n"
9733 "Information about Route Server Client\n"
9734 NEIGHBOR_ADDR_STR
9735 "Network in the BGP routing table to display\n")
9736{
9737 struct bgp *bgp;
9738 struct peer *peer;
9739
9740 /* BGP structure lookup. */
9741 if (argc == 3)
9742 {
9743 bgp = bgp_lookup_by_name (argv[0]);
9744 if (bgp == NULL)
9745 {
9746 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9747 return CMD_WARNING;
9748 }
9749 }
9750 else
9751 {
9752 bgp = bgp_get_default ();
9753 if (bgp == NULL)
9754 {
9755 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9756 return CMD_WARNING;
9757 }
9758 }
9759
9760 if (argc == 3)
9761 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9762 else
9763 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9764
9765 if (! peer)
9766 return CMD_WARNING;
9767
9768 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9769 {
9770 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9771 VTY_NEWLINE);
9772 return CMD_WARNING;
9773}
9774
9775 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9776 PEER_FLAG_RSERVER_CLIENT))
9777 {
9778 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9779 VTY_NEWLINE);
9780 return CMD_WARNING;
9781 }
9782
9783 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9784 (argc == 3) ? argv[2] : argv[1],
9785 AFI_IP, SAFI_UNICAST, NULL, 0);
9786}
9787
9788ALIAS (show_ip_bgp_view_rsclient_route,
9789 show_ip_bgp_rsclient_route_cmd,
9790 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9791 SHOW_STR
9792 IP_STR
9793 BGP_STR
9794 "Information about Route Server Client\n"
9795 NEIGHBOR_ADDR_STR
9796 "Network in the BGP routing table to display\n")
9797
9798DEFUN (show_ip_bgp_view_rsclient_prefix,
9799 show_ip_bgp_view_rsclient_prefix_cmd,
9800 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9801 SHOW_STR
9802 IP_STR
9803 BGP_STR
9804 "BGP view\n"
9805 "BGP view name\n"
9806 "Information about Route Server Client\n"
9807 NEIGHBOR_ADDR_STR
9808 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9809{
9810 struct bgp *bgp;
9811 struct peer *peer;
9812
9813 /* BGP structure lookup. */
9814 if (argc == 3)
9815 {
9816 bgp = bgp_lookup_by_name (argv[0]);
9817 if (bgp == NULL)
9818 {
9819 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9820 return CMD_WARNING;
9821 }
9822 }
9823 else
9824 {
9825 bgp = bgp_get_default ();
9826 if (bgp == NULL)
9827 {
9828 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9829 return CMD_WARNING;
9830 }
9831 }
9832
9833 if (argc == 3)
9834 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9835 else
9836 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9837
9838 if (! peer)
9839 return CMD_WARNING;
9840
9841 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9842 {
9843 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9844 VTY_NEWLINE);
9845 return CMD_WARNING;
9846}
9847
9848 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9849 PEER_FLAG_RSERVER_CLIENT))
9850{
9851 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9852 VTY_NEWLINE);
9853 return CMD_WARNING;
9854 }
9855
9856 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9857 (argc == 3) ? argv[2] : argv[1],
9858 AFI_IP, SAFI_UNICAST, NULL, 1);
9859}
9860
9861ALIAS (show_ip_bgp_view_rsclient_prefix,
9862 show_ip_bgp_rsclient_prefix_cmd,
9863 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9864 SHOW_STR
9865 IP_STR
9866 BGP_STR
9867 "Information about Route Server Client\n"
9868 NEIGHBOR_ADDR_STR
9869 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9870
9871
paul718e3742002-12-13 20:15:29 +00009872#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009873DEFUN (show_bgp_view_neighbor_routes,
9874 show_bgp_view_neighbor_routes_cmd,
9875 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9876 SHOW_STR
9877 BGP_STR
9878 "BGP view\n"
9879 "BGP view name\n"
9880 "Detailed information on TCP and BGP neighbor connections\n"
9881 "Neighbor to display information about\n"
9882 "Neighbor to display information about\n"
9883 "Display routes learned from neighbor\n")
9884{
9885 struct peer *peer;
9886
9887 if (argc == 2)
9888 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9889 else
9890 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9891
9892 if (! peer)
9893 return CMD_WARNING;
9894
9895 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9896 bgp_show_type_neighbor);
9897}
9898
9899ALIAS (show_bgp_view_neighbor_routes,
9900 show_bgp_view_ipv6_neighbor_routes_cmd,
9901 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9902 SHOW_STR
9903 BGP_STR
9904 "BGP view\n"
9905 "BGP view name\n"
9906 "Address family\n"
9907 "Detailed information on TCP and BGP neighbor connections\n"
9908 "Neighbor to display information about\n"
9909 "Neighbor to display information about\n"
9910 "Display routes learned from neighbor\n")
9911
9912DEFUN (show_bgp_view_neighbor_damp,
9913 show_bgp_view_neighbor_damp_cmd,
9914 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9915 SHOW_STR
9916 BGP_STR
9917 "BGP view\n"
9918 "BGP view name\n"
9919 "Detailed information on TCP and BGP neighbor connections\n"
9920 "Neighbor to display information about\n"
9921 "Neighbor to display information about\n"
9922 "Display the dampened routes received from neighbor\n")
9923{
9924 struct peer *peer;
9925
9926 if (argc == 2)
9927 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9928 else
9929 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9930
9931 if (! peer)
9932 return CMD_WARNING;
9933
9934 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9935 bgp_show_type_damp_neighbor);
9936}
9937
9938ALIAS (show_bgp_view_neighbor_damp,
9939 show_bgp_view_ipv6_neighbor_damp_cmd,
9940 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9941 SHOW_STR
9942 BGP_STR
9943 "BGP view\n"
9944 "BGP view name\n"
9945 "Address family\n"
9946 "Detailed information on TCP and BGP neighbor connections\n"
9947 "Neighbor to display information about\n"
9948 "Neighbor to display information about\n"
9949 "Display the dampened routes received from neighbor\n")
9950
9951DEFUN (show_bgp_view_neighbor_flap,
9952 show_bgp_view_neighbor_flap_cmd,
9953 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9954 SHOW_STR
9955 BGP_STR
9956 "BGP view\n"
9957 "BGP view name\n"
9958 "Detailed information on TCP and BGP neighbor connections\n"
9959 "Neighbor to display information about\n"
9960 "Neighbor to display information about\n"
9961 "Display flap statistics of the routes learned from neighbor\n")
9962{
9963 struct peer *peer;
9964
9965 if (argc == 2)
9966 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9967 else
9968 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9969
9970 if (! peer)
9971 return CMD_WARNING;
9972
9973 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9974 bgp_show_type_flap_neighbor);
9975}
9976
9977ALIAS (show_bgp_view_neighbor_flap,
9978 show_bgp_view_ipv6_neighbor_flap_cmd,
9979 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9980 SHOW_STR
9981 BGP_STR
9982 "BGP view\n"
9983 "BGP view name\n"
9984 "Address family\n"
9985 "Detailed information on TCP and BGP neighbor connections\n"
9986 "Neighbor to display information about\n"
9987 "Neighbor to display information about\n"
9988 "Display flap statistics of the routes learned from neighbor\n")
9989
9990ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009991 show_bgp_neighbor_routes_cmd,
9992 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9993 SHOW_STR
9994 BGP_STR
9995 "Detailed information on TCP and BGP neighbor connections\n"
9996 "Neighbor to display information about\n"
9997 "Neighbor to display information about\n"
9998 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009999
paulbb46e942003-10-24 19:02:03 +000010000
10001ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010002 show_bgp_ipv6_neighbor_routes_cmd,
10003 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10004 SHOW_STR
10005 BGP_STR
10006 "Address family\n"
10007 "Detailed information on TCP and BGP neighbor connections\n"
10008 "Neighbor to display information about\n"
10009 "Neighbor to display information about\n"
10010 "Display routes learned from neighbor\n")
10011
10012/* old command */
paulbb46e942003-10-24 19:02:03 +000010013ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010014 ipv6_bgp_neighbor_routes_cmd,
10015 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10016 SHOW_STR
10017 IPV6_STR
10018 BGP_STR
10019 "Detailed information on TCP and BGP neighbor connections\n"
10020 "Neighbor to display information about\n"
10021 "Neighbor to display information about\n"
10022 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010023
10024/* old command */
10025DEFUN (ipv6_mbgp_neighbor_routes,
10026 ipv6_mbgp_neighbor_routes_cmd,
10027 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10028 SHOW_STR
10029 IPV6_STR
10030 MBGP_STR
10031 "Detailed information on TCP and BGP neighbor connections\n"
10032 "Neighbor to display information about\n"
10033 "Neighbor to display information about\n"
10034 "Display routes learned from neighbor\n")
10035{
paulbb46e942003-10-24 19:02:03 +000010036 struct peer *peer;
10037
10038 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10039 if (! peer)
10040 return CMD_WARNING;
10041
10042 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010043 bgp_show_type_neighbor);
10044}
paulbb46e942003-10-24 19:02:03 +000010045
10046ALIAS (show_bgp_view_neighbor_flap,
10047 show_bgp_neighbor_flap_cmd,
10048 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10049 SHOW_STR
10050 BGP_STR
10051 "Detailed information on TCP and BGP neighbor connections\n"
10052 "Neighbor to display information about\n"
10053 "Neighbor to display information about\n"
10054 "Display flap statistics of the routes learned from neighbor\n")
10055
10056ALIAS (show_bgp_view_neighbor_flap,
10057 show_bgp_ipv6_neighbor_flap_cmd,
10058 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10059 SHOW_STR
10060 BGP_STR
10061 "Address family\n"
10062 "Detailed information on TCP and BGP neighbor connections\n"
10063 "Neighbor to display information about\n"
10064 "Neighbor to display information about\n"
10065 "Display flap statistics of the routes learned from neighbor\n")
10066
10067ALIAS (show_bgp_view_neighbor_damp,
10068 show_bgp_neighbor_damp_cmd,
10069 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10070 SHOW_STR
10071 BGP_STR
10072 "Detailed information on TCP and BGP neighbor connections\n"
10073 "Neighbor to display information about\n"
10074 "Neighbor to display information about\n"
10075 "Display the dampened routes received from neighbor\n")
10076
10077ALIAS (show_bgp_view_neighbor_damp,
10078 show_bgp_ipv6_neighbor_damp_cmd,
10079 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10080 SHOW_STR
10081 BGP_STR
10082 "Address family\n"
10083 "Detailed information on TCP and BGP neighbor connections\n"
10084 "Neighbor to display information about\n"
10085 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010086 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010087
10088DEFUN (show_bgp_view_rsclient,
10089 show_bgp_view_rsclient_cmd,
10090 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10091 SHOW_STR
10092 BGP_STR
10093 "BGP view\n"
10094 "BGP view name\n"
10095 "Information about Route Server Client\n"
10096 NEIGHBOR_ADDR_STR)
10097{
10098 struct bgp_table *table;
10099 struct peer *peer;
10100
10101 if (argc == 2)
10102 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10103 else
10104 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10105
10106 if (! peer)
10107 return CMD_WARNING;
10108
10109 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10110 {
10111 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10112 VTY_NEWLINE);
10113 return CMD_WARNING;
10114 }
10115
10116 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10117 PEER_FLAG_RSERVER_CLIENT))
10118 {
10119 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10120 VTY_NEWLINE);
10121 return CMD_WARNING;
10122 }
10123
10124 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10125
ajs5a646652004-11-05 01:25:55 +000010126 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010127}
10128
10129ALIAS (show_bgp_view_rsclient,
10130 show_bgp_rsclient_cmd,
10131 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10132 SHOW_STR
10133 BGP_STR
10134 "Information about Route Server Client\n"
10135 NEIGHBOR_ADDR_STR)
10136
10137DEFUN (show_bgp_view_rsclient_route,
10138 show_bgp_view_rsclient_route_cmd,
10139 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10140 SHOW_STR
10141 BGP_STR
10142 "BGP view\n"
10143 "BGP view name\n"
10144 "Information about Route Server Client\n"
10145 NEIGHBOR_ADDR_STR
10146 "Network in the BGP routing table to display\n")
10147{
10148 struct bgp *bgp;
10149 struct peer *peer;
10150
10151 /* BGP structure lookup. */
10152 if (argc == 3)
10153 {
10154 bgp = bgp_lookup_by_name (argv[0]);
10155 if (bgp == NULL)
10156 {
10157 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10158 return CMD_WARNING;
10159 }
10160 }
10161 else
10162 {
10163 bgp = bgp_get_default ();
10164 if (bgp == NULL)
10165 {
10166 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10167 return CMD_WARNING;
10168 }
10169 }
10170
10171 if (argc == 3)
10172 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10173 else
10174 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10175
10176 if (! peer)
10177 return CMD_WARNING;
10178
10179 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10180 {
10181 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10182 VTY_NEWLINE);
10183 return CMD_WARNING;
10184 }
10185
10186 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10187 PEER_FLAG_RSERVER_CLIENT))
10188 {
10189 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10190 VTY_NEWLINE);
10191 return CMD_WARNING;
10192 }
10193
10194 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10195 (argc == 3) ? argv[2] : argv[1],
10196 AFI_IP6, SAFI_UNICAST, NULL, 0);
10197}
10198
10199ALIAS (show_bgp_view_rsclient_route,
10200 show_bgp_rsclient_route_cmd,
10201 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10202 SHOW_STR
10203 BGP_STR
10204 "Information about Route Server Client\n"
10205 NEIGHBOR_ADDR_STR
10206 "Network in the BGP routing table to display\n")
10207
10208DEFUN (show_bgp_view_rsclient_prefix,
10209 show_bgp_view_rsclient_prefix_cmd,
10210 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10211 SHOW_STR
10212 BGP_STR
10213 "BGP view\n"
10214 "BGP view name\n"
10215 "Information about Route Server Client\n"
10216 NEIGHBOR_ADDR_STR
10217 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10218{
10219 struct bgp *bgp;
10220 struct peer *peer;
10221
10222 /* BGP structure lookup. */
10223 if (argc == 3)
10224 {
10225 bgp = bgp_lookup_by_name (argv[0]);
10226 if (bgp == NULL)
10227 {
10228 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10229 return CMD_WARNING;
10230 }
10231 }
10232 else
10233 {
10234 bgp = bgp_get_default ();
10235 if (bgp == NULL)
10236 {
10237 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10238 return CMD_WARNING;
10239 }
10240 }
10241
10242 if (argc == 3)
10243 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10244 else
10245 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10246
10247 if (! peer)
10248 return CMD_WARNING;
10249
10250 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10251 {
10252 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10253 VTY_NEWLINE);
10254 return CMD_WARNING;
10255 }
10256
10257 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10258 PEER_FLAG_RSERVER_CLIENT))
10259 {
10260 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10261 VTY_NEWLINE);
10262 return CMD_WARNING;
10263 }
10264
10265 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10266 (argc == 3) ? argv[2] : argv[1],
10267 AFI_IP6, SAFI_UNICAST, NULL, 1);
10268}
10269
10270ALIAS (show_bgp_view_rsclient_prefix,
10271 show_bgp_rsclient_prefix_cmd,
10272 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10273 SHOW_STR
10274 BGP_STR
10275 "Information about Route Server Client\n"
10276 NEIGHBOR_ADDR_STR
10277 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10278
paul718e3742002-12-13 20:15:29 +000010279#endif /* HAVE_IPV6 */
10280
10281struct bgp_table *bgp_distance_table;
10282
10283struct bgp_distance
10284{
10285 /* Distance value for the IP source prefix. */
10286 u_char distance;
10287
10288 /* Name of the access-list to be matched. */
10289 char *access_list;
10290};
10291
paul94f2b392005-06-28 12:44:16 +000010292static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +000010293bgp_distance_new ()
10294{
10295 struct bgp_distance *new;
10296 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
10297 memset (new, 0, sizeof (struct bgp_distance));
10298 return new;
10299}
10300
paul94f2b392005-06-28 12:44:16 +000010301static void
paul718e3742002-12-13 20:15:29 +000010302bgp_distance_free (struct bgp_distance *bdistance)
10303{
10304 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10305}
10306
paul94f2b392005-06-28 12:44:16 +000010307static int
paulfd79ac92004-10-13 05:06:08 +000010308bgp_distance_set (struct vty *vty, const char *distance_str,
10309 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010310{
10311 int ret;
10312 struct prefix_ipv4 p;
10313 u_char distance;
10314 struct bgp_node *rn;
10315 struct bgp_distance *bdistance;
10316
10317 ret = str2prefix_ipv4 (ip_str, &p);
10318 if (ret == 0)
10319 {
10320 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10321 return CMD_WARNING;
10322 }
10323
10324 distance = atoi (distance_str);
10325
10326 /* Get BGP distance node. */
10327 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10328 if (rn->info)
10329 {
10330 bdistance = rn->info;
10331 bgp_unlock_node (rn);
10332 }
10333 else
10334 {
10335 bdistance = bgp_distance_new ();
10336 rn->info = bdistance;
10337 }
10338
10339 /* Set distance value. */
10340 bdistance->distance = distance;
10341
10342 /* Reset access-list configuration. */
10343 if (bdistance->access_list)
10344 {
10345 free (bdistance->access_list);
10346 bdistance->access_list = NULL;
10347 }
10348 if (access_list_str)
10349 bdistance->access_list = strdup (access_list_str);
10350
10351 return CMD_SUCCESS;
10352}
10353
paul94f2b392005-06-28 12:44:16 +000010354static int
paulfd79ac92004-10-13 05:06:08 +000010355bgp_distance_unset (struct vty *vty, const char *distance_str,
10356 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010357{
10358 int ret;
10359 struct prefix_ipv4 p;
10360 u_char distance;
10361 struct bgp_node *rn;
10362 struct bgp_distance *bdistance;
10363
10364 ret = str2prefix_ipv4 (ip_str, &p);
10365 if (ret == 0)
10366 {
10367 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10368 return CMD_WARNING;
10369 }
10370
10371 distance = atoi (distance_str);
10372
10373 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10374 if (! rn)
10375 {
10376 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10377 return CMD_WARNING;
10378 }
10379
10380 bdistance = rn->info;
10381
10382 if (bdistance->access_list)
10383 free (bdistance->access_list);
10384 bgp_distance_free (bdistance);
10385
10386 rn->info = NULL;
10387 bgp_unlock_node (rn);
10388 bgp_unlock_node (rn);
10389
10390 return CMD_SUCCESS;
10391}
10392
paul94f2b392005-06-28 12:44:16 +000010393static void
paul718e3742002-12-13 20:15:29 +000010394bgp_distance_reset ()
10395{
10396 struct bgp_node *rn;
10397 struct bgp_distance *bdistance;
10398
10399 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10400 if ((bdistance = rn->info) != NULL)
10401 {
10402 if (bdistance->access_list)
10403 free (bdistance->access_list);
10404 bgp_distance_free (bdistance);
10405 rn->info = NULL;
10406 bgp_unlock_node (rn);
10407 }
10408}
10409
10410/* Apply BGP information to distance method. */
10411u_char
10412bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10413{
10414 struct bgp_node *rn;
10415 struct prefix_ipv4 q;
10416 struct peer *peer;
10417 struct bgp_distance *bdistance;
10418 struct access_list *alist;
10419 struct bgp_static *bgp_static;
10420
10421 if (! bgp)
10422 return 0;
10423
10424 if (p->family != AF_INET)
10425 return 0;
10426
10427 peer = rinfo->peer;
10428
10429 if (peer->su.sa.sa_family != AF_INET)
10430 return 0;
10431
10432 memset (&q, 0, sizeof (struct prefix_ipv4));
10433 q.family = AF_INET;
10434 q.prefix = peer->su.sin.sin_addr;
10435 q.prefixlen = IPV4_MAX_BITLEN;
10436
10437 /* Check source address. */
10438 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10439 if (rn)
10440 {
10441 bdistance = rn->info;
10442 bgp_unlock_node (rn);
10443
10444 if (bdistance->access_list)
10445 {
10446 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10447 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10448 return bdistance->distance;
10449 }
10450 else
10451 return bdistance->distance;
10452 }
10453
10454 /* Backdoor check. */
10455 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10456 if (rn)
10457 {
10458 bgp_static = rn->info;
10459 bgp_unlock_node (rn);
10460
10461 if (bgp_static->backdoor)
10462 {
10463 if (bgp->distance_local)
10464 return bgp->distance_local;
10465 else
10466 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10467 }
10468 }
10469
10470 if (peer_sort (peer) == BGP_PEER_EBGP)
10471 {
10472 if (bgp->distance_ebgp)
10473 return bgp->distance_ebgp;
10474 return ZEBRA_EBGP_DISTANCE_DEFAULT;
10475 }
10476 else
10477 {
10478 if (bgp->distance_ibgp)
10479 return bgp->distance_ibgp;
10480 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10481 }
10482}
10483
10484DEFUN (bgp_distance,
10485 bgp_distance_cmd,
10486 "distance bgp <1-255> <1-255> <1-255>",
10487 "Define an administrative distance\n"
10488 "BGP distance\n"
10489 "Distance for routes external to the AS\n"
10490 "Distance for routes internal to the AS\n"
10491 "Distance for local routes\n")
10492{
10493 struct bgp *bgp;
10494
10495 bgp = vty->index;
10496
10497 bgp->distance_ebgp = atoi (argv[0]);
10498 bgp->distance_ibgp = atoi (argv[1]);
10499 bgp->distance_local = atoi (argv[2]);
10500 return CMD_SUCCESS;
10501}
10502
10503DEFUN (no_bgp_distance,
10504 no_bgp_distance_cmd,
10505 "no distance bgp <1-255> <1-255> <1-255>",
10506 NO_STR
10507 "Define an administrative distance\n"
10508 "BGP distance\n"
10509 "Distance for routes external to the AS\n"
10510 "Distance for routes internal to the AS\n"
10511 "Distance for local routes\n")
10512{
10513 struct bgp *bgp;
10514
10515 bgp = vty->index;
10516
10517 bgp->distance_ebgp= 0;
10518 bgp->distance_ibgp = 0;
10519 bgp->distance_local = 0;
10520 return CMD_SUCCESS;
10521}
10522
10523ALIAS (no_bgp_distance,
10524 no_bgp_distance2_cmd,
10525 "no distance bgp",
10526 NO_STR
10527 "Define an administrative distance\n"
10528 "BGP distance\n")
10529
10530DEFUN (bgp_distance_source,
10531 bgp_distance_source_cmd,
10532 "distance <1-255> A.B.C.D/M",
10533 "Define an administrative distance\n"
10534 "Administrative distance\n"
10535 "IP source prefix\n")
10536{
10537 bgp_distance_set (vty, argv[0], argv[1], NULL);
10538 return CMD_SUCCESS;
10539}
10540
10541DEFUN (no_bgp_distance_source,
10542 no_bgp_distance_source_cmd,
10543 "no distance <1-255> A.B.C.D/M",
10544 NO_STR
10545 "Define an administrative distance\n"
10546 "Administrative distance\n"
10547 "IP source prefix\n")
10548{
10549 bgp_distance_unset (vty, argv[0], argv[1], NULL);
10550 return CMD_SUCCESS;
10551}
10552
10553DEFUN (bgp_distance_source_access_list,
10554 bgp_distance_source_access_list_cmd,
10555 "distance <1-255> A.B.C.D/M WORD",
10556 "Define an administrative distance\n"
10557 "Administrative distance\n"
10558 "IP source prefix\n"
10559 "Access list name\n")
10560{
10561 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
10562 return CMD_SUCCESS;
10563}
10564
10565DEFUN (no_bgp_distance_source_access_list,
10566 no_bgp_distance_source_access_list_cmd,
10567 "no distance <1-255> A.B.C.D/M WORD",
10568 NO_STR
10569 "Define an administrative distance\n"
10570 "Administrative distance\n"
10571 "IP source prefix\n"
10572 "Access list name\n")
10573{
10574 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
10575 return CMD_SUCCESS;
10576}
10577
10578DEFUN (bgp_damp_set,
10579 bgp_damp_set_cmd,
10580 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10581 "BGP Specific commands\n"
10582 "Enable route-flap dampening\n"
10583 "Half-life time for the penalty\n"
10584 "Value to start reusing a route\n"
10585 "Value to start suppressing a route\n"
10586 "Maximum duration to suppress a stable route\n")
10587{
10588 struct bgp *bgp;
10589 int half = DEFAULT_HALF_LIFE * 60;
10590 int reuse = DEFAULT_REUSE;
10591 int suppress = DEFAULT_SUPPRESS;
10592 int max = 4 * half;
10593
10594 if (argc == 4)
10595 {
10596 half = atoi (argv[0]) * 60;
10597 reuse = atoi (argv[1]);
10598 suppress = atoi (argv[2]);
10599 max = atoi (argv[3]) * 60;
10600 }
10601 else if (argc == 1)
10602 {
10603 half = atoi (argv[0]) * 60;
10604 max = 4 * half;
10605 }
10606
10607 bgp = vty->index;
10608 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10609 half, reuse, suppress, max);
10610}
10611
10612ALIAS (bgp_damp_set,
10613 bgp_damp_set2_cmd,
10614 "bgp dampening <1-45>",
10615 "BGP Specific commands\n"
10616 "Enable route-flap dampening\n"
10617 "Half-life time for the penalty\n")
10618
10619ALIAS (bgp_damp_set,
10620 bgp_damp_set3_cmd,
10621 "bgp dampening",
10622 "BGP Specific commands\n"
10623 "Enable route-flap dampening\n")
10624
10625DEFUN (bgp_damp_unset,
10626 bgp_damp_unset_cmd,
10627 "no bgp dampening",
10628 NO_STR
10629 "BGP Specific commands\n"
10630 "Enable route-flap dampening\n")
10631{
10632 struct bgp *bgp;
10633
10634 bgp = vty->index;
10635 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10636}
10637
10638ALIAS (bgp_damp_unset,
10639 bgp_damp_unset2_cmd,
10640 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10641 NO_STR
10642 "BGP Specific commands\n"
10643 "Enable route-flap dampening\n"
10644 "Half-life time for the penalty\n"
10645 "Value to start reusing a route\n"
10646 "Value to start suppressing a route\n"
10647 "Maximum duration to suppress a stable route\n")
10648
10649DEFUN (show_ip_bgp_dampened_paths,
10650 show_ip_bgp_dampened_paths_cmd,
10651 "show ip bgp dampened-paths",
10652 SHOW_STR
10653 IP_STR
10654 BGP_STR
10655 "Display paths suppressed due to dampening\n")
10656{
ajs5a646652004-11-05 01:25:55 +000010657 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10658 NULL);
paul718e3742002-12-13 20:15:29 +000010659}
10660
10661DEFUN (show_ip_bgp_flap_statistics,
10662 show_ip_bgp_flap_statistics_cmd,
10663 "show ip bgp flap-statistics",
10664 SHOW_STR
10665 IP_STR
10666 BGP_STR
10667 "Display flap statistics of routes\n")
10668{
ajs5a646652004-11-05 01:25:55 +000010669 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10670 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010671}
10672
10673/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010674static int
paulfd79ac92004-10-13 05:06:08 +000010675bgp_clear_damp_route (struct vty *vty, const char *view_name,
10676 const char *ip_str, afi_t afi, safi_t safi,
10677 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010678{
10679 int ret;
10680 struct prefix match;
10681 struct bgp_node *rn;
10682 struct bgp_node *rm;
10683 struct bgp_info *ri;
10684 struct bgp_info *ri_temp;
10685 struct bgp *bgp;
10686 struct bgp_table *table;
10687
10688 /* BGP structure lookup. */
10689 if (view_name)
10690 {
10691 bgp = bgp_lookup_by_name (view_name);
10692 if (bgp == NULL)
10693 {
10694 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10695 return CMD_WARNING;
10696 }
10697 }
10698 else
10699 {
10700 bgp = bgp_get_default ();
10701 if (bgp == NULL)
10702 {
10703 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10704 return CMD_WARNING;
10705 }
10706 }
10707
10708 /* Check IP address argument. */
10709 ret = str2prefix (ip_str, &match);
10710 if (! ret)
10711 {
10712 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10713 return CMD_WARNING;
10714 }
10715
10716 match.family = afi2family (afi);
10717
10718 if (safi == SAFI_MPLS_VPN)
10719 {
10720 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10721 {
10722 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10723 continue;
10724
10725 if ((table = rn->info) != NULL)
10726 if ((rm = bgp_node_match (table, &match)) != NULL)
10727 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10728 {
10729 ri = rm->info;
10730 while (ri)
10731 {
10732 if (ri->damp_info)
10733 {
10734 ri_temp = ri->next;
10735 bgp_damp_info_free (ri->damp_info, 1);
10736 ri = ri_temp;
10737 }
10738 else
10739 ri = ri->next;
10740 }
10741 }
10742 }
10743 }
10744 else
10745 {
10746 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10747 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10748 {
10749 ri = rn->info;
10750 while (ri)
10751 {
10752 if (ri->damp_info)
10753 {
10754 ri_temp = ri->next;
10755 bgp_damp_info_free (ri->damp_info, 1);
10756 ri = ri_temp;
10757 }
10758 else
10759 ri = ri->next;
10760 }
10761 }
10762 }
10763
10764 return CMD_SUCCESS;
10765}
10766
10767DEFUN (clear_ip_bgp_dampening,
10768 clear_ip_bgp_dampening_cmd,
10769 "clear ip bgp dampening",
10770 CLEAR_STR
10771 IP_STR
10772 BGP_STR
10773 "Clear route flap dampening information\n")
10774{
10775 bgp_damp_info_clean ();
10776 return CMD_SUCCESS;
10777}
10778
10779DEFUN (clear_ip_bgp_dampening_prefix,
10780 clear_ip_bgp_dampening_prefix_cmd,
10781 "clear ip bgp dampening A.B.C.D/M",
10782 CLEAR_STR
10783 IP_STR
10784 BGP_STR
10785 "Clear route flap dampening information\n"
10786 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10787{
10788 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10789 SAFI_UNICAST, NULL, 1);
10790}
10791
10792DEFUN (clear_ip_bgp_dampening_address,
10793 clear_ip_bgp_dampening_address_cmd,
10794 "clear ip bgp dampening A.B.C.D",
10795 CLEAR_STR
10796 IP_STR
10797 BGP_STR
10798 "Clear route flap dampening information\n"
10799 "Network to clear damping information\n")
10800{
10801 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10802 SAFI_UNICAST, NULL, 0);
10803}
10804
10805DEFUN (clear_ip_bgp_dampening_address_mask,
10806 clear_ip_bgp_dampening_address_mask_cmd,
10807 "clear ip bgp dampening A.B.C.D A.B.C.D",
10808 CLEAR_STR
10809 IP_STR
10810 BGP_STR
10811 "Clear route flap dampening information\n"
10812 "Network to clear damping information\n"
10813 "Network mask\n")
10814{
10815 int ret;
10816 char prefix_str[BUFSIZ];
10817
10818 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10819 if (! ret)
10820 {
10821 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10822 return CMD_WARNING;
10823 }
10824
10825 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10826 SAFI_UNICAST, NULL, 0);
10827}
10828
paul94f2b392005-06-28 12:44:16 +000010829static int
paul718e3742002-12-13 20:15:29 +000010830bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10831 afi_t afi, safi_t safi, int *write)
10832{
10833 struct bgp_node *prn;
10834 struct bgp_node *rn;
10835 struct bgp_table *table;
10836 struct prefix *p;
10837 struct prefix_rd *prd;
10838 struct bgp_static *bgp_static;
10839 u_int32_t label;
10840 char buf[SU_ADDRSTRLEN];
10841 char rdbuf[RD_ADDRSTRLEN];
10842
10843 /* Network configuration. */
10844 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10845 if ((table = prn->info) != NULL)
10846 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10847 if ((bgp_static = rn->info) != NULL)
10848 {
10849 p = &rn->p;
10850 prd = (struct prefix_rd *) &prn->p;
10851
10852 /* "address-family" display. */
10853 bgp_config_write_family_header (vty, afi, safi, write);
10854
10855 /* "network" configuration display. */
10856 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10857 label = decode_label (bgp_static->tag);
10858
10859 vty_out (vty, " network %s/%d rd %s tag %d",
10860 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10861 p->prefixlen,
10862 rdbuf, label);
10863 vty_out (vty, "%s", VTY_NEWLINE);
10864 }
10865 return 0;
10866}
10867
10868/* Configuration of static route announcement and aggregate
10869 information. */
10870int
10871bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10872 afi_t afi, safi_t safi, int *write)
10873{
10874 struct bgp_node *rn;
10875 struct prefix *p;
10876 struct bgp_static *bgp_static;
10877 struct bgp_aggregate *bgp_aggregate;
10878 char buf[SU_ADDRSTRLEN];
10879
10880 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10881 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10882
10883 /* Network configuration. */
10884 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10885 if ((bgp_static = rn->info) != NULL)
10886 {
10887 p = &rn->p;
10888
10889 /* "address-family" display. */
10890 bgp_config_write_family_header (vty, afi, safi, write);
10891
10892 /* "network" configuration display. */
10893 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10894 {
10895 u_int32_t destination;
10896 struct in_addr netmask;
10897
10898 destination = ntohl (p->u.prefix4.s_addr);
10899 masklen2ip (p->prefixlen, &netmask);
10900 vty_out (vty, " network %s",
10901 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10902
10903 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10904 || (IN_CLASSB (destination) && p->prefixlen == 16)
10905 || (IN_CLASSA (destination) && p->prefixlen == 8)
10906 || p->u.prefix4.s_addr == 0)
10907 {
10908 /* Natural mask is not display. */
10909 }
10910 else
10911 vty_out (vty, " mask %s", inet_ntoa (netmask));
10912 }
10913 else
10914 {
10915 vty_out (vty, " network %s/%d",
10916 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10917 p->prefixlen);
10918 }
10919
10920 if (bgp_static->rmap.name)
10921 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10922 else if (bgp_static->backdoor)
10923 vty_out (vty, " backdoor");
10924
10925 vty_out (vty, "%s", VTY_NEWLINE);
10926 }
10927
10928 /* Aggregate-address configuration. */
10929 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10930 if ((bgp_aggregate = rn->info) != NULL)
10931 {
10932 p = &rn->p;
10933
10934 /* "address-family" display. */
10935 bgp_config_write_family_header (vty, afi, safi, write);
10936
10937 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10938 {
10939 struct in_addr netmask;
10940
10941 masklen2ip (p->prefixlen, &netmask);
10942 vty_out (vty, " aggregate-address %s %s",
10943 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10944 inet_ntoa (netmask));
10945 }
10946 else
10947 {
10948 vty_out (vty, " aggregate-address %s/%d",
10949 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10950 p->prefixlen);
10951 }
10952
10953 if (bgp_aggregate->as_set)
10954 vty_out (vty, " as-set");
10955
10956 if (bgp_aggregate->summary_only)
10957 vty_out (vty, " summary-only");
10958
10959 vty_out (vty, "%s", VTY_NEWLINE);
10960 }
10961
10962 return 0;
10963}
10964
10965int
10966bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10967{
10968 struct bgp_node *rn;
10969 struct bgp_distance *bdistance;
10970
10971 /* Distance configuration. */
10972 if (bgp->distance_ebgp
10973 && bgp->distance_ibgp
10974 && bgp->distance_local
10975 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10976 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10977 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10978 vty_out (vty, " distance bgp %d %d %d%s",
10979 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10980 VTY_NEWLINE);
10981
10982 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10983 if ((bdistance = rn->info) != NULL)
10984 {
10985 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10986 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10987 bdistance->access_list ? bdistance->access_list : "",
10988 VTY_NEWLINE);
10989 }
10990
10991 return 0;
10992}
10993
10994/* Allocate routing table structure and install commands. */
10995void
10996bgp_route_init ()
10997{
10998 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000010999 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011000
11001 /* IPv4 BGP commands. */
11002 install_element (BGP_NODE, &bgp_network_cmd);
11003 install_element (BGP_NODE, &bgp_network_mask_cmd);
11004 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11005 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11006 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11007 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11008 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11009 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11010 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
11011 install_element (BGP_NODE, &no_bgp_network_cmd);
11012 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11013 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11014 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11015 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11016 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11017 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11018 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11019 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
11020
11021 install_element (BGP_NODE, &aggregate_address_cmd);
11022 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11023 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11024 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11025 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11026 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11027 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11028 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11029 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11030 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11031 install_element (BGP_NODE, &no_aggregate_address_cmd);
11032 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11033 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11034 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11035 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11036 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11037 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11038 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11039 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11040 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11041
11042 /* IPv4 unicast configuration. */
11043 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11044 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11045 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11046 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11047 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11048 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
11049 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11050 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11051 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11052 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11053 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11054 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11055 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11056 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11057 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11058 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11059 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11060 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11061 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11062 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11063 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11064 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11065 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11066 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11067 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11068 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11069 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11070 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11071 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11072 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11073 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11074 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11075
11076 /* IPv4 multicast configuration. */
11077 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11078 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11079 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11080 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11081 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11082 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
11083 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11084 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11085 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11086 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11087 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11088 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11089 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11090 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11091 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11092 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11093 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11094 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11095 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11096 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11097 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11098 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11099 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11100 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11101 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11102 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11103 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11104 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11105 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11106 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11107 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11108 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11109
11110 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11111 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11112 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11113 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11114 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11115 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11116 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11117 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11118 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11119 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11120 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11121 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11122 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11123 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11124 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11125 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11126 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11127 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11128 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11129 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11130 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11131 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11132 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11133 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11134 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11135 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11136 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11137 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11138 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11139 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11140 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11141 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11142 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11143 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11144 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11145 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11146 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11147 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11148 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11149 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11150 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11151 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11152 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11153 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11154 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11155 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11156 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11157 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11158 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11159 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11160 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11161 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11162 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11163 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11164 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11165 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11166 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11167 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11168 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11169 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11170 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11171 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11172 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11173 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11174 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11175 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11176 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011177 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11178 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11179 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11180 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11181 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11182 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011183
11184 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11185 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11186 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11187 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11188 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11189 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11190 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11191 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11192 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11193 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11194 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11195 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11196 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11197 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11198 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11199 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11200 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11201 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11202 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11203 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11204 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11205 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11206 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11207 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11208 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11209 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11210 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11211 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11212 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11213 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11214 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11215 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11216 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11217 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11218 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11219 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11220 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11221 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11222 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11223 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11224 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11225 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11226 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11227 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11228 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11229 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11230 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11231 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11232 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11233 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11234 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11235 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11236 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11237 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11238 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11239 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11240 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11241 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11242 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11243 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11244 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11245 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11246 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11247 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11248 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11249 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11250 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011251 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11252 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11253 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11254 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11255 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11256 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011257
11258 /* BGP dampening clear commands */
11259 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11260 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11261 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11262 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11263
Paul Jakmaff7924f2006-09-04 01:10:36 +000011264 /* prefix count */
11265 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11266 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11267 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011268#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011269 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11270
paul718e3742002-12-13 20:15:29 +000011271 /* New config IPv6 BGP commands. */
11272 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11273 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
11274 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11275 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
11276
11277 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11278 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11279 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11280 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11281
11282 /* Old config IPv6 BGP commands. */
11283 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11284 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11285
11286 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11287 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11288 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11289 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11290
11291 install_element (VIEW_NODE, &show_bgp_cmd);
11292 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11293 install_element (VIEW_NODE, &show_bgp_route_cmd);
11294 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11295 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11296 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11297 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11298 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11299 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11300 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11301 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11302 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11303 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11304 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11305 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11306 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11307 install_element (VIEW_NODE, &show_bgp_community_cmd);
11308 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11309 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11310 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11311 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11312 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11313 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11314 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11315 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11316 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11317 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11318 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11319 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11320 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11321 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11322 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11323 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11324 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11325 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11326 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11327 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11328 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11329 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11330 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11331 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11332 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11333 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11334 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11335 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11336 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011337 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11338 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11339 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11340 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011341 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11342 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11343 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011344 install_element (VIEW_NODE, &show_bgp_view_cmd);
11345 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11346 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11347 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11348 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11349 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11350 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11351 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11352 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11353 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11354 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11355 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11356 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11357 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11358 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11359 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11360 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11361 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011362 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11363 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11364 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011365
11366 install_element (ENABLE_NODE, &show_bgp_cmd);
11367 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11368 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11369 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11370 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11371 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11372 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11373 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11374 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11375 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11376 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11377 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11378 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11379 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11380 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11381 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11382 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11383 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11384 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11385 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11386 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11387 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11388 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
11389 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
11390 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
11391 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
11392 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
11393 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
11394 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
11395 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
11396 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
11397 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
11398 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
11399 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
11400 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
11401 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11402 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
11403 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11404 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
11405 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11406 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
11407 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11408 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
11409 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11410 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11411 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011412 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
11413 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11414 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
11415 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011416 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
11417 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
11418 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011419 install_element (ENABLE_NODE, &show_bgp_view_cmd);
11420 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
11421 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
11422 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
11423 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
11424 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
11425 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11426 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11427 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11428 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11429 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
11430 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11431 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11432 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11433 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
11434 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11435 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
11436 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011437 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
11438 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
11439 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000011440
11441 /* Statistics */
11442 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
11443 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
11444 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
11445 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
11446
paul718e3742002-12-13 20:15:29 +000011447 /* old command */
11448 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
11449 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
11450 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
11451 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
11452 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
11453 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
11454 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
11455 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
11456 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
11457 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
11458 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
11459 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
11460 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
11461 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
11462 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
11463 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
11464 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11465 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11466 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
11467 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
11468 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
11469 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
11470 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11471 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
11472 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
11473 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
11474 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
11475 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
11476 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
11477 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
11478 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11479 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11480 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11481 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
11482 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11483 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000011484
paul718e3742002-12-13 20:15:29 +000011485 /* old command */
11486 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
11487 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
11488 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
11489 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
11490 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
11491 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
11492 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
11493 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
11494 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
11495 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
11496 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
11497 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
11498 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
11499 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
11500 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
11501 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
11502 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11503 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11504 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
11505 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
11506 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
11507 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
11508 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11509 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
11510 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
11511 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
11512 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
11513 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
11514 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
11515 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
11516 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11517 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11518 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11519 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
11520 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11521 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
11522
11523 /* old command */
11524 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11525 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11526 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11527 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11528
11529 /* old command */
11530 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11531 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11532 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11533 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11534
11535 /* old command */
11536 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
11537 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
11538 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11539 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11540#endif /* HAVE_IPV6 */
11541
11542 install_element (BGP_NODE, &bgp_distance_cmd);
11543 install_element (BGP_NODE, &no_bgp_distance_cmd);
11544 install_element (BGP_NODE, &no_bgp_distance2_cmd);
11545 install_element (BGP_NODE, &bgp_distance_source_cmd);
11546 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
11547 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
11548 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
11549
11550 install_element (BGP_NODE, &bgp_damp_set_cmd);
11551 install_element (BGP_NODE, &bgp_damp_set2_cmd);
11552 install_element (BGP_NODE, &bgp_damp_set3_cmd);
11553 install_element (BGP_NODE, &bgp_damp_unset_cmd);
11554 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
11555 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
11556 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
11557 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
11558 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
11559 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
11560}