blob: 65f54e770926e00510aebab29ea5619eaf2328d1 [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
Paul Jakmafb982c22007-05-04 20:15:47 +000092/* Allocate bgp_info_extra */
93static struct bgp_info_extra *
94bgp_info_extra_new (void)
95{
96 struct bgp_info_extra *new;
97 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
98 return new;
99}
100
101static void
102bgp_info_extra_free (struct bgp_info_extra **extra)
103{
104 if (extra && *extra)
105 {
106 if ((*extra)->damp_info)
107 bgp_damp_info_free ((*extra)->damp_info, 0);
108
109 (*extra)->damp_info = NULL;
110
111 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
112
113 *extra = NULL;
114 }
115}
116
117/* Get bgp_info extra information for the given bgp_info, lazy allocated
118 * if required.
119 */
120struct bgp_info_extra *
121bgp_info_extra_get (struct bgp_info *ri)
122{
123 if (!ri->extra)
124 ri->extra = bgp_info_extra_new();
125 return ri->extra;
126}
127
paul718e3742002-12-13 20:15:29 +0000128/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000129static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800130bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000131{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700132 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000133}
134
135/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000136static void
paul718e3742002-12-13 20:15:29 +0000137bgp_info_free (struct bgp_info *binfo)
138{
139 if (binfo->attr)
140 bgp_attr_unintern (binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000141
142 bgp_info_extra_free (&binfo->extra);
paul718e3742002-12-13 20:15:29 +0000143
paul200df112005-06-01 11:17:05 +0000144 peer_unlock (binfo->peer); /* bgp_info peer reference */
145
paul718e3742002-12-13 20:15:29 +0000146 XFREE (MTYPE_BGP_ROUTE, binfo);
147}
148
paul200df112005-06-01 11:17:05 +0000149struct bgp_info *
150bgp_info_lock (struct bgp_info *binfo)
151{
152 binfo->lock++;
153 return binfo;
154}
155
156struct bgp_info *
157bgp_info_unlock (struct bgp_info *binfo)
158{
159 assert (binfo && binfo->lock > 0);
160 binfo->lock--;
161
162 if (binfo->lock == 0)
163 {
164#if 0
165 zlog_debug ("%s: unlocked and freeing", __func__);
166 zlog_backtrace (LOG_DEBUG);
167#endif
168 bgp_info_free (binfo);
169 return NULL;
170 }
171
172#if 0
173 if (binfo->lock == 1)
174 {
175 zlog_debug ("%s: unlocked to 1", __func__);
176 zlog_backtrace (LOG_DEBUG);
177 }
178#endif
179
180 return binfo;
181}
182
paul718e3742002-12-13 20:15:29 +0000183void
184bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
185{
186 struct bgp_info *top;
187
188 top = rn->info;
paul200df112005-06-01 11:17:05 +0000189
paul718e3742002-12-13 20:15:29 +0000190 ri->next = rn->info;
191 ri->prev = NULL;
192 if (top)
193 top->prev = ri;
194 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000195
196 bgp_info_lock (ri);
197 bgp_lock_node (rn);
198 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000199}
200
paulb40d9392005-08-22 22:34:41 +0000201/* Do the actual removal of info from RIB, for use by bgp_process
202 completion callback *only* */
203static void
204bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000205{
206 if (ri->next)
207 ri->next->prev = ri->prev;
208 if (ri->prev)
209 ri->prev->next = ri->next;
210 else
211 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000212
213 bgp_info_unlock (ri);
214 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000215}
216
paulb40d9392005-08-22 22:34:41 +0000217void
218bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
219{
Paul Jakma1a392d42006-09-07 00:24:49 +0000220 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
221 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000222 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
223}
224
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000225/* undo the effects of a previous call to bgp_info_delete; typically
226 called when a route is deleted and then quickly re-added before the
227 deletion has been processed */
228static void
229bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
230{
231 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
232 /* unset of previous already took care of pcount */
233 SET_FLAG (ri->flags, BGP_INFO_VALID);
234}
235
Paul Jakma1a392d42006-09-07 00:24:49 +0000236/* Adjust pcount as required */
237static void
238bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
239{
Paul Jakma6f585442006-10-22 19:13:07 +0000240 assert (rn && rn->table);
241 assert (ri && ri->peer && ri->peer->bgp);
242
Paul Jakma1a392d42006-09-07 00:24:49 +0000243 /* Ignore 'pcount' for RS-client tables */
244 if (rn->table->type != BGP_TABLE_MAIN
245 || ri->peer == ri->peer->bgp->peer_self)
246 return;
247
248 if (BGP_INFO_HOLDDOWN (ri)
249 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
250 {
251
252 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
253
254 /* slight hack, but more robust against errors. */
255 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
256 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
257 else
258 {
259 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
260 __func__, ri->peer->host);
261 zlog_backtrace (LOG_WARNING);
262 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
263 }
264 }
265 else if (!BGP_INFO_HOLDDOWN (ri)
266 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
267 {
268 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
269 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
270 }
271}
272
273
274/* Set/unset bgp_info flags, adjusting any other state as needed.
275 * This is here primarily to keep prefix-count in check.
276 */
277void
278bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
279{
280 SET_FLAG (ri->flags, flag);
281
282 /* early bath if we know it's not a flag that changes useability state */
283 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
284 return;
285
286 bgp_pcount_adjust (rn, ri);
287}
288
289void
290bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
291{
292 UNSET_FLAG (ri->flags, flag);
293
294 /* early bath if we know it's not a flag that changes useability state */
295 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
296 return;
297
298 bgp_pcount_adjust (rn, ri);
299}
300
paul718e3742002-12-13 20:15:29 +0000301/* Get MED value. If MED value is missing and "bgp bestpath
302 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000303static u_int32_t
paul718e3742002-12-13 20:15:29 +0000304bgp_med_value (struct attr *attr, struct bgp *bgp)
305{
306 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
307 return attr->med;
308 else
309 {
310 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000311 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000312 else
313 return 0;
314 }
315}
316
317/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000318static int
paul718e3742002-12-13 20:15:29 +0000319bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
320{
321 u_int32_t new_pref;
322 u_int32_t exist_pref;
323 u_int32_t new_med;
324 u_int32_t exist_med;
Paul Jakmafb982c22007-05-04 20:15:47 +0000325 u_int32_t new_weight = 0;
326 u_int32_t exist_weight = 0;
paul718e3742002-12-13 20:15:29 +0000327 struct in_addr new_id;
328 struct in_addr exist_id;
329 int new_cluster;
330 int exist_cluster;
331 int internal_as_route = 0;
332 int confed_as_route = 0;
333 int ret;
334
335 /* 0. Null check. */
336 if (new == NULL)
337 return 0;
338 if (exist == NULL)
339 return 1;
340
341 /* 1. Weight check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000342 if (new->attr->extra)
343 new_weight = new->attr->extra->weight;
344 if (exist->attr->extra)
345 exist_weight = exist->attr->extra->weight;
346 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000347 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000348 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000349 return 0;
350
351 /* 2. Local preference check. */
352 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
353 new_pref = new->attr->local_pref;
354 else
355 new_pref = bgp->default_local_pref;
356
357 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
358 exist_pref = exist->attr->local_pref;
359 else
360 exist_pref = bgp->default_local_pref;
361
362 if (new_pref > exist_pref)
363 return 1;
364 if (new_pref < exist_pref)
365 return 0;
366
367 /* 3. Local route check. */
368 if (new->sub_type == BGP_ROUTE_STATIC)
369 return 1;
370 if (exist->sub_type == BGP_ROUTE_STATIC)
371 return 0;
372
373 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
374 return 1;
375 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
376 return 0;
377
378 if (new->sub_type == BGP_ROUTE_AGGREGATE)
379 return 1;
380 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
381 return 0;
382
383 /* 4. AS path length check. */
384 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
385 {
paulfe69a502005-09-10 16:55:02 +0000386 int exist_hops = aspath_count_hops (exist->attr->aspath);
387 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
388
hasso68118452005-04-08 15:40:36 +0000389 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
390 {
paulfe69a502005-09-10 16:55:02 +0000391 int aspath_hops;
392
393 aspath_hops = aspath_count_hops (new->attr->aspath);
394 aspath_hops += aspath_count_confeds (new->attr->aspath);
395
396 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000397 return 1;
paulfe69a502005-09-10 16:55:02 +0000398 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000399 return 0;
400 }
401 else
402 {
paulfe69a502005-09-10 16:55:02 +0000403 int newhops = aspath_count_hops (new->attr->aspath);
404
405 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000406 return 1;
paulfe69a502005-09-10 16:55:02 +0000407 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000408 return 0;
409 }
paul718e3742002-12-13 20:15:29 +0000410 }
411
412 /* 5. Origin check. */
413 if (new->attr->origin < exist->attr->origin)
414 return 1;
415 if (new->attr->origin > exist->attr->origin)
416 return 0;
417
418 /* 6. MED check. */
paulfe69a502005-09-10 16:55:02 +0000419 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
420 && aspath_count_hops (exist->attr->aspath) == 0);
421 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
422 && aspath_count_confeds (exist->attr->aspath) > 0
423 && aspath_count_hops (new->attr->aspath) == 0
424 && aspath_count_hops (exist->attr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000425
426 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
427 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
428 && confed_as_route)
429 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
430 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
431 || internal_as_route)
432 {
433 new_med = bgp_med_value (new->attr, bgp);
434 exist_med = bgp_med_value (exist->attr, bgp);
435
436 if (new_med < exist_med)
437 return 1;
438 if (new_med > exist_med)
439 return 0;
440 }
441
442 /* 7. Peer type check. */
443 if (peer_sort (new->peer) == BGP_PEER_EBGP
444 && peer_sort (exist->peer) == BGP_PEER_IBGP)
445 return 1;
446 if (peer_sort (new->peer) == BGP_PEER_EBGP
447 && peer_sort (exist->peer) == BGP_PEER_CONFED)
448 return 1;
449 if (peer_sort (new->peer) == BGP_PEER_IBGP
450 && peer_sort (exist->peer) == BGP_PEER_EBGP)
451 return 0;
452 if (peer_sort (new->peer) == BGP_PEER_CONFED
453 && peer_sort (exist->peer) == BGP_PEER_EBGP)
454 return 0;
455
456 /* 8. IGP metric check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000457 if (new->extra || exist->extra)
458 {
459 uint32_t newm = (new->extra ? new->extra->igpmetric : 0);
460 uint32_t existm = (exist->extra ? exist->extra->igpmetric : 0);
461
462 if (newm < existm)
463 return 1;
464 if (newm > existm)
465 return 0;
466 }
paul718e3742002-12-13 20:15:29 +0000467
468 /* 9. Maximum path check. */
469
470 /* 10. If both paths are external, prefer the path that was received
471 first (the oldest one). This step minimizes route-flap, since a
472 newer path won't displace an older one, even if it was the
473 preferred route based on the additional decision criteria below. */
474 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
475 && peer_sort (new->peer) == BGP_PEER_EBGP
476 && peer_sort (exist->peer) == BGP_PEER_EBGP)
477 {
478 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
479 return 1;
480 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
481 return 0;
482 }
483
484 /* 11. Rourter-ID comparision. */
485 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000486 new_id.s_addr = new->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000487 else
488 new_id.s_addr = new->peer->remote_id.s_addr;
489 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000490 exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000491 else
492 exist_id.s_addr = exist->peer->remote_id.s_addr;
493
494 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
495 return 1;
496 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
497 return 0;
498
499 /* 12. Cluster length comparision. */
500 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000501 new_cluster = new->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000502 else
503 new_cluster = 0;
504 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000505 exist_cluster = exist->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000506 else
507 exist_cluster = 0;
508
509 if (new_cluster < exist_cluster)
510 return 1;
511 if (new_cluster > exist_cluster)
512 return 0;
513
514 /* 13. Neighbor address comparision. */
515 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
516
517 if (ret == 1)
518 return 0;
519 if (ret == -1)
520 return 1;
521
522 return 1;
523}
524
paul94f2b392005-06-28 12:44:16 +0000525static enum filter_type
paul718e3742002-12-13 20:15:29 +0000526bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
527 afi_t afi, safi_t safi)
528{
529 struct bgp_filter *filter;
530
531 filter = &peer->filter[afi][safi];
532
533 if (DISTRIBUTE_IN_NAME (filter))
534 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
535 return FILTER_DENY;
536
537 if (PREFIX_LIST_IN_NAME (filter))
538 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
539 return FILTER_DENY;
540
541 if (FILTER_LIST_IN_NAME (filter))
542 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
543 return FILTER_DENY;
544
545 return FILTER_PERMIT;
546}
547
paul94f2b392005-06-28 12:44:16 +0000548static enum filter_type
paul718e3742002-12-13 20:15:29 +0000549bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
550 afi_t afi, safi_t safi)
551{
552 struct bgp_filter *filter;
553
554 filter = &peer->filter[afi][safi];
555
556 if (DISTRIBUTE_OUT_NAME (filter))
557 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
558 return FILTER_DENY;
559
560 if (PREFIX_LIST_OUT_NAME (filter))
561 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
562 return FILTER_DENY;
563
564 if (FILTER_LIST_OUT_NAME (filter))
565 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
566 return FILTER_DENY;
567
568 return FILTER_PERMIT;
569}
570
571/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000572static int
paul718e3742002-12-13 20:15:29 +0000573bgp_community_filter (struct peer *peer, struct attr *attr)
574{
575 if (attr->community)
576 {
577 /* NO_ADVERTISE check. */
578 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
579 return 1;
580
581 /* NO_EXPORT check. */
582 if (peer_sort (peer) == BGP_PEER_EBGP &&
583 community_include (attr->community, COMMUNITY_NO_EXPORT))
584 return 1;
585
586 /* NO_EXPORT_SUBCONFED check. */
587 if (peer_sort (peer) == BGP_PEER_EBGP
588 || peer_sort (peer) == BGP_PEER_CONFED)
589 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
590 return 1;
591 }
592 return 0;
593}
594
595/* Route reflection loop check. */
596static int
597bgp_cluster_filter (struct peer *peer, struct attr *attr)
598{
599 struct in_addr cluster_id;
600
Paul Jakmafb982c22007-05-04 20:15:47 +0000601 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000602 {
603 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
604 cluster_id = peer->bgp->cluster_id;
605 else
606 cluster_id = peer->bgp->router_id;
607
Paul Jakmafb982c22007-05-04 20:15:47 +0000608 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000609 return 1;
610 }
611 return 0;
612}
613
paul94f2b392005-06-28 12:44:16 +0000614static int
paul718e3742002-12-13 20:15:29 +0000615bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
616 afi_t afi, safi_t safi)
617{
618 struct bgp_filter *filter;
619 struct bgp_info info;
620 route_map_result_t ret;
621
622 filter = &peer->filter[afi][safi];
623
624 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000625 if (peer->weight)
626 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000627
628 /* Route map apply. */
629 if (ROUTE_MAP_IN_NAME (filter))
630 {
631 /* Duplicate current value to new strucutre for modification. */
632 info.peer = peer;
633 info.attr = attr;
634
paulac41b2a2003-08-12 05:32:27 +0000635 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
636
paul718e3742002-12-13 20:15:29 +0000637 /* Apply BGP route map to the attribute. */
638 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000639
640 peer->rmap_type = 0;
641
paul718e3742002-12-13 20:15:29 +0000642 if (ret == RMAP_DENYMATCH)
643 {
644 /* Free newly generated AS path and community by route-map. */
645 bgp_attr_flush (attr);
646 return RMAP_DENY;
647 }
648 }
649 return RMAP_PERMIT;
650}
651
paul94f2b392005-06-28 12:44:16 +0000652static int
paulfee0f4c2004-09-13 05:12:46 +0000653bgp_export_modifier (struct peer *rsclient, struct peer *peer,
654 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
655{
656 struct bgp_filter *filter;
657 struct bgp_info info;
658 route_map_result_t ret;
659
660 filter = &peer->filter[afi][safi];
661
662 /* Route map apply. */
663 if (ROUTE_MAP_EXPORT_NAME (filter))
664 {
665 /* Duplicate current value to new strucutre for modification. */
666 info.peer = rsclient;
667 info.attr = attr;
668
669 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
670
671 /* Apply BGP route map to the attribute. */
672 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
673
674 rsclient->rmap_type = 0;
675
676 if (ret == RMAP_DENYMATCH)
677 {
678 /* Free newly generated AS path and community by route-map. */
679 bgp_attr_flush (attr);
680 return RMAP_DENY;
681 }
682 }
683 return RMAP_PERMIT;
684}
685
paul94f2b392005-06-28 12:44:16 +0000686static int
paulfee0f4c2004-09-13 05:12:46 +0000687bgp_import_modifier (struct peer *rsclient, struct peer *peer,
688 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
689{
690 struct bgp_filter *filter;
691 struct bgp_info info;
692 route_map_result_t ret;
693
694 filter = &rsclient->filter[afi][safi];
695
696 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000697 if (peer->weight)
698 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000699
700 /* Route map apply. */
701 if (ROUTE_MAP_IMPORT_NAME (filter))
702 {
703 /* Duplicate current value to new strucutre for modification. */
704 info.peer = peer;
705 info.attr = attr;
706
707 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
708
709 /* Apply BGP route map to the attribute. */
710 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
711
712 peer->rmap_type = 0;
713
714 if (ret == RMAP_DENYMATCH)
715 {
716 /* Free newly generated AS path and community by route-map. */
717 bgp_attr_flush (attr);
718 return RMAP_DENY;
719 }
720 }
721 return RMAP_PERMIT;
722}
723
paul94f2b392005-06-28 12:44:16 +0000724static int
paul718e3742002-12-13 20:15:29 +0000725bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
726 struct attr *attr, afi_t afi, safi_t safi)
727{
728 int ret;
729 char buf[SU_ADDRSTRLEN];
730 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000731 struct peer *from;
732 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000733 int transparent;
734 int reflect;
735
736 from = ri->peer;
737 filter = &peer->filter[afi][safi];
738 bgp = peer->bgp;
739
Paul Jakma750e8142008-07-22 21:11:48 +0000740 if (DISABLE_BGP_ANNOUNCE)
741 return 0;
paul718e3742002-12-13 20:15:29 +0000742
paulfee0f4c2004-09-13 05:12:46 +0000743 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
744 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
745 return 0;
746
paul718e3742002-12-13 20:15:29 +0000747 /* Do not send back route to sender. */
748 if (from == peer)
749 return 0;
750
paul35be31b2004-05-01 18:17:04 +0000751 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
752 if (p->family == AF_INET
753 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
754 return 0;
755#ifdef HAVE_IPV6
756 if (p->family == AF_INET6
757 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
758 return 0;
759#endif
760
paul718e3742002-12-13 20:15:29 +0000761 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000762 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000763 if (! UNSUPPRESS_MAP_NAME (filter))
764 return 0;
765
766 /* Default route check. */
767 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
768 {
769 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
770 return 0;
771#ifdef HAVE_IPV6
772 else if (p->family == AF_INET6 && p->prefixlen == 0)
773 return 0;
774#endif /* HAVE_IPV6 */
775 }
776
paul286e1e72003-08-08 00:24:31 +0000777 /* Transparency check. */
778 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
779 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
780 transparent = 1;
781 else
782 transparent = 0;
783
paul718e3742002-12-13 20:15:29 +0000784 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000785 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000786 return 0;
787
788 /* If the attribute has originator-id and it is same as remote
789 peer's id. */
790 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
791 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000792 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000793 {
794 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000795 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000796 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
797 peer->host,
798 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
799 p->prefixlen);
800 return 0;
801 }
802 }
803
804 /* ORF prefix-list filter check */
805 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
806 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
807 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
808 if (peer->orf_plist[afi][safi])
809 {
810 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
811 return 0;
812 }
813
814 /* Output filter check. */
815 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
816 {
817 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000818 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000819 "%s [Update:SEND] %s/%d is filtered",
820 peer->host,
821 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
822 p->prefixlen);
823 return 0;
824 }
825
826#ifdef BGP_SEND_ASPATH_CHECK
827 /* AS path loop check. */
828 if (aspath_loop_check (ri->attr->aspath, peer->as))
829 {
830 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000831 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400832 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000833 peer->host, peer->as);
834 return 0;
835 }
836#endif /* BGP_SEND_ASPATH_CHECK */
837
838 /* If we're a CONFED we need to loop check the CONFED ID too */
839 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
840 {
841 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
842 {
843 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000844 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400845 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000846 peer->host,
847 bgp->confed_id);
848 return 0;
849 }
850 }
851
852 /* Route-Reflect check. */
853 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
854 reflect = 1;
855 else
856 reflect = 0;
857
858 /* IBGP reflection check. */
859 if (reflect)
860 {
861 /* A route from a Client peer. */
862 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
863 {
864 /* Reflect to all the Non-Client peers and also to the
865 Client peers other than the originator. Originator check
866 is already done. So there is noting to do. */
867 /* no bgp client-to-client reflection check. */
868 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
869 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
870 return 0;
871 }
872 else
873 {
874 /* A route from a Non-client peer. Reflect to all other
875 clients. */
876 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
877 return 0;
878 }
879 }
Paul Jakma41367172007-08-06 15:24:51 +0000880
881 /* AS-Pathlimit check */
882 if (ri->attr->pathlimit.ttl && peer_sort (peer) == BGP_PEER_EBGP)
883 /* Our ASN has not yet been pre-pended, that's done in packet_attribute
884 * on output. Hence the test here is for >=.
885 */
886 if (aspath_count_hops (ri->attr->aspath) >= ri->attr->pathlimit.ttl)
887 {
888 if (BGP_DEBUG (filter, FILTER))
889 zlog_info ("%s [Update:SEND] suppressed, AS-Pathlimit TTL %u exceeded",
890 peer->host, ri->attr->pathlimit.ttl);
891 return 0;
892 }
893
paul718e3742002-12-13 20:15:29 +0000894 /* For modify attribute, copy it to temporary structure. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000895 bgp_attr_dup (attr, ri->attr);
896
paul718e3742002-12-13 20:15:29 +0000897 /* If local-preference is not set. */
898 if ((peer_sort (peer) == BGP_PEER_IBGP
899 || peer_sort (peer) == BGP_PEER_CONFED)
900 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
901 {
902 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
903 attr->local_pref = bgp->default_local_pref;
904 }
905
paul718e3742002-12-13 20:15:29 +0000906 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
907 if (peer_sort (peer) == BGP_PEER_EBGP
908 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
909 {
910 if (ri->peer != bgp->peer_self && ! transparent
911 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
912 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
913 }
914
915 /* next-hop-set */
916 if (transparent || reflect
917 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
918 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000919#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000920 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000921 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000922#endif /* HAVE_IPV6 */
923 )))
paul718e3742002-12-13 20:15:29 +0000924 {
925 /* NEXT-HOP Unchanged. */
926 }
927 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
928 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
929#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000930 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000931 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000932#endif /* HAVE_IPV6 */
933 || (peer_sort (peer) == BGP_PEER_EBGP
934 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
935 {
936 /* Set IPv4 nexthop. */
937 if (p->family == AF_INET)
938 {
939 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000940 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
941 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000942 else
943 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
944 }
945#ifdef HAVE_IPV6
946 /* Set IPv6 nexthop. */
947 if (p->family == AF_INET6)
948 {
949 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000950 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +0000951 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000952 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000953 }
954#endif /* HAVE_IPV6 */
955 }
956
957#ifdef HAVE_IPV6
958 if (p->family == AF_INET6)
959 {
paulfee0f4c2004-09-13 05:12:46 +0000960 /* Left nexthop_local unchanged if so configured. */
961 if ( CHECK_FLAG (peer->af_flags[afi][safi],
962 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
963 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000964 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
965 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +0000966 else
Paul Jakmafb982c22007-05-04 20:15:47 +0000967 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +0000968 }
969
970 /* Default nexthop_local treatment for non-RS-Clients */
971 else
972 {
paul718e3742002-12-13 20:15:29 +0000973 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000974 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000975
976 /* Set link-local address for shared network peer. */
977 if (peer->shared_network
978 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
979 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000980 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +0000981 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000982 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +0000983 }
984
985 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
986 address.*/
987 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +0000988 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000989
990 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
991 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +0000992 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000993 }
paulfee0f4c2004-09-13 05:12:46 +0000994
995 }
paul718e3742002-12-13 20:15:29 +0000996#endif /* HAVE_IPV6 */
997
Paul Jakma41367172007-08-06 15:24:51 +0000998 /* AS-Pathlimit: Check ASN for private/confed */
999 if (attr->pathlimit.ttl)
1000 {
1001 /* locally originated update */
1002 if (!attr->pathlimit.as)
1003 attr->pathlimit.as = peer->local_as;
1004
1005 /* if the AS_PATHLIMIT attribute is attached to a prefix by a
1006 member of a confederation, then when the prefix is advertised outside
1007 of the confederation boundary, then the AS number of the
1008 confederation member inside of the AS_PATHLIMIT attribute should be
1009 replaced by the confederation's AS number. */
1010 if (peer_sort (from) == BGP_PEER_CONFED
1011 && peer_sort (peer) != BGP_PEER_CONFED)
1012 attr->pathlimit.as = peer->local_as;
1013
1014 /* Private ASN should be updated whenever announcement leaves
1015 * private space. This is deliberately done after simple confed
1016 * based update..
1017 */
1018 if (attr->pathlimit.as >= BGP_PRIVATE_AS_MIN
1019 && attr->pathlimit.as <= BGP_PRIVATE_AS_MAX)
1020 {
1021 if (peer->local_as < BGP_PRIVATE_AS_MIN
1022 || peer->local_as > BGP_PRIVATE_AS_MAX)
1023 attr->pathlimit.as = peer->local_as;
1024 /* Ours is private, try using theirs.. */
1025 else if (peer->as < BGP_PRIVATE_AS_MIN
1026 || peer->local_as > BGP_PRIVATE_AS_MAX)
1027 attr->pathlimit.as = peer->as;
1028 }
1029 }
1030
paul718e3742002-12-13 20:15:29 +00001031 /* If this is EBGP peer and remove-private-AS is set. */
1032 if (peer_sort (peer) == BGP_PEER_EBGP
1033 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1034 && aspath_private_as_check (attr->aspath))
1035 attr->aspath = aspath_empty_get ();
1036
1037 /* Route map & unsuppress-map apply. */
1038 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001039 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001040 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001041 struct bgp_info info;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001042 struct attr dummy_attr = { 0 };
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001043
paul718e3742002-12-13 20:15:29 +00001044 info.peer = peer;
1045 info.attr = attr;
1046
1047 /* The route reflector is not allowed to modify the attributes
1048 of the reflected IBGP routes. */
1049 if (peer_sort (from) == BGP_PEER_IBGP
1050 && peer_sort (peer) == BGP_PEER_IBGP)
1051 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001053 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001054 }
paulac41b2a2003-08-12 05:32:27 +00001055
1056 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1057
Paul Jakmafb982c22007-05-04 20:15:47 +00001058 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001059 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1060 else
1061 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1062
paulac41b2a2003-08-12 05:32:27 +00001063 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001064
Paul Jakma9eda90c2007-08-30 13:36:17 +00001065 if (dummy_attr.extra)
1066 bgp_attr_extra_free (&dummy_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001067
paul718e3742002-12-13 20:15:29 +00001068 if (ret == RMAP_DENYMATCH)
1069 {
1070 bgp_attr_flush (attr);
1071 return 0;
1072 }
1073 }
1074 return 1;
1075}
1076
paul94f2b392005-06-28 12:44:16 +00001077static int
paulfee0f4c2004-09-13 05:12:46 +00001078bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1079 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001080{
paulfee0f4c2004-09-13 05:12:46 +00001081 int ret;
1082 char buf[SU_ADDRSTRLEN];
1083 struct bgp_filter *filter;
1084 struct bgp_info info;
1085 struct peer *from;
1086 struct bgp *bgp;
1087
1088 from = ri->peer;
1089 filter = &rsclient->filter[afi][safi];
1090 bgp = rsclient->bgp;
1091
Paul Jakma750e8142008-07-22 21:11:48 +00001092 if (DISABLE_BGP_ANNOUNCE)
1093 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001094
1095 /* Do not send back route to sender. */
1096 if (from == rsclient)
1097 return 0;
1098
1099 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001100 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001101 if (! UNSUPPRESS_MAP_NAME (filter))
1102 return 0;
1103
1104 /* Default route check. */
1105 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1106 PEER_STATUS_DEFAULT_ORIGINATE))
1107 {
1108 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1109 return 0;
1110#ifdef HAVE_IPV6
1111 else if (p->family == AF_INET6 && p->prefixlen == 0)
1112 return 0;
1113#endif /* HAVE_IPV6 */
1114 }
1115
1116 /* If the attribute has originator-id and it is same as remote
1117 peer's id. */
1118 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1119 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001120 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1121 &ri->attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001122 {
1123 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001124 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001125 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1126 rsclient->host,
1127 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1128 p->prefixlen);
1129 return 0;
1130 }
1131 }
1132
1133 /* ORF prefix-list filter check */
1134 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1135 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1136 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1137 if (rsclient->orf_plist[afi][safi])
1138 {
1139 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1140 return 0;
1141 }
1142
1143 /* Output filter check. */
1144 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1145 {
1146 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001147 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001148 "%s [Update:SEND] %s/%d is filtered",
1149 rsclient->host,
1150 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1151 p->prefixlen);
1152 return 0;
1153 }
1154
1155#ifdef BGP_SEND_ASPATH_CHECK
1156 /* AS path loop check. */
1157 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1158 {
1159 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001160 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001161 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001162 rsclient->host, rsclient->as);
1163 return 0;
1164 }
1165#endif /* BGP_SEND_ASPATH_CHECK */
1166
1167 /* For modify attribute, copy it to temporary structure. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001168 bgp_attr_dup (attr, ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001169
1170 /* next-hop-set */
1171 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1172#ifdef HAVE_IPV6
1173 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001174 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001175#endif /* HAVE_IPV6 */
1176 )
1177 {
1178 /* Set IPv4 nexthop. */
1179 if (p->family == AF_INET)
1180 {
1181 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001182 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001183 IPV4_MAX_BYTELEN);
1184 else
1185 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1186 }
1187#ifdef HAVE_IPV6
1188 /* Set IPv6 nexthop. */
1189 if (p->family == AF_INET6)
1190 {
1191 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001192 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001193 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001194 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001195 }
1196#endif /* HAVE_IPV6 */
1197 }
1198
1199#ifdef HAVE_IPV6
1200 if (p->family == AF_INET6)
1201 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001202 struct attr_extra *attre = attr->extra;
1203
1204 assert (attr->extra);
1205
paulfee0f4c2004-09-13 05:12:46 +00001206 /* Left nexthop_local unchanged if so configured. */
1207 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1208 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1209 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001210 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1211 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001212 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001213 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001214 }
1215
1216 /* Default nexthop_local treatment for RS-Clients */
1217 else
1218 {
1219 /* Announcer and RS-Client are both in the same network */
1220 if (rsclient->shared_network && from->shared_network &&
1221 (rsclient->ifindex == from->ifindex))
1222 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001223 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1224 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001225 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001226 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001227 }
1228
1229 /* Set link-local address for shared network peer. */
1230 else if (rsclient->shared_network
1231 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1232 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001233 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001234 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001235 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001236 }
1237
1238 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001240 }
1241
1242 }
1243#endif /* HAVE_IPV6 */
1244
1245
1246 /* If this is EBGP peer and remove-private-AS is set. */
1247 if (peer_sort (rsclient) == BGP_PEER_EBGP
1248 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1249 && aspath_private_as_check (attr->aspath))
1250 attr->aspath = aspath_empty_get ();
1251
1252 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001253 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001254 {
1255 info.peer = rsclient;
1256 info.attr = attr;
1257
1258 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1259
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001261 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1262 else
1263 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1264
1265 rsclient->rmap_type = 0;
1266
1267 if (ret == RMAP_DENYMATCH)
1268 {
1269 bgp_attr_flush (attr);
1270 return 0;
1271 }
1272 }
1273
1274 return 1;
1275}
1276
1277struct bgp_info_pair
1278{
1279 struct bgp_info *old;
1280 struct bgp_info *new;
1281};
1282
paul94f2b392005-06-28 12:44:16 +00001283static void
paulfee0f4c2004-09-13 05:12:46 +00001284bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1285{
paul718e3742002-12-13 20:15:29 +00001286 struct bgp_info *new_select;
1287 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001288 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001289 struct bgp_info *ri1;
1290 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001291 struct bgp_info *nextri = NULL;
1292
paul718e3742002-12-13 20:15:29 +00001293 /* bgp deterministic-med */
1294 new_select = NULL;
1295 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1296 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1297 {
1298 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1299 continue;
1300 if (BGP_INFO_HOLDDOWN (ri1))
1301 continue;
1302
1303 new_select = ri1;
1304 if (ri1->next)
1305 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1306 {
1307 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1308 continue;
1309 if (BGP_INFO_HOLDDOWN (ri2))
1310 continue;
1311
1312 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1313 || aspath_cmp_left_confed (ri1->attr->aspath,
1314 ri2->attr->aspath))
1315 {
1316 if (bgp_info_cmp (bgp, ri2, new_select))
1317 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001318 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001319 new_select = ri2;
1320 }
1321
Paul Jakma1a392d42006-09-07 00:24:49 +00001322 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001323 }
1324 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001325 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1326 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001327 }
1328
1329 /* Check old selected route and new selected route. */
1330 old_select = NULL;
1331 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001332 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001333 {
1334 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1335 old_select = ri;
1336
1337 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001338 {
1339 /* reap REMOVED routes, if needs be
1340 * selected route must stay for a while longer though
1341 */
1342 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1343 && (ri != old_select))
1344 bgp_info_reap (rn, ri);
1345
1346 continue;
1347 }
paul718e3742002-12-13 20:15:29 +00001348
1349 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1350 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1351 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001352 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001353 continue;
1354 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001355 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1356 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001357
1358 if (bgp_info_cmp (bgp, ri, new_select))
1359 new_select = ri;
1360 }
paulb40d9392005-08-22 22:34:41 +00001361
paulfee0f4c2004-09-13 05:12:46 +00001362 result->old = old_select;
1363 result->new = new_select;
1364
1365 return;
1366}
1367
paul94f2b392005-06-28 12:44:16 +00001368static int
paulfee0f4c2004-09-13 05:12:46 +00001369bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001370 struct bgp_node *rn, afi_t afi, safi_t safi)
1371{
paulfee0f4c2004-09-13 05:12:46 +00001372 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001373 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001374
1375 p = &rn->p;
1376
Paul Jakma9eda90c2007-08-30 13:36:17 +00001377 /* Announce route to Established peer. */
1378 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001379 return 0;
1380
Paul Jakma9eda90c2007-08-30 13:36:17 +00001381 /* Address family configuration check. */
1382 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001383 return 0;
1384
Paul Jakma9eda90c2007-08-30 13:36:17 +00001385 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001386 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1387 PEER_STATUS_ORF_WAIT_REFRESH))
1388 return 0;
1389
1390 switch (rn->table->type)
1391 {
1392 case BGP_TABLE_MAIN:
1393 /* Announcement to peer->conf. If the route is filtered,
1394 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001395 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1396 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001397 else
1398 bgp_adj_out_unset (rn, peer, p, afi, safi);
1399 break;
1400 case BGP_TABLE_RSCLIENT:
1401 /* Announcement to peer->conf. If the route is filtered,
1402 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001403 if (selected &&
1404 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1405 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1406 else
1407 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001408 break;
1409 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001410
1411 bgp_attr_extra_free (&attr);
1412
paulfee0f4c2004-09-13 05:12:46 +00001413 return 0;
paul200df112005-06-01 11:17:05 +00001414}
paulfee0f4c2004-09-13 05:12:46 +00001415
paul200df112005-06-01 11:17:05 +00001416struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001417{
paul200df112005-06-01 11:17:05 +00001418 struct bgp *bgp;
1419 struct bgp_node *rn;
1420 afi_t afi;
1421 safi_t safi;
1422};
1423
1424static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001425bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001426{
paul0fb58d52005-11-14 14:31:49 +00001427 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001428 struct bgp *bgp = pq->bgp;
1429 struct bgp_node *rn = pq->rn;
1430 afi_t afi = pq->afi;
1431 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001432 struct bgp_info *new_select;
1433 struct bgp_info *old_select;
1434 struct bgp_info_pair old_and_new;
1435 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001436 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001437 struct peer *rsclient = rn->table->owner;
1438
Paul Jakmafb982c22007-05-04 20:15:47 +00001439 memset (&attr, 0, sizeof (struct attr));
paulfee0f4c2004-09-13 05:12:46 +00001440 /* Best path selection. */
1441 bgp_best_selection (bgp, rn, &old_and_new);
1442 new_select = old_and_new.new;
1443 old_select = old_and_new.old;
1444
paul200df112005-06-01 11:17:05 +00001445 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1446 {
1447 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1448 {
1449 /* Nothing to do. */
1450 if (old_select && old_select == new_select)
1451 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1452 continue;
paulfee0f4c2004-09-13 05:12:46 +00001453
paul200df112005-06-01 11:17:05 +00001454 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001455 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
paul200df112005-06-01 11:17:05 +00001456 if (new_select)
1457 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001458 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1459 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
paul200df112005-06-01 11:17:05 +00001460 }
paulfee0f4c2004-09-13 05:12:46 +00001461
Paul Jakma9eda90c2007-08-30 13:36:17 +00001462 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001463 }
1464 }
1465 else
1466 {
hassob7395792005-08-26 12:58:38 +00001467 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001468 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001469 if (new_select)
1470 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001471 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1472 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001473 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001474 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001475 }
paulfee0f4c2004-09-13 05:12:46 +00001476
paulb40d9392005-08-22 22:34:41 +00001477 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1478 bgp_info_reap (rn, old_select);
1479
Paul Jakmafb982c22007-05-04 20:15:47 +00001480 bgp_attr_extra_free (&attr);
1481
paul200df112005-06-01 11:17:05 +00001482 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1483 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001484}
1485
paul200df112005-06-01 11:17:05 +00001486static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001487bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001488{
paul0fb58d52005-11-14 14:31:49 +00001489 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001490 struct bgp *bgp = pq->bgp;
1491 struct bgp_node *rn = pq->rn;
1492 afi_t afi = pq->afi;
1493 safi_t safi = pq->safi;
1494 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001495 struct bgp_info *new_select;
1496 struct bgp_info *old_select;
1497 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001498 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001499 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001500
paulfee0f4c2004-09-13 05:12:46 +00001501 /* Best path selection. */
1502 bgp_best_selection (bgp, rn, &old_and_new);
1503 old_select = old_and_new.old;
1504 new_select = old_and_new.new;
1505
1506 /* Nothing to do. */
1507 if (old_select && old_select == new_select)
1508 {
1509 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001510 {
1511 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1512 bgp_zebra_announce (p, old_select, bgp);
1513
1514 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1515 return WQ_SUCCESS;
1516 }
paulfee0f4c2004-09-13 05:12:46 +00001517 }
paul718e3742002-12-13 20:15:29 +00001518
hasso338b3422005-02-23 14:27:24 +00001519 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001520 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001521 if (new_select)
1522 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001523 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1524 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001525 }
1526
1527
paul718e3742002-12-13 20:15:29 +00001528 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001529 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001530 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001531 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001532 }
1533
1534 /* FIB update. */
1535 if (safi == SAFI_UNICAST && ! bgp->name &&
1536 ! bgp_option_check (BGP_OPT_NO_FIB))
1537 {
1538 if (new_select
1539 && new_select->type == ZEBRA_ROUTE_BGP
1540 && new_select->sub_type == BGP_ROUTE_NORMAL)
1541 bgp_zebra_announce (p, new_select, bgp);
1542 else
1543 {
1544 /* Withdraw the route from the kernel. */
1545 if (old_select
1546 && old_select->type == ZEBRA_ROUTE_BGP
1547 && old_select->sub_type == BGP_ROUTE_NORMAL)
1548 bgp_zebra_withdraw (p, old_select);
1549 }
1550 }
paulb40d9392005-08-22 22:34:41 +00001551
1552 /* Reap old select bgp_info, it it has been removed */
1553 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1554 bgp_info_reap (rn, old_select);
1555
paul200df112005-06-01 11:17:05 +00001556 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1557 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001558}
1559
paul200df112005-06-01 11:17:05 +00001560static void
paul0fb58d52005-11-14 14:31:49 +00001561bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001562{
paul0fb58d52005-11-14 14:31:49 +00001563 struct bgp_process_queue *pq = data;
1564
paul200df112005-06-01 11:17:05 +00001565 bgp_unlock_node (pq->rn);
1566 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1567}
1568
1569static void
1570bgp_process_queue_init (void)
1571{
1572 bm->process_main_queue
1573 = work_queue_new (bm->master, "process_main_queue");
1574 bm->process_rsclient_queue
1575 = work_queue_new (bm->master, "process_rsclient_queue");
1576
1577 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1578 {
1579 zlog_err ("%s: Failed to allocate work queue", __func__);
1580 exit (1);
1581 }
1582
1583 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1584 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1585 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1586 bm->process_rsclient_queue->spec.del_item_data
1587 = bm->process_main_queue->spec.del_item_data;
1588 bm->process_main_queue->spec.max_retries
1589 = bm->process_main_queue->spec.max_retries = 0;
1590 bm->process_rsclient_queue->spec.hold
Paul Jakma09dd5612006-09-14 03:38:16 +00001591 = bm->process_main_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001592}
1593
1594void
paulfee0f4c2004-09-13 05:12:46 +00001595bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1596{
paul200df112005-06-01 11:17:05 +00001597 struct bgp_process_queue *pqnode;
1598
1599 /* already scheduled for processing? */
1600 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1601 return;
1602
1603 if ( (bm->process_main_queue == NULL) ||
1604 (bm->process_rsclient_queue == NULL) )
1605 bgp_process_queue_init ();
1606
1607 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1608 sizeof (struct bgp_process_queue));
1609 if (!pqnode)
1610 return;
1611
1612 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1613 pqnode->bgp = bgp;
1614 pqnode->afi = afi;
1615 pqnode->safi = safi;
1616
paulfee0f4c2004-09-13 05:12:46 +00001617 switch (rn->table->type)
1618 {
paul200df112005-06-01 11:17:05 +00001619 case BGP_TABLE_MAIN:
1620 work_queue_add (bm->process_main_queue, pqnode);
1621 break;
1622 case BGP_TABLE_RSCLIENT:
1623 work_queue_add (bm->process_rsclient_queue, pqnode);
1624 break;
paulfee0f4c2004-09-13 05:12:46 +00001625 }
paul200df112005-06-01 11:17:05 +00001626
1627 return;
paulfee0f4c2004-09-13 05:12:46 +00001628}
hasso0a486e52005-02-01 20:57:17 +00001629
paul94f2b392005-06-28 12:44:16 +00001630static int
hasso0a486e52005-02-01 20:57:17 +00001631bgp_maximum_prefix_restart_timer (struct thread *thread)
1632{
1633 struct peer *peer;
1634
1635 peer = THREAD_ARG (thread);
1636 peer->t_pmax_restart = NULL;
1637
1638 if (BGP_DEBUG (events, EVENTS))
1639 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1640 peer->host);
1641
1642 peer_clear (peer);
1643
1644 return 0;
1645}
1646
paulfee0f4c2004-09-13 05:12:46 +00001647int
paul5228ad22004-06-04 17:58:18 +00001648bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1649 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001650{
hassoe0701b72004-05-20 09:19:34 +00001651 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1652 return 0;
1653
1654 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001655 {
hassoe0701b72004-05-20 09:19:34 +00001656 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1657 && ! always)
1658 return 0;
paul718e3742002-12-13 20:15:29 +00001659
hassoe0701b72004-05-20 09:19:34 +00001660 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001661 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1662 "limit %ld", afi_safi_print (afi, safi), peer->host,
1663 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001664 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001665
hassoe0701b72004-05-20 09:19:34 +00001666 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1667 return 0;
paul718e3742002-12-13 20:15:29 +00001668
hassoe0701b72004-05-20 09:19:34 +00001669 {
paul5228ad22004-06-04 17:58:18 +00001670 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001671
1672 if (safi == SAFI_MPLS_VPN)
1673 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001674
1675 ndata[0] = (afi >> 8);
1676 ndata[1] = afi;
1677 ndata[2] = safi;
1678 ndata[3] = (peer->pmax[afi][safi] >> 24);
1679 ndata[4] = (peer->pmax[afi][safi] >> 16);
1680 ndata[5] = (peer->pmax[afi][safi] >> 8);
1681 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001682
1683 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1684 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1685 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1686 }
hasso0a486e52005-02-01 20:57:17 +00001687
1688 /* restart timer start */
1689 if (peer->pmax_restart[afi][safi])
1690 {
1691 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1692
1693 if (BGP_DEBUG (events, EVENTS))
1694 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1695 peer->host, peer->v_pmax_restart);
1696
1697 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1698 peer->v_pmax_restart);
1699 }
1700
hassoe0701b72004-05-20 09:19:34 +00001701 return 1;
paul718e3742002-12-13 20:15:29 +00001702 }
hassoe0701b72004-05-20 09:19:34 +00001703 else
1704 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1705
1706 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1707 {
1708 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1709 && ! always)
1710 return 0;
1711
1712 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001713 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1714 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1715 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001716 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1717 }
1718 else
1719 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001720 return 0;
1721}
1722
paulb40d9392005-08-22 22:34:41 +00001723/* Unconditionally remove the route from the RIB, without taking
1724 * damping into consideration (eg, because the session went down)
1725 */
paul94f2b392005-06-28 12:44:16 +00001726static void
paul718e3742002-12-13 20:15:29 +00001727bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1728 afi_t afi, safi_t safi)
1729{
paul902212c2006-02-05 17:51:19 +00001730 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1731
1732 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1733 bgp_info_delete (rn, ri); /* keep historical info */
1734
paulb40d9392005-08-22 22:34:41 +00001735 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001736}
1737
paul94f2b392005-06-28 12:44:16 +00001738static void
paul718e3742002-12-13 20:15:29 +00001739bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001740 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001741{
paul718e3742002-12-13 20:15:29 +00001742 int status = BGP_DAMP_NONE;
1743
paulb40d9392005-08-22 22:34:41 +00001744 /* apply dampening, if result is suppressed, we'll be retaining
1745 * the bgp_info in the RIB for historical reference.
1746 */
1747 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1748 && peer_sort (peer) == BGP_PEER_EBGP)
1749 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1750 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001751 {
paul902212c2006-02-05 17:51:19 +00001752 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1753 return;
1754 }
1755
1756 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001757}
1758
paul94f2b392005-06-28 12:44:16 +00001759static void
paulfee0f4c2004-09-13 05:12:46 +00001760bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1761 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1762 int sub_type, struct prefix_rd *prd, u_char *tag)
1763{
1764 struct bgp_node *rn;
1765 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001766 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001767 struct attr *attr_new;
1768 struct attr *attr_new2;
1769 struct bgp_info *ri;
1770 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001771 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001772 char buf[SU_ADDRSTRLEN];
1773
Paul Jakmafb982c22007-05-04 20:15:47 +00001774 //memset (new_attr, 0, sizeof (struct attr));
1775
paulfee0f4c2004-09-13 05:12:46 +00001776 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1777 if (peer == rsclient)
1778 return;
1779
1780 bgp = peer->bgp;
1781 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1782
1783 /* Check previously received route. */
1784 for (ri = rn->info; ri; ri = ri->next)
1785 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1786 break;
1787
1788 /* AS path loop check. */
1789 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1790 {
1791 reason = "as-path contains our own AS;";
1792 goto filtered;
1793 }
1794
1795 /* Route reflector originator ID check. */
1796 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001797 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001798 {
1799 reason = "originator is us;";
1800 goto filtered;
1801 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001802
1803 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001804
1805 /* Apply export policy. */
1806 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1807 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1808 {
1809 reason = "export-policy;";
1810 goto filtered;
1811 }
1812
1813 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001814
paulfee0f4c2004-09-13 05:12:46 +00001815 /* Apply import policy. */
1816 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1817 {
1818 bgp_attr_unintern (attr_new2);
1819
1820 reason = "import-policy;";
1821 goto filtered;
1822 }
1823
1824 attr_new = bgp_attr_intern (&new_attr);
1825 bgp_attr_unintern (attr_new2);
1826
1827 /* IPv4 unicast next hop check. */
1828 if (afi == AFI_IP && safi == SAFI_UNICAST)
1829 {
1830 /* Next hop must not be 0.0.0.0 nor Class E address. */
1831 if (new_attr.nexthop.s_addr == 0
1832 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1833 {
1834 bgp_attr_unintern (attr_new);
1835
1836 reason = "martian next-hop;";
1837 goto filtered;
1838 }
1839 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001840
1841 /* new_attr isn't passed to any functions after here */
1842 bgp_attr_extra_free (&new_attr);
1843
paulfee0f4c2004-09-13 05:12:46 +00001844 /* If the update is implicit withdraw. */
1845 if (ri)
1846 {
1847 ri->uptime = time (NULL);
1848
1849 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001850 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1851 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001852 {
1853
Paul Jakma1a392d42006-09-07 00:24:49 +00001854 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001855
1856 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001857 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001858 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1859 peer->host,
1860 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1861 p->prefixlen, rsclient->host);
1862
1863 bgp_unlock_node (rn);
1864 bgp_attr_unintern (attr_new);
1865
1866 return;
1867 }
1868
Paul Jakma16d2e242007-04-10 19:32:10 +00001869 /* Withdraw/Announce before we fully processed the withdraw */
1870 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1871 bgp_info_restore (rn, ri);
1872
paulfee0f4c2004-09-13 05:12:46 +00001873 /* Received Logging. */
1874 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001875 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001876 peer->host,
1877 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1878 p->prefixlen, rsclient->host);
1879
1880 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001881 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001882
1883 /* Update to new attribute. */
1884 bgp_attr_unintern (ri->attr);
1885 ri->attr = attr_new;
1886
1887 /* Update MPLS tag. */
1888 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001889 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001890
Paul Jakma1a392d42006-09-07 00:24:49 +00001891 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001892
1893 /* Process change. */
1894 bgp_process (bgp, rn, afi, safi);
1895 bgp_unlock_node (rn);
1896
1897 return;
1898 }
1899
1900 /* Received Logging. */
1901 if (BGP_DEBUG (update, UPDATE_IN))
1902 {
ajsd2c1f162004-12-08 21:10:20 +00001903 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001904 peer->host,
1905 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1906 p->prefixlen, rsclient->host);
1907 }
1908
1909 /* Make new BGP info. */
1910 new = bgp_info_new ();
1911 new->type = type;
1912 new->sub_type = sub_type;
1913 new->peer = peer;
1914 new->attr = attr_new;
1915 new->uptime = time (NULL);
1916
1917 /* Update MPLS tag. */
1918 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001919 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001920
Paul Jakma1a392d42006-09-07 00:24:49 +00001921 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001922
1923 /* Register new BGP information. */
1924 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001925
1926 /* route_node_get lock */
1927 bgp_unlock_node (rn);
1928
paulfee0f4c2004-09-13 05:12:46 +00001929 /* Process change. */
1930 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001931
1932 bgp_attr_extra_free (&new_attr);
1933
paulfee0f4c2004-09-13 05:12:46 +00001934 return;
1935
1936 filtered:
1937
1938 /* This BGP update is filtered. Log the reason then update BGP entry. */
1939 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001940 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001941 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1942 peer->host,
1943 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1944 p->prefixlen, rsclient->host, reason);
1945
1946 if (ri)
paulb40d9392005-08-22 22:34:41 +00001947 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001948
1949 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001950
1951 if (new_attr.extra)
1952 bgp_attr_extra_free (&new_attr);
1953
paulfee0f4c2004-09-13 05:12:46 +00001954 return;
1955}
1956
paul94f2b392005-06-28 12:44:16 +00001957static void
paulfee0f4c2004-09-13 05:12:46 +00001958bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1959 struct peer *peer, struct prefix *p, int type, int sub_type,
1960 struct prefix_rd *prd, u_char *tag)
1961 {
1962 struct bgp_node *rn;
1963 struct bgp_info *ri;
1964 char buf[SU_ADDRSTRLEN];
1965
1966 if (rsclient == peer)
1967 return;
1968
1969 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1970
1971 /* Lookup withdrawn route. */
1972 for (ri = rn->info; ri; ri = ri->next)
1973 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1974 break;
1975
1976 /* Withdraw specified route from routing table. */
1977 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001978 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001979 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001980 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001981 "%s Can't find the route %s/%d", peer->host,
1982 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1983 p->prefixlen);
1984
1985 /* Unlock bgp_node_get() lock. */
1986 bgp_unlock_node (rn);
1987 }
1988
paul94f2b392005-06-28 12:44:16 +00001989static int
paulfee0f4c2004-09-13 05:12:46 +00001990bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001991 afi_t afi, safi_t safi, int type, int sub_type,
1992 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1993{
1994 int ret;
1995 int aspath_loop_count = 0;
1996 struct bgp_node *rn;
1997 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001998 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00001999 struct attr *attr_new;
2000 struct bgp_info *ri;
2001 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002002 const char *reason;
paul718e3742002-12-13 20:15:29 +00002003 char buf[SU_ADDRSTRLEN];
2004
2005 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002006 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002007
paul718e3742002-12-13 20:15:29 +00002008 /* When peer's soft reconfiguration enabled. Record input packet in
2009 Adj-RIBs-In. */
2010 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2011 && peer != bgp->peer_self && ! soft_reconfig)
2012 bgp_adj_in_set (rn, peer, attr);
2013
2014 /* Check previously received route. */
2015 for (ri = rn->info; ri; ri = ri->next)
2016 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2017 break;
2018
2019 /* AS path local-as loop check. */
2020 if (peer->change_local_as)
2021 {
2022 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2023 aspath_loop_count = 1;
2024
2025 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2026 {
2027 reason = "as-path contains our own AS;";
2028 goto filtered;
2029 }
2030 }
2031
2032 /* AS path loop check. */
2033 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2034 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2035 && aspath_loop_check(attr->aspath, bgp->confed_id)
2036 > peer->allowas_in[afi][safi]))
2037 {
2038 reason = "as-path contains our own AS;";
2039 goto filtered;
2040 }
2041
2042 /* Route reflector originator ID check. */
2043 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002044 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002045 {
2046 reason = "originator is us;";
2047 goto filtered;
2048 }
2049
2050 /* Route reflector cluster ID check. */
2051 if (bgp_cluster_filter (peer, attr))
2052 {
2053 reason = "reflected from the same cluster;";
2054 goto filtered;
2055 }
2056
2057 /* Apply incoming filter. */
2058 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2059 {
2060 reason = "filter;";
2061 goto filtered;
2062 }
2063
2064 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002065 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002066
2067 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2068 {
2069 reason = "route-map;";
2070 goto filtered;
2071 }
2072
2073 /* IPv4 unicast next hop check. */
2074 if (afi == AFI_IP && safi == SAFI_UNICAST)
2075 {
2076 /* If the peer is EBGP and nexthop is not on connected route,
2077 discard it. */
2078 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2079 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002080 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002081 {
2082 reason = "non-connected next-hop;";
2083 goto filtered;
2084 }
2085
2086 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2087 must not be my own address. */
2088 if (bgp_nexthop_self (afi, &new_attr)
2089 || new_attr.nexthop.s_addr == 0
2090 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2091 {
2092 reason = "martian next-hop;";
2093 goto filtered;
2094 }
2095 }
2096
2097 attr_new = bgp_attr_intern (&new_attr);
2098
2099 /* If the update is implicit withdraw. */
2100 if (ri)
2101 {
2102 ri->uptime = time (NULL);
2103
2104 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002105 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2106 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002107 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002108 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002109
2110 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2111 && peer_sort (peer) == BGP_PEER_EBGP
2112 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2113 {
2114 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002115 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002116 peer->host,
2117 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2118 p->prefixlen);
2119
paul902212c2006-02-05 17:51:19 +00002120 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2121 {
2122 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2123 bgp_process (bgp, rn, afi, safi);
2124 }
paul718e3742002-12-13 20:15:29 +00002125 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002126 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002127 {
2128 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002129 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002130 "%s rcvd %s/%d...duplicate ignored",
2131 peer->host,
2132 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2133 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002134
2135 /* graceful restart STALE flag unset. */
2136 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2137 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002138 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002139 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002140 }
paul718e3742002-12-13 20:15:29 +00002141 }
2142
2143 bgp_unlock_node (rn);
2144 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002145 bgp_attr_extra_free (&new_attr);
2146
paul718e3742002-12-13 20:15:29 +00002147 return 0;
2148 }
2149
Paul Jakma16d2e242007-04-10 19:32:10 +00002150 /* Withdraw/Announce before we fully processed the withdraw */
2151 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2152 {
2153 if (BGP_DEBUG (update, UPDATE_IN))
2154 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2155 peer->host,
2156 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2157 p->prefixlen);
2158 bgp_info_restore (rn, ri);
2159 }
2160
paul718e3742002-12-13 20:15:29 +00002161 /* Received Logging. */
2162 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002163 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002164 peer->host,
2165 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2166 p->prefixlen);
2167
hasso93406d82005-02-02 14:40:33 +00002168 /* graceful restart STALE flag unset. */
2169 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002170 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002171
paul718e3742002-12-13 20:15:29 +00002172 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002173 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002174
2175 /* implicit withdraw, decrement aggregate and pcount here.
2176 * only if update is accepted, they'll increment below.
2177 */
paul902212c2006-02-05 17:51:19 +00002178 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2179
paul718e3742002-12-13 20:15:29 +00002180 /* Update bgp route dampening information. */
2181 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2182 && peer_sort (peer) == BGP_PEER_EBGP)
2183 {
2184 /* This is implicit withdraw so we should update dampening
2185 information. */
2186 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2187 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002188 }
2189
paul718e3742002-12-13 20:15:29 +00002190 /* Update to new attribute. */
2191 bgp_attr_unintern (ri->attr);
2192 ri->attr = attr_new;
2193
2194 /* Update MPLS tag. */
2195 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002196 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002197
2198 /* Update bgp route dampening information. */
2199 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2200 && peer_sort (peer) == BGP_PEER_EBGP)
2201 {
2202 /* Now we do normal update dampening. */
2203 ret = bgp_damp_update (ri, rn, afi, safi);
2204 if (ret == BGP_DAMP_SUPPRESSED)
2205 {
2206 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002207 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002208 return 0;
2209 }
2210 }
2211
2212 /* Nexthop reachability check. */
2213 if ((afi == AFI_IP || afi == AFI_IP6)
2214 && safi == SAFI_UNICAST
2215 && (peer_sort (peer) == BGP_PEER_IBGP
2216 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002217 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002218 {
2219 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002220 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002221 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002222 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002223 }
2224 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002225 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002226
2227 /* Process change. */
2228 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2229
2230 bgp_process (bgp, rn, afi, safi);
2231 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002232 bgp_attr_extra_free (&new_attr);
2233
paul718e3742002-12-13 20:15:29 +00002234 return 0;
2235 }
2236
2237 /* Received Logging. */
2238 if (BGP_DEBUG (update, UPDATE_IN))
2239 {
ajsd2c1f162004-12-08 21:10:20 +00002240 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002241 peer->host,
2242 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2243 p->prefixlen);
2244 }
2245
paul718e3742002-12-13 20:15:29 +00002246 /* Make new BGP info. */
2247 new = bgp_info_new ();
2248 new->type = type;
2249 new->sub_type = sub_type;
2250 new->peer = peer;
2251 new->attr = attr_new;
2252 new->uptime = time (NULL);
2253
2254 /* Update MPLS tag. */
2255 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002256 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002257
2258 /* Nexthop reachability check. */
2259 if ((afi == AFI_IP || afi == AFI_IP6)
2260 && safi == SAFI_UNICAST
2261 && (peer_sort (peer) == BGP_PEER_IBGP
2262 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002263 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002264 {
2265 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002266 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002267 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002268 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002269 }
2270 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002271 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002272
paul902212c2006-02-05 17:51:19 +00002273 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002274 bgp_aggregate_increment (bgp, p, new, afi, safi);
2275
2276 /* Register new BGP information. */
2277 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002278
2279 /* route_node_get lock */
2280 bgp_unlock_node (rn);
2281
Paul Jakmafb982c22007-05-04 20:15:47 +00002282 bgp_attr_extra_free (&new_attr);
2283
paul718e3742002-12-13 20:15:29 +00002284 /* If maximum prefix count is configured and current prefix
2285 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002286 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2287 return -1;
paul718e3742002-12-13 20:15:29 +00002288
2289 /* Process change. */
2290 bgp_process (bgp, rn, afi, safi);
2291
2292 return 0;
2293
2294 /* This BGP update is filtered. Log the reason then update BGP
2295 entry. */
2296 filtered:
2297 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002298 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002299 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2300 peer->host,
2301 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2302 p->prefixlen, reason);
2303
2304 if (ri)
paulb40d9392005-08-22 22:34:41 +00002305 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002306
2307 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002308
2309 bgp_attr_extra_free (&new_attr);
2310
paul718e3742002-12-13 20:15:29 +00002311 return 0;
2312}
2313
2314int
paulfee0f4c2004-09-13 05:12:46 +00002315bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2316 afi_t afi, safi_t safi, int type, int sub_type,
2317 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2318{
2319 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002320 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002321 struct bgp *bgp;
2322 int ret;
2323
2324 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2325 soft_reconfig);
2326
2327 bgp = peer->bgp;
2328
2329 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002330 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002331 {
2332 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2333 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2334 sub_type, prd, tag);
2335 }
2336
2337 return ret;
2338}
2339
2340int
paul718e3742002-12-13 20:15:29 +00002341bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002342 afi_t afi, safi_t safi, int type, int sub_type,
2343 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002344{
2345 struct bgp *bgp;
2346 char buf[SU_ADDRSTRLEN];
2347 struct bgp_node *rn;
2348 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002349 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002350 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002351
2352 bgp = peer->bgp;
2353
paulfee0f4c2004-09-13 05:12:46 +00002354 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002355 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002356 {
2357 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2358 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2359 }
2360
paul718e3742002-12-13 20:15:29 +00002361 /* Logging. */
2362 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002363 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002364 peer->host,
2365 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2366 p->prefixlen);
2367
2368 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002369 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002370
2371 /* If peer is soft reconfiguration enabled. Record input packet for
2372 further calculation. */
2373 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2374 && peer != bgp->peer_self)
2375 bgp_adj_in_unset (rn, peer);
2376
2377 /* Lookup withdrawn route. */
2378 for (ri = rn->info; ri; ri = ri->next)
2379 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2380 break;
2381
2382 /* Withdraw specified route from routing table. */
2383 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002384 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002385 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002386 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002387 "%s Can't find the route %s/%d", peer->host,
2388 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2389 p->prefixlen);
2390
2391 /* Unlock bgp_node_get() lock. */
2392 bgp_unlock_node (rn);
2393
2394 return 0;
2395}
2396
2397void
2398bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2399{
2400 struct bgp *bgp;
2401 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00002402 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002403 struct prefix p;
2404 struct bgp_info binfo;
2405 struct peer *from;
2406 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002407
Paul Jakmab2497022007-06-14 11:17:58 +00002408 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002409 return;
2410
paul718e3742002-12-13 20:15:29 +00002411 bgp = peer->bgp;
2412 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002413
paul718e3742002-12-13 20:15:29 +00002414 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2415 aspath = attr.aspath;
2416 attr.local_pref = bgp->default_local_pref;
2417 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2418
2419 if (afi == AFI_IP)
2420 str2prefix ("0.0.0.0/0", &p);
2421#ifdef HAVE_IPV6
2422 else if (afi == AFI_IP6)
2423 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002424 struct attr_extra *ae;
2425 attr.extra = NULL;
2426
2427 ae = bgp_attr_extra_get (&attr);
2428 attr.extra = ae;
2429
paul718e3742002-12-13 20:15:29 +00002430 str2prefix ("::/0", &p);
2431
2432 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002433 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002434 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002435 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002436
2437 /* If the peer is on shared nextwork and we have link-local
2438 nexthop set it. */
2439 if (peer->shared_network
2440 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2441 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002442 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002443 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002444 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002445 }
2446 }
2447#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002448
2449 if (peer->default_rmap[afi][safi].name)
2450 {
2451 binfo.peer = bgp->peer_self;
2452 binfo.attr = &attr;
2453
paulfee0f4c2004-09-13 05:12:46 +00002454 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2455
paul718e3742002-12-13 20:15:29 +00002456 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2457 RMAP_BGP, &binfo);
2458
paulfee0f4c2004-09-13 05:12:46 +00002459 bgp->peer_self->rmap_type = 0;
2460
paul718e3742002-12-13 20:15:29 +00002461 if (ret == RMAP_DENYMATCH)
2462 {
2463 bgp_attr_flush (&attr);
2464 withdraw = 1;
2465 }
2466 }
2467
2468 if (withdraw)
2469 {
2470 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2471 bgp_default_withdraw_send (peer, afi, safi);
2472 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2473 }
2474 else
2475 {
2476 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2477 bgp_default_update_send (peer, &attr, afi, safi, from);
2478 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002479
2480 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002481 aspath_unintern (aspath);
2482}
2483
2484static void
2485bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002486 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002487{
2488 struct bgp_node *rn;
2489 struct bgp_info *ri;
2490 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00002491
2492 memset (&attr, 0, sizeof (struct attr));
2493
paul718e3742002-12-13 20:15:29 +00002494 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002495 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002496
2497 if (safi != SAFI_MPLS_VPN
2498 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2499 bgp_default_originate (peer, afi, safi, 0);
2500
2501 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2502 for (ri = rn->info; ri; ri = ri->next)
2503 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2504 {
paulfee0f4c2004-09-13 05:12:46 +00002505 if ( (rsclient) ?
2506 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2507 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002508 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2509 else
2510 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002511
2512 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002513 }
2514}
2515
2516void
2517bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2518{
2519 struct bgp_node *rn;
2520 struct bgp_table *table;
2521
2522 if (peer->status != Established)
2523 return;
2524
2525 if (! peer->afc_nego[afi][safi])
2526 return;
2527
2528 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2529 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2530 return;
2531
2532 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002533 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002534 else
2535 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2536 rn = bgp_route_next(rn))
2537 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002538 bgp_announce_table (peer, afi, safi, table, 0);
2539
2540 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2541 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002542}
2543
2544void
2545bgp_announce_route_all (struct peer *peer)
2546{
2547 afi_t afi;
2548 safi_t safi;
2549
2550 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2551 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2552 bgp_announce_route (peer, afi, safi);
2553}
2554
2555static void
paulfee0f4c2004-09-13 05:12:46 +00002556bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2557 safi_t safi, struct bgp_table *table)
2558{
2559 struct bgp_node *rn;
2560 struct bgp_adj_in *ain;
2561
2562 if (! table)
2563 table = rsclient->bgp->rib[afi][safi];
2564
2565 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2566 for (ain = rn->adj_in; ain; ain = ain->next)
2567 {
2568 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2569 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2570 }
2571}
2572
2573void
2574bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2575{
2576 struct bgp_table *table;
2577 struct bgp_node *rn;
2578
2579 if (safi != SAFI_MPLS_VPN)
2580 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2581
2582 else
2583 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2584 rn = bgp_route_next (rn))
2585 if ((table = rn->info) != NULL)
2586 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2587}
2588
2589static void
paul718e3742002-12-13 20:15:29 +00002590bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2591 struct bgp_table *table)
2592{
2593 int ret;
2594 struct bgp_node *rn;
2595 struct bgp_adj_in *ain;
2596
2597 if (! table)
2598 table = peer->bgp->rib[afi][safi];
2599
2600 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2601 for (ain = rn->adj_in; ain; ain = ain->next)
2602 {
2603 if (ain->peer == peer)
2604 {
2605 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2606 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2607 NULL, NULL, 1);
2608 if (ret < 0)
2609 {
2610 bgp_unlock_node (rn);
2611 return;
2612 }
2613 continue;
2614 }
2615 }
2616}
2617
2618void
2619bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2620{
2621 struct bgp_node *rn;
2622 struct bgp_table *table;
2623
2624 if (peer->status != Established)
2625 return;
2626
2627 if (safi != SAFI_MPLS_VPN)
2628 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2629 else
2630 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2631 rn = bgp_route_next (rn))
2632 if ((table = rn->info) != NULL)
2633 bgp_soft_reconfig_table (peer, afi, safi, table);
2634}
2635
paul200df112005-06-01 11:17:05 +00002636static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002637bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002638{
Paul Jakma64e580a2006-02-21 01:09:01 +00002639 struct bgp_node *rn = data;
2640 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002641 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002642 afi_t afi = rn->table->afi;
2643 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002644
Paul Jakma64e580a2006-02-21 01:09:01 +00002645 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002646
Paul Jakma64e580a2006-02-21 01:09:01 +00002647 for (ri = rn->info; ri; ri = ri->next)
2648 if (ri->peer == peer)
paul200df112005-06-01 11:17:05 +00002649 {
2650 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002651 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2652 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002653 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002654 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2655 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002656 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002657 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002658 break;
2659 }
paul200df112005-06-01 11:17:05 +00002660 return WQ_SUCCESS;
2661}
2662
2663static void
paul0fb58d52005-11-14 14:31:49 +00002664bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002665{
Paul Jakma64e580a2006-02-21 01:09:01 +00002666 struct bgp_node *rn = data;
2667
2668 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002669}
2670
2671static void
paul94f2b392005-06-28 12:44:16 +00002672bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002673{
Paul Jakma64e580a2006-02-21 01:09:01 +00002674 struct peer *peer = wq->spec.data;
2675
Paul Jakma64e580a2006-02-21 01:09:01 +00002676 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002677
2678 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002679 BGP_EVENT_ADD (peer, Clearing_Completed);
paul200df112005-06-01 11:17:05 +00002680}
2681
2682static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002683bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002684{
Paul Jakma64e580a2006-02-21 01:09:01 +00002685#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2686 char wname[CLEAR_QUEUE_NAME_LEN];
2687
2688 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2689#undef CLEAR_QUEUE_NAME_LEN
2690
2691 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002692 {
2693 zlog_err ("%s: Failed to allocate work queue", __func__);
2694 exit (1);
2695 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002696 peer->clear_node_queue->spec.hold = 10;
2697 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2698 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2699 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2700 peer->clear_node_queue->spec.max_retries = 0;
2701
2702 /* we only 'lock' this peer reference when the queue is actually active */
2703 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002704}
2705
paul718e3742002-12-13 20:15:29 +00002706static void
2707bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002708 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002709{
2710 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002711
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002712
paul718e3742002-12-13 20:15:29 +00002713 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002714 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002715
hasso6cf159b2005-03-21 10:28:14 +00002716 /* If still no table => afi/safi isn't configured at all or smth. */
2717 if (! table)
2718 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002719
2720 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2721 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002722 struct bgp_info *ri;
2723 struct bgp_adj_in *ain;
2724 struct bgp_adj_out *aout;
2725
Paul Jakma65ca75e2006-05-04 08:08:15 +00002726 if (rn->info == NULL)
2727 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002728
2729 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2730 * queued for every clearing peer, regardless of whether it is
2731 * relevant to the peer at hand.
2732 *
2733 * Overview: There are 3 different indices which need to be
2734 * scrubbed, potentially, when a peer is removed:
2735 *
2736 * 1 peer's routes visible via the RIB (ie accepted routes)
2737 * 2 peer's routes visible by the (optional) peer's adj-in index
2738 * 3 other routes visible by the peer's adj-out index
2739 *
2740 * 3 there is no hurry in scrubbing, once the struct peer is
2741 * removed from bgp->peer, we could just GC such deleted peer's
2742 * adj-outs at our leisure.
2743 *
2744 * 1 and 2 must be 'scrubbed' in some way, at least made
2745 * invisible via RIB index before peer session is allowed to be
2746 * brought back up. So one needs to know when such a 'search' is
2747 * complete.
2748 *
2749 * Ideally:
2750 *
2751 * - there'd be a single global queue or a single RIB walker
2752 * - rather than tracking which route_nodes still need to be
2753 * examined on a peer basis, we'd track which peers still
2754 * aren't cleared
2755 *
2756 * Given that our per-peer prefix-counts now should be reliable,
2757 * this may actually be achievable. It doesn't seem to be a huge
2758 * problem at this time,
2759 */
2760 for (ri = rn->info; ri; ri = ri->next)
2761 if (ri->peer == peer)
2762 {
2763 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2764 work_queue_add (peer->clear_node_queue, rn);
2765 }
2766
2767 for (ain = rn->adj_in; ain; ain = ain->next)
2768 if (ain->peer == peer)
2769 {
2770 bgp_adj_in_remove (rn, ain);
2771 bgp_unlock_node (rn);
2772 break;
2773 }
2774 for (aout = rn->adj_out; aout; aout = aout->next)
2775 if (aout->peer == peer)
2776 {
2777 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2778 bgp_unlock_node (rn);
2779 break;
2780 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002781 }
2782 return;
2783}
2784
2785void
2786bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2787{
2788 struct bgp_node *rn;
2789 struct bgp_table *table;
2790 struct peer *rsclient;
2791 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002792
Paul Jakma64e580a2006-02-21 01:09:01 +00002793 if (peer->clear_node_queue == NULL)
2794 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002795
Paul Jakmaca058a32006-09-14 02:58:49 +00002796 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2797 * Idle until it receives a Clearing_Completed event. This protects
2798 * against peers which flap faster than we can we clear, which could
2799 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002800 *
2801 * a) race with routes from the new session being installed before
2802 * clear_route_node visits the node (to delete the route of that
2803 * peer)
2804 * b) resource exhaustion, clear_route_node likely leads to an entry
2805 * on the process_main queue. Fast-flapping could cause that queue
2806 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002807 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002808 if (!peer->clear_node_queue->thread)
2809 peer_lock (peer); /* bgp_clear_node_complete */
paul200df112005-06-01 11:17:05 +00002810
paul718e3742002-12-13 20:15:29 +00002811 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002812 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002813 else
2814 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2815 rn = bgp_route_next (rn))
2816 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002817 bgp_clear_route_table (peer, afi, safi, table, NULL);
2818
paul1eb8ef22005-04-07 07:30:20 +00002819 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002820 {
2821 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2822 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2823 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002824
Paul Jakmaca058a32006-09-14 02:58:49 +00002825 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002826 * completion function won't be run by workqueue code - call it here.
2827 * XXX: Actually, this assumption doesn't hold, see
2828 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002829 *
2830 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002831 * really needed if peer state is Established - peers in
2832 * pre-Established states shouldn't have any route-update state
2833 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002834 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002835 * We still can get here in pre-Established though, through
2836 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2837 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002838 *
2839 * At some future point, this check could be move to the top of the
2840 * function, and do a quick early-return when state is
2841 * pre-Established, avoiding above list and table scans. Once we're
2842 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002843 */
2844 if (!peer->clear_node_queue->thread)
2845 bgp_clear_node_complete (peer->clear_node_queue);
Paul Jakmaca058a32006-09-14 02:58:49 +00002846 else
2847 {
2848 /* clearing queue scheduled. Normal if in Established state
2849 * (and about to transition out of it), but otherwise...
2850 */
2851 if (peer->status != Established)
2852 {
2853 plog_err (peer->log, "%s [Error] State %s is not Established,"
2854 " but routes were cleared - bug!",
2855 peer->host, LOOKUP (bgp_status_msg, peer->status));
2856 assert (peer->status == Established);
2857 }
2858 }
paul718e3742002-12-13 20:15:29 +00002859}
2860
2861void
2862bgp_clear_route_all (struct peer *peer)
2863{
2864 afi_t afi;
2865 safi_t safi;
2866
2867 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2868 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2869 bgp_clear_route (peer, afi, safi);
2870}
2871
2872void
2873bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2874{
2875 struct bgp_table *table;
2876 struct bgp_node *rn;
2877 struct bgp_adj_in *ain;
2878
2879 table = peer->bgp->rib[afi][safi];
2880
2881 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2882 for (ain = rn->adj_in; ain ; ain = ain->next)
2883 if (ain->peer == peer)
2884 {
2885 bgp_adj_in_remove (rn, ain);
2886 bgp_unlock_node (rn);
2887 break;
2888 }
2889}
hasso93406d82005-02-02 14:40:33 +00002890
2891void
2892bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2893{
2894 struct bgp_node *rn;
2895 struct bgp_info *ri;
2896 struct bgp_table *table;
2897
2898 table = peer->bgp->rib[afi][safi];
2899
2900 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2901 {
2902 for (ri = rn->info; ri; ri = ri->next)
2903 if (ri->peer == peer)
2904 {
2905 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2906 bgp_rib_remove (rn, ri, peer, afi, safi);
2907 break;
2908 }
2909 }
2910}
paul718e3742002-12-13 20:15:29 +00002911
2912/* Delete all kernel routes. */
2913void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002914bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002915{
2916 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002917 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002918 struct bgp_node *rn;
2919 struct bgp_table *table;
2920 struct bgp_info *ri;
2921
paul1eb8ef22005-04-07 07:30:20 +00002922 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002923 {
2924 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2925
2926 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2927 for (ri = rn->info; ri; ri = ri->next)
2928 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2929 && ri->type == ZEBRA_ROUTE_BGP
2930 && ri->sub_type == BGP_ROUTE_NORMAL)
2931 bgp_zebra_withdraw (&rn->p, ri);
2932
2933 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2934
2935 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2936 for (ri = rn->info; ri; ri = ri->next)
2937 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2938 && ri->type == ZEBRA_ROUTE_BGP
2939 && ri->sub_type == BGP_ROUTE_NORMAL)
2940 bgp_zebra_withdraw (&rn->p, ri);
2941 }
2942}
2943
2944void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002945bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00002946{
2947 vty_reset ();
2948 bgp_zclient_reset ();
2949 access_list_reset ();
2950 prefix_list_reset ();
2951}
2952
2953/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2954 value. */
2955int
2956bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2957{
2958 u_char *pnt;
2959 u_char *lim;
2960 struct prefix p;
2961 int psize;
2962 int ret;
2963
2964 /* Check peer status. */
2965 if (peer->status != Established)
2966 return 0;
2967
2968 pnt = packet->nlri;
2969 lim = pnt + packet->length;
2970
2971 for (; pnt < lim; pnt += psize)
2972 {
2973 /* Clear prefix structure. */
2974 memset (&p, 0, sizeof (struct prefix));
2975
2976 /* Fetch prefix length. */
2977 p.prefixlen = *pnt++;
2978 p.family = afi2family (packet->afi);
2979
2980 /* Already checked in nlri_sanity_check(). We do double check
2981 here. */
2982 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2983 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2984 return -1;
2985
2986 /* Packet size overflow check. */
2987 psize = PSIZE (p.prefixlen);
2988
2989 /* When packet overflow occur return immediately. */
2990 if (pnt + psize > lim)
2991 return -1;
2992
2993 /* Fetch prefix from NLRI packet. */
2994 memcpy (&p.u.prefix, pnt, psize);
2995
2996 /* Check address. */
2997 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2998 {
2999 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3000 {
paulf5ba3872004-07-09 12:11:31 +00003001 /*
3002 * From draft-ietf-idr-bgp4-22, Section 6.3:
3003 * If a BGP router receives an UPDATE message with a
3004 * semantically incorrect NLRI field, in which a prefix is
3005 * semantically incorrect (eg. an unexpected multicast IP
3006 * address), it should ignore the prefix.
3007 */
paul718e3742002-12-13 20:15:29 +00003008 zlog (peer->log, LOG_ERR,
3009 "IPv4 unicast NLRI is multicast address %s",
3010 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003011
paul718e3742002-12-13 20:15:29 +00003012 return -1;
3013 }
3014 }
3015
3016#ifdef HAVE_IPV6
3017 /* Check address. */
3018 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3019 {
3020 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3021 {
3022 char buf[BUFSIZ];
3023
3024 zlog (peer->log, LOG_WARNING,
3025 "IPv6 link-local NLRI received %s ignore this NLRI",
3026 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3027
3028 continue;
3029 }
3030 }
3031#endif /* HAVE_IPV6 */
3032
3033 /* Normal process. */
3034 if (attr)
3035 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3036 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3037 else
3038 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3039 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3040
3041 /* Address family configuration mismatch or maximum-prefix count
3042 overflow. */
3043 if (ret < 0)
3044 return -1;
3045 }
3046
3047 /* Packet length consistency check. */
3048 if (pnt != lim)
3049 return -1;
3050
3051 return 0;
3052}
3053
3054/* NLRI encode syntax check routine. */
3055int
3056bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3057 bgp_size_t length)
3058{
3059 u_char *end;
3060 u_char prefixlen;
3061 int psize;
3062
3063 end = pnt + length;
3064
3065 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3066 syntactic validity. If the field is syntactically incorrect,
3067 then the Error Subcode is set to Invalid Network Field. */
3068
3069 while (pnt < end)
3070 {
3071 prefixlen = *pnt++;
3072
3073 /* Prefix length check. */
3074 if ((afi == AFI_IP && prefixlen > 32)
3075 || (afi == AFI_IP6 && prefixlen > 128))
3076 {
3077 plog_err (peer->log,
3078 "%s [Error] Update packet error (wrong prefix length %d)",
3079 peer->host, prefixlen);
3080 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3081 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3082 return -1;
3083 }
3084
3085 /* Packet size overflow check. */
3086 psize = PSIZE (prefixlen);
3087
3088 if (pnt + psize > end)
3089 {
3090 plog_err (peer->log,
3091 "%s [Error] Update packet error"
3092 " (prefix data overflow prefix size is %d)",
3093 peer->host, psize);
3094 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3095 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3096 return -1;
3097 }
3098
3099 pnt += psize;
3100 }
3101
3102 /* Packet length consistency check. */
3103 if (pnt != end)
3104 {
3105 plog_err (peer->log,
3106 "%s [Error] Update packet error"
3107 " (prefix length mismatch with total length)",
3108 peer->host);
3109 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3110 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3111 return -1;
3112 }
3113 return 0;
3114}
3115
paul94f2b392005-06-28 12:44:16 +00003116static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003117bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003118{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003119 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003120}
3121
paul94f2b392005-06-28 12:44:16 +00003122static void
paul718e3742002-12-13 20:15:29 +00003123bgp_static_free (struct bgp_static *bgp_static)
3124{
3125 if (bgp_static->rmap.name)
3126 free (bgp_static->rmap.name);
3127 XFREE (MTYPE_BGP_STATIC, bgp_static);
3128}
3129
paul94f2b392005-06-28 12:44:16 +00003130static void
paulfee0f4c2004-09-13 05:12:46 +00003131bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3132 struct prefix *p, afi_t afi, safi_t safi)
3133{
3134 struct bgp_node *rn;
3135 struct bgp_info *ri;
3136
3137 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3138
3139 /* Check selected route and self inserted route. */
3140 for (ri = rn->info; ri; ri = ri->next)
3141 if (ri->peer == bgp->peer_self
3142 && ri->type == ZEBRA_ROUTE_BGP
3143 && ri->sub_type == BGP_ROUTE_STATIC)
3144 break;
3145
3146 /* Withdraw static BGP route from routing table. */
3147 if (ri)
3148 {
paulfee0f4c2004-09-13 05:12:46 +00003149 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003150 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003151 }
3152
3153 /* Unlock bgp_node_lookup. */
3154 bgp_unlock_node (rn);
3155}
3156
paul94f2b392005-06-28 12:44:16 +00003157static void
paulfee0f4c2004-09-13 05:12:46 +00003158bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003159 struct bgp_static *bgp_static,
3160 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003161{
3162 struct bgp_node *rn;
3163 struct bgp_info *ri;
3164 struct bgp_info *new;
3165 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003166 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003167 struct attr attr = {0 };
3168 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003169 struct bgp *bgp;
3170 int ret;
3171 char buf[SU_ADDRSTRLEN];
3172
3173 bgp = rsclient->bgp;
3174
Paul Jakma06e110f2006-05-12 23:29:22 +00003175 assert (bgp_static);
3176 if (!bgp_static)
3177 return;
3178
paulfee0f4c2004-09-13 05:12:46 +00003179 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3180
3181 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003182
3183 attr.nexthop = bgp_static->igpnexthop;
3184 attr.med = bgp_static->igpmetric;
3185 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003186
3187 if (bgp_static->ttl)
3188 {
3189 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3190 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3191 attr.pathlimit.as = 0;
3192 attr.pathlimit.ttl = bgp_static->ttl;
3193 }
3194
3195 if (bgp_static->atomic)
3196 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3197
paulfee0f4c2004-09-13 05:12:46 +00003198 /* Apply network route-map for export to this rsclient. */
3199 if (bgp_static->rmap.name)
3200 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003201 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003202 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003203 info.attr = &attr_tmp;
3204
paulfee0f4c2004-09-13 05:12:46 +00003205 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3206 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3207
3208 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3209
3210 rsclient->rmap_type = 0;
3211
3212 if (ret == RMAP_DENYMATCH)
3213 {
3214 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003215 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003216
3217 /* Unintern original. */
3218 aspath_unintern (attr.aspath);
3219 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003220 bgp_attr_extra_free (&attr);
3221
paulfee0f4c2004-09-13 05:12:46 +00003222 return;
3223 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003224 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003225 }
3226 else
3227 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003228
paulfee0f4c2004-09-13 05:12:46 +00003229 new_attr = *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003230
paulfee0f4c2004-09-13 05:12:46 +00003231 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3232
Paul Jakmafb982c22007-05-04 20:15:47 +00003233 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3234 == RMAP_DENY)
3235 {
paulfee0f4c2004-09-13 05:12:46 +00003236 /* This BGP update is filtered. Log the reason then update BGP entry. */
3237 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003238 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003239 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3240 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3241 p->prefixlen, rsclient->host);
3242
3243 bgp->peer_self->rmap_type = 0;
3244
3245 bgp_attr_unintern (attr_new);
3246 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003247 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003248
3249 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3250
3251 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003252 }
paulfee0f4c2004-09-13 05:12:46 +00003253
3254 bgp->peer_self->rmap_type = 0;
3255
3256 bgp_attr_unintern (attr_new);
3257 attr_new = bgp_attr_intern (&new_attr);
3258
3259 for (ri = rn->info; ri; ri = ri->next)
3260 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3261 && ri->sub_type == BGP_ROUTE_STATIC)
3262 break;
3263
3264 if (ri)
3265 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003266 if (attrhash_cmp (ri->attr, attr_new) &&
3267 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003268 {
3269 bgp_unlock_node (rn);
3270 bgp_attr_unintern (attr_new);
3271 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003272 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003273 return;
3274 }
3275 else
3276 {
3277 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003278 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003279
3280 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003281 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3282 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003283 bgp_attr_unintern (ri->attr);
3284 ri->attr = attr_new;
3285 ri->uptime = time (NULL);
3286
3287 /* Process change. */
3288 bgp_process (bgp, rn, afi, safi);
3289 bgp_unlock_node (rn);
3290 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003291 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003292 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003293 }
paulfee0f4c2004-09-13 05:12:46 +00003294 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003295
paulfee0f4c2004-09-13 05:12:46 +00003296 /* Make new BGP info. */
3297 new = bgp_info_new ();
3298 new->type = ZEBRA_ROUTE_BGP;
3299 new->sub_type = BGP_ROUTE_STATIC;
3300 new->peer = bgp->peer_self;
3301 SET_FLAG (new->flags, BGP_INFO_VALID);
3302 new->attr = attr_new;
3303 new->uptime = time (NULL);
3304
3305 /* Register new BGP information. */
3306 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003307
3308 /* route_node_get lock */
3309 bgp_unlock_node (rn);
3310
paulfee0f4c2004-09-13 05:12:46 +00003311 /* Process change. */
3312 bgp_process (bgp, rn, afi, safi);
3313
3314 /* Unintern original. */
3315 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003316 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003317}
3318
paul94f2b392005-06-28 12:44:16 +00003319static void
paulfee0f4c2004-09-13 05:12:46 +00003320bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003321 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3322{
3323 struct bgp_node *rn;
3324 struct bgp_info *ri;
3325 struct bgp_info *new;
3326 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003327 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003328 struct attr *attr_new;
3329 int ret;
3330
Paul Jakmadd8103a2006-05-12 23:27:30 +00003331 assert (bgp_static);
3332 if (!bgp_static)
3333 return;
3334
paulfee0f4c2004-09-13 05:12:46 +00003335 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003336
3337 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003338
3339 attr.nexthop = bgp_static->igpnexthop;
3340 attr.med = bgp_static->igpmetric;
3341 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003342
Paul Jakma41367172007-08-06 15:24:51 +00003343 if (bgp_static->ttl)
3344 {
3345 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3346 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3347 attr.pathlimit.as = 0;
3348 attr.pathlimit.ttl = bgp_static->ttl;
3349 }
3350
3351 if (bgp_static->atomic)
3352 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3353
paul718e3742002-12-13 20:15:29 +00003354 /* Apply route-map. */
3355 if (bgp_static->rmap.name)
3356 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003357 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003358 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003359 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003360
paulfee0f4c2004-09-13 05:12:46 +00003361 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3362
paul718e3742002-12-13 20:15:29 +00003363 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003364
paulfee0f4c2004-09-13 05:12:46 +00003365 bgp->peer_self->rmap_type = 0;
3366
paul718e3742002-12-13 20:15:29 +00003367 if (ret == RMAP_DENYMATCH)
3368 {
3369 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003370 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003371
3372 /* Unintern original. */
3373 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003374 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003375 bgp_static_withdraw (bgp, p, afi, safi);
3376 return;
3377 }
paul286e1e72003-08-08 00:24:31 +00003378 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003379 }
paul286e1e72003-08-08 00:24:31 +00003380 else
3381 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003382
3383 for (ri = rn->info; ri; ri = ri->next)
3384 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3385 && ri->sub_type == BGP_ROUTE_STATIC)
3386 break;
3387
3388 if (ri)
3389 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003390 if (attrhash_cmp (ri->attr, attr_new) &&
3391 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003392 {
3393 bgp_unlock_node (rn);
3394 bgp_attr_unintern (attr_new);
3395 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003396 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003397 return;
3398 }
3399 else
3400 {
3401 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003402 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003403
3404 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003405 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3406 bgp_info_restore(rn, ri);
3407 else
3408 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003409 bgp_attr_unintern (ri->attr);
3410 ri->attr = attr_new;
3411 ri->uptime = time (NULL);
3412
3413 /* Process change. */
3414 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3415 bgp_process (bgp, rn, afi, safi);
3416 bgp_unlock_node (rn);
3417 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003418 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003419 return;
3420 }
3421 }
3422
3423 /* Make new BGP info. */
3424 new = bgp_info_new ();
3425 new->type = ZEBRA_ROUTE_BGP;
3426 new->sub_type = BGP_ROUTE_STATIC;
3427 new->peer = bgp->peer_self;
3428 SET_FLAG (new->flags, BGP_INFO_VALID);
3429 new->attr = attr_new;
3430 new->uptime = time (NULL);
3431
3432 /* Aggregate address increment. */
3433 bgp_aggregate_increment (bgp, p, new, afi, safi);
3434
3435 /* Register new BGP information. */
3436 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003437
3438 /* route_node_get lock */
3439 bgp_unlock_node (rn);
3440
paul718e3742002-12-13 20:15:29 +00003441 /* Process change. */
3442 bgp_process (bgp, rn, afi, safi);
3443
3444 /* Unintern original. */
3445 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003446 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003447}
3448
3449void
paulfee0f4c2004-09-13 05:12:46 +00003450bgp_static_update (struct bgp *bgp, struct prefix *p,
3451 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3452{
3453 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003454 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003455
3456 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3457
paul1eb8ef22005-04-07 07:30:20 +00003458 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003459 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003460 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3461 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003462 }
3463}
3464
paul94f2b392005-06-28 12:44:16 +00003465static void
paul718e3742002-12-13 20:15:29 +00003466bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3467 u_char safi, struct prefix_rd *prd, u_char *tag)
3468{
3469 struct bgp_node *rn;
3470 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003471
paulfee0f4c2004-09-13 05:12:46 +00003472 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003473
3474 /* Make new BGP info. */
3475 new = bgp_info_new ();
3476 new->type = ZEBRA_ROUTE_BGP;
3477 new->sub_type = BGP_ROUTE_STATIC;
3478 new->peer = bgp->peer_self;
3479 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3480 SET_FLAG (new->flags, BGP_INFO_VALID);
3481 new->uptime = time (NULL);
Paul Jakmafb982c22007-05-04 20:15:47 +00003482 new->extra = bgp_info_extra_new();
3483 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003484
3485 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003486 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003487
3488 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003489 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003490
paul200df112005-06-01 11:17:05 +00003491 /* route_node_get lock */
3492 bgp_unlock_node (rn);
3493
paul718e3742002-12-13 20:15:29 +00003494 /* Process change. */
3495 bgp_process (bgp, rn, afi, safi);
3496}
3497
3498void
3499bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3500 safi_t safi)
3501{
3502 struct bgp_node *rn;
3503 struct bgp_info *ri;
3504
paulfee0f4c2004-09-13 05:12:46 +00003505 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003506
3507 /* Check selected route and self inserted route. */
3508 for (ri = rn->info; ri; ri = ri->next)
3509 if (ri->peer == bgp->peer_self
3510 && ri->type == ZEBRA_ROUTE_BGP
3511 && ri->sub_type == BGP_ROUTE_STATIC)
3512 break;
3513
3514 /* Withdraw static BGP route from routing table. */
3515 if (ri)
3516 {
3517 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003518 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003519 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003520 }
3521
3522 /* Unlock bgp_node_lookup. */
3523 bgp_unlock_node (rn);
3524}
3525
3526void
paulfee0f4c2004-09-13 05:12:46 +00003527bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3528{
3529 struct bgp_static *bgp_static;
3530 struct bgp *bgp;
3531 struct bgp_node *rn;
3532 struct prefix *p;
3533
3534 bgp = rsclient->bgp;
3535
3536 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3537 if ((bgp_static = rn->info) != NULL)
3538 {
3539 p = &rn->p;
3540
3541 bgp_static_update_rsclient (rsclient, p, bgp_static,
3542 afi, safi);
3543 }
3544}
3545
paul94f2b392005-06-28 12:44:16 +00003546static void
paul718e3742002-12-13 20:15:29 +00003547bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3548 u_char safi, struct prefix_rd *prd, u_char *tag)
3549{
3550 struct bgp_node *rn;
3551 struct bgp_info *ri;
3552
paulfee0f4c2004-09-13 05:12:46 +00003553 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003554
3555 /* Check selected route and self inserted route. */
3556 for (ri = rn->info; ri; ri = ri->next)
3557 if (ri->peer == bgp->peer_self
3558 && ri->type == ZEBRA_ROUTE_BGP
3559 && ri->sub_type == BGP_ROUTE_STATIC)
3560 break;
3561
3562 /* Withdraw static BGP route from routing table. */
3563 if (ri)
3564 {
3565 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003566 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003567 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003568 }
3569
3570 /* Unlock bgp_node_lookup. */
3571 bgp_unlock_node (rn);
3572}
3573
Paul Jakma41367172007-08-06 15:24:51 +00003574static void
3575bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3576 int ttl_edge)
3577{
3578 struct bgp_node *parent = rn;
3579 struct bgp_static *sp;
3580
3581 /* Existing static changed TTL, search parents and adjust their atomic */
3582 while ((parent = parent->parent))
3583 if ((sp = parent->info))
3584 {
3585 int sp_level = (sp->atomic ? 1 : 0);
3586 ttl_edge ? sp->atomic++ : sp->atomic--;
3587
3588 /* did we change state of parent whether atomic is set or not? */
3589 if (sp_level != (sp->atomic ? 1 : 0))
3590 {
3591 bgp_static_update (bgp, &parent->p, sp,
3592 rn->table->afi, rn->table->safi);
3593 }
3594 }
3595}
3596
paul718e3742002-12-13 20:15:29 +00003597/* Configure static BGP network. When user don't run zebra, static
3598 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003599static int
paulfd79ac92004-10-13 05:06:08 +00003600bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakma41367172007-08-06 15:24:51 +00003601 u_int16_t afi, u_char safi, const char *rmap, int backdoor,
3602 u_char ttl)
paul718e3742002-12-13 20:15:29 +00003603{
3604 int ret;
3605 struct prefix p;
3606 struct bgp_static *bgp_static;
3607 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003608 u_char need_update = 0;
3609 u_char ttl_change = 0;
3610 u_char ttl_edge = (ttl ? 1 : 0);
3611 u_char new = 0;
paul718e3742002-12-13 20:15:29 +00003612
3613 /* Convert IP prefix string to struct prefix. */
3614 ret = str2prefix (ip_str, &p);
3615 if (! ret)
3616 {
3617 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3618 return CMD_WARNING;
3619 }
3620#ifdef HAVE_IPV6
3621 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3622 {
3623 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3624 VTY_NEWLINE);
3625 return CMD_WARNING;
3626 }
3627#endif /* HAVE_IPV6 */
3628
3629 apply_mask (&p);
3630
3631 /* Set BGP static route configuration. */
3632 rn = bgp_node_get (bgp->route[afi][safi], &p);
3633
3634 if (rn->info)
3635 {
3636 /* Configuration change. */
3637 bgp_static = rn->info;
3638
3639 /* Check previous routes are installed into BGP. */
Paul Jakma41367172007-08-06 15:24:51 +00003640 if (bgp_static->valid)
3641 {
3642 if (bgp_static->backdoor != backdoor
3643 || bgp_static->ttl != ttl)
3644 need_update = 1;
3645 }
3646
3647 /* need to catch TTL set/unset transitions for handling of
3648 * ATOMIC_AGGREGATE
3649 */
3650 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3651 ttl_change = 1;
3652
paul718e3742002-12-13 20:15:29 +00003653 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003654 bgp_static->ttl = ttl;
3655
paul718e3742002-12-13 20:15:29 +00003656 if (rmap)
3657 {
3658 if (bgp_static->rmap.name)
3659 free (bgp_static->rmap.name);
3660 bgp_static->rmap.name = strdup (rmap);
3661 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3662 }
3663 else
3664 {
3665 if (bgp_static->rmap.name)
3666 free (bgp_static->rmap.name);
3667 bgp_static->rmap.name = NULL;
3668 bgp_static->rmap.map = NULL;
3669 bgp_static->valid = 0;
3670 }
3671 bgp_unlock_node (rn);
3672 }
3673 else
3674 {
3675 /* New configuration. */
3676 bgp_static = bgp_static_new ();
3677 bgp_static->backdoor = backdoor;
3678 bgp_static->valid = 0;
3679 bgp_static->igpmetric = 0;
3680 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003681 bgp_static->ttl = ttl;
3682 ttl_change = ttl_edge;
3683 new = 1;
3684
paul718e3742002-12-13 20:15:29 +00003685 if (rmap)
3686 {
3687 if (bgp_static->rmap.name)
3688 free (bgp_static->rmap.name);
3689 bgp_static->rmap.name = strdup (rmap);
3690 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3691 }
3692 rn->info = bgp_static;
3693 }
3694
Paul Jakma41367172007-08-06 15:24:51 +00003695 /* ".. sites that choose to advertise the
3696 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3697 * all less specific covering prefixes as well as the more specific
3698 * prefixes."
3699 *
3700 * So:
3701 * Prefix that has just had pathlimit set/unset:
3702 * - Must bump ATOMIC refcount on all parents.
3703 *
3704 * To catch less specific prefixes:
3705 * - Must search children for ones with TTL, bump atomic refcount
3706 * (we dont care if we're deleting a less specific prefix..)
3707 */
3708 if (ttl_change)
3709 {
3710 /* Existing static changed TTL, search parents and adjust their atomic */
3711 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3712 }
3713
3714 if (new)
3715 {
3716 struct bgp_node *child;
3717 struct bgp_static *sc;
3718
3719 /* New static, search children and bump this statics atomic.. */
3720 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3721 while ((child = bgp_route_next_until (child, rn)))
3722 {
3723 if ((sc = child->info) && sc->ttl)
3724 bgp_static->atomic++;
3725 }
3726 }
3727
paul718e3742002-12-13 20:15:29 +00003728 /* If BGP scan is not enabled, we should install this route here. */
3729 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3730 {
3731 bgp_static->valid = 1;
3732
3733 if (need_update)
3734 bgp_static_withdraw (bgp, &p, afi, safi);
3735
3736 if (! bgp_static->backdoor)
3737 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3738 }
3739
3740 return CMD_SUCCESS;
3741}
3742
3743/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003744static int
paulfd79ac92004-10-13 05:06:08 +00003745bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003746 u_int16_t afi, u_char safi)
3747{
3748 int ret;
3749 struct prefix p;
3750 struct bgp_static *bgp_static;
3751 struct bgp_node *rn;
3752
3753 /* Convert IP prefix string to struct prefix. */
3754 ret = str2prefix (ip_str, &p);
3755 if (! ret)
3756 {
3757 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3758 return CMD_WARNING;
3759 }
3760#ifdef HAVE_IPV6
3761 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3762 {
3763 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3764 VTY_NEWLINE);
3765 return CMD_WARNING;
3766 }
3767#endif /* HAVE_IPV6 */
3768
3769 apply_mask (&p);
3770
3771 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3772 if (! rn)
3773 {
3774 vty_out (vty, "%% Can't find specified static route configuration.%s",
3775 VTY_NEWLINE);
3776 return CMD_WARNING;
3777 }
3778
3779 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003780
3781 /* decrement atomic in parents, see bgp_static_set */
3782 bgp_pathlimit_update_parents (bgp, rn, 0);
3783
paul718e3742002-12-13 20:15:29 +00003784 /* Update BGP RIB. */
3785 if (! bgp_static->backdoor)
3786 bgp_static_withdraw (bgp, &p, afi, safi);
3787
3788 /* Clear configuration. */
3789 bgp_static_free (bgp_static);
3790 rn->info = NULL;
3791 bgp_unlock_node (rn);
3792 bgp_unlock_node (rn);
3793
3794 return CMD_SUCCESS;
3795}
3796
3797/* Called from bgp_delete(). Delete all static routes from the BGP
3798 instance. */
3799void
3800bgp_static_delete (struct bgp *bgp)
3801{
3802 afi_t afi;
3803 safi_t safi;
3804 struct bgp_node *rn;
3805 struct bgp_node *rm;
3806 struct bgp_table *table;
3807 struct bgp_static *bgp_static;
3808
3809 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3810 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3811 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3812 if (rn->info != NULL)
3813 {
3814 if (safi == SAFI_MPLS_VPN)
3815 {
3816 table = rn->info;
3817
3818 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3819 {
3820 bgp_static = rn->info;
3821 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3822 AFI_IP, SAFI_MPLS_VPN,
3823 (struct prefix_rd *)&rn->p,
3824 bgp_static->tag);
3825 bgp_static_free (bgp_static);
3826 rn->info = NULL;
3827 bgp_unlock_node (rn);
3828 }
3829 }
3830 else
3831 {
3832 bgp_static = rn->info;
3833 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3834 bgp_static_free (bgp_static);
3835 rn->info = NULL;
3836 bgp_unlock_node (rn);
3837 }
3838 }
3839}
3840
3841int
paulfd79ac92004-10-13 05:06:08 +00003842bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3843 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003844{
3845 int ret;
3846 struct prefix p;
3847 struct prefix_rd prd;
3848 struct bgp *bgp;
3849 struct bgp_node *prn;
3850 struct bgp_node *rn;
3851 struct bgp_table *table;
3852 struct bgp_static *bgp_static;
3853 u_char tag[3];
3854
3855 bgp = vty->index;
3856
3857 ret = str2prefix (ip_str, &p);
3858 if (! ret)
3859 {
3860 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3861 return CMD_WARNING;
3862 }
3863 apply_mask (&p);
3864
3865 ret = str2prefix_rd (rd_str, &prd);
3866 if (! ret)
3867 {
3868 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3869 return CMD_WARNING;
3870 }
3871
3872 ret = str2tag (tag_str, tag);
3873 if (! ret)
3874 {
3875 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3876 return CMD_WARNING;
3877 }
3878
3879 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3880 (struct prefix *)&prd);
3881 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003882 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003883 else
3884 bgp_unlock_node (prn);
3885 table = prn->info;
3886
3887 rn = bgp_node_get (table, &p);
3888
3889 if (rn->info)
3890 {
3891 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3892 bgp_unlock_node (rn);
3893 }
3894 else
3895 {
3896 /* New configuration. */
3897 bgp_static = bgp_static_new ();
3898 bgp_static->valid = 1;
3899 memcpy (bgp_static->tag, tag, 3);
3900 rn->info = bgp_static;
3901
3902 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3903 }
3904
3905 return CMD_SUCCESS;
3906}
3907
3908/* Configure static BGP network. */
3909int
paulfd79ac92004-10-13 05:06:08 +00003910bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3911 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003912{
3913 int ret;
3914 struct bgp *bgp;
3915 struct prefix p;
3916 struct prefix_rd prd;
3917 struct bgp_node *prn;
3918 struct bgp_node *rn;
3919 struct bgp_table *table;
3920 struct bgp_static *bgp_static;
3921 u_char tag[3];
3922
3923 bgp = vty->index;
3924
3925 /* Convert IP prefix string to struct prefix. */
3926 ret = str2prefix (ip_str, &p);
3927 if (! ret)
3928 {
3929 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3930 return CMD_WARNING;
3931 }
3932 apply_mask (&p);
3933
3934 ret = str2prefix_rd (rd_str, &prd);
3935 if (! ret)
3936 {
3937 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3938 return CMD_WARNING;
3939 }
3940
3941 ret = str2tag (tag_str, tag);
3942 if (! ret)
3943 {
3944 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3945 return CMD_WARNING;
3946 }
3947
3948 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3949 (struct prefix *)&prd);
3950 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003951 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003952 else
3953 bgp_unlock_node (prn);
3954 table = prn->info;
3955
3956 rn = bgp_node_lookup (table, &p);
3957
3958 if (rn)
3959 {
3960 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3961
3962 bgp_static = rn->info;
3963 bgp_static_free (bgp_static);
3964 rn->info = NULL;
3965 bgp_unlock_node (rn);
3966 bgp_unlock_node (rn);
3967 }
3968 else
3969 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3970
3971 return CMD_SUCCESS;
3972}
3973
3974DEFUN (bgp_network,
3975 bgp_network_cmd,
3976 "network A.B.C.D/M",
3977 "Specify a network to announce via BGP\n"
3978 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3979{
Paul Jakma41367172007-08-06 15:24:51 +00003980 u_char ttl = 0;
3981
3982 if (argc == 2)
3983 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
3984
paul718e3742002-12-13 20:15:29 +00003985 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00003986 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00003987}
3988
Paul Jakma41367172007-08-06 15:24:51 +00003989ALIAS (bgp_network,
3990 bgp_network_ttl_cmd,
3991 "network A.B.C.D/M pathlimit <0-255>",
3992 "Specify a network to announce via BGP\n"
3993 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3994 "AS-Path hopcount limit attribute\n"
3995 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3996
paul718e3742002-12-13 20:15:29 +00003997DEFUN (bgp_network_route_map,
3998 bgp_network_route_map_cmd,
3999 "network A.B.C.D/M route-map WORD",
4000 "Specify a network to announce via BGP\n"
4001 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4002 "Route-map to modify the attributes\n"
4003 "Name of the route map\n")
4004{
4005 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004006 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004007}
4008
4009DEFUN (bgp_network_backdoor,
4010 bgp_network_backdoor_cmd,
4011 "network A.B.C.D/M backdoor",
4012 "Specify a network to announce via BGP\n"
4013 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4014 "Specify a BGP backdoor route\n")
4015{
Paul Jakma41367172007-08-06 15:24:51 +00004016 u_char ttl = 0;
4017
4018 if (argc == 2)
4019 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4020
4021 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4022 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004023}
4024
Paul Jakma41367172007-08-06 15:24:51 +00004025ALIAS (bgp_network_backdoor,
4026 bgp_network_backdoor_ttl_cmd,
4027 "network A.B.C.D/M backdoor pathlimit <0-255>",
4028 "Specify a network to announce via BGP\n"
4029 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4030 "Specify a BGP backdoor route\n"
4031 "AS-Path hopcount limit attribute\n"
4032 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4033
paul718e3742002-12-13 20:15:29 +00004034DEFUN (bgp_network_mask,
4035 bgp_network_mask_cmd,
4036 "network A.B.C.D mask A.B.C.D",
4037 "Specify a network to announce via BGP\n"
4038 "Network number\n"
4039 "Network mask\n"
4040 "Network mask\n")
4041{
4042 int ret;
4043 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004044 u_char ttl = 0;
4045
4046 if (argc == 3)
4047 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4048
paul718e3742002-12-13 20:15:29 +00004049 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4050 if (! ret)
4051 {
4052 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4053 return CMD_WARNING;
4054 }
4055
4056 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004057 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004058}
4059
Paul Jakma41367172007-08-06 15:24:51 +00004060ALIAS (bgp_network_mask,
4061 bgp_network_mask_ttl_cmd,
4062 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4063 "Specify a network to announce via BGP\n"
4064 "Network number\n"
4065 "Network mask\n"
4066 "Network mask\n"
4067 "AS-Path hopcount limit attribute\n"
4068 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4069
paul718e3742002-12-13 20:15:29 +00004070DEFUN (bgp_network_mask_route_map,
4071 bgp_network_mask_route_map_cmd,
4072 "network A.B.C.D mask A.B.C.D route-map WORD",
4073 "Specify a network to announce via BGP\n"
4074 "Network number\n"
4075 "Network mask\n"
4076 "Network mask\n"
4077 "Route-map to modify the attributes\n"
4078 "Name of the route map\n")
4079{
4080 int ret;
4081 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004082
paul718e3742002-12-13 20:15:29 +00004083 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4084 if (! ret)
4085 {
4086 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4087 return CMD_WARNING;
4088 }
4089
4090 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004091 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
paul718e3742002-12-13 20:15:29 +00004092}
4093
4094DEFUN (bgp_network_mask_backdoor,
4095 bgp_network_mask_backdoor_cmd,
4096 "network A.B.C.D mask A.B.C.D backdoor",
4097 "Specify a network to announce via BGP\n"
4098 "Network number\n"
4099 "Network mask\n"
4100 "Network mask\n"
4101 "Specify a BGP backdoor route\n")
4102{
4103 int ret;
4104 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004105 u_char ttl = 0;
4106
4107 if (argc == 3)
4108 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
paul718e3742002-12-13 20:15:29 +00004109
4110 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4111 if (! ret)
4112 {
4113 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4114 return CMD_WARNING;
4115 }
4116
Paul Jakma41367172007-08-06 15:24:51 +00004117 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4118 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004119}
4120
Paul Jakma41367172007-08-06 15:24:51 +00004121ALIAS (bgp_network_mask_backdoor,
4122 bgp_network_mask_backdoor_ttl_cmd,
4123 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4124 "Specify a network to announce via BGP\n"
4125 "Network number\n"
4126 "Network mask\n"
4127 "Network mask\n"
4128 "Specify a BGP backdoor route\n"
4129 "AS-Path hopcount limit attribute\n"
4130 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4131
paul718e3742002-12-13 20:15:29 +00004132DEFUN (bgp_network_mask_natural,
4133 bgp_network_mask_natural_cmd,
4134 "network A.B.C.D",
4135 "Specify a network to announce via BGP\n"
4136 "Network number\n")
4137{
4138 int ret;
4139 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004140 u_char ttl = 0;
4141
4142 if (argc == 2)
4143 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004144
4145 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4146 if (! ret)
4147 {
4148 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4149 return CMD_WARNING;
4150 }
4151
4152 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004153 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004154}
4155
Paul Jakma41367172007-08-06 15:24:51 +00004156ALIAS (bgp_network_mask_natural,
4157 bgp_network_mask_natural_ttl_cmd,
4158 "network A.B.C.D pathlimit <0-255>",
4159 "Specify a network to announce via BGP\n"
4160 "Network number\n"
4161 "AS-Path hopcount limit attribute\n"
4162 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4163
paul718e3742002-12-13 20:15:29 +00004164DEFUN (bgp_network_mask_natural_route_map,
4165 bgp_network_mask_natural_route_map_cmd,
4166 "network A.B.C.D route-map WORD",
4167 "Specify a network to announce via BGP\n"
4168 "Network number\n"
4169 "Route-map to modify the attributes\n"
4170 "Name of the route map\n")
4171{
4172 int ret;
4173 char prefix_str[BUFSIZ];
4174
4175 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4176 if (! ret)
4177 {
4178 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4179 return CMD_WARNING;
4180 }
4181
4182 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004183 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004184}
4185
4186DEFUN (bgp_network_mask_natural_backdoor,
4187 bgp_network_mask_natural_backdoor_cmd,
4188 "network A.B.C.D backdoor",
4189 "Specify a network to announce via BGP\n"
4190 "Network number\n"
4191 "Specify a BGP backdoor route\n")
4192{
4193 int ret;
4194 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004195 u_char ttl = 0;
4196
4197 if (argc == 2)
4198 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004199
4200 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4201 if (! ret)
4202 {
4203 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4204 return CMD_WARNING;
4205 }
4206
Paul Jakma41367172007-08-06 15:24:51 +00004207 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4208 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004209}
4210
Paul Jakma41367172007-08-06 15:24:51 +00004211ALIAS (bgp_network_mask_natural_backdoor,
4212 bgp_network_mask_natural_backdoor_ttl_cmd,
4213 "network A.B.C.D backdoor pathlimit (1-255>",
4214 "Specify a network to announce via BGP\n"
4215 "Network number\n"
4216 "Specify a BGP backdoor route\n"
4217 "AS-Path hopcount limit attribute\n"
4218 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4219
paul718e3742002-12-13 20:15:29 +00004220DEFUN (no_bgp_network,
4221 no_bgp_network_cmd,
4222 "no network A.B.C.D/M",
4223 NO_STR
4224 "Specify a network to announce via BGP\n"
4225 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4226{
4227 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4228 bgp_node_safi (vty));
4229}
4230
4231ALIAS (no_bgp_network,
Paul Jakma41367172007-08-06 15:24:51 +00004232 no_bgp_network_ttl_cmd,
4233 "no network A.B.C.D/M pathlimit <0-255>",
4234 NO_STR
4235 "Specify a network to announce via BGP\n"
4236 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4237 "AS-Path hopcount limit attribute\n"
4238 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4239
4240ALIAS (no_bgp_network,
paul718e3742002-12-13 20:15:29 +00004241 no_bgp_network_route_map_cmd,
4242 "no network A.B.C.D/M route-map WORD",
4243 NO_STR
4244 "Specify a network to announce via BGP\n"
4245 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4246 "Route-map to modify the attributes\n"
4247 "Name of the route map\n")
4248
4249ALIAS (no_bgp_network,
4250 no_bgp_network_backdoor_cmd,
4251 "no network A.B.C.D/M backdoor",
4252 NO_STR
4253 "Specify a network to announce via BGP\n"
4254 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4255 "Specify a BGP backdoor route\n")
4256
Paul Jakma41367172007-08-06 15:24:51 +00004257ALIAS (no_bgp_network,
4258 no_bgp_network_backdoor_ttl_cmd,
4259 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4260 NO_STR
4261 "Specify a network to announce via BGP\n"
4262 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4263 "Specify a BGP backdoor route\n"
4264 "AS-Path hopcount limit attribute\n"
4265 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4266
paul718e3742002-12-13 20:15:29 +00004267DEFUN (no_bgp_network_mask,
4268 no_bgp_network_mask_cmd,
4269 "no network A.B.C.D mask A.B.C.D",
4270 NO_STR
4271 "Specify a network to announce via BGP\n"
4272 "Network number\n"
4273 "Network mask\n"
4274 "Network mask\n")
4275{
4276 int ret;
4277 char prefix_str[BUFSIZ];
4278
4279 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4280 if (! ret)
4281 {
4282 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4283 return CMD_WARNING;
4284 }
4285
4286 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4287 bgp_node_safi (vty));
4288}
4289
Paul Jakma41367172007-08-06 15:24:51 +00004290ALIAS (no_bgp_network,
4291 no_bgp_network_mask_ttl_cmd,
4292 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4293 NO_STR
4294 "Specify a network to announce via BGP\n"
4295 "Network number\n"
4296 "Network mask\n"
4297 "Network mask\n"
4298 "AS-Path hopcount limit attribute\n"
4299 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4300
paul718e3742002-12-13 20:15:29 +00004301ALIAS (no_bgp_network_mask,
4302 no_bgp_network_mask_route_map_cmd,
4303 "no network A.B.C.D mask A.B.C.D route-map WORD",
4304 NO_STR
4305 "Specify a network to announce via BGP\n"
4306 "Network number\n"
4307 "Network mask\n"
4308 "Network mask\n"
4309 "Route-map to modify the attributes\n"
4310 "Name of the route map\n")
4311
4312ALIAS (no_bgp_network_mask,
4313 no_bgp_network_mask_backdoor_cmd,
4314 "no network A.B.C.D mask A.B.C.D backdoor",
4315 NO_STR
4316 "Specify a network to announce via BGP\n"
4317 "Network number\n"
4318 "Network mask\n"
4319 "Network mask\n"
4320 "Specify a BGP backdoor route\n")
4321
Paul Jakma41367172007-08-06 15:24:51 +00004322ALIAS (no_bgp_network_mask,
4323 no_bgp_network_mask_backdoor_ttl_cmd,
4324 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4325 NO_STR
4326 "Specify a network to announce via BGP\n"
4327 "Network number\n"
4328 "Network mask\n"
4329 "Network mask\n"
4330 "Specify a BGP backdoor route\n"
4331 "AS-Path hopcount limit attribute\n"
4332 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4333
paul718e3742002-12-13 20:15:29 +00004334DEFUN (no_bgp_network_mask_natural,
4335 no_bgp_network_mask_natural_cmd,
4336 "no network A.B.C.D",
4337 NO_STR
4338 "Specify a network to announce via BGP\n"
4339 "Network number\n")
4340{
4341 int ret;
4342 char prefix_str[BUFSIZ];
4343
4344 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4345 if (! ret)
4346 {
4347 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4348 return CMD_WARNING;
4349 }
4350
4351 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4352 bgp_node_safi (vty));
4353}
4354
4355ALIAS (no_bgp_network_mask_natural,
4356 no_bgp_network_mask_natural_route_map_cmd,
4357 "no network A.B.C.D route-map WORD",
4358 NO_STR
4359 "Specify a network to announce via BGP\n"
4360 "Network number\n"
4361 "Route-map to modify the attributes\n"
4362 "Name of the route map\n")
4363
4364ALIAS (no_bgp_network_mask_natural,
4365 no_bgp_network_mask_natural_backdoor_cmd,
4366 "no network A.B.C.D backdoor",
4367 NO_STR
4368 "Specify a network to announce via BGP\n"
4369 "Network number\n"
4370 "Specify a BGP backdoor route\n")
4371
Paul Jakma41367172007-08-06 15:24:51 +00004372ALIAS (no_bgp_network_mask_natural,
4373 no_bgp_network_mask_natural_ttl_cmd,
4374 "no network A.B.C.D pathlimit <0-255>",
4375 NO_STR
4376 "Specify a network to announce via BGP\n"
4377 "Network number\n"
4378 "AS-Path hopcount limit attribute\n"
4379 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4380
4381ALIAS (no_bgp_network_mask_natural,
4382 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4383 "no network A.B.C.D backdoor pathlimit <0-255>",
4384 NO_STR
4385 "Specify a network to announce via BGP\n"
4386 "Network number\n"
4387 "Specify a BGP backdoor route\n"
4388 "AS-Path hopcount limit attribute\n"
4389 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4390
paul718e3742002-12-13 20:15:29 +00004391#ifdef HAVE_IPV6
4392DEFUN (ipv6_bgp_network,
4393 ipv6_bgp_network_cmd,
4394 "network X:X::X:X/M",
4395 "Specify a network to announce via BGP\n"
4396 "IPv6 prefix <network>/<length>\n")
4397{
Paul Jakma41367172007-08-06 15:24:51 +00004398 u_char ttl = 0;
4399
4400 if (argc == 2)
4401 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4402
4403 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4404 NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004405}
4406
Paul Jakma41367172007-08-06 15:24:51 +00004407ALIAS (ipv6_bgp_network,
4408 ipv6_bgp_network_ttl_cmd,
4409 "network X:X::X:X/M pathlimit <0-255>",
4410 "Specify a network to announce via BGP\n"
4411 "IPv6 prefix <network>/<length>\n"
4412 "AS-Path hopcount limit attribute\n"
4413 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4414
paul718e3742002-12-13 20:15:29 +00004415DEFUN (ipv6_bgp_network_route_map,
4416 ipv6_bgp_network_route_map_cmd,
4417 "network X:X::X:X/M route-map WORD",
4418 "Specify a network to announce via BGP\n"
4419 "IPv6 prefix <network>/<length>\n"
4420 "Route-map to modify the attributes\n"
4421 "Name of the route map\n")
4422{
4423 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakma41367172007-08-06 15:24:51 +00004424 bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004425}
4426
4427DEFUN (no_ipv6_bgp_network,
4428 no_ipv6_bgp_network_cmd,
4429 "no network X:X::X:X/M",
4430 NO_STR
4431 "Specify a network to announce via BGP\n"
4432 "IPv6 prefix <network>/<length>\n")
4433{
4434 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4435}
4436
4437ALIAS (no_ipv6_bgp_network,
4438 no_ipv6_bgp_network_route_map_cmd,
4439 "no network X:X::X:X/M route-map WORD",
4440 NO_STR
4441 "Specify a network to announce via BGP\n"
4442 "IPv6 prefix <network>/<length>\n"
4443 "Route-map to modify the attributes\n"
4444 "Name of the route map\n")
4445
Paul Jakma41367172007-08-06 15:24:51 +00004446ALIAS (no_ipv6_bgp_network,
4447 no_ipv6_bgp_network_ttl_cmd,
4448 "no network X:X::X:X/M pathlimit <0-255>",
4449 NO_STR
4450 "Specify a network to announce via BGP\n"
4451 "IPv6 prefix <network>/<length>\n"
4452 "AS-Path hopcount limit attribute\n"
4453 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4454
paul718e3742002-12-13 20:15:29 +00004455ALIAS (ipv6_bgp_network,
4456 old_ipv6_bgp_network_cmd,
4457 "ipv6 bgp network X:X::X:X/M",
4458 IPV6_STR
4459 BGP_STR
4460 "Specify a network to announce via BGP\n"
4461 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4462
4463ALIAS (no_ipv6_bgp_network,
4464 old_no_ipv6_bgp_network_cmd,
4465 "no ipv6 bgp network X:X::X:X/M",
4466 NO_STR
4467 IPV6_STR
4468 BGP_STR
4469 "Specify a network to announce via BGP\n"
4470 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4471#endif /* HAVE_IPV6 */
4472
4473/* Aggreagete address:
4474
4475 advertise-map Set condition to advertise attribute
4476 as-set Generate AS set path information
4477 attribute-map Set attributes of aggregate
4478 route-map Set parameters of aggregate
4479 summary-only Filter more specific routes from updates
4480 suppress-map Conditionally filter more specific routes from updates
4481 <cr>
4482 */
4483struct bgp_aggregate
4484{
4485 /* Summary-only flag. */
4486 u_char summary_only;
4487
4488 /* AS set generation. */
4489 u_char as_set;
4490
4491 /* Route-map for aggregated route. */
4492 struct route_map *map;
4493
4494 /* Suppress-count. */
4495 unsigned long count;
4496
4497 /* SAFI configuration. */
4498 safi_t safi;
4499};
4500
paul94f2b392005-06-28 12:44:16 +00004501static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004502bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004503{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004504 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004505}
4506
paul94f2b392005-06-28 12:44:16 +00004507static void
paul718e3742002-12-13 20:15:29 +00004508bgp_aggregate_free (struct bgp_aggregate *aggregate)
4509{
4510 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4511}
4512
paul94f2b392005-06-28 12:44:16 +00004513static void
paul718e3742002-12-13 20:15:29 +00004514bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4515 afi_t afi, safi_t safi, struct bgp_info *del,
4516 struct bgp_aggregate *aggregate)
4517{
4518 struct bgp_table *table;
4519 struct bgp_node *top;
4520 struct bgp_node *rn;
4521 u_char origin;
4522 struct aspath *aspath = NULL;
4523 struct aspath *asmerge = NULL;
4524 struct community *community = NULL;
4525 struct community *commerge = NULL;
4526 struct in_addr nexthop;
4527 u_int32_t med = 0;
4528 struct bgp_info *ri;
4529 struct bgp_info *new;
4530 int first = 1;
4531 unsigned long match = 0;
4532
4533 /* Record adding route's nexthop and med. */
4534 if (rinew)
4535 {
4536 nexthop = rinew->attr->nexthop;
4537 med = rinew->attr->med;
4538 }
4539
4540 /* ORIGIN attribute: If at least one route among routes that are
4541 aggregated has ORIGIN with the value INCOMPLETE, then the
4542 aggregated route must have the ORIGIN attribute with the value
4543 INCOMPLETE. Otherwise, if at least one route among routes that
4544 are aggregated has ORIGIN with the value EGP, then the aggregated
4545 route must have the origin attribute with the value EGP. In all
4546 other case the value of the ORIGIN attribute of the aggregated
4547 route is INTERNAL. */
4548 origin = BGP_ORIGIN_IGP;
4549
4550 table = bgp->rib[afi][safi];
4551
4552 top = bgp_node_get (table, p);
4553 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4554 if (rn->p.prefixlen > p->prefixlen)
4555 {
4556 match = 0;
4557
4558 for (ri = rn->info; ri; ri = ri->next)
4559 {
4560 if (BGP_INFO_HOLDDOWN (ri))
4561 continue;
4562
4563 if (del && ri == del)
4564 continue;
4565
4566 if (! rinew && first)
4567 {
4568 nexthop = ri->attr->nexthop;
4569 med = ri->attr->med;
4570 first = 0;
4571 }
4572
4573#ifdef AGGREGATE_NEXTHOP_CHECK
4574 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4575 || ri->attr->med != med)
4576 {
4577 if (aspath)
4578 aspath_free (aspath);
4579 if (community)
4580 community_free (community);
4581 bgp_unlock_node (rn);
4582 bgp_unlock_node (top);
4583 return;
4584 }
4585#endif /* AGGREGATE_NEXTHOP_CHECK */
4586
4587 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4588 {
4589 if (aggregate->summary_only)
4590 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004591 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004592 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004593 match++;
4594 }
4595
4596 aggregate->count++;
4597
4598 if (aggregate->as_set)
4599 {
4600 if (origin < ri->attr->origin)
4601 origin = ri->attr->origin;
4602
4603 if (aspath)
4604 {
4605 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4606 aspath_free (aspath);
4607 aspath = asmerge;
4608 }
4609 else
4610 aspath = aspath_dup (ri->attr->aspath);
4611
4612 if (ri->attr->community)
4613 {
4614 if (community)
4615 {
4616 commerge = community_merge (community,
4617 ri->attr->community);
4618 community = community_uniq_sort (commerge);
4619 community_free (commerge);
4620 }
4621 else
4622 community = community_dup (ri->attr->community);
4623 }
4624 }
4625 }
4626 }
4627 if (match)
4628 bgp_process (bgp, rn, afi, safi);
4629 }
4630 bgp_unlock_node (top);
4631
4632 if (rinew)
4633 {
4634 aggregate->count++;
4635
4636 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004637 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004638
4639 if (aggregate->as_set)
4640 {
4641 if (origin < rinew->attr->origin)
4642 origin = rinew->attr->origin;
4643
4644 if (aspath)
4645 {
4646 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4647 aspath_free (aspath);
4648 aspath = asmerge;
4649 }
4650 else
4651 aspath = aspath_dup (rinew->attr->aspath);
4652
4653 if (rinew->attr->community)
4654 {
4655 if (community)
4656 {
4657 commerge = community_merge (community,
4658 rinew->attr->community);
4659 community = community_uniq_sort (commerge);
4660 community_free (commerge);
4661 }
4662 else
4663 community = community_dup (rinew->attr->community);
4664 }
4665 }
4666 }
4667
4668 if (aggregate->count > 0)
4669 {
4670 rn = bgp_node_get (table, p);
4671 new = bgp_info_new ();
4672 new->type = ZEBRA_ROUTE_BGP;
4673 new->sub_type = BGP_ROUTE_AGGREGATE;
4674 new->peer = bgp->peer_self;
4675 SET_FLAG (new->flags, BGP_INFO_VALID);
4676 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4677 new->uptime = time (NULL);
4678
4679 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004680 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004681 bgp_process (bgp, rn, afi, safi);
4682 }
4683 else
4684 {
4685 if (aspath)
4686 aspath_free (aspath);
4687 if (community)
4688 community_free (community);
4689 }
4690}
4691
4692void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4693 struct bgp_aggregate *);
4694
4695void
4696bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4697 struct bgp_info *ri, afi_t afi, safi_t safi)
4698{
4699 struct bgp_node *child;
4700 struct bgp_node *rn;
4701 struct bgp_aggregate *aggregate;
4702
4703 /* MPLS-VPN aggregation is not yet supported. */
4704 if (safi == SAFI_MPLS_VPN)
4705 return;
4706
4707 if (p->prefixlen == 0)
4708 return;
4709
4710 if (BGP_INFO_HOLDDOWN (ri))
4711 return;
4712
4713 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4714
4715 /* Aggregate address configuration check. */
4716 for (rn = child; rn; rn = rn->parent)
4717 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4718 {
4719 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004720 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004721 }
4722 bgp_unlock_node (child);
4723}
4724
4725void
4726bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4727 struct bgp_info *del, afi_t afi, safi_t safi)
4728{
4729 struct bgp_node *child;
4730 struct bgp_node *rn;
4731 struct bgp_aggregate *aggregate;
4732
4733 /* MPLS-VPN aggregation is not yet supported. */
4734 if (safi == SAFI_MPLS_VPN)
4735 return;
4736
4737 if (p->prefixlen == 0)
4738 return;
4739
4740 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4741
4742 /* Aggregate address configuration check. */
4743 for (rn = child; rn; rn = rn->parent)
4744 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4745 {
4746 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004747 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004748 }
4749 bgp_unlock_node (child);
4750}
4751
paul94f2b392005-06-28 12:44:16 +00004752static void
paul718e3742002-12-13 20:15:29 +00004753bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4754 struct bgp_aggregate *aggregate)
4755{
4756 struct bgp_table *table;
4757 struct bgp_node *top;
4758 struct bgp_node *rn;
4759 struct bgp_info *new;
4760 struct bgp_info *ri;
4761 unsigned long match;
4762 u_char origin = BGP_ORIGIN_IGP;
4763 struct aspath *aspath = NULL;
4764 struct aspath *asmerge = NULL;
4765 struct community *community = NULL;
4766 struct community *commerge = NULL;
4767
4768 table = bgp->rib[afi][safi];
4769
4770 /* Sanity check. */
4771 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4772 return;
4773 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4774 return;
4775
4776 /* If routes exists below this node, generate aggregate routes. */
4777 top = bgp_node_get (table, p);
4778 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4779 if (rn->p.prefixlen > p->prefixlen)
4780 {
4781 match = 0;
4782
4783 for (ri = rn->info; ri; ri = ri->next)
4784 {
4785 if (BGP_INFO_HOLDDOWN (ri))
4786 continue;
4787
4788 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4789 {
4790 /* summary-only aggregate route suppress aggregated
4791 route announcement. */
4792 if (aggregate->summary_only)
4793 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004794 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004795 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004796 match++;
4797 }
4798 /* as-set aggregate route generate origin, as path,
4799 community aggregation. */
4800 if (aggregate->as_set)
4801 {
4802 if (origin < ri->attr->origin)
4803 origin = ri->attr->origin;
4804
4805 if (aspath)
4806 {
4807 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4808 aspath_free (aspath);
4809 aspath = asmerge;
4810 }
4811 else
4812 aspath = aspath_dup (ri->attr->aspath);
4813
4814 if (ri->attr->community)
4815 {
4816 if (community)
4817 {
4818 commerge = community_merge (community,
4819 ri->attr->community);
4820 community = community_uniq_sort (commerge);
4821 community_free (commerge);
4822 }
4823 else
4824 community = community_dup (ri->attr->community);
4825 }
4826 }
4827 aggregate->count++;
4828 }
4829 }
4830
4831 /* If this node is suppressed, process the change. */
4832 if (match)
4833 bgp_process (bgp, rn, afi, safi);
4834 }
4835 bgp_unlock_node (top);
4836
4837 /* Add aggregate route to BGP table. */
4838 if (aggregate->count)
4839 {
4840 rn = bgp_node_get (table, p);
4841
4842 new = bgp_info_new ();
4843 new->type = ZEBRA_ROUTE_BGP;
4844 new->sub_type = BGP_ROUTE_AGGREGATE;
4845 new->peer = bgp->peer_self;
4846 SET_FLAG (new->flags, BGP_INFO_VALID);
4847 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4848 new->uptime = time (NULL);
4849
4850 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004851 bgp_unlock_node (rn);
4852
paul718e3742002-12-13 20:15:29 +00004853 /* Process change. */
4854 bgp_process (bgp, rn, afi, safi);
4855 }
4856}
4857
4858void
4859bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4860 safi_t safi, struct bgp_aggregate *aggregate)
4861{
4862 struct bgp_table *table;
4863 struct bgp_node *top;
4864 struct bgp_node *rn;
4865 struct bgp_info *ri;
4866 unsigned long match;
4867
4868 table = bgp->rib[afi][safi];
4869
4870 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4871 return;
4872 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4873 return;
4874
4875 /* If routes exists below this node, generate aggregate routes. */
4876 top = bgp_node_get (table, p);
4877 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4878 if (rn->p.prefixlen > p->prefixlen)
4879 {
4880 match = 0;
4881
4882 for (ri = rn->info; ri; ri = ri->next)
4883 {
4884 if (BGP_INFO_HOLDDOWN (ri))
4885 continue;
4886
4887 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4888 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004889 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004890 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004891 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004892
Paul Jakmafb982c22007-05-04 20:15:47 +00004893 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004894 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004895 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004896 match++;
4897 }
4898 }
4899 aggregate->count--;
4900 }
4901 }
4902
Paul Jakmafb982c22007-05-04 20:15:47 +00004903 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004904 if (match)
4905 bgp_process (bgp, rn, afi, safi);
4906 }
4907 bgp_unlock_node (top);
4908
4909 /* Delete aggregate route from BGP table. */
4910 rn = bgp_node_get (table, p);
4911
4912 for (ri = rn->info; ri; ri = ri->next)
4913 if (ri->peer == bgp->peer_self
4914 && ri->type == ZEBRA_ROUTE_BGP
4915 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4916 break;
4917
4918 /* Withdraw static BGP route from routing table. */
4919 if (ri)
4920 {
paul718e3742002-12-13 20:15:29 +00004921 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004922 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004923 }
4924
4925 /* Unlock bgp_node_lookup. */
4926 bgp_unlock_node (rn);
4927}
4928
4929/* Aggregate route attribute. */
4930#define AGGREGATE_SUMMARY_ONLY 1
4931#define AGGREGATE_AS_SET 1
4932
paul94f2b392005-06-28 12:44:16 +00004933static int
paulfd79ac92004-10-13 05:06:08 +00004934bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4935 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004936 u_char summary_only, u_char as_set)
4937{
4938 int ret;
4939 struct prefix p;
4940 struct bgp_node *rn;
4941 struct bgp *bgp;
4942 struct bgp_aggregate *aggregate;
4943
4944 /* Convert string to prefix structure. */
4945 ret = str2prefix (prefix_str, &p);
4946 if (!ret)
4947 {
4948 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4949 return CMD_WARNING;
4950 }
4951 apply_mask (&p);
4952
4953 /* Get BGP structure. */
4954 bgp = vty->index;
4955
4956 /* Old configuration check. */
4957 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4958
4959 if (rn->info)
4960 {
4961 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4962 bgp_unlock_node (rn);
4963 return CMD_WARNING;
4964 }
4965
4966 /* Make aggregate address structure. */
4967 aggregate = bgp_aggregate_new ();
4968 aggregate->summary_only = summary_only;
4969 aggregate->as_set = as_set;
4970 aggregate->safi = safi;
4971 rn->info = aggregate;
4972
4973 /* Aggregate address insert into BGP routing table. */
4974 if (safi & SAFI_UNICAST)
4975 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4976 if (safi & SAFI_MULTICAST)
4977 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4978
4979 return CMD_SUCCESS;
4980}
4981
paul94f2b392005-06-28 12:44:16 +00004982static int
paulfd79ac92004-10-13 05:06:08 +00004983bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4984 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004985{
4986 int ret;
4987 struct prefix p;
4988 struct bgp_node *rn;
4989 struct bgp *bgp;
4990 struct bgp_aggregate *aggregate;
4991
4992 /* Convert string to prefix structure. */
4993 ret = str2prefix (prefix_str, &p);
4994 if (!ret)
4995 {
4996 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4997 return CMD_WARNING;
4998 }
4999 apply_mask (&p);
5000
5001 /* Get BGP structure. */
5002 bgp = vty->index;
5003
5004 /* Old configuration check. */
5005 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5006 if (! rn)
5007 {
5008 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5009 VTY_NEWLINE);
5010 return CMD_WARNING;
5011 }
5012
5013 aggregate = rn->info;
5014 if (aggregate->safi & SAFI_UNICAST)
5015 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5016 if (aggregate->safi & SAFI_MULTICAST)
5017 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5018
5019 /* Unlock aggregate address configuration. */
5020 rn->info = NULL;
5021 bgp_aggregate_free (aggregate);
5022 bgp_unlock_node (rn);
5023 bgp_unlock_node (rn);
5024
5025 return CMD_SUCCESS;
5026}
5027
5028DEFUN (aggregate_address,
5029 aggregate_address_cmd,
5030 "aggregate-address A.B.C.D/M",
5031 "Configure BGP aggregate entries\n"
5032 "Aggregate prefix\n")
5033{
5034 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5035}
5036
5037DEFUN (aggregate_address_mask,
5038 aggregate_address_mask_cmd,
5039 "aggregate-address A.B.C.D A.B.C.D",
5040 "Configure BGP aggregate entries\n"
5041 "Aggregate address\n"
5042 "Aggregate mask\n")
5043{
5044 int ret;
5045 char prefix_str[BUFSIZ];
5046
5047 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5048
5049 if (! ret)
5050 {
5051 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5052 return CMD_WARNING;
5053 }
5054
5055 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5056 0, 0);
5057}
5058
5059DEFUN (aggregate_address_summary_only,
5060 aggregate_address_summary_only_cmd,
5061 "aggregate-address A.B.C.D/M summary-only",
5062 "Configure BGP aggregate entries\n"
5063 "Aggregate prefix\n"
5064 "Filter more specific routes from updates\n")
5065{
5066 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5067 AGGREGATE_SUMMARY_ONLY, 0);
5068}
5069
5070DEFUN (aggregate_address_mask_summary_only,
5071 aggregate_address_mask_summary_only_cmd,
5072 "aggregate-address A.B.C.D A.B.C.D summary-only",
5073 "Configure BGP aggregate entries\n"
5074 "Aggregate address\n"
5075 "Aggregate mask\n"
5076 "Filter more specific routes from updates\n")
5077{
5078 int ret;
5079 char prefix_str[BUFSIZ];
5080
5081 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5082
5083 if (! ret)
5084 {
5085 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5086 return CMD_WARNING;
5087 }
5088
5089 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5090 AGGREGATE_SUMMARY_ONLY, 0);
5091}
5092
5093DEFUN (aggregate_address_as_set,
5094 aggregate_address_as_set_cmd,
5095 "aggregate-address A.B.C.D/M as-set",
5096 "Configure BGP aggregate entries\n"
5097 "Aggregate prefix\n"
5098 "Generate AS set path information\n")
5099{
5100 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5101 0, AGGREGATE_AS_SET);
5102}
5103
5104DEFUN (aggregate_address_mask_as_set,
5105 aggregate_address_mask_as_set_cmd,
5106 "aggregate-address A.B.C.D A.B.C.D as-set",
5107 "Configure BGP aggregate entries\n"
5108 "Aggregate address\n"
5109 "Aggregate mask\n"
5110 "Generate AS set path information\n")
5111{
5112 int ret;
5113 char prefix_str[BUFSIZ];
5114
5115 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5116
5117 if (! ret)
5118 {
5119 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5120 return CMD_WARNING;
5121 }
5122
5123 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5124 0, AGGREGATE_AS_SET);
5125}
5126
5127
5128DEFUN (aggregate_address_as_set_summary,
5129 aggregate_address_as_set_summary_cmd,
5130 "aggregate-address A.B.C.D/M as-set summary-only",
5131 "Configure BGP aggregate entries\n"
5132 "Aggregate prefix\n"
5133 "Generate AS set path information\n"
5134 "Filter more specific routes from updates\n")
5135{
5136 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5137 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5138}
5139
5140ALIAS (aggregate_address_as_set_summary,
5141 aggregate_address_summary_as_set_cmd,
5142 "aggregate-address A.B.C.D/M summary-only as-set",
5143 "Configure BGP aggregate entries\n"
5144 "Aggregate prefix\n"
5145 "Filter more specific routes from updates\n"
5146 "Generate AS set path information\n")
5147
5148DEFUN (aggregate_address_mask_as_set_summary,
5149 aggregate_address_mask_as_set_summary_cmd,
5150 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5151 "Configure BGP aggregate entries\n"
5152 "Aggregate address\n"
5153 "Aggregate mask\n"
5154 "Generate AS set path information\n"
5155 "Filter more specific routes from updates\n")
5156{
5157 int ret;
5158 char prefix_str[BUFSIZ];
5159
5160 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5161
5162 if (! ret)
5163 {
5164 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5165 return CMD_WARNING;
5166 }
5167
5168 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5169 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5170}
5171
5172ALIAS (aggregate_address_mask_as_set_summary,
5173 aggregate_address_mask_summary_as_set_cmd,
5174 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5175 "Configure BGP aggregate entries\n"
5176 "Aggregate address\n"
5177 "Aggregate mask\n"
5178 "Filter more specific routes from updates\n"
5179 "Generate AS set path information\n")
5180
5181DEFUN (no_aggregate_address,
5182 no_aggregate_address_cmd,
5183 "no aggregate-address A.B.C.D/M",
5184 NO_STR
5185 "Configure BGP aggregate entries\n"
5186 "Aggregate prefix\n")
5187{
5188 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5189}
5190
5191ALIAS (no_aggregate_address,
5192 no_aggregate_address_summary_only_cmd,
5193 "no aggregate-address A.B.C.D/M summary-only",
5194 NO_STR
5195 "Configure BGP aggregate entries\n"
5196 "Aggregate prefix\n"
5197 "Filter more specific routes from updates\n")
5198
5199ALIAS (no_aggregate_address,
5200 no_aggregate_address_as_set_cmd,
5201 "no aggregate-address A.B.C.D/M as-set",
5202 NO_STR
5203 "Configure BGP aggregate entries\n"
5204 "Aggregate prefix\n"
5205 "Generate AS set path information\n")
5206
5207ALIAS (no_aggregate_address,
5208 no_aggregate_address_as_set_summary_cmd,
5209 "no aggregate-address A.B.C.D/M as-set summary-only",
5210 NO_STR
5211 "Configure BGP aggregate entries\n"
5212 "Aggregate prefix\n"
5213 "Generate AS set path information\n"
5214 "Filter more specific routes from updates\n")
5215
5216ALIAS (no_aggregate_address,
5217 no_aggregate_address_summary_as_set_cmd,
5218 "no aggregate-address A.B.C.D/M summary-only as-set",
5219 NO_STR
5220 "Configure BGP aggregate entries\n"
5221 "Aggregate prefix\n"
5222 "Filter more specific routes from updates\n"
5223 "Generate AS set path information\n")
5224
5225DEFUN (no_aggregate_address_mask,
5226 no_aggregate_address_mask_cmd,
5227 "no aggregate-address A.B.C.D A.B.C.D",
5228 NO_STR
5229 "Configure BGP aggregate entries\n"
5230 "Aggregate address\n"
5231 "Aggregate mask\n")
5232{
5233 int ret;
5234 char prefix_str[BUFSIZ];
5235
5236 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5237
5238 if (! ret)
5239 {
5240 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5241 return CMD_WARNING;
5242 }
5243
5244 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5245}
5246
5247ALIAS (no_aggregate_address_mask,
5248 no_aggregate_address_mask_summary_only_cmd,
5249 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5250 NO_STR
5251 "Configure BGP aggregate entries\n"
5252 "Aggregate address\n"
5253 "Aggregate mask\n"
5254 "Filter more specific routes from updates\n")
5255
5256ALIAS (no_aggregate_address_mask,
5257 no_aggregate_address_mask_as_set_cmd,
5258 "no aggregate-address A.B.C.D A.B.C.D as-set",
5259 NO_STR
5260 "Configure BGP aggregate entries\n"
5261 "Aggregate address\n"
5262 "Aggregate mask\n"
5263 "Generate AS set path information\n")
5264
5265ALIAS (no_aggregate_address_mask,
5266 no_aggregate_address_mask_as_set_summary_cmd,
5267 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5268 NO_STR
5269 "Configure BGP aggregate entries\n"
5270 "Aggregate address\n"
5271 "Aggregate mask\n"
5272 "Generate AS set path information\n"
5273 "Filter more specific routes from updates\n")
5274
5275ALIAS (no_aggregate_address_mask,
5276 no_aggregate_address_mask_summary_as_set_cmd,
5277 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5278 NO_STR
5279 "Configure BGP aggregate entries\n"
5280 "Aggregate address\n"
5281 "Aggregate mask\n"
5282 "Filter more specific routes from updates\n"
5283 "Generate AS set path information\n")
5284
5285#ifdef HAVE_IPV6
5286DEFUN (ipv6_aggregate_address,
5287 ipv6_aggregate_address_cmd,
5288 "aggregate-address X:X::X:X/M",
5289 "Configure BGP aggregate entries\n"
5290 "Aggregate prefix\n")
5291{
5292 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5293}
5294
5295DEFUN (ipv6_aggregate_address_summary_only,
5296 ipv6_aggregate_address_summary_only_cmd,
5297 "aggregate-address X:X::X:X/M summary-only",
5298 "Configure BGP aggregate entries\n"
5299 "Aggregate prefix\n"
5300 "Filter more specific routes from updates\n")
5301{
5302 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5303 AGGREGATE_SUMMARY_ONLY, 0);
5304}
5305
5306DEFUN (no_ipv6_aggregate_address,
5307 no_ipv6_aggregate_address_cmd,
5308 "no aggregate-address X:X::X:X/M",
5309 NO_STR
5310 "Configure BGP aggregate entries\n"
5311 "Aggregate prefix\n")
5312{
5313 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5314}
5315
5316DEFUN (no_ipv6_aggregate_address_summary_only,
5317 no_ipv6_aggregate_address_summary_only_cmd,
5318 "no aggregate-address X:X::X:X/M summary-only",
5319 NO_STR
5320 "Configure BGP aggregate entries\n"
5321 "Aggregate prefix\n"
5322 "Filter more specific routes from updates\n")
5323{
5324 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5325}
5326
5327ALIAS (ipv6_aggregate_address,
5328 old_ipv6_aggregate_address_cmd,
5329 "ipv6 bgp aggregate-address X:X::X:X/M",
5330 IPV6_STR
5331 BGP_STR
5332 "Configure BGP aggregate entries\n"
5333 "Aggregate prefix\n")
5334
5335ALIAS (ipv6_aggregate_address_summary_only,
5336 old_ipv6_aggregate_address_summary_only_cmd,
5337 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5338 IPV6_STR
5339 BGP_STR
5340 "Configure BGP aggregate entries\n"
5341 "Aggregate prefix\n"
5342 "Filter more specific routes from updates\n")
5343
5344ALIAS (no_ipv6_aggregate_address,
5345 old_no_ipv6_aggregate_address_cmd,
5346 "no ipv6 bgp aggregate-address X:X::X:X/M",
5347 NO_STR
5348 IPV6_STR
5349 BGP_STR
5350 "Configure BGP aggregate entries\n"
5351 "Aggregate prefix\n")
5352
5353ALIAS (no_ipv6_aggregate_address_summary_only,
5354 old_no_ipv6_aggregate_address_summary_only_cmd,
5355 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5356 NO_STR
5357 IPV6_STR
5358 BGP_STR
5359 "Configure BGP aggregate entries\n"
5360 "Aggregate prefix\n"
5361 "Filter more specific routes from updates\n")
5362#endif /* HAVE_IPV6 */
5363
5364/* Redistribute route treatment. */
5365void
5366bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5367 u_int32_t metric, u_char type)
5368{
5369 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005370 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005371 struct bgp_info *new;
5372 struct bgp_info *bi;
5373 struct bgp_info info;
5374 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005375 struct attr attr = { 0 };
5376 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005377 struct attr *new_attr;
5378 afi_t afi;
5379 int ret;
5380
5381 /* Make default attribute. */
5382 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5383 if (nexthop)
5384 attr.nexthop = *nexthop;
5385
5386 attr.med = metric;
5387 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5388
paul1eb8ef22005-04-07 07:30:20 +00005389 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005390 {
5391 afi = family2afi (p->family);
5392
5393 if (bgp->redist[afi][type])
5394 {
5395 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005396 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005397
5398 if (bgp->redist_metric_flag[afi][type])
5399 attr_new.med = bgp->redist_metric[afi][type];
5400
5401 /* Apply route-map. */
5402 if (bgp->rmap[afi][type].map)
5403 {
5404 info.peer = bgp->peer_self;
5405 info.attr = &attr_new;
5406
paulfee0f4c2004-09-13 05:12:46 +00005407 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5408
paul718e3742002-12-13 20:15:29 +00005409 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5410 &info);
paulfee0f4c2004-09-13 05:12:46 +00005411
5412 bgp->peer_self->rmap_type = 0;
5413
paul718e3742002-12-13 20:15:29 +00005414 if (ret == RMAP_DENYMATCH)
5415 {
5416 /* Free uninterned attribute. */
5417 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005418 bgp_attr_extra_free (&attr_new);
5419
paul718e3742002-12-13 20:15:29 +00005420 /* Unintern original. */
5421 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005422 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005423 bgp_redistribute_delete (p, type);
5424 return;
5425 }
5426 }
5427
Paul Jakmafb982c22007-05-04 20:15:47 +00005428 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5429 afi, SAFI_UNICAST, p, NULL);
5430
paul718e3742002-12-13 20:15:29 +00005431 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005432 bgp_attr_extra_free (&attr_new);
5433
paul718e3742002-12-13 20:15:29 +00005434 for (bi = bn->info; bi; bi = bi->next)
5435 if (bi->peer == bgp->peer_self
5436 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5437 break;
5438
5439 if (bi)
5440 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005441 if (attrhash_cmp (bi->attr, new_attr) &&
5442 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005443 {
5444 bgp_attr_unintern (new_attr);
5445 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005446 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005447 bgp_unlock_node (bn);
5448 return;
5449 }
5450 else
5451 {
5452 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005453 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005454
5455 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005456 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5457 bgp_info_restore(bn, bi);
5458 else
5459 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005460 bgp_attr_unintern (bi->attr);
5461 bi->attr = new_attr;
5462 bi->uptime = time (NULL);
5463
5464 /* Process change. */
5465 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5466 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5467 bgp_unlock_node (bn);
5468 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005469 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005470 return;
5471 }
5472 }
5473
5474 new = bgp_info_new ();
5475 new->type = type;
5476 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5477 new->peer = bgp->peer_self;
5478 SET_FLAG (new->flags, BGP_INFO_VALID);
5479 new->attr = new_attr;
5480 new->uptime = time (NULL);
5481
5482 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5483 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005484 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005485 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5486 }
5487 }
5488
5489 /* Unintern original. */
5490 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005491 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005492}
5493
5494void
5495bgp_redistribute_delete (struct prefix *p, u_char type)
5496{
5497 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005498 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005499 afi_t afi;
5500 struct bgp_node *rn;
5501 struct bgp_info *ri;
5502
paul1eb8ef22005-04-07 07:30:20 +00005503 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005504 {
5505 afi = family2afi (p->family);
5506
5507 if (bgp->redist[afi][type])
5508 {
paulfee0f4c2004-09-13 05:12:46 +00005509 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005510
5511 for (ri = rn->info; ri; ri = ri->next)
5512 if (ri->peer == bgp->peer_self
5513 && ri->type == type)
5514 break;
5515
5516 if (ri)
5517 {
5518 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005519 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005520 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005521 }
5522 bgp_unlock_node (rn);
5523 }
5524 }
5525}
5526
5527/* Withdraw specified route type's route. */
5528void
5529bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5530{
5531 struct bgp_node *rn;
5532 struct bgp_info *ri;
5533 struct bgp_table *table;
5534
5535 table = bgp->rib[afi][SAFI_UNICAST];
5536
5537 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5538 {
5539 for (ri = rn->info; ri; ri = ri->next)
5540 if (ri->peer == bgp->peer_self
5541 && ri->type == type)
5542 break;
5543
5544 if (ri)
5545 {
5546 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005547 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005548 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005549 }
5550 }
5551}
5552
5553/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005554static void
paul718e3742002-12-13 20:15:29 +00005555route_vty_out_route (struct prefix *p, struct vty *vty)
5556{
5557 int len;
5558 u_int32_t destination;
5559 char buf[BUFSIZ];
5560
5561 if (p->family == AF_INET)
5562 {
5563 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5564 destination = ntohl (p->u.prefix4.s_addr);
5565
5566 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5567 || (IN_CLASSB (destination) && p->prefixlen == 16)
5568 || (IN_CLASSA (destination) && p->prefixlen == 8)
5569 || p->u.prefix4.s_addr == 0)
5570 {
5571 /* When mask is natural, mask is not displayed. */
5572 }
5573 else
5574 len += vty_out (vty, "/%d", p->prefixlen);
5575 }
5576 else
5577 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5578 p->prefixlen);
5579
5580 len = 17 - len;
5581 if (len < 1)
5582 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5583 else
5584 vty_out (vty, "%*s", len, " ");
5585}
5586
paul718e3742002-12-13 20:15:29 +00005587enum bgp_display_type
5588{
5589 normal_list,
5590};
5591
paulb40d9392005-08-22 22:34:41 +00005592/* Print the short form route status for a bgp_info */
5593static void
5594route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005595{
paulb40d9392005-08-22 22:34:41 +00005596 /* Route status display. */
5597 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5598 vty_out (vty, "R");
5599 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005600 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005601 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005602 vty_out (vty, "s");
5603 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5604 vty_out (vty, "*");
5605 else
5606 vty_out (vty, " ");
5607
5608 /* Selected */
5609 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5610 vty_out (vty, "h");
5611 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5612 vty_out (vty, "d");
5613 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5614 vty_out (vty, ">");
5615 else
5616 vty_out (vty, " ");
5617
5618 /* Internal route. */
5619 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5620 vty_out (vty, "i");
5621 else
paulb40d9392005-08-22 22:34:41 +00005622 vty_out (vty, " ");
5623}
5624
5625/* called from terminal list command */
5626void
5627route_vty_out (struct vty *vty, struct prefix *p,
5628 struct bgp_info *binfo, int display, safi_t safi)
5629{
5630 struct attr *attr;
5631
5632 /* short status lead text */
5633 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005634
5635 /* print prefix and mask */
5636 if (! display)
5637 route_vty_out_route (p, vty);
5638 else
5639 vty_out (vty, "%*s", 17, " ");
5640
5641 /* Print attribute */
5642 attr = binfo->attr;
5643 if (attr)
5644 {
5645 if (p->family == AF_INET)
5646 {
5647 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005648 vty_out (vty, "%-16s",
5649 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005650 else
5651 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5652 }
5653#ifdef HAVE_IPV6
5654 else if (p->family == AF_INET6)
5655 {
5656 int len;
5657 char buf[BUFSIZ];
5658
5659 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005660 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5661 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005662 len = 16 - len;
5663 if (len < 1)
5664 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5665 else
5666 vty_out (vty, "%*s", len, " ");
5667 }
5668#endif /* HAVE_IPV6 */
5669
5670 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5671 vty_out (vty, "%10d", attr->med);
5672 else
5673 vty_out (vty, " ");
5674
5675 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5676 vty_out (vty, "%7d", attr->local_pref);
5677 else
5678 vty_out (vty, " ");
5679
Paul Jakmafb982c22007-05-04 20:15:47 +00005680 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005681
Paul Jakmab2518c12006-05-12 23:48:40 +00005682 /* Print aspath */
5683 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005684 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005685
Paul Jakmab2518c12006-05-12 23:48:40 +00005686 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005687 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005688 }
paul718e3742002-12-13 20:15:29 +00005689 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005690}
5691
5692/* called from terminal list command */
5693void
5694route_vty_out_tmp (struct vty *vty, struct prefix *p,
5695 struct attr *attr, safi_t safi)
5696{
5697 /* Route status display. */
5698 vty_out (vty, "*");
5699 vty_out (vty, ">");
5700 vty_out (vty, " ");
5701
5702 /* print prefix and mask */
5703 route_vty_out_route (p, vty);
5704
5705 /* Print attribute */
5706 if (attr)
5707 {
5708 if (p->family == AF_INET)
5709 {
5710 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005711 vty_out (vty, "%-16s",
5712 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005713 else
5714 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5715 }
5716#ifdef HAVE_IPV6
5717 else if (p->family == AF_INET6)
5718 {
5719 int len;
5720 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005721
5722 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005723
5724 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005725 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5726 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005727 len = 16 - len;
5728 if (len < 1)
5729 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5730 else
5731 vty_out (vty, "%*s", len, " ");
5732 }
5733#endif /* HAVE_IPV6 */
5734
5735 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5736 vty_out (vty, "%10d", attr->med);
5737 else
5738 vty_out (vty, " ");
5739
5740 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5741 vty_out (vty, "%7d", attr->local_pref);
5742 else
5743 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005744
5745 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5746
Paul Jakmab2518c12006-05-12 23:48:40 +00005747 /* Print aspath */
5748 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005749 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005750
Paul Jakmab2518c12006-05-12 23:48:40 +00005751 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005752 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005753 }
paul718e3742002-12-13 20:15:29 +00005754
5755 vty_out (vty, "%s", VTY_NEWLINE);
5756}
5757
ajs5a646652004-11-05 01:25:55 +00005758void
paul718e3742002-12-13 20:15:29 +00005759route_vty_out_tag (struct vty *vty, struct prefix *p,
5760 struct bgp_info *binfo, int display, safi_t safi)
5761{
5762 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005763 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005764
5765 if (!binfo->extra)
5766 return;
5767
paulb40d9392005-08-22 22:34:41 +00005768 /* short status lead text */
5769 route_vty_short_status_out (vty, binfo);
5770
paul718e3742002-12-13 20:15:29 +00005771 /* print prefix and mask */
5772 if (! display)
5773 route_vty_out_route (p, vty);
5774 else
5775 vty_out (vty, "%*s", 17, " ");
5776
5777 /* Print attribute */
5778 attr = binfo->attr;
5779 if (attr)
5780 {
5781 if (p->family == AF_INET)
5782 {
5783 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005784 vty_out (vty, "%-16s",
5785 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005786 else
5787 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5788 }
5789#ifdef HAVE_IPV6
5790 else if (p->family == AF_INET6)
5791 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005792 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005793 char buf[BUFSIZ];
5794 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005795 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005796 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005797 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5798 buf, BUFSIZ));
5799 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005800 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005801 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5802 buf, BUFSIZ),
5803 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5804 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005805
5806 }
5807#endif /* HAVE_IPV6 */
5808 }
5809
Paul Jakmafb982c22007-05-04 20:15:47 +00005810 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005811
5812 vty_out (vty, "notag/%d", label);
5813
5814 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005815}
5816
5817/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005818static void
paul718e3742002-12-13 20:15:29 +00005819damp_route_vty_out (struct vty *vty, struct prefix *p,
5820 struct bgp_info *binfo, int display, safi_t safi)
5821{
5822 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005823 int len;
5824
paulb40d9392005-08-22 22:34:41 +00005825 /* short status lead text */
5826 route_vty_short_status_out (vty, binfo);
5827
paul718e3742002-12-13 20:15:29 +00005828 /* print prefix and mask */
5829 if (! display)
5830 route_vty_out_route (p, vty);
5831 else
5832 vty_out (vty, "%*s", 17, " ");
5833
5834 len = vty_out (vty, "%s", binfo->peer->host);
5835 len = 17 - len;
5836 if (len < 1)
5837 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5838 else
5839 vty_out (vty, "%*s", len, " ");
5840
5841 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5842
5843 /* Print attribute */
5844 attr = binfo->attr;
5845 if (attr)
5846 {
5847 /* Print aspath */
5848 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005849 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005850
5851 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005852 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005853 }
5854 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005855}
5856
5857#define BGP_UPTIME_LEN 25
5858
5859/* flap route */
ajs5a646652004-11-05 01:25:55 +00005860static void
paul718e3742002-12-13 20:15:29 +00005861flap_route_vty_out (struct vty *vty, struct prefix *p,
5862 struct bgp_info *binfo, int display, safi_t safi)
5863{
5864 struct attr *attr;
5865 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005866 char timebuf[BGP_UPTIME_LEN];
5867 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005868
5869 if (!binfo->extra)
5870 return;
5871
5872 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005873
paulb40d9392005-08-22 22:34:41 +00005874 /* short status lead text */
5875 route_vty_short_status_out (vty, binfo);
5876
paul718e3742002-12-13 20:15:29 +00005877 /* print prefix and mask */
5878 if (! display)
5879 route_vty_out_route (p, vty);
5880 else
5881 vty_out (vty, "%*s", 17, " ");
5882
5883 len = vty_out (vty, "%s", binfo->peer->host);
5884 len = 16 - len;
5885 if (len < 1)
5886 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5887 else
5888 vty_out (vty, "%*s", len, " ");
5889
5890 len = vty_out (vty, "%d", bdi->flap);
5891 len = 5 - len;
5892 if (len < 1)
5893 vty_out (vty, " ");
5894 else
5895 vty_out (vty, "%*s ", len, " ");
5896
5897 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5898 timebuf, BGP_UPTIME_LEN));
5899
5900 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5901 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5902 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5903 else
5904 vty_out (vty, "%*s ", 8, " ");
5905
5906 /* Print attribute */
5907 attr = binfo->attr;
5908 if (attr)
5909 {
5910 /* Print aspath */
5911 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005912 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005913
5914 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005915 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005916 }
5917 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005918}
5919
paul94f2b392005-06-28 12:44:16 +00005920static void
paul718e3742002-12-13 20:15:29 +00005921route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5922 struct bgp_info *binfo, afi_t afi, safi_t safi)
5923{
5924 char buf[INET6_ADDRSTRLEN];
5925 char buf1[BUFSIZ];
5926 struct attr *attr;
5927 int sockunion_vty_out (struct vty *, union sockunion *);
5928
5929 attr = binfo->attr;
5930
5931 if (attr)
5932 {
5933 /* Line1 display AS-path, Aggregator */
5934 if (attr->aspath)
5935 {
5936 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005937 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005938 vty_out (vty, "Local");
5939 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005940 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005941 }
5942
paulb40d9392005-08-22 22:34:41 +00005943 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5944 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005945 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5946 vty_out (vty, ", (stale)");
5947 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005948 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005949 attr->extra->aggregator_as,
5950 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005951 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5952 vty_out (vty, ", (Received from a RR-client)");
5953 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5954 vty_out (vty, ", (Received from a RS-client)");
5955 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5956 vty_out (vty, ", (history entry)");
5957 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5958 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005959 vty_out (vty, "%s", VTY_NEWLINE);
5960
5961 /* Line2 display Next-hop, Neighbor, Router-id */
5962 if (p->family == AF_INET)
5963 {
5964 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005965 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005966 inet_ntoa (attr->nexthop));
5967 }
5968#ifdef HAVE_IPV6
5969 else
5970 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005971 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005972 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005973 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005974 buf, INET6_ADDRSTRLEN));
5975 }
5976#endif /* HAVE_IPV6 */
5977
5978 if (binfo->peer == bgp->peer_self)
5979 {
5980 vty_out (vty, " from %s ",
5981 p->family == AF_INET ? "0.0.0.0" : "::");
5982 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5983 }
5984 else
5985 {
5986 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5987 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005988 else if (binfo->extra && binfo->extra->igpmetric)
5989 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005990 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005991 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005992 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005993 else
5994 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5995 }
5996 vty_out (vty, "%s", VTY_NEWLINE);
5997
5998#ifdef HAVE_IPV6
5999 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006000 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006001 {
6002 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006003 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006004 buf, INET6_ADDRSTRLEN),
6005 VTY_NEWLINE);
6006 }
6007#endif /* HAVE_IPV6 */
6008
6009 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6010 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6011
6012 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6013 vty_out (vty, ", metric %d", attr->med);
6014
6015 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6016 vty_out (vty, ", localpref %d", attr->local_pref);
6017 else
6018 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6019
Paul Jakmafb982c22007-05-04 20:15:47 +00006020 if (attr->extra && attr->extra->weight != 0)
6021 vty_out (vty, ", weight %d", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006022
6023 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6024 vty_out (vty, ", valid");
6025
6026 if (binfo->peer != bgp->peer_self)
6027 {
6028 if (binfo->peer->as == binfo->peer->local_as)
6029 vty_out (vty, ", internal");
6030 else
6031 vty_out (vty, ", %s",
6032 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6033 }
6034 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6035 vty_out (vty, ", aggregated, local");
6036 else if (binfo->type != ZEBRA_ROUTE_BGP)
6037 vty_out (vty, ", sourced");
6038 else
6039 vty_out (vty, ", sourced, local");
6040
6041 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6042 vty_out (vty, ", atomic-aggregate");
6043
6044 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6045 vty_out (vty, ", best");
6046
6047 vty_out (vty, "%s", VTY_NEWLINE);
6048
6049 /* Line 4 display Community */
6050 if (attr->community)
6051 vty_out (vty, " Community: %s%s", attr->community->str,
6052 VTY_NEWLINE);
6053
6054 /* Line 5 display Extended-community */
6055 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006056 vty_out (vty, " Extended Community: %s%s",
6057 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006058
6059 /* Line 6 display Originator, Cluster-id */
6060 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6061 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6062 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006063 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006064 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006065 vty_out (vty, " Originator: %s",
6066 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006067
6068 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6069 {
6070 int i;
6071 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006072 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6073 vty_out (vty, "%s ",
6074 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006075 }
6076 vty_out (vty, "%s", VTY_NEWLINE);
6077 }
Paul Jakma41367172007-08-06 15:24:51 +00006078
6079 /* 7: AS Pathlimit */
6080 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6081 {
6082
6083 vty_out (vty, " AS-Pathlimit: %u",
6084 attr->pathlimit.ttl);
6085 if (attr->pathlimit.as)
6086 vty_out (vty, " (%u)", attr->pathlimit.as);
6087 vty_out (vty, "%s", VTY_NEWLINE);
6088 }
6089
Paul Jakmafb982c22007-05-04 20:15:47 +00006090 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006091 bgp_damp_info_vty (vty, binfo);
6092
6093 /* Line 7 display Uptime */
6094 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
6095 }
6096 vty_out (vty, "%s", VTY_NEWLINE);
6097}
6098
paulb40d9392005-08-22 22:34:41 +00006099#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 +00006100#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006101#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6102#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6103#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6104
6105enum bgp_show_type
6106{
6107 bgp_show_type_normal,
6108 bgp_show_type_regexp,
6109 bgp_show_type_prefix_list,
6110 bgp_show_type_filter_list,
6111 bgp_show_type_route_map,
6112 bgp_show_type_neighbor,
6113 bgp_show_type_cidr_only,
6114 bgp_show_type_prefix_longer,
6115 bgp_show_type_community_all,
6116 bgp_show_type_community,
6117 bgp_show_type_community_exact,
6118 bgp_show_type_community_list,
6119 bgp_show_type_community_list_exact,
6120 bgp_show_type_flap_statistics,
6121 bgp_show_type_flap_address,
6122 bgp_show_type_flap_prefix,
6123 bgp_show_type_flap_cidr_only,
6124 bgp_show_type_flap_regexp,
6125 bgp_show_type_flap_filter_list,
6126 bgp_show_type_flap_prefix_list,
6127 bgp_show_type_flap_prefix_longer,
6128 bgp_show_type_flap_route_map,
6129 bgp_show_type_flap_neighbor,
6130 bgp_show_type_dampend_paths,
6131 bgp_show_type_damp_neighbor
6132};
6133
ajs5a646652004-11-05 01:25:55 +00006134static int
paulfee0f4c2004-09-13 05:12:46 +00006135bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006136 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006137{
paul718e3742002-12-13 20:15:29 +00006138 struct bgp_info *ri;
6139 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006140 int header = 1;
paul718e3742002-12-13 20:15:29 +00006141 int display;
ajs5a646652004-11-05 01:25:55 +00006142 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006143
6144 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006145 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006146
paul718e3742002-12-13 20:15:29 +00006147 /* Start processing of routes. */
6148 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6149 if (rn->info != NULL)
6150 {
6151 display = 0;
6152
6153 for (ri = rn->info; ri; ri = ri->next)
6154 {
ajs5a646652004-11-05 01:25:55 +00006155 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006156 || type == bgp_show_type_flap_address
6157 || type == bgp_show_type_flap_prefix
6158 || type == bgp_show_type_flap_cidr_only
6159 || type == bgp_show_type_flap_regexp
6160 || type == bgp_show_type_flap_filter_list
6161 || type == bgp_show_type_flap_prefix_list
6162 || type == bgp_show_type_flap_prefix_longer
6163 || type == bgp_show_type_flap_route_map
6164 || type == bgp_show_type_flap_neighbor
6165 || type == bgp_show_type_dampend_paths
6166 || type == bgp_show_type_damp_neighbor)
6167 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006168 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006169 continue;
6170 }
6171 if (type == bgp_show_type_regexp
6172 || type == bgp_show_type_flap_regexp)
6173 {
ajs5a646652004-11-05 01:25:55 +00006174 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006175
6176 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6177 continue;
6178 }
6179 if (type == bgp_show_type_prefix_list
6180 || type == bgp_show_type_flap_prefix_list)
6181 {
ajs5a646652004-11-05 01:25:55 +00006182 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006183
6184 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6185 continue;
6186 }
6187 if (type == bgp_show_type_filter_list
6188 || type == bgp_show_type_flap_filter_list)
6189 {
ajs5a646652004-11-05 01:25:55 +00006190 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006191
6192 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6193 continue;
6194 }
6195 if (type == bgp_show_type_route_map
6196 || type == bgp_show_type_flap_route_map)
6197 {
ajs5a646652004-11-05 01:25:55 +00006198 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006199 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006200 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006201 int ret;
6202
Paul Jakmafb982c22007-05-04 20:15:47 +00006203 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006204 binfo.peer = ri->peer;
6205 binfo.attr = &dummy_attr;
6206
6207 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006208
6209 bgp_attr_extra_free (&dummy_attr);
6210
paul718e3742002-12-13 20:15:29 +00006211 if (ret == RMAP_DENYMATCH)
6212 continue;
6213 }
6214 if (type == bgp_show_type_neighbor
6215 || type == bgp_show_type_flap_neighbor
6216 || type == bgp_show_type_damp_neighbor)
6217 {
ajs5a646652004-11-05 01:25:55 +00006218 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006219
6220 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6221 continue;
6222 }
6223 if (type == bgp_show_type_cidr_only
6224 || type == bgp_show_type_flap_cidr_only)
6225 {
6226 u_int32_t destination;
6227
6228 destination = ntohl (rn->p.u.prefix4.s_addr);
6229 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6230 continue;
6231 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6232 continue;
6233 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6234 continue;
6235 }
6236 if (type == bgp_show_type_prefix_longer
6237 || type == bgp_show_type_flap_prefix_longer)
6238 {
ajs5a646652004-11-05 01:25:55 +00006239 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006240
6241 if (! prefix_match (p, &rn->p))
6242 continue;
6243 }
6244 if (type == bgp_show_type_community_all)
6245 {
6246 if (! ri->attr->community)
6247 continue;
6248 }
6249 if (type == bgp_show_type_community)
6250 {
ajs5a646652004-11-05 01:25:55 +00006251 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006252
6253 if (! ri->attr->community ||
6254 ! community_match (ri->attr->community, com))
6255 continue;
6256 }
6257 if (type == bgp_show_type_community_exact)
6258 {
ajs5a646652004-11-05 01:25:55 +00006259 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006260
6261 if (! ri->attr->community ||
6262 ! community_cmp (ri->attr->community, com))
6263 continue;
6264 }
6265 if (type == bgp_show_type_community_list)
6266 {
ajs5a646652004-11-05 01:25:55 +00006267 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006268
6269 if (! community_list_match (ri->attr->community, list))
6270 continue;
6271 }
6272 if (type == bgp_show_type_community_list_exact)
6273 {
ajs5a646652004-11-05 01:25:55 +00006274 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006275
6276 if (! community_list_exact_match (ri->attr->community, list))
6277 continue;
6278 }
6279 if (type == bgp_show_type_flap_address
6280 || type == bgp_show_type_flap_prefix)
6281 {
ajs5a646652004-11-05 01:25:55 +00006282 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006283
6284 if (! prefix_match (&rn->p, p))
6285 continue;
6286
6287 if (type == bgp_show_type_flap_prefix)
6288 if (p->prefixlen != rn->p.prefixlen)
6289 continue;
6290 }
6291 if (type == bgp_show_type_dampend_paths
6292 || type == bgp_show_type_damp_neighbor)
6293 {
6294 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6295 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6296 continue;
6297 }
6298
6299 if (header)
6300 {
hasso93406d82005-02-02 14:40:33 +00006301 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6302 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6303 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006304 if (type == bgp_show_type_dampend_paths
6305 || type == bgp_show_type_damp_neighbor)
6306 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6307 else if (type == bgp_show_type_flap_statistics
6308 || type == bgp_show_type_flap_address
6309 || type == bgp_show_type_flap_prefix
6310 || type == bgp_show_type_flap_cidr_only
6311 || type == bgp_show_type_flap_regexp
6312 || type == bgp_show_type_flap_filter_list
6313 || type == bgp_show_type_flap_prefix_list
6314 || type == bgp_show_type_flap_prefix_longer
6315 || type == bgp_show_type_flap_route_map
6316 || type == bgp_show_type_flap_neighbor)
6317 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6318 else
6319 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006320 header = 0;
6321 }
6322
6323 if (type == bgp_show_type_dampend_paths
6324 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006325 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006326 else if (type == bgp_show_type_flap_statistics
6327 || type == bgp_show_type_flap_address
6328 || type == bgp_show_type_flap_prefix
6329 || type == bgp_show_type_flap_cidr_only
6330 || type == bgp_show_type_flap_regexp
6331 || type == bgp_show_type_flap_filter_list
6332 || type == bgp_show_type_flap_prefix_list
6333 || type == bgp_show_type_flap_prefix_longer
6334 || type == bgp_show_type_flap_route_map
6335 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006336 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006337 else
ajs5a646652004-11-05 01:25:55 +00006338 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006339 display++;
6340 }
6341 if (display)
ajs5a646652004-11-05 01:25:55 +00006342 output_count++;
paul718e3742002-12-13 20:15:29 +00006343 }
6344
6345 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006346 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006347 {
6348 if (type == bgp_show_type_normal)
6349 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6350 }
6351 else
6352 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006353 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006354
6355 return CMD_SUCCESS;
6356}
6357
ajs5a646652004-11-05 01:25:55 +00006358static int
paulfee0f4c2004-09-13 05:12:46 +00006359bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006360 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006361{
6362 struct bgp_table *table;
6363
6364 if (bgp == NULL) {
6365 bgp = bgp_get_default ();
6366 }
6367
6368 if (bgp == NULL)
6369 {
6370 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6371 return CMD_WARNING;
6372 }
6373
6374
6375 table = bgp->rib[afi][safi];
6376
ajs5a646652004-11-05 01:25:55 +00006377 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006378}
6379
paul718e3742002-12-13 20:15:29 +00006380/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006381static void
paul718e3742002-12-13 20:15:29 +00006382route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6383 struct bgp_node *rn,
6384 struct prefix_rd *prd, afi_t afi, safi_t safi)
6385{
6386 struct bgp_info *ri;
6387 struct prefix *p;
6388 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006389 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006390 char buf1[INET6_ADDRSTRLEN];
6391 char buf2[INET6_ADDRSTRLEN];
6392 int count = 0;
6393 int best = 0;
6394 int suppress = 0;
6395 int no_export = 0;
6396 int no_advertise = 0;
6397 int local_as = 0;
6398 int first = 0;
6399
6400 p = &rn->p;
6401 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6402 (safi == SAFI_MPLS_VPN ?
6403 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6404 safi == SAFI_MPLS_VPN ? ":" : "",
6405 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6406 p->prefixlen, VTY_NEWLINE);
6407
6408 for (ri = rn->info; ri; ri = ri->next)
6409 {
6410 count++;
6411 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6412 {
6413 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006414 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006415 suppress = 1;
6416 if (ri->attr->community != NULL)
6417 {
6418 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6419 no_advertise = 1;
6420 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6421 no_export = 1;
6422 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6423 local_as = 1;
6424 }
6425 }
6426 }
6427
6428 vty_out (vty, "Paths: (%d available", count);
6429 if (best)
6430 {
6431 vty_out (vty, ", best #%d", best);
6432 if (safi == SAFI_UNICAST)
6433 vty_out (vty, ", table Default-IP-Routing-Table");
6434 }
6435 else
6436 vty_out (vty, ", no best path");
6437 if (no_advertise)
6438 vty_out (vty, ", not advertised to any peer");
6439 else if (no_export)
6440 vty_out (vty, ", not advertised to EBGP peer");
6441 else if (local_as)
6442 vty_out (vty, ", not advertised outside local AS");
6443 if (suppress)
6444 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6445 vty_out (vty, ")%s", VTY_NEWLINE);
6446
6447 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006448 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006449 {
6450 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6451 {
6452 if (! first)
6453 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6454 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6455 first = 1;
6456 }
6457 }
6458 if (! first)
6459 vty_out (vty, " Not advertised to any peer");
6460 vty_out (vty, "%s", VTY_NEWLINE);
6461}
6462
6463/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006464static int
paulfee0f4c2004-09-13 05:12:46 +00006465bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006466 struct bgp_table *rib, const char *ip_str,
6467 afi_t afi, safi_t safi, struct prefix_rd *prd,
6468 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006469{
6470 int ret;
6471 int header;
6472 int display = 0;
6473 struct prefix match;
6474 struct bgp_node *rn;
6475 struct bgp_node *rm;
6476 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006477 struct bgp_table *table;
6478
paul718e3742002-12-13 20:15:29 +00006479 /* Check IP address argument. */
6480 ret = str2prefix (ip_str, &match);
6481 if (! ret)
6482 {
6483 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6484 return CMD_WARNING;
6485 }
6486
6487 match.family = afi2family (afi);
6488
6489 if (safi == SAFI_MPLS_VPN)
6490 {
paulfee0f4c2004-09-13 05:12:46 +00006491 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006492 {
6493 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6494 continue;
6495
6496 if ((table = rn->info) != NULL)
6497 {
6498 header = 1;
6499
6500 if ((rm = bgp_node_match (table, &match)) != NULL)
6501 {
6502 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6503 continue;
6504
6505 for (ri = rm->info; ri; ri = ri->next)
6506 {
6507 if (header)
6508 {
6509 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6510 AFI_IP, SAFI_MPLS_VPN);
6511
6512 header = 0;
6513 }
6514 display++;
6515 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6516 }
6517 }
6518 }
6519 }
6520 }
6521 else
6522 {
6523 header = 1;
6524
paulfee0f4c2004-09-13 05:12:46 +00006525 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006526 {
6527 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6528 {
6529 for (ri = rn->info; ri; ri = ri->next)
6530 {
6531 if (header)
6532 {
6533 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6534 header = 0;
6535 }
6536 display++;
6537 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6538 }
6539 }
6540 }
6541 }
6542
6543 if (! display)
6544 {
6545 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6546 return CMD_WARNING;
6547 }
6548
6549 return CMD_SUCCESS;
6550}
6551
paulfee0f4c2004-09-13 05:12:46 +00006552/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006553static int
paulfd79ac92004-10-13 05:06:08 +00006554bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006555 afi_t afi, safi_t safi, struct prefix_rd *prd,
6556 int prefix_check)
6557{
6558 struct bgp *bgp;
6559
6560 /* BGP structure lookup. */
6561 if (view_name)
6562 {
6563 bgp = bgp_lookup_by_name (view_name);
6564 if (bgp == NULL)
6565 {
6566 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6567 return CMD_WARNING;
6568 }
6569 }
6570 else
6571 {
6572 bgp = bgp_get_default ();
6573 if (bgp == NULL)
6574 {
6575 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6576 return CMD_WARNING;
6577 }
6578 }
6579
6580 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6581 afi, safi, prd, prefix_check);
6582}
6583
paul718e3742002-12-13 20:15:29 +00006584/* BGP route print out function. */
6585DEFUN (show_ip_bgp,
6586 show_ip_bgp_cmd,
6587 "show ip bgp",
6588 SHOW_STR
6589 IP_STR
6590 BGP_STR)
6591{
ajs5a646652004-11-05 01:25:55 +00006592 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006593}
6594
6595DEFUN (show_ip_bgp_ipv4,
6596 show_ip_bgp_ipv4_cmd,
6597 "show ip bgp ipv4 (unicast|multicast)",
6598 SHOW_STR
6599 IP_STR
6600 BGP_STR
6601 "Address family\n"
6602 "Address Family modifier\n"
6603 "Address Family modifier\n")
6604{
6605 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006606 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6607 NULL);
paul718e3742002-12-13 20:15:29 +00006608
ajs5a646652004-11-05 01:25:55 +00006609 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006610}
6611
6612DEFUN (show_ip_bgp_route,
6613 show_ip_bgp_route_cmd,
6614 "show ip bgp A.B.C.D",
6615 SHOW_STR
6616 IP_STR
6617 BGP_STR
6618 "Network in the BGP routing table to display\n")
6619{
6620 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6621}
6622
6623DEFUN (show_ip_bgp_ipv4_route,
6624 show_ip_bgp_ipv4_route_cmd,
6625 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6626 SHOW_STR
6627 IP_STR
6628 BGP_STR
6629 "Address family\n"
6630 "Address Family modifier\n"
6631 "Address Family modifier\n"
6632 "Network in the BGP routing table to display\n")
6633{
6634 if (strncmp (argv[0], "m", 1) == 0)
6635 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6636
6637 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6638}
6639
6640DEFUN (show_ip_bgp_vpnv4_all_route,
6641 show_ip_bgp_vpnv4_all_route_cmd,
6642 "show ip bgp vpnv4 all A.B.C.D",
6643 SHOW_STR
6644 IP_STR
6645 BGP_STR
6646 "Display VPNv4 NLRI specific information\n"
6647 "Display information about all VPNv4 NLRIs\n"
6648 "Network in the BGP routing table to display\n")
6649{
6650 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6651}
6652
6653DEFUN (show_ip_bgp_vpnv4_rd_route,
6654 show_ip_bgp_vpnv4_rd_route_cmd,
6655 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6656 SHOW_STR
6657 IP_STR
6658 BGP_STR
6659 "Display VPNv4 NLRI specific information\n"
6660 "Display information for a route distinguisher\n"
6661 "VPN Route Distinguisher\n"
6662 "Network in the BGP routing table to display\n")
6663{
6664 int ret;
6665 struct prefix_rd prd;
6666
6667 ret = str2prefix_rd (argv[0], &prd);
6668 if (! ret)
6669 {
6670 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6671 return CMD_WARNING;
6672 }
6673 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6674}
6675
6676DEFUN (show_ip_bgp_prefix,
6677 show_ip_bgp_prefix_cmd,
6678 "show ip bgp A.B.C.D/M",
6679 SHOW_STR
6680 IP_STR
6681 BGP_STR
6682 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6683{
6684 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6685}
6686
6687DEFUN (show_ip_bgp_ipv4_prefix,
6688 show_ip_bgp_ipv4_prefix_cmd,
6689 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6690 SHOW_STR
6691 IP_STR
6692 BGP_STR
6693 "Address family\n"
6694 "Address Family modifier\n"
6695 "Address Family modifier\n"
6696 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6697{
6698 if (strncmp (argv[0], "m", 1) == 0)
6699 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6700
6701 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6702}
6703
6704DEFUN (show_ip_bgp_vpnv4_all_prefix,
6705 show_ip_bgp_vpnv4_all_prefix_cmd,
6706 "show ip bgp vpnv4 all A.B.C.D/M",
6707 SHOW_STR
6708 IP_STR
6709 BGP_STR
6710 "Display VPNv4 NLRI specific information\n"
6711 "Display information about all VPNv4 NLRIs\n"
6712 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6713{
6714 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6715}
6716
6717DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6718 show_ip_bgp_vpnv4_rd_prefix_cmd,
6719 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6720 SHOW_STR
6721 IP_STR
6722 BGP_STR
6723 "Display VPNv4 NLRI specific information\n"
6724 "Display information for a route distinguisher\n"
6725 "VPN Route Distinguisher\n"
6726 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6727{
6728 int ret;
6729 struct prefix_rd prd;
6730
6731 ret = str2prefix_rd (argv[0], &prd);
6732 if (! ret)
6733 {
6734 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6735 return CMD_WARNING;
6736 }
6737 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6738}
6739
6740DEFUN (show_ip_bgp_view,
6741 show_ip_bgp_view_cmd,
6742 "show ip bgp view WORD",
6743 SHOW_STR
6744 IP_STR
6745 BGP_STR
6746 "BGP view\n"
6747 "BGP view name\n")
6748{
paulbb46e942003-10-24 19:02:03 +00006749 struct bgp *bgp;
6750
6751 /* BGP structure lookup. */
6752 bgp = bgp_lookup_by_name (argv[0]);
6753 if (bgp == NULL)
6754 {
6755 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6756 return CMD_WARNING;
6757 }
6758
ajs5a646652004-11-05 01:25:55 +00006759 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006760}
6761
6762DEFUN (show_ip_bgp_view_route,
6763 show_ip_bgp_view_route_cmd,
6764 "show ip bgp view WORD A.B.C.D",
6765 SHOW_STR
6766 IP_STR
6767 BGP_STR
6768 "BGP view\n"
6769 "BGP view name\n"
6770 "Network in the BGP routing table to display\n")
6771{
6772 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6773}
6774
6775DEFUN (show_ip_bgp_view_prefix,
6776 show_ip_bgp_view_prefix_cmd,
6777 "show ip bgp view WORD A.B.C.D/M",
6778 SHOW_STR
6779 IP_STR
6780 BGP_STR
6781 "BGP view\n"
6782 "BGP view name\n"
6783 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6784{
6785 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6786}
6787
6788#ifdef HAVE_IPV6
6789DEFUN (show_bgp,
6790 show_bgp_cmd,
6791 "show bgp",
6792 SHOW_STR
6793 BGP_STR)
6794{
ajs5a646652004-11-05 01:25:55 +00006795 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6796 NULL);
paul718e3742002-12-13 20:15:29 +00006797}
6798
6799ALIAS (show_bgp,
6800 show_bgp_ipv6_cmd,
6801 "show bgp ipv6",
6802 SHOW_STR
6803 BGP_STR
6804 "Address family\n")
6805
6806/* old command */
6807DEFUN (show_ipv6_bgp,
6808 show_ipv6_bgp_cmd,
6809 "show ipv6 bgp",
6810 SHOW_STR
6811 IP_STR
6812 BGP_STR)
6813{
ajs5a646652004-11-05 01:25:55 +00006814 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6815 NULL);
paul718e3742002-12-13 20:15:29 +00006816}
6817
6818DEFUN (show_bgp_route,
6819 show_bgp_route_cmd,
6820 "show bgp X:X::X:X",
6821 SHOW_STR
6822 BGP_STR
6823 "Network in the BGP routing table to display\n")
6824{
6825 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6826}
6827
6828ALIAS (show_bgp_route,
6829 show_bgp_ipv6_route_cmd,
6830 "show bgp ipv6 X:X::X:X",
6831 SHOW_STR
6832 BGP_STR
6833 "Address family\n"
6834 "Network in the BGP routing table to display\n")
6835
6836/* old command */
6837DEFUN (show_ipv6_bgp_route,
6838 show_ipv6_bgp_route_cmd,
6839 "show ipv6 bgp X:X::X:X",
6840 SHOW_STR
6841 IP_STR
6842 BGP_STR
6843 "Network in the BGP routing table to display\n")
6844{
6845 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6846}
6847
6848DEFUN (show_bgp_prefix,
6849 show_bgp_prefix_cmd,
6850 "show bgp X:X::X:X/M",
6851 SHOW_STR
6852 BGP_STR
6853 "IPv6 prefix <network>/<length>\n")
6854{
6855 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6856}
6857
6858ALIAS (show_bgp_prefix,
6859 show_bgp_ipv6_prefix_cmd,
6860 "show bgp ipv6 X:X::X:X/M",
6861 SHOW_STR
6862 BGP_STR
6863 "Address family\n"
6864 "IPv6 prefix <network>/<length>\n")
6865
6866/* old command */
6867DEFUN (show_ipv6_bgp_prefix,
6868 show_ipv6_bgp_prefix_cmd,
6869 "show ipv6 bgp X:X::X:X/M",
6870 SHOW_STR
6871 IP_STR
6872 BGP_STR
6873 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6874{
6875 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6876}
6877
paulbb46e942003-10-24 19:02:03 +00006878DEFUN (show_bgp_view,
6879 show_bgp_view_cmd,
6880 "show bgp view WORD",
6881 SHOW_STR
6882 BGP_STR
6883 "BGP view\n"
6884 "View name\n")
6885{
6886 struct bgp *bgp;
6887
6888 /* BGP structure lookup. */
6889 bgp = bgp_lookup_by_name (argv[0]);
6890 if (bgp == NULL)
6891 {
6892 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6893 return CMD_WARNING;
6894 }
6895
ajs5a646652004-11-05 01:25:55 +00006896 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006897}
6898
6899ALIAS (show_bgp_view,
6900 show_bgp_view_ipv6_cmd,
6901 "show bgp view WORD ipv6",
6902 SHOW_STR
6903 BGP_STR
6904 "BGP view\n"
6905 "View name\n"
6906 "Address family\n")
6907
6908DEFUN (show_bgp_view_route,
6909 show_bgp_view_route_cmd,
6910 "show bgp view WORD X:X::X:X",
6911 SHOW_STR
6912 BGP_STR
6913 "BGP view\n"
6914 "View name\n"
6915 "Network in the BGP routing table to display\n")
6916{
6917 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6918}
6919
6920ALIAS (show_bgp_view_route,
6921 show_bgp_view_ipv6_route_cmd,
6922 "show bgp view WORD ipv6 X:X::X:X",
6923 SHOW_STR
6924 BGP_STR
6925 "BGP view\n"
6926 "View name\n"
6927 "Address family\n"
6928 "Network in the BGP routing table to display\n")
6929
6930DEFUN (show_bgp_view_prefix,
6931 show_bgp_view_prefix_cmd,
6932 "show bgp view WORD X:X::X:X/M",
6933 SHOW_STR
6934 BGP_STR
6935 "BGP view\n"
6936 "View name\n"
6937 "IPv6 prefix <network>/<length>\n")
6938{
6939 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6940}
6941
6942ALIAS (show_bgp_view_prefix,
6943 show_bgp_view_ipv6_prefix_cmd,
6944 "show bgp view WORD ipv6 X:X::X:X/M",
6945 SHOW_STR
6946 BGP_STR
6947 "BGP view\n"
6948 "View name\n"
6949 "Address family\n"
6950 "IPv6 prefix <network>/<length>\n")
6951
paul718e3742002-12-13 20:15:29 +00006952/* old command */
6953DEFUN (show_ipv6_mbgp,
6954 show_ipv6_mbgp_cmd,
6955 "show ipv6 mbgp",
6956 SHOW_STR
6957 IP_STR
6958 MBGP_STR)
6959{
ajs5a646652004-11-05 01:25:55 +00006960 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6961 NULL);
paul718e3742002-12-13 20:15:29 +00006962}
6963
6964/* old command */
6965DEFUN (show_ipv6_mbgp_route,
6966 show_ipv6_mbgp_route_cmd,
6967 "show ipv6 mbgp X:X::X:X",
6968 SHOW_STR
6969 IP_STR
6970 MBGP_STR
6971 "Network in the MBGP routing table to display\n")
6972{
6973 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6974}
6975
6976/* old command */
6977DEFUN (show_ipv6_mbgp_prefix,
6978 show_ipv6_mbgp_prefix_cmd,
6979 "show ipv6 mbgp X:X::X:X/M",
6980 SHOW_STR
6981 IP_STR
6982 MBGP_STR
6983 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6984{
6985 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6986}
6987#endif
6988
paul718e3742002-12-13 20:15:29 +00006989
paul94f2b392005-06-28 12:44:16 +00006990static int
paulfd79ac92004-10-13 05:06:08 +00006991bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006992 safi_t safi, enum bgp_show_type type)
6993{
6994 int i;
6995 struct buffer *b;
6996 char *regstr;
6997 int first;
6998 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006999 int rc;
paul718e3742002-12-13 20:15:29 +00007000
7001 first = 0;
7002 b = buffer_new (1024);
7003 for (i = 0; i < argc; i++)
7004 {
7005 if (first)
7006 buffer_putc (b, ' ');
7007 else
7008 {
7009 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7010 continue;
7011 first = 1;
7012 }
7013
7014 buffer_putstr (b, argv[i]);
7015 }
7016 buffer_putc (b, '\0');
7017
7018 regstr = buffer_getstr (b);
7019 buffer_free (b);
7020
7021 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007022 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007023 if (! regex)
7024 {
7025 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7026 VTY_NEWLINE);
7027 return CMD_WARNING;
7028 }
7029
ajs5a646652004-11-05 01:25:55 +00007030 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7031 bgp_regex_free (regex);
7032 return rc;
paul718e3742002-12-13 20:15:29 +00007033}
7034
7035DEFUN (show_ip_bgp_regexp,
7036 show_ip_bgp_regexp_cmd,
7037 "show ip bgp regexp .LINE",
7038 SHOW_STR
7039 IP_STR
7040 BGP_STR
7041 "Display routes matching the AS path regular expression\n"
7042 "A regular-expression to match the BGP AS paths\n")
7043{
7044 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7045 bgp_show_type_regexp);
7046}
7047
7048DEFUN (show_ip_bgp_flap_regexp,
7049 show_ip_bgp_flap_regexp_cmd,
7050 "show ip bgp flap-statistics regexp .LINE",
7051 SHOW_STR
7052 IP_STR
7053 BGP_STR
7054 "Display flap statistics of routes\n"
7055 "Display routes matching the AS path regular expression\n"
7056 "A regular-expression to match the BGP AS paths\n")
7057{
7058 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7059 bgp_show_type_flap_regexp);
7060}
7061
7062DEFUN (show_ip_bgp_ipv4_regexp,
7063 show_ip_bgp_ipv4_regexp_cmd,
7064 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7065 SHOW_STR
7066 IP_STR
7067 BGP_STR
7068 "Address family\n"
7069 "Address Family modifier\n"
7070 "Address Family modifier\n"
7071 "Display routes matching the AS path regular expression\n"
7072 "A regular-expression to match the BGP AS paths\n")
7073{
7074 if (strncmp (argv[0], "m", 1) == 0)
7075 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7076 bgp_show_type_regexp);
7077
7078 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7079 bgp_show_type_regexp);
7080}
7081
7082#ifdef HAVE_IPV6
7083DEFUN (show_bgp_regexp,
7084 show_bgp_regexp_cmd,
7085 "show bgp regexp .LINE",
7086 SHOW_STR
7087 BGP_STR
7088 "Display routes matching the AS path regular expression\n"
7089 "A regular-expression to match the BGP AS paths\n")
7090{
7091 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7092 bgp_show_type_regexp);
7093}
7094
7095ALIAS (show_bgp_regexp,
7096 show_bgp_ipv6_regexp_cmd,
7097 "show bgp ipv6 regexp .LINE",
7098 SHOW_STR
7099 BGP_STR
7100 "Address family\n"
7101 "Display routes matching the AS path regular expression\n"
7102 "A regular-expression to match the BGP AS paths\n")
7103
7104/* old command */
7105DEFUN (show_ipv6_bgp_regexp,
7106 show_ipv6_bgp_regexp_cmd,
7107 "show ipv6 bgp regexp .LINE",
7108 SHOW_STR
7109 IP_STR
7110 BGP_STR
7111 "Display routes matching the AS path regular expression\n"
7112 "A regular-expression to match the BGP AS paths\n")
7113{
7114 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7115 bgp_show_type_regexp);
7116}
7117
7118/* old command */
7119DEFUN (show_ipv6_mbgp_regexp,
7120 show_ipv6_mbgp_regexp_cmd,
7121 "show ipv6 mbgp regexp .LINE",
7122 SHOW_STR
7123 IP_STR
7124 BGP_STR
7125 "Display routes matching the AS path regular expression\n"
7126 "A regular-expression to match the MBGP AS paths\n")
7127{
7128 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7129 bgp_show_type_regexp);
7130}
7131#endif /* HAVE_IPV6 */
7132
paul94f2b392005-06-28 12:44:16 +00007133static int
paulfd79ac92004-10-13 05:06:08 +00007134bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007135 safi_t safi, enum bgp_show_type type)
7136{
7137 struct prefix_list *plist;
7138
7139 plist = prefix_list_lookup (afi, prefix_list_str);
7140 if (plist == NULL)
7141 {
7142 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7143 prefix_list_str, VTY_NEWLINE);
7144 return CMD_WARNING;
7145 }
7146
ajs5a646652004-11-05 01:25:55 +00007147 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007148}
7149
7150DEFUN (show_ip_bgp_prefix_list,
7151 show_ip_bgp_prefix_list_cmd,
7152 "show ip bgp prefix-list WORD",
7153 SHOW_STR
7154 IP_STR
7155 BGP_STR
7156 "Display routes conforming to the prefix-list\n"
7157 "IP prefix-list name\n")
7158{
7159 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7160 bgp_show_type_prefix_list);
7161}
7162
7163DEFUN (show_ip_bgp_flap_prefix_list,
7164 show_ip_bgp_flap_prefix_list_cmd,
7165 "show ip bgp flap-statistics prefix-list WORD",
7166 SHOW_STR
7167 IP_STR
7168 BGP_STR
7169 "Display flap statistics of routes\n"
7170 "Display routes conforming to the prefix-list\n"
7171 "IP prefix-list name\n")
7172{
7173 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7174 bgp_show_type_flap_prefix_list);
7175}
7176
7177DEFUN (show_ip_bgp_ipv4_prefix_list,
7178 show_ip_bgp_ipv4_prefix_list_cmd,
7179 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7180 SHOW_STR
7181 IP_STR
7182 BGP_STR
7183 "Address family\n"
7184 "Address Family modifier\n"
7185 "Address Family modifier\n"
7186 "Display routes conforming to the prefix-list\n"
7187 "IP prefix-list name\n")
7188{
7189 if (strncmp (argv[0], "m", 1) == 0)
7190 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7191 bgp_show_type_prefix_list);
7192
7193 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7194 bgp_show_type_prefix_list);
7195}
7196
7197#ifdef HAVE_IPV6
7198DEFUN (show_bgp_prefix_list,
7199 show_bgp_prefix_list_cmd,
7200 "show bgp prefix-list WORD",
7201 SHOW_STR
7202 BGP_STR
7203 "Display routes conforming to the prefix-list\n"
7204 "IPv6 prefix-list name\n")
7205{
7206 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7207 bgp_show_type_prefix_list);
7208}
7209
7210ALIAS (show_bgp_prefix_list,
7211 show_bgp_ipv6_prefix_list_cmd,
7212 "show bgp ipv6 prefix-list WORD",
7213 SHOW_STR
7214 BGP_STR
7215 "Address family\n"
7216 "Display routes conforming to the prefix-list\n"
7217 "IPv6 prefix-list name\n")
7218
7219/* old command */
7220DEFUN (show_ipv6_bgp_prefix_list,
7221 show_ipv6_bgp_prefix_list_cmd,
7222 "show ipv6 bgp prefix-list WORD",
7223 SHOW_STR
7224 IPV6_STR
7225 BGP_STR
7226 "Display routes matching the prefix-list\n"
7227 "IPv6 prefix-list name\n")
7228{
7229 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7230 bgp_show_type_prefix_list);
7231}
7232
7233/* old command */
7234DEFUN (show_ipv6_mbgp_prefix_list,
7235 show_ipv6_mbgp_prefix_list_cmd,
7236 "show ipv6 mbgp prefix-list WORD",
7237 SHOW_STR
7238 IPV6_STR
7239 MBGP_STR
7240 "Display routes matching the prefix-list\n"
7241 "IPv6 prefix-list name\n")
7242{
7243 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7244 bgp_show_type_prefix_list);
7245}
7246#endif /* HAVE_IPV6 */
7247
paul94f2b392005-06-28 12:44:16 +00007248static int
paulfd79ac92004-10-13 05:06:08 +00007249bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007250 safi_t safi, enum bgp_show_type type)
7251{
7252 struct as_list *as_list;
7253
7254 as_list = as_list_lookup (filter);
7255 if (as_list == NULL)
7256 {
7257 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7258 return CMD_WARNING;
7259 }
7260
ajs5a646652004-11-05 01:25:55 +00007261 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007262}
7263
7264DEFUN (show_ip_bgp_filter_list,
7265 show_ip_bgp_filter_list_cmd,
7266 "show ip bgp filter-list WORD",
7267 SHOW_STR
7268 IP_STR
7269 BGP_STR
7270 "Display routes conforming to the filter-list\n"
7271 "Regular expression access list name\n")
7272{
7273 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7274 bgp_show_type_filter_list);
7275}
7276
7277DEFUN (show_ip_bgp_flap_filter_list,
7278 show_ip_bgp_flap_filter_list_cmd,
7279 "show ip bgp flap-statistics filter-list WORD",
7280 SHOW_STR
7281 IP_STR
7282 BGP_STR
7283 "Display flap statistics of routes\n"
7284 "Display routes conforming to the filter-list\n"
7285 "Regular expression access list name\n")
7286{
7287 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7288 bgp_show_type_flap_filter_list);
7289}
7290
7291DEFUN (show_ip_bgp_ipv4_filter_list,
7292 show_ip_bgp_ipv4_filter_list_cmd,
7293 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7294 SHOW_STR
7295 IP_STR
7296 BGP_STR
7297 "Address family\n"
7298 "Address Family modifier\n"
7299 "Address Family modifier\n"
7300 "Display routes conforming to the filter-list\n"
7301 "Regular expression access list name\n")
7302{
7303 if (strncmp (argv[0], "m", 1) == 0)
7304 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7305 bgp_show_type_filter_list);
7306
7307 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7308 bgp_show_type_filter_list);
7309}
7310
7311#ifdef HAVE_IPV6
7312DEFUN (show_bgp_filter_list,
7313 show_bgp_filter_list_cmd,
7314 "show bgp filter-list WORD",
7315 SHOW_STR
7316 BGP_STR
7317 "Display routes conforming to the filter-list\n"
7318 "Regular expression access list name\n")
7319{
7320 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7321 bgp_show_type_filter_list);
7322}
7323
7324ALIAS (show_bgp_filter_list,
7325 show_bgp_ipv6_filter_list_cmd,
7326 "show bgp ipv6 filter-list WORD",
7327 SHOW_STR
7328 BGP_STR
7329 "Address family\n"
7330 "Display routes conforming to the filter-list\n"
7331 "Regular expression access list name\n")
7332
7333/* old command */
7334DEFUN (show_ipv6_bgp_filter_list,
7335 show_ipv6_bgp_filter_list_cmd,
7336 "show ipv6 bgp filter-list WORD",
7337 SHOW_STR
7338 IPV6_STR
7339 BGP_STR
7340 "Display routes conforming to the filter-list\n"
7341 "Regular expression access list name\n")
7342{
7343 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7344 bgp_show_type_filter_list);
7345}
7346
7347/* old command */
7348DEFUN (show_ipv6_mbgp_filter_list,
7349 show_ipv6_mbgp_filter_list_cmd,
7350 "show ipv6 mbgp filter-list WORD",
7351 SHOW_STR
7352 IPV6_STR
7353 MBGP_STR
7354 "Display routes conforming to the filter-list\n"
7355 "Regular expression access list name\n")
7356{
7357 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7358 bgp_show_type_filter_list);
7359}
7360#endif /* HAVE_IPV6 */
7361
paul94f2b392005-06-28 12:44:16 +00007362static int
paulfd79ac92004-10-13 05:06:08 +00007363bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007364 safi_t safi, enum bgp_show_type type)
7365{
7366 struct route_map *rmap;
7367
7368 rmap = route_map_lookup_by_name (rmap_str);
7369 if (! rmap)
7370 {
7371 vty_out (vty, "%% %s is not a valid route-map name%s",
7372 rmap_str, VTY_NEWLINE);
7373 return CMD_WARNING;
7374 }
7375
ajs5a646652004-11-05 01:25:55 +00007376 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007377}
7378
7379DEFUN (show_ip_bgp_route_map,
7380 show_ip_bgp_route_map_cmd,
7381 "show ip bgp route-map WORD",
7382 SHOW_STR
7383 IP_STR
7384 BGP_STR
7385 "Display routes matching the route-map\n"
7386 "A route-map to match on\n")
7387{
7388 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7389 bgp_show_type_route_map);
7390}
7391
7392DEFUN (show_ip_bgp_flap_route_map,
7393 show_ip_bgp_flap_route_map_cmd,
7394 "show ip bgp flap-statistics route-map WORD",
7395 SHOW_STR
7396 IP_STR
7397 BGP_STR
7398 "Display flap statistics of routes\n"
7399 "Display routes matching the route-map\n"
7400 "A route-map to match on\n")
7401{
7402 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7403 bgp_show_type_flap_route_map);
7404}
7405
7406DEFUN (show_ip_bgp_ipv4_route_map,
7407 show_ip_bgp_ipv4_route_map_cmd,
7408 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7409 SHOW_STR
7410 IP_STR
7411 BGP_STR
7412 "Address family\n"
7413 "Address Family modifier\n"
7414 "Address Family modifier\n"
7415 "Display routes matching the route-map\n"
7416 "A route-map to match on\n")
7417{
7418 if (strncmp (argv[0], "m", 1) == 0)
7419 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7420 bgp_show_type_route_map);
7421
7422 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7423 bgp_show_type_route_map);
7424}
7425
7426DEFUN (show_bgp_route_map,
7427 show_bgp_route_map_cmd,
7428 "show bgp route-map WORD",
7429 SHOW_STR
7430 BGP_STR
7431 "Display routes matching the route-map\n"
7432 "A route-map to match on\n")
7433{
7434 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7435 bgp_show_type_route_map);
7436}
7437
7438ALIAS (show_bgp_route_map,
7439 show_bgp_ipv6_route_map_cmd,
7440 "show bgp ipv6 route-map WORD",
7441 SHOW_STR
7442 BGP_STR
7443 "Address family\n"
7444 "Display routes matching the route-map\n"
7445 "A route-map to match on\n")
7446
7447DEFUN (show_ip_bgp_cidr_only,
7448 show_ip_bgp_cidr_only_cmd,
7449 "show ip bgp cidr-only",
7450 SHOW_STR
7451 IP_STR
7452 BGP_STR
7453 "Display only routes with non-natural netmasks\n")
7454{
7455 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007456 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007457}
7458
7459DEFUN (show_ip_bgp_flap_cidr_only,
7460 show_ip_bgp_flap_cidr_only_cmd,
7461 "show ip bgp flap-statistics cidr-only",
7462 SHOW_STR
7463 IP_STR
7464 BGP_STR
7465 "Display flap statistics of routes\n"
7466 "Display only routes with non-natural netmasks\n")
7467{
7468 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007469 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007470}
7471
7472DEFUN (show_ip_bgp_ipv4_cidr_only,
7473 show_ip_bgp_ipv4_cidr_only_cmd,
7474 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7475 SHOW_STR
7476 IP_STR
7477 BGP_STR
7478 "Address family\n"
7479 "Address Family modifier\n"
7480 "Address Family modifier\n"
7481 "Display only routes with non-natural netmasks\n")
7482{
7483 if (strncmp (argv[0], "m", 1) == 0)
7484 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007485 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007486
7487 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007488 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007489}
7490
7491DEFUN (show_ip_bgp_community_all,
7492 show_ip_bgp_community_all_cmd,
7493 "show ip bgp community",
7494 SHOW_STR
7495 IP_STR
7496 BGP_STR
7497 "Display routes matching the communities\n")
7498{
7499 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007500 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007501}
7502
7503DEFUN (show_ip_bgp_ipv4_community_all,
7504 show_ip_bgp_ipv4_community_all_cmd,
7505 "show ip bgp ipv4 (unicast|multicast) community",
7506 SHOW_STR
7507 IP_STR
7508 BGP_STR
7509 "Address family\n"
7510 "Address Family modifier\n"
7511 "Address Family modifier\n"
7512 "Display routes matching the communities\n")
7513{
7514 if (strncmp (argv[0], "m", 1) == 0)
7515 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007516 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007517
7518 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007519 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007520}
7521
7522#ifdef HAVE_IPV6
7523DEFUN (show_bgp_community_all,
7524 show_bgp_community_all_cmd,
7525 "show bgp community",
7526 SHOW_STR
7527 BGP_STR
7528 "Display routes matching the communities\n")
7529{
7530 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007531 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007532}
7533
7534ALIAS (show_bgp_community_all,
7535 show_bgp_ipv6_community_all_cmd,
7536 "show bgp ipv6 community",
7537 SHOW_STR
7538 BGP_STR
7539 "Address family\n"
7540 "Display routes matching the communities\n")
7541
7542/* old command */
7543DEFUN (show_ipv6_bgp_community_all,
7544 show_ipv6_bgp_community_all_cmd,
7545 "show ipv6 bgp community",
7546 SHOW_STR
7547 IPV6_STR
7548 BGP_STR
7549 "Display routes matching the communities\n")
7550{
7551 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007552 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007553}
7554
7555/* old command */
7556DEFUN (show_ipv6_mbgp_community_all,
7557 show_ipv6_mbgp_community_all_cmd,
7558 "show ipv6 mbgp community",
7559 SHOW_STR
7560 IPV6_STR
7561 MBGP_STR
7562 "Display routes matching the communities\n")
7563{
7564 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007565 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007566}
7567#endif /* HAVE_IPV6 */
7568
paul94f2b392005-06-28 12:44:16 +00007569static int
paulfd79ac92004-10-13 05:06:08 +00007570bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7571 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007572{
7573 struct community *com;
7574 struct buffer *b;
7575 int i;
7576 char *str;
7577 int first = 0;
7578
7579 b = buffer_new (1024);
7580 for (i = 0; i < argc; i++)
7581 {
7582 if (first)
7583 buffer_putc (b, ' ');
7584 else
7585 {
7586 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7587 continue;
7588 first = 1;
7589 }
7590
7591 buffer_putstr (b, argv[i]);
7592 }
7593 buffer_putc (b, '\0');
7594
7595 str = buffer_getstr (b);
7596 buffer_free (b);
7597
7598 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007599 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007600 if (! com)
7601 {
7602 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7603 return CMD_WARNING;
7604 }
7605
ajs5a646652004-11-05 01:25:55 +00007606 return bgp_show (vty, NULL, afi, safi,
7607 (exact ? bgp_show_type_community_exact :
7608 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007609}
7610
7611DEFUN (show_ip_bgp_community,
7612 show_ip_bgp_community_cmd,
7613 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7614 SHOW_STR
7615 IP_STR
7616 BGP_STR
7617 "Display routes matching the communities\n"
7618 "community number\n"
7619 "Do not send outside local AS (well-known community)\n"
7620 "Do not advertise to any peer (well-known community)\n"
7621 "Do not export to next AS (well-known community)\n")
7622{
7623 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7624}
7625
7626ALIAS (show_ip_bgp_community,
7627 show_ip_bgp_community2_cmd,
7628 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7629 SHOW_STR
7630 IP_STR
7631 BGP_STR
7632 "Display routes matching the communities\n"
7633 "community number\n"
7634 "Do not send outside local AS (well-known community)\n"
7635 "Do not advertise to any peer (well-known community)\n"
7636 "Do not export to next AS (well-known community)\n"
7637 "community number\n"
7638 "Do not send outside local AS (well-known community)\n"
7639 "Do not advertise to any peer (well-known community)\n"
7640 "Do not export to next AS (well-known community)\n")
7641
7642ALIAS (show_ip_bgp_community,
7643 show_ip_bgp_community3_cmd,
7644 "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)",
7645 SHOW_STR
7646 IP_STR
7647 BGP_STR
7648 "Display routes matching the communities\n"
7649 "community number\n"
7650 "Do not send outside local AS (well-known community)\n"
7651 "Do not advertise to any peer (well-known community)\n"
7652 "Do not export to next AS (well-known community)\n"
7653 "community number\n"
7654 "Do not send outside local AS (well-known community)\n"
7655 "Do not advertise to any peer (well-known community)\n"
7656 "Do not export to next AS (well-known community)\n"
7657 "community number\n"
7658 "Do not send outside local AS (well-known community)\n"
7659 "Do not advertise to any peer (well-known community)\n"
7660 "Do not export to next AS (well-known community)\n")
7661
7662ALIAS (show_ip_bgp_community,
7663 show_ip_bgp_community4_cmd,
7664 "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)",
7665 SHOW_STR
7666 IP_STR
7667 BGP_STR
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 "community number\n"
7678 "Do not send outside local AS (well-known community)\n"
7679 "Do not advertise to any peer (well-known community)\n"
7680 "Do not export to next AS (well-known community)\n"
7681 "community number\n"
7682 "Do not send outside local AS (well-known community)\n"
7683 "Do not advertise to any peer (well-known community)\n"
7684 "Do not export to next AS (well-known community)\n")
7685
7686DEFUN (show_ip_bgp_ipv4_community,
7687 show_ip_bgp_ipv4_community_cmd,
7688 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7689 SHOW_STR
7690 IP_STR
7691 BGP_STR
7692 "Address family\n"
7693 "Address Family modifier\n"
7694 "Address Family modifier\n"
7695 "Display routes matching the communities\n"
7696 "community number\n"
7697 "Do not send outside local AS (well-known community)\n"
7698 "Do not advertise to any peer (well-known community)\n"
7699 "Do not export to next AS (well-known community)\n")
7700{
7701 if (strncmp (argv[0], "m", 1) == 0)
7702 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7703
7704 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7705}
7706
7707ALIAS (show_ip_bgp_ipv4_community,
7708 show_ip_bgp_ipv4_community2_cmd,
7709 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7710 SHOW_STR
7711 IP_STR
7712 BGP_STR
7713 "Address family\n"
7714 "Address Family modifier\n"
7715 "Address Family modifier\n"
7716 "Display routes matching the communities\n"
7717 "community number\n"
7718 "Do not send outside local AS (well-known community)\n"
7719 "Do not advertise to any peer (well-known community)\n"
7720 "Do not export to next AS (well-known community)\n"
7721 "community number\n"
7722 "Do not send outside local AS (well-known community)\n"
7723 "Do not advertise to any peer (well-known community)\n"
7724 "Do not export to next AS (well-known community)\n")
7725
7726ALIAS (show_ip_bgp_ipv4_community,
7727 show_ip_bgp_ipv4_community3_cmd,
7728 "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)",
7729 SHOW_STR
7730 IP_STR
7731 BGP_STR
7732 "Address family\n"
7733 "Address Family modifier\n"
7734 "Address Family modifier\n"
7735 "Display routes matching the communities\n"
7736 "community number\n"
7737 "Do not send outside local AS (well-known community)\n"
7738 "Do not advertise to any peer (well-known community)\n"
7739 "Do not export to next AS (well-known community)\n"
7740 "community number\n"
7741 "Do not send outside local AS (well-known community)\n"
7742 "Do not advertise to any peer (well-known community)\n"
7743 "Do not export to next AS (well-known community)\n"
7744 "community number\n"
7745 "Do not send outside local AS (well-known community)\n"
7746 "Do not advertise to any peer (well-known community)\n"
7747 "Do not export to next AS (well-known community)\n")
7748
7749ALIAS (show_ip_bgp_ipv4_community,
7750 show_ip_bgp_ipv4_community4_cmd,
7751 "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)",
7752 SHOW_STR
7753 IP_STR
7754 BGP_STR
7755 "Address family\n"
7756 "Address Family modifier\n"
7757 "Address Family modifier\n"
7758 "Display routes matching the communities\n"
7759 "community number\n"
7760 "Do not send outside local AS (well-known community)\n"
7761 "Do not advertise to any peer (well-known community)\n"
7762 "Do not export to next AS (well-known community)\n"
7763 "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 "community number\n"
7768 "Do not send outside local AS (well-known community)\n"
7769 "Do not advertise to any peer (well-known community)\n"
7770 "Do not export to next AS (well-known community)\n"
7771 "community number\n"
7772 "Do not send outside local AS (well-known community)\n"
7773 "Do not advertise to any peer (well-known community)\n"
7774 "Do not export to next AS (well-known community)\n")
7775
7776DEFUN (show_ip_bgp_community_exact,
7777 show_ip_bgp_community_exact_cmd,
7778 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7779 SHOW_STR
7780 IP_STR
7781 BGP_STR
7782 "Display routes matching the communities\n"
7783 "community number\n"
7784 "Do not send outside local AS (well-known community)\n"
7785 "Do not advertise to any peer (well-known community)\n"
7786 "Do not export to next AS (well-known community)\n"
7787 "Exact match of the communities")
7788{
7789 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7790}
7791
7792ALIAS (show_ip_bgp_community_exact,
7793 show_ip_bgp_community2_exact_cmd,
7794 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7795 SHOW_STR
7796 IP_STR
7797 BGP_STR
7798 "Display routes matching the communities\n"
7799 "community number\n"
7800 "Do not send outside local AS (well-known community)\n"
7801 "Do not advertise to any peer (well-known community)\n"
7802 "Do not export to next AS (well-known community)\n"
7803 "community number\n"
7804 "Do not send outside local AS (well-known community)\n"
7805 "Do not advertise to any peer (well-known community)\n"
7806 "Do not export to next AS (well-known community)\n"
7807 "Exact match of the communities")
7808
7809ALIAS (show_ip_bgp_community_exact,
7810 show_ip_bgp_community3_exact_cmd,
7811 "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",
7812 SHOW_STR
7813 IP_STR
7814 BGP_STR
7815 "Display routes matching the communities\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n"
7824 "community number\n"
7825 "Do not send outside local AS (well-known community)\n"
7826 "Do not advertise to any peer (well-known community)\n"
7827 "Do not export to next AS (well-known community)\n"
7828 "Exact match of the communities")
7829
7830ALIAS (show_ip_bgp_community_exact,
7831 show_ip_bgp_community4_exact_cmd,
7832 "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",
7833 SHOW_STR
7834 IP_STR
7835 BGP_STR
7836 "Display routes matching the communities\n"
7837 "community number\n"
7838 "Do not send outside local AS (well-known community)\n"
7839 "Do not advertise to any peer (well-known community)\n"
7840 "Do not export to next AS (well-known community)\n"
7841 "community number\n"
7842 "Do not send outside local AS (well-known community)\n"
7843 "Do not advertise to any peer (well-known community)\n"
7844 "Do not export to next AS (well-known community)\n"
7845 "community number\n"
7846 "Do not send outside local AS (well-known community)\n"
7847 "Do not advertise to any peer (well-known community)\n"
7848 "Do not export to next AS (well-known community)\n"
7849 "community number\n"
7850 "Do not send outside local AS (well-known community)\n"
7851 "Do not advertise to any peer (well-known community)\n"
7852 "Do not export to next AS (well-known community)\n"
7853 "Exact match of the communities")
7854
7855DEFUN (show_ip_bgp_ipv4_community_exact,
7856 show_ip_bgp_ipv4_community_exact_cmd,
7857 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7858 SHOW_STR
7859 IP_STR
7860 BGP_STR
7861 "Address family\n"
7862 "Address Family modifier\n"
7863 "Address Family modifier\n"
7864 "Display routes matching the communities\n"
7865 "community number\n"
7866 "Do not send outside local AS (well-known community)\n"
7867 "Do not advertise to any peer (well-known community)\n"
7868 "Do not export to next AS (well-known community)\n"
7869 "Exact match of the communities")
7870{
7871 if (strncmp (argv[0], "m", 1) == 0)
7872 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7873
7874 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7875}
7876
7877ALIAS (show_ip_bgp_ipv4_community_exact,
7878 show_ip_bgp_ipv4_community2_exact_cmd,
7879 "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",
7880 SHOW_STR
7881 IP_STR
7882 BGP_STR
7883 "Address family\n"
7884 "Address Family modifier\n"
7885 "Address Family modifier\n"
7886 "Display routes matching the communities\n"
7887 "community number\n"
7888 "Do not send outside local AS (well-known community)\n"
7889 "Do not advertise to any peer (well-known community)\n"
7890 "Do not export to next AS (well-known community)\n"
7891 "community number\n"
7892 "Do not send outside local AS (well-known community)\n"
7893 "Do not advertise to any peer (well-known community)\n"
7894 "Do not export to next AS (well-known community)\n"
7895 "Exact match of the communities")
7896
7897ALIAS (show_ip_bgp_ipv4_community_exact,
7898 show_ip_bgp_ipv4_community3_exact_cmd,
7899 "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",
7900 SHOW_STR
7901 IP_STR
7902 BGP_STR
7903 "Address family\n"
7904 "Address Family modifier\n"
7905 "Address Family modifier\n"
7906 "Display routes matching the communities\n"
7907 "community number\n"
7908 "Do not send outside local AS (well-known community)\n"
7909 "Do not advertise to any peer (well-known community)\n"
7910 "Do not export to next AS (well-known community)\n"
7911 "community number\n"
7912 "Do not send outside local AS (well-known community)\n"
7913 "Do not advertise to any peer (well-known community)\n"
7914 "Do not export to next AS (well-known community)\n"
7915 "community number\n"
7916 "Do not send outside local AS (well-known community)\n"
7917 "Do not advertise to any peer (well-known community)\n"
7918 "Do not export to next AS (well-known community)\n"
7919 "Exact match of the communities")
7920
7921ALIAS (show_ip_bgp_ipv4_community_exact,
7922 show_ip_bgp_ipv4_community4_exact_cmd,
7923 "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",
7924 SHOW_STR
7925 IP_STR
7926 BGP_STR
7927 "Address family\n"
7928 "Address Family modifier\n"
7929 "Address Family modifier\n"
7930 "Display routes matching the communities\n"
7931 "community number\n"
7932 "Do not send outside local AS (well-known community)\n"
7933 "Do not advertise to any peer (well-known community)\n"
7934 "Do not export to next AS (well-known community)\n"
7935 "community number\n"
7936 "Do not send outside local AS (well-known community)\n"
7937 "Do not advertise to any peer (well-known community)\n"
7938 "Do not export to next AS (well-known community)\n"
7939 "community number\n"
7940 "Do not send outside local AS (well-known community)\n"
7941 "Do not advertise to any peer (well-known community)\n"
7942 "Do not export to next AS (well-known community)\n"
7943 "community number\n"
7944 "Do not send outside local AS (well-known community)\n"
7945 "Do not advertise to any peer (well-known community)\n"
7946 "Do not export to next AS (well-known community)\n"
7947 "Exact match of the communities")
7948
7949#ifdef HAVE_IPV6
7950DEFUN (show_bgp_community,
7951 show_bgp_community_cmd,
7952 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7953 SHOW_STR
7954 BGP_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{
7961 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7962}
7963
7964ALIAS (show_bgp_community,
7965 show_bgp_ipv6_community_cmd,
7966 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7967 SHOW_STR
7968 BGP_STR
7969 "Address family\n"
7970 "Display routes matching the communities\n"
7971 "community number\n"
7972 "Do not send outside local AS (well-known community)\n"
7973 "Do not advertise to any peer (well-known community)\n"
7974 "Do not export to next AS (well-known community)\n")
7975
7976ALIAS (show_bgp_community,
7977 show_bgp_community2_cmd,
7978 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7979 SHOW_STR
7980 BGP_STR
7981 "Display routes matching the communities\n"
7982 "community number\n"
7983 "Do not send outside local AS (well-known community)\n"
7984 "Do not advertise to any peer (well-known community)\n"
7985 "Do not export to next AS (well-known community)\n"
7986 "community number\n"
7987 "Do not send outside local AS (well-known community)\n"
7988 "Do not advertise to any peer (well-known community)\n"
7989 "Do not export to next AS (well-known community)\n")
7990
7991ALIAS (show_bgp_community,
7992 show_bgp_ipv6_community2_cmd,
7993 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7994 SHOW_STR
7995 BGP_STR
7996 "Address family\n"
7997 "Display routes matching the communities\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n")
8006
8007ALIAS (show_bgp_community,
8008 show_bgp_community3_cmd,
8009 "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)",
8010 SHOW_STR
8011 BGP_STR
8012 "Display routes matching the communities\n"
8013 "community number\n"
8014 "Do not send outside local AS (well-known community)\n"
8015 "Do not advertise to any peer (well-known community)\n"
8016 "Do not export to next AS (well-known community)\n"
8017 "community number\n"
8018 "Do not send outside local AS (well-known community)\n"
8019 "Do not advertise to any peer (well-known community)\n"
8020 "Do not export to next AS (well-known community)\n"
8021 "community number\n"
8022 "Do not send outside local AS (well-known community)\n"
8023 "Do not advertise to any peer (well-known community)\n"
8024 "Do not export to next AS (well-known community)\n")
8025
8026ALIAS (show_bgp_community,
8027 show_bgp_ipv6_community3_cmd,
8028 "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)",
8029 SHOW_STR
8030 BGP_STR
8031 "Address family\n"
8032 "Display routes matching the communities\n"
8033 "community number\n"
8034 "Do not send outside local AS (well-known community)\n"
8035 "Do not advertise to any peer (well-known community)\n"
8036 "Do not export to next AS (well-known community)\n"
8037 "community number\n"
8038 "Do not send outside local AS (well-known community)\n"
8039 "Do not advertise to any peer (well-known community)\n"
8040 "Do not export to next AS (well-known community)\n"
8041 "community number\n"
8042 "Do not send outside local AS (well-known community)\n"
8043 "Do not advertise to any peer (well-known community)\n"
8044 "Do not export to next AS (well-known community)\n")
8045
8046ALIAS (show_bgp_community,
8047 show_bgp_community4_cmd,
8048 "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)",
8049 SHOW_STR
8050 BGP_STR
8051 "Display routes matching the communities\n"
8052 "community number\n"
8053 "Do not send outside local AS (well-known community)\n"
8054 "Do not advertise to any peer (well-known community)\n"
8055 "Do not export to next AS (well-known community)\n"
8056 "community number\n"
8057 "Do not send outside local AS (well-known community)\n"
8058 "Do not advertise to any peer (well-known community)\n"
8059 "Do not export to next AS (well-known community)\n"
8060 "community number\n"
8061 "Do not send outside local AS (well-known community)\n"
8062 "Do not advertise to any peer (well-known community)\n"
8063 "Do not export to next AS (well-known community)\n"
8064 "community number\n"
8065 "Do not send outside local AS (well-known community)\n"
8066 "Do not advertise to any peer (well-known community)\n"
8067 "Do not export to next AS (well-known community)\n")
8068
8069ALIAS (show_bgp_community,
8070 show_bgp_ipv6_community4_cmd,
8071 "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)",
8072 SHOW_STR
8073 BGP_STR
8074 "Address family\n"
8075 "Display routes matching the communities\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n"
8080 "community number\n"
8081 "Do not send outside local AS (well-known community)\n"
8082 "Do not advertise to any peer (well-known community)\n"
8083 "Do not export to next AS (well-known community)\n"
8084 "community number\n"
8085 "Do not send outside local AS (well-known community)\n"
8086 "Do not advertise to any peer (well-known community)\n"
8087 "Do not export to next AS (well-known community)\n"
8088 "community number\n"
8089 "Do not send outside local AS (well-known community)\n"
8090 "Do not advertise to any peer (well-known community)\n"
8091 "Do not export to next AS (well-known community)\n")
8092
8093/* old command */
8094DEFUN (show_ipv6_bgp_community,
8095 show_ipv6_bgp_community_cmd,
8096 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8097 SHOW_STR
8098 IPV6_STR
8099 BGP_STR
8100 "Display routes matching the communities\n"
8101 "community number\n"
8102 "Do not send outside local AS (well-known community)\n"
8103 "Do not advertise to any peer (well-known community)\n"
8104 "Do not export to next AS (well-known community)\n")
8105{
8106 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8107}
8108
8109/* old command */
8110ALIAS (show_ipv6_bgp_community,
8111 show_ipv6_bgp_community2_cmd,
8112 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8113 SHOW_STR
8114 IPV6_STR
8115 BGP_STR
8116 "Display routes matching the communities\n"
8117 "community number\n"
8118 "Do not send outside local AS (well-known community)\n"
8119 "Do not advertise to any peer (well-known community)\n"
8120 "Do not export to next AS (well-known community)\n"
8121 "community number\n"
8122 "Do not send outside local AS (well-known community)\n"
8123 "Do not advertise to any peer (well-known community)\n"
8124 "Do not export to next AS (well-known community)\n")
8125
8126/* old command */
8127ALIAS (show_ipv6_bgp_community,
8128 show_ipv6_bgp_community3_cmd,
8129 "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)",
8130 SHOW_STR
8131 IPV6_STR
8132 BGP_STR
8133 "Display routes matching the communities\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\n"
8138 "community number\n"
8139 "Do not send outside local AS (well-known community)\n"
8140 "Do not advertise to any peer (well-known community)\n"
8141 "Do not export to next AS (well-known community)\n"
8142 "community number\n"
8143 "Do not send outside local AS (well-known community)\n"
8144 "Do not advertise to any peer (well-known community)\n"
8145 "Do not export to next AS (well-known community)\n")
8146
8147/* old command */
8148ALIAS (show_ipv6_bgp_community,
8149 show_ipv6_bgp_community4_cmd,
8150 "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)",
8151 SHOW_STR
8152 IPV6_STR
8153 BGP_STR
8154 "Display routes matching the communities\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n"
8163 "community number\n"
8164 "Do not send outside local AS (well-known community)\n"
8165 "Do not advertise to any peer (well-known community)\n"
8166 "Do not export to next AS (well-known community)\n"
8167 "community number\n"
8168 "Do not send outside local AS (well-known community)\n"
8169 "Do not advertise to any peer (well-known community)\n"
8170 "Do not export to next AS (well-known community)\n")
8171
8172DEFUN (show_bgp_community_exact,
8173 show_bgp_community_exact_cmd,
8174 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8175 SHOW_STR
8176 BGP_STR
8177 "Display routes matching the communities\n"
8178 "community number\n"
8179 "Do not send outside local AS (well-known community)\n"
8180 "Do not advertise to any peer (well-known community)\n"
8181 "Do not export to next AS (well-known community)\n"
8182 "Exact match of the communities")
8183{
8184 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8185}
8186
8187ALIAS (show_bgp_community_exact,
8188 show_bgp_ipv6_community_exact_cmd,
8189 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8190 SHOW_STR
8191 BGP_STR
8192 "Address family\n"
8193 "Display routes matching the communities\n"
8194 "community number\n"
8195 "Do not send outside local AS (well-known community)\n"
8196 "Do not advertise to any peer (well-known community)\n"
8197 "Do not export to next AS (well-known community)\n"
8198 "Exact match of the communities")
8199
8200ALIAS (show_bgp_community_exact,
8201 show_bgp_community2_exact_cmd,
8202 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8203 SHOW_STR
8204 BGP_STR
8205 "Display routes matching the communities\n"
8206 "community number\n"
8207 "Do not send outside local AS (well-known community)\n"
8208 "Do not advertise to any peer (well-known community)\n"
8209 "Do not export to next AS (well-known community)\n"
8210 "community number\n"
8211 "Do not send outside local AS (well-known community)\n"
8212 "Do not advertise to any peer (well-known community)\n"
8213 "Do not export to next AS (well-known community)\n"
8214 "Exact match of the communities")
8215
8216ALIAS (show_bgp_community_exact,
8217 show_bgp_ipv6_community2_exact_cmd,
8218 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8219 SHOW_STR
8220 BGP_STR
8221 "Address family\n"
8222 "Display routes matching the communities\n"
8223 "community number\n"
8224 "Do not send outside local AS (well-known community)\n"
8225 "Do not advertise to any peer (well-known community)\n"
8226 "Do not export to next AS (well-known community)\n"
8227 "community number\n"
8228 "Do not send outside local AS (well-known community)\n"
8229 "Do not advertise to any peer (well-known community)\n"
8230 "Do not export to next AS (well-known community)\n"
8231 "Exact match of the communities")
8232
8233ALIAS (show_bgp_community_exact,
8234 show_bgp_community3_exact_cmd,
8235 "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",
8236 SHOW_STR
8237 BGP_STR
8238 "Display routes matching the communities\n"
8239 "community number\n"
8240 "Do not send outside local AS (well-known community)\n"
8241 "Do not advertise to any peer (well-known community)\n"
8242 "Do not export to next AS (well-known community)\n"
8243 "community number\n"
8244 "Do not send outside local AS (well-known community)\n"
8245 "Do not advertise to any peer (well-known community)\n"
8246 "Do not export to next AS (well-known community)\n"
8247 "community number\n"
8248 "Do not send outside local AS (well-known community)\n"
8249 "Do not advertise to any peer (well-known community)\n"
8250 "Do not export to next AS (well-known community)\n"
8251 "Exact match of the communities")
8252
8253ALIAS (show_bgp_community_exact,
8254 show_bgp_ipv6_community3_exact_cmd,
8255 "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",
8256 SHOW_STR
8257 BGP_STR
8258 "Address family\n"
8259 "Display routes matching the communities\n"
8260 "community number\n"
8261 "Do not send outside local AS (well-known community)\n"
8262 "Do not advertise to any peer (well-known community)\n"
8263 "Do not export to next AS (well-known community)\n"
8264 "community number\n"
8265 "Do not send outside local AS (well-known community)\n"
8266 "Do not advertise to any peer (well-known community)\n"
8267 "Do not export to next AS (well-known community)\n"
8268 "community number\n"
8269 "Do not send outside local AS (well-known community)\n"
8270 "Do not advertise to any peer (well-known community)\n"
8271 "Do not export to next AS (well-known community)\n"
8272 "Exact match of the communities")
8273
8274ALIAS (show_bgp_community_exact,
8275 show_bgp_community4_exact_cmd,
8276 "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",
8277 SHOW_STR
8278 BGP_STR
8279 "Display routes matching the communities\n"
8280 "community number\n"
8281 "Do not send outside local AS (well-known community)\n"
8282 "Do not advertise to any peer (well-known community)\n"
8283 "Do not export to next AS (well-known community)\n"
8284 "community number\n"
8285 "Do not send outside local AS (well-known community)\n"
8286 "Do not advertise to any peer (well-known community)\n"
8287 "Do not export to next AS (well-known community)\n"
8288 "community number\n"
8289 "Do not send outside local AS (well-known community)\n"
8290 "Do not advertise to any peer (well-known community)\n"
8291 "Do not export to next AS (well-known community)\n"
8292 "community number\n"
8293 "Do not send outside local AS (well-known community)\n"
8294 "Do not advertise to any peer (well-known community)\n"
8295 "Do not export to next AS (well-known community)\n"
8296 "Exact match of the communities")
8297
8298ALIAS (show_bgp_community_exact,
8299 show_bgp_ipv6_community4_exact_cmd,
8300 "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",
8301 SHOW_STR
8302 BGP_STR
8303 "Address family\n"
8304 "Display routes matching the communities\n"
8305 "community number\n"
8306 "Do not send outside local AS (well-known community)\n"
8307 "Do not advertise to any peer (well-known community)\n"
8308 "Do not export to next AS (well-known community)\n"
8309 "community number\n"
8310 "Do not send outside local AS (well-known community)\n"
8311 "Do not advertise to any peer (well-known community)\n"
8312 "Do not export to next AS (well-known community)\n"
8313 "community number\n"
8314 "Do not send outside local AS (well-known community)\n"
8315 "Do not advertise to any peer (well-known community)\n"
8316 "Do not export to next AS (well-known community)\n"
8317 "community number\n"
8318 "Do not send outside local AS (well-known community)\n"
8319 "Do not advertise to any peer (well-known community)\n"
8320 "Do not export to next AS (well-known community)\n"
8321 "Exact match of the communities")
8322
8323/* old command */
8324DEFUN (show_ipv6_bgp_community_exact,
8325 show_ipv6_bgp_community_exact_cmd,
8326 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8327 SHOW_STR
8328 IPV6_STR
8329 BGP_STR
8330 "Display routes matching the communities\n"
8331 "community number\n"
8332 "Do not send outside local AS (well-known community)\n"
8333 "Do not advertise to any peer (well-known community)\n"
8334 "Do not export to next AS (well-known community)\n"
8335 "Exact match of the communities")
8336{
8337 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8338}
8339
8340/* old command */
8341ALIAS (show_ipv6_bgp_community_exact,
8342 show_ipv6_bgp_community2_exact_cmd,
8343 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8344 SHOW_STR
8345 IPV6_STR
8346 BGP_STR
8347 "Display routes matching the communities\n"
8348 "community number\n"
8349 "Do not send outside local AS (well-known community)\n"
8350 "Do not advertise to any peer (well-known community)\n"
8351 "Do not export to next AS (well-known community)\n"
8352 "community number\n"
8353 "Do not send outside local AS (well-known community)\n"
8354 "Do not advertise to any peer (well-known community)\n"
8355 "Do not export to next AS (well-known community)\n"
8356 "Exact match of the communities")
8357
8358/* old command */
8359ALIAS (show_ipv6_bgp_community_exact,
8360 show_ipv6_bgp_community3_exact_cmd,
8361 "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",
8362 SHOW_STR
8363 IPV6_STR
8364 BGP_STR
8365 "Display routes matching the communities\n"
8366 "community number\n"
8367 "Do not send outside local AS (well-known community)\n"
8368 "Do not advertise to any peer (well-known community)\n"
8369 "Do not export to next AS (well-known community)\n"
8370 "community number\n"
8371 "Do not send outside local AS (well-known community)\n"
8372 "Do not advertise to any peer (well-known community)\n"
8373 "Do not export to next AS (well-known community)\n"
8374 "community number\n"
8375 "Do not send outside local AS (well-known community)\n"
8376 "Do not advertise to any peer (well-known community)\n"
8377 "Do not export to next AS (well-known community)\n"
8378 "Exact match of the communities")
8379
8380/* old command */
8381ALIAS (show_ipv6_bgp_community_exact,
8382 show_ipv6_bgp_community4_exact_cmd,
8383 "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",
8384 SHOW_STR
8385 IPV6_STR
8386 BGP_STR
8387 "Display routes matching the communities\n"
8388 "community number\n"
8389 "Do not send outside local AS (well-known community)\n"
8390 "Do not advertise to any peer (well-known community)\n"
8391 "Do not export to next AS (well-known community)\n"
8392 "community number\n"
8393 "Do not send outside local AS (well-known community)\n"
8394 "Do not advertise to any peer (well-known community)\n"
8395 "Do not export to next AS (well-known community)\n"
8396 "community number\n"
8397 "Do not send outside local AS (well-known community)\n"
8398 "Do not advertise to any peer (well-known community)\n"
8399 "Do not export to next AS (well-known community)\n"
8400 "community number\n"
8401 "Do not send outside local AS (well-known community)\n"
8402 "Do not advertise to any peer (well-known community)\n"
8403 "Do not export to next AS (well-known community)\n"
8404 "Exact match of the communities")
8405
8406/* old command */
8407DEFUN (show_ipv6_mbgp_community,
8408 show_ipv6_mbgp_community_cmd,
8409 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8410 SHOW_STR
8411 IPV6_STR
8412 MBGP_STR
8413 "Display routes matching the communities\n"
8414 "community number\n"
8415 "Do not send outside local AS (well-known community)\n"
8416 "Do not advertise to any peer (well-known community)\n"
8417 "Do not export to next AS (well-known community)\n")
8418{
8419 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8420}
8421
8422/* old command */
8423ALIAS (show_ipv6_mbgp_community,
8424 show_ipv6_mbgp_community2_cmd,
8425 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8426 SHOW_STR
8427 IPV6_STR
8428 MBGP_STR
8429 "Display routes matching the communities\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n"
8434 "community number\n"
8435 "Do not send outside local AS (well-known community)\n"
8436 "Do not advertise to any peer (well-known community)\n"
8437 "Do not export to next AS (well-known community)\n")
8438
8439/* old command */
8440ALIAS (show_ipv6_mbgp_community,
8441 show_ipv6_mbgp_community3_cmd,
8442 "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)",
8443 SHOW_STR
8444 IPV6_STR
8445 MBGP_STR
8446 "Display routes matching the communities\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n"
8455 "community number\n"
8456 "Do not send outside local AS (well-known community)\n"
8457 "Do not advertise to any peer (well-known community)\n"
8458 "Do not export to next AS (well-known community)\n")
8459
8460/* old command */
8461ALIAS (show_ipv6_mbgp_community,
8462 show_ipv6_mbgp_community4_cmd,
8463 "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)",
8464 SHOW_STR
8465 IPV6_STR
8466 MBGP_STR
8467 "Display routes matching the communities\n"
8468 "community number\n"
8469 "Do not send outside local AS (well-known community)\n"
8470 "Do not advertise to any peer (well-known community)\n"
8471 "Do not export to next AS (well-known community)\n"
8472 "community number\n"
8473 "Do not send outside local AS (well-known community)\n"
8474 "Do not advertise to any peer (well-known community)\n"
8475 "Do not export to next AS (well-known community)\n"
8476 "community number\n"
8477 "Do not send outside local AS (well-known community)\n"
8478 "Do not advertise to any peer (well-known community)\n"
8479 "Do not export to next AS (well-known community)\n"
8480 "community number\n"
8481 "Do not send outside local AS (well-known community)\n"
8482 "Do not advertise to any peer (well-known community)\n"
8483 "Do not export to next AS (well-known community)\n")
8484
8485/* old command */
8486DEFUN (show_ipv6_mbgp_community_exact,
8487 show_ipv6_mbgp_community_exact_cmd,
8488 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8489 SHOW_STR
8490 IPV6_STR
8491 MBGP_STR
8492 "Display routes matching the communities\n"
8493 "community number\n"
8494 "Do not send outside local AS (well-known community)\n"
8495 "Do not advertise to any peer (well-known community)\n"
8496 "Do not export to next AS (well-known community)\n"
8497 "Exact match of the communities")
8498{
8499 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8500}
8501
8502/* old command */
8503ALIAS (show_ipv6_mbgp_community_exact,
8504 show_ipv6_mbgp_community2_exact_cmd,
8505 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8506 SHOW_STR
8507 IPV6_STR
8508 MBGP_STR
8509 "Display routes matching the communities\n"
8510 "community number\n"
8511 "Do not send outside local AS (well-known community)\n"
8512 "Do not advertise to any peer (well-known community)\n"
8513 "Do not export to next AS (well-known community)\n"
8514 "community number\n"
8515 "Do not send outside local AS (well-known community)\n"
8516 "Do not advertise to any peer (well-known community)\n"
8517 "Do not export to next AS (well-known community)\n"
8518 "Exact match of the communities")
8519
8520/* old command */
8521ALIAS (show_ipv6_mbgp_community_exact,
8522 show_ipv6_mbgp_community3_exact_cmd,
8523 "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",
8524 SHOW_STR
8525 IPV6_STR
8526 MBGP_STR
8527 "Display routes matching the communities\n"
8528 "community number\n"
8529 "Do not send outside local AS (well-known community)\n"
8530 "Do not advertise to any peer (well-known community)\n"
8531 "Do not export to next AS (well-known community)\n"
8532 "community number\n"
8533 "Do not send outside local AS (well-known community)\n"
8534 "Do not advertise to any peer (well-known community)\n"
8535 "Do not export to next AS (well-known community)\n"
8536 "community number\n"
8537 "Do not send outside local AS (well-known community)\n"
8538 "Do not advertise to any peer (well-known community)\n"
8539 "Do not export to next AS (well-known community)\n"
8540 "Exact match of the communities")
8541
8542/* old command */
8543ALIAS (show_ipv6_mbgp_community_exact,
8544 show_ipv6_mbgp_community4_exact_cmd,
8545 "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",
8546 SHOW_STR
8547 IPV6_STR
8548 MBGP_STR
8549 "Display routes matching the communities\n"
8550 "community number\n"
8551 "Do not send outside local AS (well-known community)\n"
8552 "Do not advertise to any peer (well-known community)\n"
8553 "Do not export to next AS (well-known community)\n"
8554 "community number\n"
8555 "Do not send outside local AS (well-known community)\n"
8556 "Do not advertise to any peer (well-known community)\n"
8557 "Do not export to next AS (well-known community)\n"
8558 "community number\n"
8559 "Do not send outside local AS (well-known community)\n"
8560 "Do not advertise to any peer (well-known community)\n"
8561 "Do not export to next AS (well-known community)\n"
8562 "community number\n"
8563 "Do not send outside local AS (well-known community)\n"
8564 "Do not advertise to any peer (well-known community)\n"
8565 "Do not export to next AS (well-known community)\n"
8566 "Exact match of the communities")
8567#endif /* HAVE_IPV6 */
8568
paul94f2b392005-06-28 12:44:16 +00008569static int
paulfd79ac92004-10-13 05:06:08 +00008570bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008571 u_int16_t afi, u_char safi)
8572{
8573 struct community_list *list;
8574
hassofee6e4e2005-02-02 16:29:31 +00008575 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008576 if (list == NULL)
8577 {
8578 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8579 VTY_NEWLINE);
8580 return CMD_WARNING;
8581 }
8582
ajs5a646652004-11-05 01:25:55 +00008583 return bgp_show (vty, NULL, afi, safi,
8584 (exact ? bgp_show_type_community_list_exact :
8585 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008586}
8587
8588DEFUN (show_ip_bgp_community_list,
8589 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008590 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008591 SHOW_STR
8592 IP_STR
8593 BGP_STR
8594 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008595 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008596 "community-list name\n")
8597{
8598 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8599}
8600
8601DEFUN (show_ip_bgp_ipv4_community_list,
8602 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008603 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008604 SHOW_STR
8605 IP_STR
8606 BGP_STR
8607 "Address family\n"
8608 "Address Family modifier\n"
8609 "Address Family modifier\n"
8610 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008611 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008612 "community-list name\n")
8613{
8614 if (strncmp (argv[0], "m", 1) == 0)
8615 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8616
8617 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8618}
8619
8620DEFUN (show_ip_bgp_community_list_exact,
8621 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008622 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008623 SHOW_STR
8624 IP_STR
8625 BGP_STR
8626 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008627 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008628 "community-list name\n"
8629 "Exact match of the communities\n")
8630{
8631 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8632}
8633
8634DEFUN (show_ip_bgp_ipv4_community_list_exact,
8635 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008636 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008637 SHOW_STR
8638 IP_STR
8639 BGP_STR
8640 "Address family\n"
8641 "Address Family modifier\n"
8642 "Address Family modifier\n"
8643 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008644 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008645 "community-list name\n"
8646 "Exact match of the communities\n")
8647{
8648 if (strncmp (argv[0], "m", 1) == 0)
8649 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8650
8651 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8652}
8653
8654#ifdef HAVE_IPV6
8655DEFUN (show_bgp_community_list,
8656 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008657 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008658 SHOW_STR
8659 BGP_STR
8660 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008661 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008662 "community-list name\n")
8663{
8664 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8665}
8666
8667ALIAS (show_bgp_community_list,
8668 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008669 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008670 SHOW_STR
8671 BGP_STR
8672 "Address family\n"
8673 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008674 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008675 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008676
8677/* old command */
8678DEFUN (show_ipv6_bgp_community_list,
8679 show_ipv6_bgp_community_list_cmd,
8680 "show ipv6 bgp community-list WORD",
8681 SHOW_STR
8682 IPV6_STR
8683 BGP_STR
8684 "Display routes matching the community-list\n"
8685 "community-list name\n")
8686{
8687 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8688}
8689
8690/* old command */
8691DEFUN (show_ipv6_mbgp_community_list,
8692 show_ipv6_mbgp_community_list_cmd,
8693 "show ipv6 mbgp community-list WORD",
8694 SHOW_STR
8695 IPV6_STR
8696 MBGP_STR
8697 "Display routes matching the community-list\n"
8698 "community-list name\n")
8699{
8700 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8701}
8702
8703DEFUN (show_bgp_community_list_exact,
8704 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008705 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008706 SHOW_STR
8707 BGP_STR
8708 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008709 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008710 "community-list name\n"
8711 "Exact match of the communities\n")
8712{
8713 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8714}
8715
8716ALIAS (show_bgp_community_list_exact,
8717 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008718 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008719 SHOW_STR
8720 BGP_STR
8721 "Address family\n"
8722 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008723 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008724 "community-list name\n"
8725 "Exact match of the communities\n")
8726
8727/* old command */
8728DEFUN (show_ipv6_bgp_community_list_exact,
8729 show_ipv6_bgp_community_list_exact_cmd,
8730 "show ipv6 bgp community-list WORD exact-match",
8731 SHOW_STR
8732 IPV6_STR
8733 BGP_STR
8734 "Display routes matching the community-list\n"
8735 "community-list name\n"
8736 "Exact match of the communities\n")
8737{
8738 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8739}
8740
8741/* old command */
8742DEFUN (show_ipv6_mbgp_community_list_exact,
8743 show_ipv6_mbgp_community_list_exact_cmd,
8744 "show ipv6 mbgp community-list WORD exact-match",
8745 SHOW_STR
8746 IPV6_STR
8747 MBGP_STR
8748 "Display routes matching the community-list\n"
8749 "community-list name\n"
8750 "Exact match of the communities\n")
8751{
8752 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8753}
8754#endif /* HAVE_IPV6 */
8755
paul94f2b392005-06-28 12:44:16 +00008756static int
paulfd79ac92004-10-13 05:06:08 +00008757bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008758 safi_t safi, enum bgp_show_type type)
8759{
8760 int ret;
8761 struct prefix *p;
8762
8763 p = prefix_new();
8764
8765 ret = str2prefix (prefix, p);
8766 if (! ret)
8767 {
8768 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8769 return CMD_WARNING;
8770 }
8771
ajs5a646652004-11-05 01:25:55 +00008772 ret = bgp_show (vty, NULL, afi, safi, type, p);
8773 prefix_free(p);
8774 return ret;
paul718e3742002-12-13 20:15:29 +00008775}
8776
8777DEFUN (show_ip_bgp_prefix_longer,
8778 show_ip_bgp_prefix_longer_cmd,
8779 "show ip bgp A.B.C.D/M longer-prefixes",
8780 SHOW_STR
8781 IP_STR
8782 BGP_STR
8783 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8784 "Display route and more specific routes\n")
8785{
8786 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8787 bgp_show_type_prefix_longer);
8788}
8789
8790DEFUN (show_ip_bgp_flap_prefix_longer,
8791 show_ip_bgp_flap_prefix_longer_cmd,
8792 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8793 SHOW_STR
8794 IP_STR
8795 BGP_STR
8796 "Display flap statistics of routes\n"
8797 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8798 "Display route and more specific routes\n")
8799{
8800 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8801 bgp_show_type_flap_prefix_longer);
8802}
8803
8804DEFUN (show_ip_bgp_ipv4_prefix_longer,
8805 show_ip_bgp_ipv4_prefix_longer_cmd,
8806 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8807 SHOW_STR
8808 IP_STR
8809 BGP_STR
8810 "Address family\n"
8811 "Address Family modifier\n"
8812 "Address Family modifier\n"
8813 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8814 "Display route and more specific routes\n")
8815{
8816 if (strncmp (argv[0], "m", 1) == 0)
8817 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8818 bgp_show_type_prefix_longer);
8819
8820 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8821 bgp_show_type_prefix_longer);
8822}
8823
8824DEFUN (show_ip_bgp_flap_address,
8825 show_ip_bgp_flap_address_cmd,
8826 "show ip bgp flap-statistics A.B.C.D",
8827 SHOW_STR
8828 IP_STR
8829 BGP_STR
8830 "Display flap statistics of routes\n"
8831 "Network in the BGP routing table to display\n")
8832{
8833 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8834 bgp_show_type_flap_address);
8835}
8836
8837DEFUN (show_ip_bgp_flap_prefix,
8838 show_ip_bgp_flap_prefix_cmd,
8839 "show ip bgp flap-statistics A.B.C.D/M",
8840 SHOW_STR
8841 IP_STR
8842 BGP_STR
8843 "Display flap statistics of routes\n"
8844 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8845{
8846 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8847 bgp_show_type_flap_prefix);
8848}
8849#ifdef HAVE_IPV6
8850DEFUN (show_bgp_prefix_longer,
8851 show_bgp_prefix_longer_cmd,
8852 "show bgp X:X::X:X/M longer-prefixes",
8853 SHOW_STR
8854 BGP_STR
8855 "IPv6 prefix <network>/<length>\n"
8856 "Display route and more specific routes\n")
8857{
8858 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8859 bgp_show_type_prefix_longer);
8860}
8861
8862ALIAS (show_bgp_prefix_longer,
8863 show_bgp_ipv6_prefix_longer_cmd,
8864 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8865 SHOW_STR
8866 BGP_STR
8867 "Address family\n"
8868 "IPv6 prefix <network>/<length>\n"
8869 "Display route and more specific routes\n")
8870
8871/* old command */
8872DEFUN (show_ipv6_bgp_prefix_longer,
8873 show_ipv6_bgp_prefix_longer_cmd,
8874 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8875 SHOW_STR
8876 IPV6_STR
8877 BGP_STR
8878 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8879 "Display route and more specific routes\n")
8880{
8881 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8882 bgp_show_type_prefix_longer);
8883}
8884
8885/* old command */
8886DEFUN (show_ipv6_mbgp_prefix_longer,
8887 show_ipv6_mbgp_prefix_longer_cmd,
8888 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8889 SHOW_STR
8890 IPV6_STR
8891 MBGP_STR
8892 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8893 "Display route and more specific routes\n")
8894{
8895 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8896 bgp_show_type_prefix_longer);
8897}
8898#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008899
paul94f2b392005-06-28 12:44:16 +00008900static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008901peer_lookup_in_view (struct vty *vty, const char *view_name,
8902 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008903{
8904 int ret;
8905 struct bgp *bgp;
8906 struct peer *peer;
8907 union sockunion su;
8908
8909 /* BGP structure lookup. */
8910 if (view_name)
8911 {
8912 bgp = bgp_lookup_by_name (view_name);
8913 if (! bgp)
8914 {
8915 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8916 return NULL;
8917 }
8918 }
paul5228ad22004-06-04 17:58:18 +00008919 else
paulbb46e942003-10-24 19:02:03 +00008920 {
8921 bgp = bgp_get_default ();
8922 if (! bgp)
8923 {
8924 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8925 return NULL;
8926 }
8927 }
8928
8929 /* Get peer sockunion. */
8930 ret = str2sockunion (ip_str, &su);
8931 if (ret < 0)
8932 {
8933 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8934 return NULL;
8935 }
8936
8937 /* Peer structure lookup. */
8938 peer = peer_lookup (bgp, &su);
8939 if (! peer)
8940 {
8941 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8942 return NULL;
8943 }
8944
8945 return peer;
8946}
Paul Jakma2815e612006-09-14 02:56:07 +00008947
8948enum bgp_stats
8949{
8950 BGP_STATS_MAXBITLEN = 0,
8951 BGP_STATS_RIB,
8952 BGP_STATS_PREFIXES,
8953 BGP_STATS_TOTPLEN,
8954 BGP_STATS_UNAGGREGATEABLE,
8955 BGP_STATS_MAX_AGGREGATEABLE,
8956 BGP_STATS_AGGREGATES,
8957 BGP_STATS_SPACE,
8958 BGP_STATS_ASPATH_COUNT,
8959 BGP_STATS_ASPATH_MAXHOPS,
8960 BGP_STATS_ASPATH_TOTHOPS,
8961 BGP_STATS_ASPATH_MAXSIZE,
8962 BGP_STATS_ASPATH_TOTSIZE,
8963 BGP_STATS_ASN_HIGHEST,
8964 BGP_STATS_MAX,
8965};
paulbb46e942003-10-24 19:02:03 +00008966
Paul Jakma2815e612006-09-14 02:56:07 +00008967static const char *table_stats_strs[] =
8968{
8969 [BGP_STATS_PREFIXES] = "Total Prefixes",
8970 [BGP_STATS_TOTPLEN] = "Average prefix length",
8971 [BGP_STATS_RIB] = "Total Advertisements",
8972 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8973 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8974 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8975 [BGP_STATS_SPACE] = "Address space advertised",
8976 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8977 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8978 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8979 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8980 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8981 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8982 [BGP_STATS_MAX] = NULL,
8983};
8984
8985struct bgp_table_stats
8986{
8987 struct bgp_table *table;
8988 unsigned long long counts[BGP_STATS_MAX];
8989};
8990
8991#if 0
8992#define TALLY_SIGFIG 100000
8993static unsigned long
8994ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8995{
8996 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8997 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8998 unsigned long ret = newtot / count;
8999
9000 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9001 return ret + 1;
9002 else
9003 return ret;
9004}
9005#endif
9006
9007static int
9008bgp_table_stats_walker (struct thread *t)
9009{
9010 struct bgp_node *rn;
9011 struct bgp_node *top;
9012 struct bgp_table_stats *ts = THREAD_ARG (t);
9013 unsigned int space = 0;
9014
Paul Jakma53d9f672006-10-15 23:41:16 +00009015 if (!(top = bgp_table_top (ts->table)))
9016 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009017
9018 switch (top->p.family)
9019 {
9020 case AF_INET:
9021 space = IPV4_MAX_BITLEN;
9022 break;
9023 case AF_INET6:
9024 space = IPV6_MAX_BITLEN;
9025 break;
9026 }
9027
9028 ts->counts[BGP_STATS_MAXBITLEN] = space;
9029
9030 for (rn = top; rn; rn = bgp_route_next (rn))
9031 {
9032 struct bgp_info *ri;
9033 struct bgp_node *prn = rn->parent;
9034 unsigned int rinum = 0;
9035
9036 if (rn == top)
9037 continue;
9038
9039 if (!rn->info)
9040 continue;
9041
9042 ts->counts[BGP_STATS_PREFIXES]++;
9043 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9044
9045#if 0
9046 ts->counts[BGP_STATS_AVGPLEN]
9047 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9048 ts->counts[BGP_STATS_AVGPLEN],
9049 rn->p.prefixlen);
9050#endif
9051
9052 /* check if the prefix is included by any other announcements */
9053 while (prn && !prn->info)
9054 prn = prn->parent;
9055
9056 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009057 {
9058 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9059 /* announced address space */
9060 if (space)
9061 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9062 }
Paul Jakma2815e612006-09-14 02:56:07 +00009063 else if (prn->info)
9064 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9065
Paul Jakma2815e612006-09-14 02:56:07 +00009066 for (ri = rn->info; ri; ri = ri->next)
9067 {
9068 rinum++;
9069 ts->counts[BGP_STATS_RIB]++;
9070
9071 if (ri->attr &&
9072 (CHECK_FLAG (ri->attr->flag,
9073 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9074 ts->counts[BGP_STATS_AGGREGATES]++;
9075
9076 /* as-path stats */
9077 if (ri->attr && ri->attr->aspath)
9078 {
9079 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9080 unsigned int size = aspath_size (ri->attr->aspath);
9081 as_t highest = aspath_highest (ri->attr->aspath);
9082
9083 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9084
9085 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9086 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9087
9088 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9089 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9090
9091 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9092 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9093#if 0
9094 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9095 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9096 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9097 hops);
9098 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9099 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9100 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9101 size);
9102#endif
9103 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9104 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9105 }
9106 }
9107 }
9108 return 0;
9109}
9110
9111static int
9112bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9113{
9114 struct bgp_table_stats ts;
9115 unsigned int i;
9116
9117 if (!bgp->rib[afi][safi])
9118 {
9119 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9120 return CMD_WARNING;
9121 }
9122
9123 memset (&ts, 0, sizeof (ts));
9124 ts.table = bgp->rib[afi][safi];
9125 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9126
9127 vty_out (vty, "BGP %s RIB statistics%s%s",
9128 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9129
9130 for (i = 0; i < BGP_STATS_MAX; i++)
9131 {
9132 if (!table_stats_strs[i])
9133 continue;
9134
9135 switch (i)
9136 {
9137#if 0
9138 case BGP_STATS_ASPATH_AVGHOPS:
9139 case BGP_STATS_ASPATH_AVGSIZE:
9140 case BGP_STATS_AVGPLEN:
9141 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9142 vty_out (vty, "%12.2f",
9143 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9144 break;
9145#endif
9146 case BGP_STATS_ASPATH_TOTHOPS:
9147 case BGP_STATS_ASPATH_TOTSIZE:
9148 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9149 vty_out (vty, "%12.2f",
9150 ts.counts[i] ?
9151 (float)ts.counts[i] /
9152 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9153 : 0);
9154 break;
9155 case BGP_STATS_TOTPLEN:
9156 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9157 vty_out (vty, "%12.2f",
9158 ts.counts[i] ?
9159 (float)ts.counts[i] /
9160 (float)ts.counts[BGP_STATS_PREFIXES]
9161 : 0);
9162 break;
9163 case BGP_STATS_SPACE:
9164 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9165 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9166 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9167 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009168 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009169 vty_out (vty, "%12.2f%s",
9170 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009171 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009172 VTY_NEWLINE);
9173 vty_out (vty, "%30s: ", "/8 equivalent ");
9174 vty_out (vty, "%12.2f%s",
9175 (float)ts.counts[BGP_STATS_SPACE] /
9176 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9177 VTY_NEWLINE);
9178 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9179 break;
9180 vty_out (vty, "%30s: ", "/24 equivalent ");
9181 vty_out (vty, "%12.2f",
9182 (float)ts.counts[BGP_STATS_SPACE] /
9183 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9184 break;
9185 default:
9186 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9187 vty_out (vty, "%12llu", ts.counts[i]);
9188 }
9189
9190 vty_out (vty, "%s", VTY_NEWLINE);
9191 }
9192 return CMD_SUCCESS;
9193}
9194
9195static int
9196bgp_table_stats_vty (struct vty *vty, const char *name,
9197 const char *afi_str, const char *safi_str)
9198{
9199 struct bgp *bgp;
9200 afi_t afi;
9201 safi_t safi;
9202
9203 if (name)
9204 bgp = bgp_lookup_by_name (name);
9205 else
9206 bgp = bgp_get_default ();
9207
9208 if (!bgp)
9209 {
9210 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9211 return CMD_WARNING;
9212 }
9213 if (strncmp (afi_str, "ipv", 3) == 0)
9214 {
9215 if (strncmp (afi_str, "ipv4", 4) == 0)
9216 afi = AFI_IP;
9217 else if (strncmp (afi_str, "ipv6", 4) == 0)
9218 afi = AFI_IP6;
9219 else
9220 {
9221 vty_out (vty, "%% Invalid address family %s%s",
9222 afi_str, VTY_NEWLINE);
9223 return CMD_WARNING;
9224 }
9225 if (strncmp (safi_str, "m", 1) == 0)
9226 safi = SAFI_MULTICAST;
9227 else if (strncmp (safi_str, "u", 1) == 0)
9228 safi = SAFI_UNICAST;
9229 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9230 safi = BGP_SAFI_VPNV4;
9231 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9232 safi = BGP_SAFI_VPNV6;
9233 else
9234 {
9235 vty_out (vty, "%% Invalid subsequent address family %s%s",
9236 safi_str, VTY_NEWLINE);
9237 return CMD_WARNING;
9238 }
9239 }
9240 else
9241 {
9242 vty_out (vty, "%% Invalid address family %s%s",
9243 afi_str, VTY_NEWLINE);
9244 return CMD_WARNING;
9245 }
9246
9247 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9248 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9249 {
9250 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9251 afi_str, safi_str, VTY_NEWLINE);
9252 return CMD_WARNING;
9253 }
9254 return bgp_table_stats (vty, bgp, afi, safi);
9255}
9256
9257DEFUN (show_bgp_statistics,
9258 show_bgp_statistics_cmd,
9259 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9260 SHOW_STR
9261 BGP_STR
9262 "Address family\n"
9263 "Address family\n"
9264 "Address Family modifier\n"
9265 "Address Family modifier\n"
9266 "BGP RIB advertisement statistics\n")
9267{
9268 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9269}
9270
9271ALIAS (show_bgp_statistics,
9272 show_bgp_statistics_vpnv4_cmd,
9273 "show bgp (ipv4) (vpnv4) statistics",
9274 SHOW_STR
9275 BGP_STR
9276 "Address family\n"
9277 "Address Family modifier\n"
9278 "BGP RIB advertisement statistics\n")
9279
9280DEFUN (show_bgp_statistics_view,
9281 show_bgp_statistics_view_cmd,
9282 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9283 SHOW_STR
9284 BGP_STR
9285 "BGP view\n"
9286 "Address family\n"
9287 "Address family\n"
9288 "Address Family modifier\n"
9289 "Address Family modifier\n"
9290 "BGP RIB advertisement statistics\n")
9291{
9292 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9293}
9294
9295ALIAS (show_bgp_statistics_view,
9296 show_bgp_statistics_view_vpnv4_cmd,
9297 "show bgp view WORD (ipv4) (vpnv4) statistics",
9298 SHOW_STR
9299 BGP_STR
9300 "BGP view\n"
9301 "Address family\n"
9302 "Address Family modifier\n"
9303 "BGP RIB advertisement statistics\n")
9304
Paul Jakmaff7924f2006-09-04 01:10:36 +00009305enum bgp_pcounts
9306{
9307 PCOUNT_ADJ_IN = 0,
9308 PCOUNT_DAMPED,
9309 PCOUNT_REMOVED,
9310 PCOUNT_HISTORY,
9311 PCOUNT_STALE,
9312 PCOUNT_VALID,
9313 PCOUNT_ALL,
9314 PCOUNT_COUNTED,
9315 PCOUNT_PFCNT, /* the figure we display to users */
9316 PCOUNT_MAX,
9317};
9318
9319static const char *pcount_strs[] =
9320{
9321 [PCOUNT_ADJ_IN] = "Adj-in",
9322 [PCOUNT_DAMPED] = "Damped",
9323 [PCOUNT_REMOVED] = "Removed",
9324 [PCOUNT_HISTORY] = "History",
9325 [PCOUNT_STALE] = "Stale",
9326 [PCOUNT_VALID] = "Valid",
9327 [PCOUNT_ALL] = "All RIB",
9328 [PCOUNT_COUNTED] = "PfxCt counted",
9329 [PCOUNT_PFCNT] = "Useable",
9330 [PCOUNT_MAX] = NULL,
9331};
9332
Paul Jakma2815e612006-09-14 02:56:07 +00009333struct peer_pcounts
9334{
9335 unsigned int count[PCOUNT_MAX];
9336 const struct peer *peer;
9337 const struct bgp_table *table;
9338};
9339
Paul Jakmaff7924f2006-09-04 01:10:36 +00009340static int
Paul Jakma2815e612006-09-14 02:56:07 +00009341bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009342{
9343 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009344 struct peer_pcounts *pc = THREAD_ARG (t);
9345 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009346
Paul Jakma2815e612006-09-14 02:56:07 +00009347 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009348 {
9349 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009350 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009351
9352 for (ain = rn->adj_in; ain; ain = ain->next)
9353 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009354 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009355
Paul Jakmaff7924f2006-09-04 01:10:36 +00009356 for (ri = rn->info; ri; ri = ri->next)
9357 {
9358 char buf[SU_ADDRSTRLEN];
9359
9360 if (ri->peer != peer)
9361 continue;
9362
Paul Jakma2815e612006-09-14 02:56:07 +00009363 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009364
9365 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009366 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009367 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009368 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009369 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009370 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009371 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009372 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009373 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009374 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009375 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009376 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009377
9378 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9379 {
Paul Jakma2815e612006-09-14 02:56:07 +00009380 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009381 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009382 plog_warn (peer->log,
9383 "%s [pcount] %s/%d is counted but flags 0x%x",
9384 peer->host,
9385 inet_ntop(rn->p.family, &rn->p.u.prefix,
9386 buf, SU_ADDRSTRLEN),
9387 rn->p.prefixlen,
9388 ri->flags);
9389 }
9390 else
9391 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009392 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009393 plog_warn (peer->log,
9394 "%s [pcount] %s/%d not counted but flags 0x%x",
9395 peer->host,
9396 inet_ntop(rn->p.family, &rn->p.u.prefix,
9397 buf, SU_ADDRSTRLEN),
9398 rn->p.prefixlen,
9399 ri->flags);
9400 }
9401 }
9402 }
Paul Jakma2815e612006-09-14 02:56:07 +00009403 return 0;
9404}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009405
Paul Jakma2815e612006-09-14 02:56:07 +00009406static int
9407bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9408{
9409 struct peer_pcounts pcounts = { .peer = peer };
9410 unsigned int i;
9411
9412 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9413 || !peer->bgp->rib[afi][safi])
9414 {
9415 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9416 return CMD_WARNING;
9417 }
9418
9419 memset (&pcounts, 0, sizeof(pcounts));
9420 pcounts.peer = peer;
9421 pcounts.table = peer->bgp->rib[afi][safi];
9422
9423 /* in-place call via thread subsystem so as to record execution time
9424 * stats for the thread-walk (i.e. ensure this can't be blamed on
9425 * on just vty_read()).
9426 */
9427 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9428
Paul Jakmaff7924f2006-09-04 01:10:36 +00009429 vty_out (vty, "Prefix counts for %s, %s%s",
9430 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9431 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9432 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9433 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9434
9435 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009436 vty_out (vty, "%20s: %-10d%s",
9437 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009438
Paul Jakma2815e612006-09-14 02:56:07 +00009439 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009440 {
9441 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9442 peer->host, VTY_NEWLINE);
9443 vty_out (vty, "Please report this bug, with the above command output%s",
9444 VTY_NEWLINE);
9445 }
9446
9447 return CMD_SUCCESS;
9448}
9449
9450DEFUN (show_ip_bgp_neighbor_prefix_counts,
9451 show_ip_bgp_neighbor_prefix_counts_cmd,
9452 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9453 SHOW_STR
9454 IP_STR
9455 BGP_STR
9456 "Detailed information on TCP and BGP neighbor connections\n"
9457 "Neighbor to display information about\n"
9458 "Neighbor to display information about\n"
9459 "Display detailed prefix count information\n")
9460{
9461 struct peer *peer;
9462
9463 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9464 if (! peer)
9465 return CMD_WARNING;
9466
9467 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9468}
9469
9470DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9471 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9472 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9473 SHOW_STR
9474 BGP_STR
9475 "Address family\n"
9476 "Detailed information on TCP and BGP neighbor connections\n"
9477 "Neighbor to display information about\n"
9478 "Neighbor to display information about\n"
9479 "Display detailed prefix count information\n")
9480{
9481 struct peer *peer;
9482
9483 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9484 if (! peer)
9485 return CMD_WARNING;
9486
9487 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9488}
9489
9490DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9491 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9492 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9493 SHOW_STR
9494 IP_STR
9495 BGP_STR
9496 "Address family\n"
9497 "Address Family modifier\n"
9498 "Address Family modifier\n"
9499 "Detailed information on TCP and BGP neighbor connections\n"
9500 "Neighbor to display information about\n"
9501 "Neighbor to display information about\n"
9502 "Display detailed prefix count information\n")
9503{
9504 struct peer *peer;
9505
9506 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9507 if (! peer)
9508 return CMD_WARNING;
9509
9510 if (strncmp (argv[0], "m", 1) == 0)
9511 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9512
9513 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9514}
9515
9516DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9517 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9518 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9519 SHOW_STR
9520 IP_STR
9521 BGP_STR
9522 "Address family\n"
9523 "Address Family modifier\n"
9524 "Address Family modifier\n"
9525 "Detailed information on TCP and BGP neighbor connections\n"
9526 "Neighbor to display information about\n"
9527 "Neighbor to display information about\n"
9528 "Display detailed prefix count information\n")
9529{
9530 struct peer *peer;
9531
9532 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9533 if (! peer)
9534 return CMD_WARNING;
9535
9536 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9537}
9538
9539
paul94f2b392005-06-28 12:44:16 +00009540static void
paul718e3742002-12-13 20:15:29 +00009541show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9542 int in)
9543{
9544 struct bgp_table *table;
9545 struct bgp_adj_in *ain;
9546 struct bgp_adj_out *adj;
9547 unsigned long output_count;
9548 struct bgp_node *rn;
9549 int header1 = 1;
9550 struct bgp *bgp;
9551 int header2 = 1;
9552
paulbb46e942003-10-24 19:02:03 +00009553 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009554
9555 if (! bgp)
9556 return;
9557
9558 table = bgp->rib[afi][safi];
9559
9560 output_count = 0;
9561
9562 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9563 PEER_STATUS_DEFAULT_ORIGINATE))
9564 {
9565 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 +00009566 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9567 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009568
9569 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9570 VTY_NEWLINE, VTY_NEWLINE);
9571 header1 = 0;
9572 }
9573
9574 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9575 if (in)
9576 {
9577 for (ain = rn->adj_in; ain; ain = ain->next)
9578 if (ain->peer == peer)
9579 {
9580 if (header1)
9581 {
9582 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 +00009583 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9584 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009585 header1 = 0;
9586 }
9587 if (header2)
9588 {
9589 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9590 header2 = 0;
9591 }
9592 if (ain->attr)
9593 {
9594 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9595 output_count++;
9596 }
9597 }
9598 }
9599 else
9600 {
9601 for (adj = rn->adj_out; adj; adj = adj->next)
9602 if (adj->peer == peer)
9603 {
9604 if (header1)
9605 {
9606 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 +00009607 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9608 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009609 header1 = 0;
9610 }
9611 if (header2)
9612 {
9613 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9614 header2 = 0;
9615 }
9616 if (adj->attr)
9617 {
9618 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9619 output_count++;
9620 }
9621 }
9622 }
9623
9624 if (output_count != 0)
9625 vty_out (vty, "%sTotal number of prefixes %ld%s",
9626 VTY_NEWLINE, output_count, VTY_NEWLINE);
9627}
9628
paul94f2b392005-06-28 12:44:16 +00009629static int
paulbb46e942003-10-24 19:02:03 +00009630peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9631{
paul718e3742002-12-13 20:15:29 +00009632 if (! peer || ! peer->afc[afi][safi])
9633 {
9634 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9635 return CMD_WARNING;
9636 }
9637
9638 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9639 {
9640 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9641 VTY_NEWLINE);
9642 return CMD_WARNING;
9643 }
9644
9645 show_adj_route (vty, peer, afi, safi, in);
9646
9647 return CMD_SUCCESS;
9648}
9649
9650DEFUN (show_ip_bgp_neighbor_advertised_route,
9651 show_ip_bgp_neighbor_advertised_route_cmd,
9652 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9653 SHOW_STR
9654 IP_STR
9655 BGP_STR
9656 "Detailed information on TCP and BGP neighbor connections\n"
9657 "Neighbor to display information about\n"
9658 "Neighbor to display information about\n"
9659 "Display the routes advertised to a BGP neighbor\n")
9660{
paulbb46e942003-10-24 19:02:03 +00009661 struct peer *peer;
9662
9663 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9664 if (! peer)
9665 return CMD_WARNING;
9666
9667 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009668}
9669
9670DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9671 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9672 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9673 SHOW_STR
9674 IP_STR
9675 BGP_STR
9676 "Address family\n"
9677 "Address Family modifier\n"
9678 "Address Family modifier\n"
9679 "Detailed information on TCP and BGP neighbor connections\n"
9680 "Neighbor to display information about\n"
9681 "Neighbor to display information about\n"
9682 "Display the routes advertised to a BGP neighbor\n")
9683{
paulbb46e942003-10-24 19:02:03 +00009684 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009685
paulbb46e942003-10-24 19:02:03 +00009686 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9687 if (! peer)
9688 return CMD_WARNING;
9689
9690 if (strncmp (argv[0], "m", 1) == 0)
9691 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9692
9693 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009694}
9695
9696#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009697DEFUN (show_bgp_view_neighbor_advertised_route,
9698 show_bgp_view_neighbor_advertised_route_cmd,
9699 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9700 SHOW_STR
9701 BGP_STR
9702 "BGP view\n"
9703 "View name\n"
9704 "Detailed information on TCP and BGP neighbor connections\n"
9705 "Neighbor to display information about\n"
9706 "Neighbor to display information about\n"
9707 "Display the routes advertised to a BGP neighbor\n")
9708{
9709 struct peer *peer;
9710
9711 if (argc == 2)
9712 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9713 else
9714 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9715
9716 if (! peer)
9717 return CMD_WARNING;
9718
9719 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9720}
9721
9722ALIAS (show_bgp_view_neighbor_advertised_route,
9723 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9724 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9725 SHOW_STR
9726 BGP_STR
9727 "BGP view\n"
9728 "View name\n"
9729 "Address family\n"
9730 "Detailed information on TCP and BGP neighbor connections\n"
9731 "Neighbor to display information about\n"
9732 "Neighbor to display information about\n"
9733 "Display the routes advertised to a BGP neighbor\n")
9734
9735DEFUN (show_bgp_view_neighbor_received_routes,
9736 show_bgp_view_neighbor_received_routes_cmd,
9737 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9738 SHOW_STR
9739 BGP_STR
9740 "BGP view\n"
9741 "View name\n"
9742 "Detailed information on TCP and BGP neighbor connections\n"
9743 "Neighbor to display information about\n"
9744 "Neighbor to display information about\n"
9745 "Display the received routes from neighbor\n")
9746{
9747 struct peer *peer;
9748
9749 if (argc == 2)
9750 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9751 else
9752 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9753
9754 if (! peer)
9755 return CMD_WARNING;
9756
9757 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9758}
9759
9760ALIAS (show_bgp_view_neighbor_received_routes,
9761 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9762 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9763 SHOW_STR
9764 BGP_STR
9765 "BGP view\n"
9766 "View name\n"
9767 "Address family\n"
9768 "Detailed information on TCP and BGP neighbor connections\n"
9769 "Neighbor to display information about\n"
9770 "Neighbor to display information about\n"
9771 "Display the received routes from neighbor\n")
9772
9773ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009774 show_bgp_neighbor_advertised_route_cmd,
9775 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9776 SHOW_STR
9777 BGP_STR
9778 "Detailed information on TCP and BGP neighbor connections\n"
9779 "Neighbor to display information about\n"
9780 "Neighbor to display information about\n"
9781 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009782
9783ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009784 show_bgp_ipv6_neighbor_advertised_route_cmd,
9785 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9786 SHOW_STR
9787 BGP_STR
9788 "Address family\n"
9789 "Detailed information on TCP and BGP neighbor connections\n"
9790 "Neighbor to display information about\n"
9791 "Neighbor to display information about\n"
9792 "Display the routes advertised to a BGP neighbor\n")
9793
9794/* old command */
paulbb46e942003-10-24 19:02:03 +00009795ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009796 ipv6_bgp_neighbor_advertised_route_cmd,
9797 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9798 SHOW_STR
9799 IPV6_STR
9800 BGP_STR
9801 "Detailed information on TCP and BGP neighbor connections\n"
9802 "Neighbor to display information about\n"
9803 "Neighbor to display information about\n"
9804 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009805
paul718e3742002-12-13 20:15:29 +00009806/* old command */
9807DEFUN (ipv6_mbgp_neighbor_advertised_route,
9808 ipv6_mbgp_neighbor_advertised_route_cmd,
9809 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9810 SHOW_STR
9811 IPV6_STR
9812 MBGP_STR
9813 "Detailed information on TCP and BGP neighbor connections\n"
9814 "Neighbor to display information about\n"
9815 "Neighbor to display information about\n"
9816 "Display the routes advertised to a BGP neighbor\n")
9817{
paulbb46e942003-10-24 19:02:03 +00009818 struct peer *peer;
9819
9820 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9821 if (! peer)
9822 return CMD_WARNING;
9823
9824 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009825}
9826#endif /* HAVE_IPV6 */
9827
9828DEFUN (show_ip_bgp_neighbor_received_routes,
9829 show_ip_bgp_neighbor_received_routes_cmd,
9830 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9831 SHOW_STR
9832 IP_STR
9833 BGP_STR
9834 "Detailed information on TCP and BGP neighbor connections\n"
9835 "Neighbor to display information about\n"
9836 "Neighbor to display information about\n"
9837 "Display the received routes from neighbor\n")
9838{
paulbb46e942003-10-24 19:02:03 +00009839 struct peer *peer;
9840
9841 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9842 if (! peer)
9843 return CMD_WARNING;
9844
9845 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009846}
9847
9848DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9849 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9850 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9851 SHOW_STR
9852 IP_STR
9853 BGP_STR
9854 "Address family\n"
9855 "Address Family modifier\n"
9856 "Address Family modifier\n"
9857 "Detailed information on TCP and BGP neighbor connections\n"
9858 "Neighbor to display information about\n"
9859 "Neighbor to display information about\n"
9860 "Display the received routes from neighbor\n")
9861{
paulbb46e942003-10-24 19:02:03 +00009862 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009863
paulbb46e942003-10-24 19:02:03 +00009864 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9865 if (! peer)
9866 return CMD_WARNING;
9867
9868 if (strncmp (argv[0], "m", 1) == 0)
9869 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9870
9871 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009872}
9873
9874DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9875 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9876 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9877 SHOW_STR
9878 IP_STR
9879 BGP_STR
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 information received from a BGP neighbor\n"
9884 "Display the prefixlist filter\n")
9885{
9886 char name[BUFSIZ];
9887 union sockunion *su;
9888 struct peer *peer;
9889 int count;
9890
9891 su = sockunion_str2su (argv[0]);
9892 if (su == NULL)
9893 return CMD_WARNING;
9894
9895 peer = peer_lookup (NULL, su);
9896 if (! peer)
9897 return CMD_WARNING;
9898
9899 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9900 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9901 if (count)
9902 {
9903 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9904 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9905 }
9906
9907 return CMD_SUCCESS;
9908}
9909
9910DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9911 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9912 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9913 SHOW_STR
9914 IP_STR
9915 BGP_STR
9916 "Address family\n"
9917 "Address Family modifier\n"
9918 "Address Family modifier\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 information received from a BGP neighbor\n"
9923 "Display the prefixlist filter\n")
9924{
9925 char name[BUFSIZ];
9926 union sockunion *su;
9927 struct peer *peer;
9928 int count;
9929
9930 su = sockunion_str2su (argv[1]);
9931 if (su == NULL)
9932 return CMD_WARNING;
9933
9934 peer = peer_lookup (NULL, su);
9935 if (! peer)
9936 return CMD_WARNING;
9937
9938 if (strncmp (argv[0], "m", 1) == 0)
9939 {
9940 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9941 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9942 if (count)
9943 {
9944 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9945 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9946 }
9947 }
9948 else
9949 {
9950 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9951 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9952 if (count)
9953 {
9954 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9955 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9956 }
9957 }
9958
9959 return CMD_SUCCESS;
9960}
9961
9962
9963#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009964ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009965 show_bgp_neighbor_received_routes_cmd,
9966 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9967 SHOW_STR
9968 BGP_STR
9969 "Detailed information on TCP and BGP neighbor connections\n"
9970 "Neighbor to display information about\n"
9971 "Neighbor to display information about\n"
9972 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009973
paulbb46e942003-10-24 19:02:03 +00009974ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009975 show_bgp_ipv6_neighbor_received_routes_cmd,
9976 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9977 SHOW_STR
9978 BGP_STR
9979 "Address family\n"
9980 "Detailed information on TCP and BGP neighbor connections\n"
9981 "Neighbor to display information about\n"
9982 "Neighbor to display information about\n"
9983 "Display the received routes from neighbor\n")
9984
9985DEFUN (show_bgp_neighbor_received_prefix_filter,
9986 show_bgp_neighbor_received_prefix_filter_cmd,
9987 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9988 SHOW_STR
9989 BGP_STR
9990 "Detailed information on TCP and BGP neighbor connections\n"
9991 "Neighbor to display information about\n"
9992 "Neighbor to display information about\n"
9993 "Display information received from a BGP neighbor\n"
9994 "Display the prefixlist filter\n")
9995{
9996 char name[BUFSIZ];
9997 union sockunion *su;
9998 struct peer *peer;
9999 int count;
10000
10001 su = sockunion_str2su (argv[0]);
10002 if (su == NULL)
10003 return CMD_WARNING;
10004
10005 peer = peer_lookup (NULL, su);
10006 if (! peer)
10007 return CMD_WARNING;
10008
10009 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10010 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10011 if (count)
10012 {
10013 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10014 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10015 }
10016
10017 return CMD_SUCCESS;
10018}
10019
10020ALIAS (show_bgp_neighbor_received_prefix_filter,
10021 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10022 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10023 SHOW_STR
10024 BGP_STR
10025 "Address family\n"
10026 "Detailed information on TCP and BGP neighbor connections\n"
10027 "Neighbor to display information about\n"
10028 "Neighbor to display information about\n"
10029 "Display information received from a BGP neighbor\n"
10030 "Display the prefixlist filter\n")
10031
10032/* old command */
paulbb46e942003-10-24 19:02:03 +000010033ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010034 ipv6_bgp_neighbor_received_routes_cmd,
10035 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10036 SHOW_STR
10037 IPV6_STR
10038 BGP_STR
10039 "Detailed information on TCP and BGP neighbor connections\n"
10040 "Neighbor to display information about\n"
10041 "Neighbor to display information about\n"
10042 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010043
10044/* old command */
10045DEFUN (ipv6_mbgp_neighbor_received_routes,
10046 ipv6_mbgp_neighbor_received_routes_cmd,
10047 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10048 SHOW_STR
10049 IPV6_STR
10050 MBGP_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 the received routes from neighbor\n")
10055{
paulbb46e942003-10-24 19:02:03 +000010056 struct peer *peer;
10057
10058 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10059 if (! peer)
10060 return CMD_WARNING;
10061
10062 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010063}
paulbb46e942003-10-24 19:02:03 +000010064
10065DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10066 show_bgp_view_neighbor_received_prefix_filter_cmd,
10067 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10068 SHOW_STR
10069 BGP_STR
10070 "BGP view\n"
10071 "View name\n"
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 information received from a BGP neighbor\n"
10076 "Display the prefixlist filter\n")
10077{
10078 char name[BUFSIZ];
10079 union sockunion *su;
10080 struct peer *peer;
10081 struct bgp *bgp;
10082 int count;
10083
10084 /* BGP structure lookup. */
10085 bgp = bgp_lookup_by_name (argv[0]);
10086 if (bgp == NULL)
10087 {
10088 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10089 return CMD_WARNING;
10090 }
10091
10092 su = sockunion_str2su (argv[1]);
10093 if (su == NULL)
10094 return CMD_WARNING;
10095
10096 peer = peer_lookup (bgp, su);
10097 if (! peer)
10098 return CMD_WARNING;
10099
10100 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10101 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10102 if (count)
10103 {
10104 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10105 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10106 }
10107
10108 return CMD_SUCCESS;
10109}
10110
10111ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10112 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10113 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10114 SHOW_STR
10115 BGP_STR
10116 "BGP view\n"
10117 "View name\n"
10118 "Address family\n"
10119 "Detailed information on TCP and BGP neighbor connections\n"
10120 "Neighbor to display information about\n"
10121 "Neighbor to display information about\n"
10122 "Display information received from a BGP neighbor\n"
10123 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010124#endif /* HAVE_IPV6 */
10125
paul94f2b392005-06-28 12:44:16 +000010126static int
paulbb46e942003-10-24 19:02:03 +000010127bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010128 safi_t safi, enum bgp_show_type type)
10129{
paul718e3742002-12-13 20:15:29 +000010130 if (! peer || ! peer->afc[afi][safi])
10131 {
10132 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010133 return CMD_WARNING;
10134 }
10135
ajs5a646652004-11-05 01:25:55 +000010136 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010137}
10138
10139DEFUN (show_ip_bgp_neighbor_routes,
10140 show_ip_bgp_neighbor_routes_cmd,
10141 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10142 SHOW_STR
10143 IP_STR
10144 BGP_STR
10145 "Detailed information on TCP and BGP neighbor connections\n"
10146 "Neighbor to display information about\n"
10147 "Neighbor to display information about\n"
10148 "Display routes learned from neighbor\n")
10149{
paulbb46e942003-10-24 19:02:03 +000010150 struct peer *peer;
10151
10152 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10153 if (! peer)
10154 return CMD_WARNING;
10155
10156 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010157 bgp_show_type_neighbor);
10158}
10159
10160DEFUN (show_ip_bgp_neighbor_flap,
10161 show_ip_bgp_neighbor_flap_cmd,
10162 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10163 SHOW_STR
10164 IP_STR
10165 BGP_STR
10166 "Detailed information on TCP and BGP neighbor connections\n"
10167 "Neighbor to display information about\n"
10168 "Neighbor to display information about\n"
10169 "Display flap statistics of the routes learned from neighbor\n")
10170{
paulbb46e942003-10-24 19:02:03 +000010171 struct peer *peer;
10172
10173 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10174 if (! peer)
10175 return CMD_WARNING;
10176
10177 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010178 bgp_show_type_flap_neighbor);
10179}
10180
10181DEFUN (show_ip_bgp_neighbor_damp,
10182 show_ip_bgp_neighbor_damp_cmd,
10183 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10184 SHOW_STR
10185 IP_STR
10186 BGP_STR
10187 "Detailed information on TCP and BGP neighbor connections\n"
10188 "Neighbor to display information about\n"
10189 "Neighbor to display information about\n"
10190 "Display the dampened routes received from neighbor\n")
10191{
paulbb46e942003-10-24 19:02:03 +000010192 struct peer *peer;
10193
10194 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10195 if (! peer)
10196 return CMD_WARNING;
10197
10198 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010199 bgp_show_type_damp_neighbor);
10200}
10201
10202DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10203 show_ip_bgp_ipv4_neighbor_routes_cmd,
10204 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10205 SHOW_STR
10206 IP_STR
10207 BGP_STR
10208 "Address family\n"
10209 "Address Family modifier\n"
10210 "Address Family modifier\n"
10211 "Detailed information on TCP and BGP neighbor connections\n"
10212 "Neighbor to display information about\n"
10213 "Neighbor to display information about\n"
10214 "Display routes learned from neighbor\n")
10215{
paulbb46e942003-10-24 19:02:03 +000010216 struct peer *peer;
10217
10218 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10219 if (! peer)
10220 return CMD_WARNING;
10221
paul718e3742002-12-13 20:15:29 +000010222 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010223 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010224 bgp_show_type_neighbor);
10225
paulbb46e942003-10-24 19:02:03 +000010226 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010227 bgp_show_type_neighbor);
10228}
paulbb46e942003-10-24 19:02:03 +000010229
paulfee0f4c2004-09-13 05:12:46 +000010230DEFUN (show_ip_bgp_view_rsclient,
10231 show_ip_bgp_view_rsclient_cmd,
10232 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10233 SHOW_STR
10234 IP_STR
10235 BGP_STR
10236 "BGP view\n"
10237 "BGP view name\n"
10238 "Information about Route Server Client\n"
10239 NEIGHBOR_ADDR_STR)
10240{
10241 struct bgp_table *table;
10242 struct peer *peer;
10243
10244 if (argc == 2)
10245 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10246 else
10247 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10248
10249 if (! peer)
10250 return CMD_WARNING;
10251
10252 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10253 {
10254 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10255 VTY_NEWLINE);
10256 return CMD_WARNING;
10257 }
10258
10259 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10260 PEER_FLAG_RSERVER_CLIENT))
10261 {
10262 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10263 VTY_NEWLINE);
10264 return CMD_WARNING;
10265 }
10266
10267 table = peer->rib[AFI_IP][SAFI_UNICAST];
10268
ajs5a646652004-11-05 01:25:55 +000010269 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010270}
10271
10272ALIAS (show_ip_bgp_view_rsclient,
10273 show_ip_bgp_rsclient_cmd,
10274 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10275 SHOW_STR
10276 IP_STR
10277 BGP_STR
10278 "Information about Route Server Client\n"
10279 NEIGHBOR_ADDR_STR)
10280
10281DEFUN (show_ip_bgp_view_rsclient_route,
10282 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010283 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010284 SHOW_STR
10285 IP_STR
10286 BGP_STR
10287 "BGP view\n"
10288 "BGP view name\n"
10289 "Information about Route Server Client\n"
10290 NEIGHBOR_ADDR_STR
10291 "Network in the BGP routing table to display\n")
10292{
10293 struct bgp *bgp;
10294 struct peer *peer;
10295
10296 /* BGP structure lookup. */
10297 if (argc == 3)
10298 {
10299 bgp = bgp_lookup_by_name (argv[0]);
10300 if (bgp == NULL)
10301 {
10302 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10303 return CMD_WARNING;
10304 }
10305 }
10306 else
10307 {
10308 bgp = bgp_get_default ();
10309 if (bgp == NULL)
10310 {
10311 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10312 return CMD_WARNING;
10313 }
10314 }
10315
10316 if (argc == 3)
10317 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10318 else
10319 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10320
10321 if (! peer)
10322 return CMD_WARNING;
10323
10324 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10325 {
10326 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10327 VTY_NEWLINE);
10328 return CMD_WARNING;
10329}
10330
10331 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10332 PEER_FLAG_RSERVER_CLIENT))
10333 {
10334 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10335 VTY_NEWLINE);
10336 return CMD_WARNING;
10337 }
10338
10339 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10340 (argc == 3) ? argv[2] : argv[1],
10341 AFI_IP, SAFI_UNICAST, NULL, 0);
10342}
10343
10344ALIAS (show_ip_bgp_view_rsclient_route,
10345 show_ip_bgp_rsclient_route_cmd,
10346 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10347 SHOW_STR
10348 IP_STR
10349 BGP_STR
10350 "Information about Route Server Client\n"
10351 NEIGHBOR_ADDR_STR
10352 "Network in the BGP routing table to display\n")
10353
10354DEFUN (show_ip_bgp_view_rsclient_prefix,
10355 show_ip_bgp_view_rsclient_prefix_cmd,
10356 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10357 SHOW_STR
10358 IP_STR
10359 BGP_STR
10360 "BGP view\n"
10361 "BGP view name\n"
10362 "Information about Route Server Client\n"
10363 NEIGHBOR_ADDR_STR
10364 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10365{
10366 struct bgp *bgp;
10367 struct peer *peer;
10368
10369 /* BGP structure lookup. */
10370 if (argc == 3)
10371 {
10372 bgp = bgp_lookup_by_name (argv[0]);
10373 if (bgp == NULL)
10374 {
10375 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10376 return CMD_WARNING;
10377 }
10378 }
10379 else
10380 {
10381 bgp = bgp_get_default ();
10382 if (bgp == NULL)
10383 {
10384 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10385 return CMD_WARNING;
10386 }
10387 }
10388
10389 if (argc == 3)
10390 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10391 else
10392 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10393
10394 if (! peer)
10395 return CMD_WARNING;
10396
10397 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10398 {
10399 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10400 VTY_NEWLINE);
10401 return CMD_WARNING;
10402}
10403
10404 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10405 PEER_FLAG_RSERVER_CLIENT))
10406{
10407 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10408 VTY_NEWLINE);
10409 return CMD_WARNING;
10410 }
10411
10412 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10413 (argc == 3) ? argv[2] : argv[1],
10414 AFI_IP, SAFI_UNICAST, NULL, 1);
10415}
10416
10417ALIAS (show_ip_bgp_view_rsclient_prefix,
10418 show_ip_bgp_rsclient_prefix_cmd,
10419 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10420 SHOW_STR
10421 IP_STR
10422 BGP_STR
10423 "Information about Route Server Client\n"
10424 NEIGHBOR_ADDR_STR
10425 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10426
10427
paul718e3742002-12-13 20:15:29 +000010428#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010429DEFUN (show_bgp_view_neighbor_routes,
10430 show_bgp_view_neighbor_routes_cmd,
10431 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10432 SHOW_STR
10433 BGP_STR
10434 "BGP view\n"
10435 "BGP view name\n"
10436 "Detailed information on TCP and BGP neighbor connections\n"
10437 "Neighbor to display information about\n"
10438 "Neighbor to display information about\n"
10439 "Display routes learned from neighbor\n")
10440{
10441 struct peer *peer;
10442
10443 if (argc == 2)
10444 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10445 else
10446 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10447
10448 if (! peer)
10449 return CMD_WARNING;
10450
10451 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10452 bgp_show_type_neighbor);
10453}
10454
10455ALIAS (show_bgp_view_neighbor_routes,
10456 show_bgp_view_ipv6_neighbor_routes_cmd,
10457 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10458 SHOW_STR
10459 BGP_STR
10460 "BGP view\n"
10461 "BGP view name\n"
10462 "Address family\n"
10463 "Detailed information on TCP and BGP neighbor connections\n"
10464 "Neighbor to display information about\n"
10465 "Neighbor to display information about\n"
10466 "Display routes learned from neighbor\n")
10467
10468DEFUN (show_bgp_view_neighbor_damp,
10469 show_bgp_view_neighbor_damp_cmd,
10470 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10471 SHOW_STR
10472 BGP_STR
10473 "BGP view\n"
10474 "BGP view name\n"
10475 "Detailed information on TCP and BGP neighbor connections\n"
10476 "Neighbor to display information about\n"
10477 "Neighbor to display information about\n"
10478 "Display the dampened routes received from neighbor\n")
10479{
10480 struct peer *peer;
10481
10482 if (argc == 2)
10483 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10484 else
10485 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10486
10487 if (! peer)
10488 return CMD_WARNING;
10489
10490 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10491 bgp_show_type_damp_neighbor);
10492}
10493
10494ALIAS (show_bgp_view_neighbor_damp,
10495 show_bgp_view_ipv6_neighbor_damp_cmd,
10496 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10497 SHOW_STR
10498 BGP_STR
10499 "BGP view\n"
10500 "BGP view name\n"
10501 "Address family\n"
10502 "Detailed information on TCP and BGP neighbor connections\n"
10503 "Neighbor to display information about\n"
10504 "Neighbor to display information about\n"
10505 "Display the dampened routes received from neighbor\n")
10506
10507DEFUN (show_bgp_view_neighbor_flap,
10508 show_bgp_view_neighbor_flap_cmd,
10509 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10510 SHOW_STR
10511 BGP_STR
10512 "BGP view\n"
10513 "BGP view name\n"
10514 "Detailed information on TCP and BGP neighbor connections\n"
10515 "Neighbor to display information about\n"
10516 "Neighbor to display information about\n"
10517 "Display flap statistics of the routes learned from neighbor\n")
10518{
10519 struct peer *peer;
10520
10521 if (argc == 2)
10522 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10523 else
10524 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10525
10526 if (! peer)
10527 return CMD_WARNING;
10528
10529 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10530 bgp_show_type_flap_neighbor);
10531}
10532
10533ALIAS (show_bgp_view_neighbor_flap,
10534 show_bgp_view_ipv6_neighbor_flap_cmd,
10535 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10536 SHOW_STR
10537 BGP_STR
10538 "BGP view\n"
10539 "BGP view name\n"
10540 "Address family\n"
10541 "Detailed information on TCP and BGP neighbor connections\n"
10542 "Neighbor to display information about\n"
10543 "Neighbor to display information about\n"
10544 "Display flap statistics of the routes learned from neighbor\n")
10545
10546ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010547 show_bgp_neighbor_routes_cmd,
10548 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10549 SHOW_STR
10550 BGP_STR
10551 "Detailed information on TCP and BGP neighbor connections\n"
10552 "Neighbor to display information about\n"
10553 "Neighbor to display information about\n"
10554 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010555
paulbb46e942003-10-24 19:02:03 +000010556
10557ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010558 show_bgp_ipv6_neighbor_routes_cmd,
10559 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10560 SHOW_STR
10561 BGP_STR
10562 "Address family\n"
10563 "Detailed information on TCP and BGP neighbor connections\n"
10564 "Neighbor to display information about\n"
10565 "Neighbor to display information about\n"
10566 "Display routes learned from neighbor\n")
10567
10568/* old command */
paulbb46e942003-10-24 19:02:03 +000010569ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010570 ipv6_bgp_neighbor_routes_cmd,
10571 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10572 SHOW_STR
10573 IPV6_STR
10574 BGP_STR
10575 "Detailed information on TCP and BGP neighbor connections\n"
10576 "Neighbor to display information about\n"
10577 "Neighbor to display information about\n"
10578 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010579
10580/* old command */
10581DEFUN (ipv6_mbgp_neighbor_routes,
10582 ipv6_mbgp_neighbor_routes_cmd,
10583 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10584 SHOW_STR
10585 IPV6_STR
10586 MBGP_STR
10587 "Detailed information on TCP and BGP neighbor connections\n"
10588 "Neighbor to display information about\n"
10589 "Neighbor to display information about\n"
10590 "Display routes learned from neighbor\n")
10591{
paulbb46e942003-10-24 19:02:03 +000010592 struct peer *peer;
10593
10594 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10595 if (! peer)
10596 return CMD_WARNING;
10597
10598 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010599 bgp_show_type_neighbor);
10600}
paulbb46e942003-10-24 19:02:03 +000010601
10602ALIAS (show_bgp_view_neighbor_flap,
10603 show_bgp_neighbor_flap_cmd,
10604 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10605 SHOW_STR
10606 BGP_STR
10607 "Detailed information on TCP and BGP neighbor connections\n"
10608 "Neighbor to display information about\n"
10609 "Neighbor to display information about\n"
10610 "Display flap statistics of the routes learned from neighbor\n")
10611
10612ALIAS (show_bgp_view_neighbor_flap,
10613 show_bgp_ipv6_neighbor_flap_cmd,
10614 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10615 SHOW_STR
10616 BGP_STR
10617 "Address family\n"
10618 "Detailed information on TCP and BGP neighbor connections\n"
10619 "Neighbor to display information about\n"
10620 "Neighbor to display information about\n"
10621 "Display flap statistics of the routes learned from neighbor\n")
10622
10623ALIAS (show_bgp_view_neighbor_damp,
10624 show_bgp_neighbor_damp_cmd,
10625 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10626 SHOW_STR
10627 BGP_STR
10628 "Detailed information on TCP and BGP neighbor connections\n"
10629 "Neighbor to display information about\n"
10630 "Neighbor to display information about\n"
10631 "Display the dampened routes received from neighbor\n")
10632
10633ALIAS (show_bgp_view_neighbor_damp,
10634 show_bgp_ipv6_neighbor_damp_cmd,
10635 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10636 SHOW_STR
10637 BGP_STR
10638 "Address family\n"
10639 "Detailed information on TCP and BGP neighbor connections\n"
10640 "Neighbor to display information about\n"
10641 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010642 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010643
10644DEFUN (show_bgp_view_rsclient,
10645 show_bgp_view_rsclient_cmd,
10646 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10647 SHOW_STR
10648 BGP_STR
10649 "BGP view\n"
10650 "BGP view name\n"
10651 "Information about Route Server Client\n"
10652 NEIGHBOR_ADDR_STR)
10653{
10654 struct bgp_table *table;
10655 struct peer *peer;
10656
10657 if (argc == 2)
10658 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10659 else
10660 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10661
10662 if (! peer)
10663 return CMD_WARNING;
10664
10665 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10666 {
10667 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10668 VTY_NEWLINE);
10669 return CMD_WARNING;
10670 }
10671
10672 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10673 PEER_FLAG_RSERVER_CLIENT))
10674 {
10675 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10676 VTY_NEWLINE);
10677 return CMD_WARNING;
10678 }
10679
10680 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10681
ajs5a646652004-11-05 01:25:55 +000010682 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010683}
10684
10685ALIAS (show_bgp_view_rsclient,
10686 show_bgp_rsclient_cmd,
10687 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10688 SHOW_STR
10689 BGP_STR
10690 "Information about Route Server Client\n"
10691 NEIGHBOR_ADDR_STR)
10692
10693DEFUN (show_bgp_view_rsclient_route,
10694 show_bgp_view_rsclient_route_cmd,
10695 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10696 SHOW_STR
10697 BGP_STR
10698 "BGP view\n"
10699 "BGP view name\n"
10700 "Information about Route Server Client\n"
10701 NEIGHBOR_ADDR_STR
10702 "Network in the BGP routing table to display\n")
10703{
10704 struct bgp *bgp;
10705 struct peer *peer;
10706
10707 /* BGP structure lookup. */
10708 if (argc == 3)
10709 {
10710 bgp = bgp_lookup_by_name (argv[0]);
10711 if (bgp == NULL)
10712 {
10713 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10714 return CMD_WARNING;
10715 }
10716 }
10717 else
10718 {
10719 bgp = bgp_get_default ();
10720 if (bgp == NULL)
10721 {
10722 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10723 return CMD_WARNING;
10724 }
10725 }
10726
10727 if (argc == 3)
10728 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10729 else
10730 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10731
10732 if (! peer)
10733 return CMD_WARNING;
10734
10735 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10736 {
10737 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10738 VTY_NEWLINE);
10739 return CMD_WARNING;
10740 }
10741
10742 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10743 PEER_FLAG_RSERVER_CLIENT))
10744 {
10745 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10746 VTY_NEWLINE);
10747 return CMD_WARNING;
10748 }
10749
10750 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10751 (argc == 3) ? argv[2] : argv[1],
10752 AFI_IP6, SAFI_UNICAST, NULL, 0);
10753}
10754
10755ALIAS (show_bgp_view_rsclient_route,
10756 show_bgp_rsclient_route_cmd,
10757 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10758 SHOW_STR
10759 BGP_STR
10760 "Information about Route Server Client\n"
10761 NEIGHBOR_ADDR_STR
10762 "Network in the BGP routing table to display\n")
10763
10764DEFUN (show_bgp_view_rsclient_prefix,
10765 show_bgp_view_rsclient_prefix_cmd,
10766 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10767 SHOW_STR
10768 BGP_STR
10769 "BGP view\n"
10770 "BGP view name\n"
10771 "Information about Route Server Client\n"
10772 NEIGHBOR_ADDR_STR
10773 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10774{
10775 struct bgp *bgp;
10776 struct peer *peer;
10777
10778 /* BGP structure lookup. */
10779 if (argc == 3)
10780 {
10781 bgp = bgp_lookup_by_name (argv[0]);
10782 if (bgp == NULL)
10783 {
10784 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10785 return CMD_WARNING;
10786 }
10787 }
10788 else
10789 {
10790 bgp = bgp_get_default ();
10791 if (bgp == NULL)
10792 {
10793 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10794 return CMD_WARNING;
10795 }
10796 }
10797
10798 if (argc == 3)
10799 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10800 else
10801 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10802
10803 if (! peer)
10804 return CMD_WARNING;
10805
10806 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10807 {
10808 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10809 VTY_NEWLINE);
10810 return CMD_WARNING;
10811 }
10812
10813 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10814 PEER_FLAG_RSERVER_CLIENT))
10815 {
10816 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10817 VTY_NEWLINE);
10818 return CMD_WARNING;
10819 }
10820
10821 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10822 (argc == 3) ? argv[2] : argv[1],
10823 AFI_IP6, SAFI_UNICAST, NULL, 1);
10824}
10825
10826ALIAS (show_bgp_view_rsclient_prefix,
10827 show_bgp_rsclient_prefix_cmd,
10828 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10829 SHOW_STR
10830 BGP_STR
10831 "Information about Route Server Client\n"
10832 NEIGHBOR_ADDR_STR
10833 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10834
paul718e3742002-12-13 20:15:29 +000010835#endif /* HAVE_IPV6 */
10836
10837struct bgp_table *bgp_distance_table;
10838
10839struct bgp_distance
10840{
10841 /* Distance value for the IP source prefix. */
10842 u_char distance;
10843
10844 /* Name of the access-list to be matched. */
10845 char *access_list;
10846};
10847
paul94f2b392005-06-28 12:44:16 +000010848static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010849bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010850{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010851 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010852}
10853
paul94f2b392005-06-28 12:44:16 +000010854static void
paul718e3742002-12-13 20:15:29 +000010855bgp_distance_free (struct bgp_distance *bdistance)
10856{
10857 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10858}
10859
paul94f2b392005-06-28 12:44:16 +000010860static int
paulfd79ac92004-10-13 05:06:08 +000010861bgp_distance_set (struct vty *vty, const char *distance_str,
10862 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010863{
10864 int ret;
10865 struct prefix_ipv4 p;
10866 u_char distance;
10867 struct bgp_node *rn;
10868 struct bgp_distance *bdistance;
10869
10870 ret = str2prefix_ipv4 (ip_str, &p);
10871 if (ret == 0)
10872 {
10873 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10874 return CMD_WARNING;
10875 }
10876
10877 distance = atoi (distance_str);
10878
10879 /* Get BGP distance node. */
10880 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10881 if (rn->info)
10882 {
10883 bdistance = rn->info;
10884 bgp_unlock_node (rn);
10885 }
10886 else
10887 {
10888 bdistance = bgp_distance_new ();
10889 rn->info = bdistance;
10890 }
10891
10892 /* Set distance value. */
10893 bdistance->distance = distance;
10894
10895 /* Reset access-list configuration. */
10896 if (bdistance->access_list)
10897 {
10898 free (bdistance->access_list);
10899 bdistance->access_list = NULL;
10900 }
10901 if (access_list_str)
10902 bdistance->access_list = strdup (access_list_str);
10903
10904 return CMD_SUCCESS;
10905}
10906
paul94f2b392005-06-28 12:44:16 +000010907static int
paulfd79ac92004-10-13 05:06:08 +000010908bgp_distance_unset (struct vty *vty, const char *distance_str,
10909 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010910{
10911 int ret;
10912 struct prefix_ipv4 p;
10913 u_char distance;
10914 struct bgp_node *rn;
10915 struct bgp_distance *bdistance;
10916
10917 ret = str2prefix_ipv4 (ip_str, &p);
10918 if (ret == 0)
10919 {
10920 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10921 return CMD_WARNING;
10922 }
10923
10924 distance = atoi (distance_str);
10925
10926 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10927 if (! rn)
10928 {
10929 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10930 return CMD_WARNING;
10931 }
10932
10933 bdistance = rn->info;
10934
10935 if (bdistance->access_list)
10936 free (bdistance->access_list);
10937 bgp_distance_free (bdistance);
10938
10939 rn->info = NULL;
10940 bgp_unlock_node (rn);
10941 bgp_unlock_node (rn);
10942
10943 return CMD_SUCCESS;
10944}
10945
paul94f2b392005-06-28 12:44:16 +000010946static void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010947bgp_distance_reset (void)
paul718e3742002-12-13 20:15:29 +000010948{
10949 struct bgp_node *rn;
10950 struct bgp_distance *bdistance;
10951
10952 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10953 if ((bdistance = rn->info) != NULL)
10954 {
10955 if (bdistance->access_list)
10956 free (bdistance->access_list);
10957 bgp_distance_free (bdistance);
10958 rn->info = NULL;
10959 bgp_unlock_node (rn);
10960 }
10961}
10962
10963/* Apply BGP information to distance method. */
10964u_char
10965bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10966{
10967 struct bgp_node *rn;
10968 struct prefix_ipv4 q;
10969 struct peer *peer;
10970 struct bgp_distance *bdistance;
10971 struct access_list *alist;
10972 struct bgp_static *bgp_static;
10973
10974 if (! bgp)
10975 return 0;
10976
10977 if (p->family != AF_INET)
10978 return 0;
10979
10980 peer = rinfo->peer;
10981
10982 if (peer->su.sa.sa_family != AF_INET)
10983 return 0;
10984
10985 memset (&q, 0, sizeof (struct prefix_ipv4));
10986 q.family = AF_INET;
10987 q.prefix = peer->su.sin.sin_addr;
10988 q.prefixlen = IPV4_MAX_BITLEN;
10989
10990 /* Check source address. */
10991 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10992 if (rn)
10993 {
10994 bdistance = rn->info;
10995 bgp_unlock_node (rn);
10996
10997 if (bdistance->access_list)
10998 {
10999 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11000 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11001 return bdistance->distance;
11002 }
11003 else
11004 return bdistance->distance;
11005 }
11006
11007 /* Backdoor check. */
11008 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11009 if (rn)
11010 {
11011 bgp_static = rn->info;
11012 bgp_unlock_node (rn);
11013
11014 if (bgp_static->backdoor)
11015 {
11016 if (bgp->distance_local)
11017 return bgp->distance_local;
11018 else
11019 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11020 }
11021 }
11022
11023 if (peer_sort (peer) == BGP_PEER_EBGP)
11024 {
11025 if (bgp->distance_ebgp)
11026 return bgp->distance_ebgp;
11027 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11028 }
11029 else
11030 {
11031 if (bgp->distance_ibgp)
11032 return bgp->distance_ibgp;
11033 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11034 }
11035}
11036
11037DEFUN (bgp_distance,
11038 bgp_distance_cmd,
11039 "distance bgp <1-255> <1-255> <1-255>",
11040 "Define an administrative distance\n"
11041 "BGP distance\n"
11042 "Distance for routes external to the AS\n"
11043 "Distance for routes internal to the AS\n"
11044 "Distance for local routes\n")
11045{
11046 struct bgp *bgp;
11047
11048 bgp = vty->index;
11049
11050 bgp->distance_ebgp = atoi (argv[0]);
11051 bgp->distance_ibgp = atoi (argv[1]);
11052 bgp->distance_local = atoi (argv[2]);
11053 return CMD_SUCCESS;
11054}
11055
11056DEFUN (no_bgp_distance,
11057 no_bgp_distance_cmd,
11058 "no distance bgp <1-255> <1-255> <1-255>",
11059 NO_STR
11060 "Define an administrative distance\n"
11061 "BGP distance\n"
11062 "Distance for routes external to the AS\n"
11063 "Distance for routes internal to the AS\n"
11064 "Distance for local routes\n")
11065{
11066 struct bgp *bgp;
11067
11068 bgp = vty->index;
11069
11070 bgp->distance_ebgp= 0;
11071 bgp->distance_ibgp = 0;
11072 bgp->distance_local = 0;
11073 return CMD_SUCCESS;
11074}
11075
11076ALIAS (no_bgp_distance,
11077 no_bgp_distance2_cmd,
11078 "no distance bgp",
11079 NO_STR
11080 "Define an administrative distance\n"
11081 "BGP distance\n")
11082
11083DEFUN (bgp_distance_source,
11084 bgp_distance_source_cmd,
11085 "distance <1-255> A.B.C.D/M",
11086 "Define an administrative distance\n"
11087 "Administrative distance\n"
11088 "IP source prefix\n")
11089{
11090 bgp_distance_set (vty, argv[0], argv[1], NULL);
11091 return CMD_SUCCESS;
11092}
11093
11094DEFUN (no_bgp_distance_source,
11095 no_bgp_distance_source_cmd,
11096 "no distance <1-255> A.B.C.D/M",
11097 NO_STR
11098 "Define an administrative distance\n"
11099 "Administrative distance\n"
11100 "IP source prefix\n")
11101{
11102 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11103 return CMD_SUCCESS;
11104}
11105
11106DEFUN (bgp_distance_source_access_list,
11107 bgp_distance_source_access_list_cmd,
11108 "distance <1-255> A.B.C.D/M WORD",
11109 "Define an administrative distance\n"
11110 "Administrative distance\n"
11111 "IP source prefix\n"
11112 "Access list name\n")
11113{
11114 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11115 return CMD_SUCCESS;
11116}
11117
11118DEFUN (no_bgp_distance_source_access_list,
11119 no_bgp_distance_source_access_list_cmd,
11120 "no distance <1-255> A.B.C.D/M WORD",
11121 NO_STR
11122 "Define an administrative distance\n"
11123 "Administrative distance\n"
11124 "IP source prefix\n"
11125 "Access list name\n")
11126{
11127 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11128 return CMD_SUCCESS;
11129}
11130
11131DEFUN (bgp_damp_set,
11132 bgp_damp_set_cmd,
11133 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11134 "BGP Specific commands\n"
11135 "Enable route-flap dampening\n"
11136 "Half-life time for the penalty\n"
11137 "Value to start reusing a route\n"
11138 "Value to start suppressing a route\n"
11139 "Maximum duration to suppress a stable route\n")
11140{
11141 struct bgp *bgp;
11142 int half = DEFAULT_HALF_LIFE * 60;
11143 int reuse = DEFAULT_REUSE;
11144 int suppress = DEFAULT_SUPPRESS;
11145 int max = 4 * half;
11146
11147 if (argc == 4)
11148 {
11149 half = atoi (argv[0]) * 60;
11150 reuse = atoi (argv[1]);
11151 suppress = atoi (argv[2]);
11152 max = atoi (argv[3]) * 60;
11153 }
11154 else if (argc == 1)
11155 {
11156 half = atoi (argv[0]) * 60;
11157 max = 4 * half;
11158 }
11159
11160 bgp = vty->index;
11161 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11162 half, reuse, suppress, max);
11163}
11164
11165ALIAS (bgp_damp_set,
11166 bgp_damp_set2_cmd,
11167 "bgp dampening <1-45>",
11168 "BGP Specific commands\n"
11169 "Enable route-flap dampening\n"
11170 "Half-life time for the penalty\n")
11171
11172ALIAS (bgp_damp_set,
11173 bgp_damp_set3_cmd,
11174 "bgp dampening",
11175 "BGP Specific commands\n"
11176 "Enable route-flap dampening\n")
11177
11178DEFUN (bgp_damp_unset,
11179 bgp_damp_unset_cmd,
11180 "no bgp dampening",
11181 NO_STR
11182 "BGP Specific commands\n"
11183 "Enable route-flap dampening\n")
11184{
11185 struct bgp *bgp;
11186
11187 bgp = vty->index;
11188 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11189}
11190
11191ALIAS (bgp_damp_unset,
11192 bgp_damp_unset2_cmd,
11193 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11194 NO_STR
11195 "BGP Specific commands\n"
11196 "Enable route-flap dampening\n"
11197 "Half-life time for the penalty\n"
11198 "Value to start reusing a route\n"
11199 "Value to start suppressing a route\n"
11200 "Maximum duration to suppress a stable route\n")
11201
11202DEFUN (show_ip_bgp_dampened_paths,
11203 show_ip_bgp_dampened_paths_cmd,
11204 "show ip bgp dampened-paths",
11205 SHOW_STR
11206 IP_STR
11207 BGP_STR
11208 "Display paths suppressed due to dampening\n")
11209{
ajs5a646652004-11-05 01:25:55 +000011210 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11211 NULL);
paul718e3742002-12-13 20:15:29 +000011212}
11213
11214DEFUN (show_ip_bgp_flap_statistics,
11215 show_ip_bgp_flap_statistics_cmd,
11216 "show ip bgp flap-statistics",
11217 SHOW_STR
11218 IP_STR
11219 BGP_STR
11220 "Display flap statistics of routes\n")
11221{
ajs5a646652004-11-05 01:25:55 +000011222 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11223 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011224}
11225
11226/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011227static int
paulfd79ac92004-10-13 05:06:08 +000011228bgp_clear_damp_route (struct vty *vty, const char *view_name,
11229 const char *ip_str, afi_t afi, safi_t safi,
11230 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011231{
11232 int ret;
11233 struct prefix match;
11234 struct bgp_node *rn;
11235 struct bgp_node *rm;
11236 struct bgp_info *ri;
11237 struct bgp_info *ri_temp;
11238 struct bgp *bgp;
11239 struct bgp_table *table;
11240
11241 /* BGP structure lookup. */
11242 if (view_name)
11243 {
11244 bgp = bgp_lookup_by_name (view_name);
11245 if (bgp == NULL)
11246 {
11247 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11248 return CMD_WARNING;
11249 }
11250 }
11251 else
11252 {
11253 bgp = bgp_get_default ();
11254 if (bgp == NULL)
11255 {
11256 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11257 return CMD_WARNING;
11258 }
11259 }
11260
11261 /* Check IP address argument. */
11262 ret = str2prefix (ip_str, &match);
11263 if (! ret)
11264 {
11265 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11266 return CMD_WARNING;
11267 }
11268
11269 match.family = afi2family (afi);
11270
11271 if (safi == SAFI_MPLS_VPN)
11272 {
11273 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11274 {
11275 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11276 continue;
11277
11278 if ((table = rn->info) != NULL)
11279 if ((rm = bgp_node_match (table, &match)) != NULL)
11280 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11281 {
11282 ri = rm->info;
11283 while (ri)
11284 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011285 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011286 {
11287 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011288 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011289 ri = ri_temp;
11290 }
11291 else
11292 ri = ri->next;
11293 }
11294 }
11295 }
11296 }
11297 else
11298 {
11299 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11300 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11301 {
11302 ri = rn->info;
11303 while (ri)
11304 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011305 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011306 {
11307 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011308 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011309 ri = ri_temp;
11310 }
11311 else
11312 ri = ri->next;
11313 }
11314 }
11315 }
11316
11317 return CMD_SUCCESS;
11318}
11319
11320DEFUN (clear_ip_bgp_dampening,
11321 clear_ip_bgp_dampening_cmd,
11322 "clear ip bgp dampening",
11323 CLEAR_STR
11324 IP_STR
11325 BGP_STR
11326 "Clear route flap dampening information\n")
11327{
11328 bgp_damp_info_clean ();
11329 return CMD_SUCCESS;
11330}
11331
11332DEFUN (clear_ip_bgp_dampening_prefix,
11333 clear_ip_bgp_dampening_prefix_cmd,
11334 "clear ip bgp dampening A.B.C.D/M",
11335 CLEAR_STR
11336 IP_STR
11337 BGP_STR
11338 "Clear route flap dampening information\n"
11339 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11340{
11341 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11342 SAFI_UNICAST, NULL, 1);
11343}
11344
11345DEFUN (clear_ip_bgp_dampening_address,
11346 clear_ip_bgp_dampening_address_cmd,
11347 "clear ip bgp dampening A.B.C.D",
11348 CLEAR_STR
11349 IP_STR
11350 BGP_STR
11351 "Clear route flap dampening information\n"
11352 "Network to clear damping information\n")
11353{
11354 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11355 SAFI_UNICAST, NULL, 0);
11356}
11357
11358DEFUN (clear_ip_bgp_dampening_address_mask,
11359 clear_ip_bgp_dampening_address_mask_cmd,
11360 "clear ip bgp dampening A.B.C.D A.B.C.D",
11361 CLEAR_STR
11362 IP_STR
11363 BGP_STR
11364 "Clear route flap dampening information\n"
11365 "Network to clear damping information\n"
11366 "Network mask\n")
11367{
11368 int ret;
11369 char prefix_str[BUFSIZ];
11370
11371 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11372 if (! ret)
11373 {
11374 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11375 return CMD_WARNING;
11376 }
11377
11378 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11379 SAFI_UNICAST, NULL, 0);
11380}
11381
paul94f2b392005-06-28 12:44:16 +000011382static int
paul718e3742002-12-13 20:15:29 +000011383bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11384 afi_t afi, safi_t safi, int *write)
11385{
11386 struct bgp_node *prn;
11387 struct bgp_node *rn;
11388 struct bgp_table *table;
11389 struct prefix *p;
11390 struct prefix_rd *prd;
11391 struct bgp_static *bgp_static;
11392 u_int32_t label;
11393 char buf[SU_ADDRSTRLEN];
11394 char rdbuf[RD_ADDRSTRLEN];
11395
11396 /* Network configuration. */
11397 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11398 if ((table = prn->info) != NULL)
11399 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11400 if ((bgp_static = rn->info) != NULL)
11401 {
11402 p = &rn->p;
11403 prd = (struct prefix_rd *) &prn->p;
11404
11405 /* "address-family" display. */
11406 bgp_config_write_family_header (vty, afi, safi, write);
11407
11408 /* "network" configuration display. */
11409 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11410 label = decode_label (bgp_static->tag);
11411
11412 vty_out (vty, " network %s/%d rd %s tag %d",
11413 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11414 p->prefixlen,
11415 rdbuf, label);
11416 vty_out (vty, "%s", VTY_NEWLINE);
11417 }
11418 return 0;
11419}
11420
11421/* Configuration of static route announcement and aggregate
11422 information. */
11423int
11424bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11425 afi_t afi, safi_t safi, int *write)
11426{
11427 struct bgp_node *rn;
11428 struct prefix *p;
11429 struct bgp_static *bgp_static;
11430 struct bgp_aggregate *bgp_aggregate;
11431 char buf[SU_ADDRSTRLEN];
11432
11433 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11434 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11435
11436 /* Network configuration. */
11437 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11438 if ((bgp_static = rn->info) != NULL)
11439 {
11440 p = &rn->p;
11441
11442 /* "address-family" display. */
11443 bgp_config_write_family_header (vty, afi, safi, write);
11444
11445 /* "network" configuration display. */
11446 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11447 {
11448 u_int32_t destination;
11449 struct in_addr netmask;
11450
11451 destination = ntohl (p->u.prefix4.s_addr);
11452 masklen2ip (p->prefixlen, &netmask);
11453 vty_out (vty, " network %s",
11454 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11455
11456 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11457 || (IN_CLASSB (destination) && p->prefixlen == 16)
11458 || (IN_CLASSA (destination) && p->prefixlen == 8)
11459 || p->u.prefix4.s_addr == 0)
11460 {
11461 /* Natural mask is not display. */
11462 }
11463 else
11464 vty_out (vty, " mask %s", inet_ntoa (netmask));
11465 }
11466 else
11467 {
11468 vty_out (vty, " network %s/%d",
11469 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11470 p->prefixlen);
11471 }
11472
11473 if (bgp_static->rmap.name)
11474 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011475 else
11476 {
11477 if (bgp_static->backdoor)
11478 vty_out (vty, " backdoor");
11479 if (bgp_static->ttl)
11480 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11481 }
paul718e3742002-12-13 20:15:29 +000011482
11483 vty_out (vty, "%s", VTY_NEWLINE);
11484 }
11485
11486 /* Aggregate-address configuration. */
11487 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11488 if ((bgp_aggregate = rn->info) != NULL)
11489 {
11490 p = &rn->p;
11491
11492 /* "address-family" display. */
11493 bgp_config_write_family_header (vty, afi, safi, write);
11494
11495 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11496 {
11497 struct in_addr netmask;
11498
11499 masklen2ip (p->prefixlen, &netmask);
11500 vty_out (vty, " aggregate-address %s %s",
11501 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11502 inet_ntoa (netmask));
11503 }
11504 else
11505 {
11506 vty_out (vty, " aggregate-address %s/%d",
11507 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11508 p->prefixlen);
11509 }
11510
11511 if (bgp_aggregate->as_set)
11512 vty_out (vty, " as-set");
11513
11514 if (bgp_aggregate->summary_only)
11515 vty_out (vty, " summary-only");
11516
11517 vty_out (vty, "%s", VTY_NEWLINE);
11518 }
11519
11520 return 0;
11521}
11522
11523int
11524bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11525{
11526 struct bgp_node *rn;
11527 struct bgp_distance *bdistance;
11528
11529 /* Distance configuration. */
11530 if (bgp->distance_ebgp
11531 && bgp->distance_ibgp
11532 && bgp->distance_local
11533 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11534 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11535 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11536 vty_out (vty, " distance bgp %d %d %d%s",
11537 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11538 VTY_NEWLINE);
11539
11540 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11541 if ((bdistance = rn->info) != NULL)
11542 {
11543 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11544 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11545 bdistance->access_list ? bdistance->access_list : "",
11546 VTY_NEWLINE);
11547 }
11548
11549 return 0;
11550}
11551
11552/* Allocate routing table structure and install commands. */
11553void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011554bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011555{
11556 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011557 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011558
11559 /* IPv4 BGP commands. */
11560 install_element (BGP_NODE, &bgp_network_cmd);
11561 install_element (BGP_NODE, &bgp_network_mask_cmd);
11562 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11563 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11564 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11565 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11566 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11567 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11568 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011569 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11570 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11571 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11572 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11573 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11574 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011575 install_element (BGP_NODE, &no_bgp_network_cmd);
11576 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11577 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11578 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11579 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11580 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11581 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11582 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11583 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011584 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11585 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11586 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11587 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11588 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11589 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011590
11591 install_element (BGP_NODE, &aggregate_address_cmd);
11592 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11593 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11594 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11595 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11596 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11597 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11598 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11599 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11600 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11601 install_element (BGP_NODE, &no_aggregate_address_cmd);
11602 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11603 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11604 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11605 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11606 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11607 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11608 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11609 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11610 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11611
11612 /* IPv4 unicast configuration. */
11613 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11614 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11615 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11616 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11617 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11618 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011619 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11620 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11621 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11622 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11623 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11624 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011625 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11626 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11627 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11628 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11629 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011630 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11631 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11632 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11633 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11634 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11635 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011636 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11637 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11638 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11639 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11640 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11641 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11642 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11643 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11644 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11645 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11646 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11647 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11648 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11649 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11650 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11651 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11652 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11653 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11654 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11655 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11656
11657 /* IPv4 multicast configuration. */
11658 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11659 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11660 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11661 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11662 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11663 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011664 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11665 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11666 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11667 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11668 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11669 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011670 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11671 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11672 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11673 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11674 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11675 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011676 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11677 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11678 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11679 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11680 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11681 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011682 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11683 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11684 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11685 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11686 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11687 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11688 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11689 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11690 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11691 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11692 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11693 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11694 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11695 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11696 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11697 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11698 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11699 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11700 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11701 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11702
11703 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11704 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11705 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11706 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11707 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11708 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11709 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11710 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11711 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11712 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11713 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11714 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11715 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11716 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11717 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11718 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11719 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11720 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11721 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11722 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11723 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11724 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11725 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11726 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11727 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11728 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11729 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11730 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11731 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11732 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11733 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11734 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11735 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11736 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11737 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11738 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11739 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11740 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11741 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11742 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11743 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11744 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11745 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11746 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11747 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11748 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11749 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11750 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11751 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11752 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11753 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11754 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11755 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11756 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11757 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11758 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11759 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11760 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11761 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11762 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11763 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11764 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11765 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11766 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11767 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11768 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11769 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011770 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11771 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11772 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11773 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11774 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11775 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011776
11777 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11778 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11779 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11780 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11781 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11782 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11783 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11784 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11785 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11786 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11787 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11788 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11789 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11790 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11791 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11792 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11793 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11794 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11795 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11796 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11797 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11798 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11799 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11800 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11801 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11802 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11803 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11804 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11805 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11806 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011807
11808 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11809 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11810 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11811 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11812 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11813 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11814 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11815 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11816 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11817 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11818 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11819 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11820 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11821 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11822 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11823 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11824 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11825 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11826 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11827 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11828 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11829 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11830 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11831 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11832 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11833 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11834 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11835 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11836 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11837 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11838 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11839 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11840 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11841 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11842 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11843 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11844 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11845 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11846 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11847 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11848 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11849 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11850 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11851 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11852 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11853 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11854 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11855 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11856 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11857 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11858 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11859 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11860 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11861 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11862 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11863 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11864 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11865 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11866 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11867 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11868 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11869 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11870 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11871 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11872 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11873 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11874 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011875 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11876 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11877 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11878 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11879 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11880 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011881
11882 /* BGP dampening clear commands */
11883 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11884 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11885 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11886 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11887
Paul Jakmaff7924f2006-09-04 01:10:36 +000011888 /* prefix count */
11889 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11890 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11891 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011892#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011893 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11894
paul718e3742002-12-13 20:15:29 +000011895 /* New config IPv6 BGP commands. */
11896 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11897 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011898 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011899 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11900 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011901 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011902
11903 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11904 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11905 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11906 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11907
11908 /* Old config IPv6 BGP commands. */
11909 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11910 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11911
11912 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11913 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11914 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11915 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11916
11917 install_element (VIEW_NODE, &show_bgp_cmd);
11918 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11919 install_element (VIEW_NODE, &show_bgp_route_cmd);
11920 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11921 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11922 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11923 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11924 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11925 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11926 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11927 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11928 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11929 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11930 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11931 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11932 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11933 install_element (VIEW_NODE, &show_bgp_community_cmd);
11934 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11935 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11936 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11937 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11938 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11939 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11940 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11941 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11942 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11943 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11944 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11945 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11946 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11947 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11948 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11949 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11950 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11951 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11952 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11953 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11954 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11955 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11956 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11957 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11958 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11959 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11960 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11961 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11962 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011963 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11964 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11965 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11966 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011967 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11968 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11969 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011970 install_element (VIEW_NODE, &show_bgp_view_cmd);
11971 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11972 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11973 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11974 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11975 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11976 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11977 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11978 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11979 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11980 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11981 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11982 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11983 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11984 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11985 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11986 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11987 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011988 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11989 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11990 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011991
11992 /* Restricted:
11993 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
11994 */
11995 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
11996 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
11997 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
11998 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
11999 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12000 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12001 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12002 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12003 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12004 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12005 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12006 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12007 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12008 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12009 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12010 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12011 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12012 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12013 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12014 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12015 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
12016 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
12017 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12018 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12019 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12020 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12021 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12022 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12023 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
12024 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012025
12026 install_element (ENABLE_NODE, &show_bgp_cmd);
12027 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
12028 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12029 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
12030 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12031 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
12032 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12033 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12034 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12035 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12036 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12037 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12038 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12039 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12040 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12041 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12042 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12043 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12044 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12045 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12046 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12047 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12048 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12049 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12050 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12051 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12052 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12053 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12054 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12055 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12056 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12057 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12058 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12059 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12060 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12061 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12062 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12063 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12064 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12065 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12066 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12067 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12068 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12069 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12070 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12071 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012072 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12073 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12074 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12075 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012076 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12077 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12078 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012079 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12080 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12081 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12082 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12083 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12084 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12085 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12086 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12087 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12088 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12089 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12090 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12091 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12092 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12093 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12094 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12095 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12096 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012097 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12098 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12099 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012100
12101 /* Statistics */
12102 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12103 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12104 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12105 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12106
paul718e3742002-12-13 20:15:29 +000012107 /* old command */
12108 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12109 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12110 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12111 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12112 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12113 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12114 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12115 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12116 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12117 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12118 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12119 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12120 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12121 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12122 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12123 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12124 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12125 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12126 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12127 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12128 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12129 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12130 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12131 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12132 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12133 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12134 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12135 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12136 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12137 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12138 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12139 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12140 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12141 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12142 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12143 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012144
paul718e3742002-12-13 20:15:29 +000012145 /* old command */
12146 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12147 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12148 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12149 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12150 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12151 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12152 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12153 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12154 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12155 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12156 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12157 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12158 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12159 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12160 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12161 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12162 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12163 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12164 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12165 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12166 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12167 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12168 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12169 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12170 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12171 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12172 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12173 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12174 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12175 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12176 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12177 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12178 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12179 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12180 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12181 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12182
12183 /* old command */
12184 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12185 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12186 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12187 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12188
12189 /* old command */
12190 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12191 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12192 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12193 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12194
12195 /* old command */
12196 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12197 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12198 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12199 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12200#endif /* HAVE_IPV6 */
12201
12202 install_element (BGP_NODE, &bgp_distance_cmd);
12203 install_element (BGP_NODE, &no_bgp_distance_cmd);
12204 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12205 install_element (BGP_NODE, &bgp_distance_source_cmd);
12206 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12207 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12208 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12209
12210 install_element (BGP_NODE, &bgp_damp_set_cmd);
12211 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12212 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12213 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12214 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12215 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12216 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12217 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12218 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12219 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12220}