blob: 4f3f85b329bf7cc50cf99c2cb54f199296169b41 [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 */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070059extern const char *bgp_origin_str[];
60extern const char *bgp_origin_long_str[];
paul718e3742002-12-13 20:15:29 +000061
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
Stephen Hemminger0088b5d2009-05-21 08:51:03 -07001565 bgp_unlock(pq->bgp);
paul200df112005-06-01 11:17:05 +00001566 bgp_unlock_node (pq->rn);
1567 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1568}
1569
1570static void
1571bgp_process_queue_init (void)
1572{
1573 bm->process_main_queue
1574 = work_queue_new (bm->master, "process_main_queue");
1575 bm->process_rsclient_queue
1576 = work_queue_new (bm->master, "process_rsclient_queue");
1577
1578 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1579 {
1580 zlog_err ("%s: Failed to allocate work queue", __func__);
1581 exit (1);
1582 }
1583
1584 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1585 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1586 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1587 bm->process_rsclient_queue->spec.del_item_data
1588 = bm->process_main_queue->spec.del_item_data;
1589 bm->process_main_queue->spec.max_retries
1590 = bm->process_main_queue->spec.max_retries = 0;
1591 bm->process_rsclient_queue->spec.hold
Paul Jakma09dd5612006-09-14 03:38:16 +00001592 = bm->process_main_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001593}
1594
1595void
paulfee0f4c2004-09-13 05:12:46 +00001596bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1597{
paul200df112005-06-01 11:17:05 +00001598 struct bgp_process_queue *pqnode;
1599
1600 /* already scheduled for processing? */
1601 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1602 return;
1603
1604 if ( (bm->process_main_queue == NULL) ||
1605 (bm->process_rsclient_queue == NULL) )
1606 bgp_process_queue_init ();
1607
1608 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1609 sizeof (struct bgp_process_queue));
1610 if (!pqnode)
1611 return;
1612
1613 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1614 pqnode->bgp = bgp;
Stephen Hemminger0088b5d2009-05-21 08:51:03 -07001615 bgp_lock(bgp);
paul200df112005-06-01 11:17:05 +00001616 pqnode->afi = afi;
1617 pqnode->safi = safi;
1618
paulfee0f4c2004-09-13 05:12:46 +00001619 switch (rn->table->type)
1620 {
paul200df112005-06-01 11:17:05 +00001621 case BGP_TABLE_MAIN:
1622 work_queue_add (bm->process_main_queue, pqnode);
1623 break;
1624 case BGP_TABLE_RSCLIENT:
1625 work_queue_add (bm->process_rsclient_queue, pqnode);
1626 break;
paulfee0f4c2004-09-13 05:12:46 +00001627 }
paul200df112005-06-01 11:17:05 +00001628
1629 return;
paulfee0f4c2004-09-13 05:12:46 +00001630}
hasso0a486e52005-02-01 20:57:17 +00001631
paul94f2b392005-06-28 12:44:16 +00001632static int
hasso0a486e52005-02-01 20:57:17 +00001633bgp_maximum_prefix_restart_timer (struct thread *thread)
1634{
1635 struct peer *peer;
1636
1637 peer = THREAD_ARG (thread);
1638 peer->t_pmax_restart = NULL;
1639
1640 if (BGP_DEBUG (events, EVENTS))
1641 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1642 peer->host);
1643
1644 peer_clear (peer);
1645
1646 return 0;
1647}
1648
paulfee0f4c2004-09-13 05:12:46 +00001649int
paul5228ad22004-06-04 17:58:18 +00001650bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1651 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001652{
hassoe0701b72004-05-20 09:19:34 +00001653 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1654 return 0;
1655
1656 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001657 {
hassoe0701b72004-05-20 09:19:34 +00001658 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1659 && ! always)
1660 return 0;
paul718e3742002-12-13 20:15:29 +00001661
hassoe0701b72004-05-20 09:19:34 +00001662 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001663 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1664 "limit %ld", afi_safi_print (afi, safi), peer->host,
1665 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001666 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001667
hassoe0701b72004-05-20 09:19:34 +00001668 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1669 return 0;
paul718e3742002-12-13 20:15:29 +00001670
hassoe0701b72004-05-20 09:19:34 +00001671 {
paul5228ad22004-06-04 17:58:18 +00001672 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001673
1674 if (safi == SAFI_MPLS_VPN)
1675 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001676
1677 ndata[0] = (afi >> 8);
1678 ndata[1] = afi;
1679 ndata[2] = safi;
1680 ndata[3] = (peer->pmax[afi][safi] >> 24);
1681 ndata[4] = (peer->pmax[afi][safi] >> 16);
1682 ndata[5] = (peer->pmax[afi][safi] >> 8);
1683 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001684
1685 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1686 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1687 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1688 }
hasso0a486e52005-02-01 20:57:17 +00001689
1690 /* restart timer start */
1691 if (peer->pmax_restart[afi][safi])
1692 {
1693 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1694
1695 if (BGP_DEBUG (events, EVENTS))
1696 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1697 peer->host, peer->v_pmax_restart);
1698
1699 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1700 peer->v_pmax_restart);
1701 }
1702
hassoe0701b72004-05-20 09:19:34 +00001703 return 1;
paul718e3742002-12-13 20:15:29 +00001704 }
hassoe0701b72004-05-20 09:19:34 +00001705 else
1706 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1707
1708 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1709 {
1710 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1711 && ! always)
1712 return 0;
1713
1714 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001715 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1716 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1717 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001718 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1719 }
1720 else
1721 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001722 return 0;
1723}
1724
paulb40d9392005-08-22 22:34:41 +00001725/* Unconditionally remove the route from the RIB, without taking
1726 * damping into consideration (eg, because the session went down)
1727 */
paul94f2b392005-06-28 12:44:16 +00001728static void
paul718e3742002-12-13 20:15:29 +00001729bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1730 afi_t afi, safi_t safi)
1731{
paul902212c2006-02-05 17:51:19 +00001732 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1733
1734 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1735 bgp_info_delete (rn, ri); /* keep historical info */
1736
paulb40d9392005-08-22 22:34:41 +00001737 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001738}
1739
paul94f2b392005-06-28 12:44:16 +00001740static void
paul718e3742002-12-13 20:15:29 +00001741bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001742 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001743{
paul718e3742002-12-13 20:15:29 +00001744 int status = BGP_DAMP_NONE;
1745
paulb40d9392005-08-22 22:34:41 +00001746 /* apply dampening, if result is suppressed, we'll be retaining
1747 * the bgp_info in the RIB for historical reference.
1748 */
1749 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1750 && peer_sort (peer) == BGP_PEER_EBGP)
1751 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1752 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001753 {
paul902212c2006-02-05 17:51:19 +00001754 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1755 return;
1756 }
1757
1758 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001759}
1760
paul94f2b392005-06-28 12:44:16 +00001761static void
paulfee0f4c2004-09-13 05:12:46 +00001762bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1763 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1764 int sub_type, struct prefix_rd *prd, u_char *tag)
1765{
1766 struct bgp_node *rn;
1767 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001768 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001769 struct attr *attr_new;
1770 struct attr *attr_new2;
1771 struct bgp_info *ri;
1772 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001773 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001774 char buf[SU_ADDRSTRLEN];
1775
Paul Jakmafb982c22007-05-04 20:15:47 +00001776 //memset (new_attr, 0, sizeof (struct attr));
1777
paulfee0f4c2004-09-13 05:12:46 +00001778 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1779 if (peer == rsclient)
1780 return;
1781
1782 bgp = peer->bgp;
1783 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1784
1785 /* Check previously received route. */
1786 for (ri = rn->info; ri; ri = ri->next)
1787 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1788 break;
1789
1790 /* AS path loop check. */
1791 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1792 {
1793 reason = "as-path contains our own AS;";
1794 goto filtered;
1795 }
1796
1797 /* Route reflector originator ID check. */
1798 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001799 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001800 {
1801 reason = "originator is us;";
1802 goto filtered;
1803 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001804
1805 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001806
1807 /* Apply export policy. */
1808 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1809 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1810 {
1811 reason = "export-policy;";
1812 goto filtered;
1813 }
1814
1815 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001816
paulfee0f4c2004-09-13 05:12:46 +00001817 /* Apply import policy. */
1818 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1819 {
1820 bgp_attr_unintern (attr_new2);
1821
1822 reason = "import-policy;";
1823 goto filtered;
1824 }
1825
1826 attr_new = bgp_attr_intern (&new_attr);
1827 bgp_attr_unintern (attr_new2);
1828
1829 /* IPv4 unicast next hop check. */
1830 if (afi == AFI_IP && safi == SAFI_UNICAST)
1831 {
1832 /* Next hop must not be 0.0.0.0 nor Class E address. */
1833 if (new_attr.nexthop.s_addr == 0
1834 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1835 {
1836 bgp_attr_unintern (attr_new);
1837
1838 reason = "martian next-hop;";
1839 goto filtered;
1840 }
1841 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001842
1843 /* new_attr isn't passed to any functions after here */
1844 bgp_attr_extra_free (&new_attr);
1845
paulfee0f4c2004-09-13 05:12:46 +00001846 /* If the update is implicit withdraw. */
1847 if (ri)
1848 {
1849 ri->uptime = time (NULL);
1850
1851 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001852 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1853 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001854 {
1855
Paul Jakma1a392d42006-09-07 00:24:49 +00001856 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001857
1858 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001859 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001860 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1861 peer->host,
1862 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1863 p->prefixlen, rsclient->host);
1864
1865 bgp_unlock_node (rn);
1866 bgp_attr_unintern (attr_new);
1867
1868 return;
1869 }
1870
Paul Jakma16d2e242007-04-10 19:32:10 +00001871 /* Withdraw/Announce before we fully processed the withdraw */
1872 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1873 bgp_info_restore (rn, ri);
1874
paulfee0f4c2004-09-13 05:12:46 +00001875 /* Received Logging. */
1876 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001877 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001878 peer->host,
1879 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1880 p->prefixlen, rsclient->host);
1881
1882 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001883 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001884
1885 /* Update to new attribute. */
1886 bgp_attr_unintern (ri->attr);
1887 ri->attr = attr_new;
1888
1889 /* Update MPLS tag. */
1890 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001891 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001892
Paul Jakma1a392d42006-09-07 00:24:49 +00001893 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001894
1895 /* Process change. */
1896 bgp_process (bgp, rn, afi, safi);
1897 bgp_unlock_node (rn);
1898
1899 return;
1900 }
1901
1902 /* Received Logging. */
1903 if (BGP_DEBUG (update, UPDATE_IN))
1904 {
ajsd2c1f162004-12-08 21:10:20 +00001905 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001906 peer->host,
1907 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1908 p->prefixlen, rsclient->host);
1909 }
1910
1911 /* Make new BGP info. */
1912 new = bgp_info_new ();
1913 new->type = type;
1914 new->sub_type = sub_type;
1915 new->peer = peer;
1916 new->attr = attr_new;
1917 new->uptime = time (NULL);
1918
1919 /* Update MPLS tag. */
1920 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001921 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001922
Paul Jakma1a392d42006-09-07 00:24:49 +00001923 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001924
1925 /* Register new BGP information. */
1926 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001927
1928 /* route_node_get lock */
1929 bgp_unlock_node (rn);
1930
paulfee0f4c2004-09-13 05:12:46 +00001931 /* Process change. */
1932 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001933
1934 bgp_attr_extra_free (&new_attr);
1935
paulfee0f4c2004-09-13 05:12:46 +00001936 return;
1937
1938 filtered:
1939
1940 /* This BGP update is filtered. Log the reason then update BGP entry. */
1941 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001942 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001943 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1944 peer->host,
1945 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1946 p->prefixlen, rsclient->host, reason);
1947
1948 if (ri)
paulb40d9392005-08-22 22:34:41 +00001949 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001950
1951 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001952
1953 if (new_attr.extra)
1954 bgp_attr_extra_free (&new_attr);
1955
paulfee0f4c2004-09-13 05:12:46 +00001956 return;
1957}
1958
paul94f2b392005-06-28 12:44:16 +00001959static void
paulfee0f4c2004-09-13 05:12:46 +00001960bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1961 struct peer *peer, struct prefix *p, int type, int sub_type,
1962 struct prefix_rd *prd, u_char *tag)
1963 {
1964 struct bgp_node *rn;
1965 struct bgp_info *ri;
1966 char buf[SU_ADDRSTRLEN];
1967
1968 if (rsclient == peer)
1969 return;
1970
1971 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1972
1973 /* Lookup withdrawn route. */
1974 for (ri = rn->info; ri; ri = ri->next)
1975 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1976 break;
1977
1978 /* Withdraw specified route from routing table. */
1979 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001980 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001981 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001982 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001983 "%s Can't find the route %s/%d", peer->host,
1984 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1985 p->prefixlen);
1986
1987 /* Unlock bgp_node_get() lock. */
1988 bgp_unlock_node (rn);
1989 }
1990
paul94f2b392005-06-28 12:44:16 +00001991static int
paulfee0f4c2004-09-13 05:12:46 +00001992bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001993 afi_t afi, safi_t safi, int type, int sub_type,
1994 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1995{
1996 int ret;
1997 int aspath_loop_count = 0;
1998 struct bgp_node *rn;
1999 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002000 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002001 struct attr *attr_new;
2002 struct bgp_info *ri;
2003 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002004 const char *reason;
paul718e3742002-12-13 20:15:29 +00002005 char buf[SU_ADDRSTRLEN];
2006
2007 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002008 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002009
paul718e3742002-12-13 20:15:29 +00002010 /* When peer's soft reconfiguration enabled. Record input packet in
2011 Adj-RIBs-In. */
2012 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2013 && peer != bgp->peer_self && ! soft_reconfig)
2014 bgp_adj_in_set (rn, peer, attr);
2015
2016 /* Check previously received route. */
2017 for (ri = rn->info; ri; ri = ri->next)
2018 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2019 break;
2020
2021 /* AS path local-as loop check. */
2022 if (peer->change_local_as)
2023 {
2024 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2025 aspath_loop_count = 1;
2026
2027 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2028 {
2029 reason = "as-path contains our own AS;";
2030 goto filtered;
2031 }
2032 }
2033
2034 /* AS path loop check. */
2035 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2036 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2037 && aspath_loop_check(attr->aspath, bgp->confed_id)
2038 > peer->allowas_in[afi][safi]))
2039 {
2040 reason = "as-path contains our own AS;";
2041 goto filtered;
2042 }
2043
2044 /* Route reflector originator ID check. */
2045 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002046 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002047 {
2048 reason = "originator is us;";
2049 goto filtered;
2050 }
2051
2052 /* Route reflector cluster ID check. */
2053 if (bgp_cluster_filter (peer, attr))
2054 {
2055 reason = "reflected from the same cluster;";
2056 goto filtered;
2057 }
2058
2059 /* Apply incoming filter. */
2060 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2061 {
2062 reason = "filter;";
2063 goto filtered;
2064 }
2065
2066 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002067 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002068
2069 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2070 {
2071 reason = "route-map;";
2072 goto filtered;
2073 }
2074
2075 /* IPv4 unicast next hop check. */
2076 if (afi == AFI_IP && safi == SAFI_UNICAST)
2077 {
2078 /* If the peer is EBGP and nexthop is not on connected route,
2079 discard it. */
2080 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2081 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002082 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002083 {
2084 reason = "non-connected next-hop;";
2085 goto filtered;
2086 }
2087
2088 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2089 must not be my own address. */
2090 if (bgp_nexthop_self (afi, &new_attr)
2091 || new_attr.nexthop.s_addr == 0
2092 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2093 {
2094 reason = "martian next-hop;";
2095 goto filtered;
2096 }
2097 }
2098
2099 attr_new = bgp_attr_intern (&new_attr);
2100
2101 /* If the update is implicit withdraw. */
2102 if (ri)
2103 {
2104 ri->uptime = time (NULL);
2105
2106 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002107 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2108 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002109 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002110 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002111
2112 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2113 && peer_sort (peer) == BGP_PEER_EBGP
2114 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2115 {
2116 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002117 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002118 peer->host,
2119 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2120 p->prefixlen);
2121
paul902212c2006-02-05 17:51:19 +00002122 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2123 {
2124 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2125 bgp_process (bgp, rn, afi, safi);
2126 }
paul718e3742002-12-13 20:15:29 +00002127 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002128 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002129 {
2130 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002131 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002132 "%s rcvd %s/%d...duplicate ignored",
2133 peer->host,
2134 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2135 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002136
2137 /* graceful restart STALE flag unset. */
2138 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2139 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002140 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002141 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002142 }
paul718e3742002-12-13 20:15:29 +00002143 }
2144
2145 bgp_unlock_node (rn);
2146 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002147 bgp_attr_extra_free (&new_attr);
2148
paul718e3742002-12-13 20:15:29 +00002149 return 0;
2150 }
2151
Paul Jakma16d2e242007-04-10 19:32:10 +00002152 /* Withdraw/Announce before we fully processed the withdraw */
2153 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2154 {
2155 if (BGP_DEBUG (update, UPDATE_IN))
2156 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2157 peer->host,
2158 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2159 p->prefixlen);
2160 bgp_info_restore (rn, ri);
2161 }
2162
paul718e3742002-12-13 20:15:29 +00002163 /* Received Logging. */
2164 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002165 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002166 peer->host,
2167 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2168 p->prefixlen);
2169
hasso93406d82005-02-02 14:40:33 +00002170 /* graceful restart STALE flag unset. */
2171 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002172 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002173
paul718e3742002-12-13 20:15:29 +00002174 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002175 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002176
2177 /* implicit withdraw, decrement aggregate and pcount here.
2178 * only if update is accepted, they'll increment below.
2179 */
paul902212c2006-02-05 17:51:19 +00002180 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2181
paul718e3742002-12-13 20:15:29 +00002182 /* Update bgp route dampening information. */
2183 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2184 && peer_sort (peer) == BGP_PEER_EBGP)
2185 {
2186 /* This is implicit withdraw so we should update dampening
2187 information. */
2188 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2189 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002190 }
2191
paul718e3742002-12-13 20:15:29 +00002192 /* Update to new attribute. */
2193 bgp_attr_unintern (ri->attr);
2194 ri->attr = attr_new;
2195
2196 /* Update MPLS tag. */
2197 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002198 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002199
2200 /* Update bgp route dampening information. */
2201 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2202 && peer_sort (peer) == BGP_PEER_EBGP)
2203 {
2204 /* Now we do normal update dampening. */
2205 ret = bgp_damp_update (ri, rn, afi, safi);
2206 if (ret == BGP_DAMP_SUPPRESSED)
2207 {
2208 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002209 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002210 return 0;
2211 }
2212 }
2213
2214 /* Nexthop reachability check. */
2215 if ((afi == AFI_IP || afi == AFI_IP6)
2216 && safi == SAFI_UNICAST
2217 && (peer_sort (peer) == BGP_PEER_IBGP
2218 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002219 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002220 {
2221 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002222 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002223 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002224 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002225 }
2226 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002227 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002228
2229 /* Process change. */
2230 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2231
2232 bgp_process (bgp, rn, afi, safi);
2233 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002234 bgp_attr_extra_free (&new_attr);
2235
paul718e3742002-12-13 20:15:29 +00002236 return 0;
2237 }
2238
2239 /* Received Logging. */
2240 if (BGP_DEBUG (update, UPDATE_IN))
2241 {
ajsd2c1f162004-12-08 21:10:20 +00002242 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002243 peer->host,
2244 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2245 p->prefixlen);
2246 }
2247
paul718e3742002-12-13 20:15:29 +00002248 /* Make new BGP info. */
2249 new = bgp_info_new ();
2250 new->type = type;
2251 new->sub_type = sub_type;
2252 new->peer = peer;
2253 new->attr = attr_new;
2254 new->uptime = time (NULL);
2255
2256 /* Update MPLS tag. */
2257 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002258 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002259
2260 /* Nexthop reachability check. */
2261 if ((afi == AFI_IP || afi == AFI_IP6)
2262 && safi == SAFI_UNICAST
2263 && (peer_sort (peer) == BGP_PEER_IBGP
2264 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002265 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002266 {
2267 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002268 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002269 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002270 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002271 }
2272 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002273 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002274
paul902212c2006-02-05 17:51:19 +00002275 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002276 bgp_aggregate_increment (bgp, p, new, afi, safi);
2277
2278 /* Register new BGP information. */
2279 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002280
2281 /* route_node_get lock */
2282 bgp_unlock_node (rn);
2283
Paul Jakmafb982c22007-05-04 20:15:47 +00002284 bgp_attr_extra_free (&new_attr);
2285
paul718e3742002-12-13 20:15:29 +00002286 /* If maximum prefix count is configured and current prefix
2287 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002288 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2289 return -1;
paul718e3742002-12-13 20:15:29 +00002290
2291 /* Process change. */
2292 bgp_process (bgp, rn, afi, safi);
2293
2294 return 0;
2295
2296 /* This BGP update is filtered. Log the reason then update BGP
2297 entry. */
2298 filtered:
2299 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002300 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002301 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2302 peer->host,
2303 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2304 p->prefixlen, reason);
2305
2306 if (ri)
paulb40d9392005-08-22 22:34:41 +00002307 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002308
2309 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002310
2311 bgp_attr_extra_free (&new_attr);
2312
paul718e3742002-12-13 20:15:29 +00002313 return 0;
2314}
2315
2316int
paulfee0f4c2004-09-13 05:12:46 +00002317bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2318 afi_t afi, safi_t safi, int type, int sub_type,
2319 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2320{
2321 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002322 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002323 struct bgp *bgp;
2324 int ret;
2325
2326 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2327 soft_reconfig);
2328
2329 bgp = peer->bgp;
2330
2331 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002332 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002333 {
2334 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2335 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2336 sub_type, prd, tag);
2337 }
2338
2339 return ret;
2340}
2341
2342int
paul718e3742002-12-13 20:15:29 +00002343bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002344 afi_t afi, safi_t safi, int type, int sub_type,
2345 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002346{
2347 struct bgp *bgp;
2348 char buf[SU_ADDRSTRLEN];
2349 struct bgp_node *rn;
2350 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002351 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002352 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002353
2354 bgp = peer->bgp;
2355
paulfee0f4c2004-09-13 05:12:46 +00002356 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002357 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002358 {
2359 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2360 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2361 }
2362
paul718e3742002-12-13 20:15:29 +00002363 /* Logging. */
2364 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002365 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002366 peer->host,
2367 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2368 p->prefixlen);
2369
2370 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002371 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002372
2373 /* If peer is soft reconfiguration enabled. Record input packet for
2374 further calculation. */
2375 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2376 && peer != bgp->peer_self)
2377 bgp_adj_in_unset (rn, peer);
2378
2379 /* Lookup withdrawn route. */
2380 for (ri = rn->info; ri; ri = ri->next)
2381 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2382 break;
2383
2384 /* Withdraw specified route from routing table. */
2385 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002386 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002387 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002388 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002389 "%s Can't find the route %s/%d", peer->host,
2390 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2391 p->prefixlen);
2392
2393 /* Unlock bgp_node_get() lock. */
2394 bgp_unlock_node (rn);
2395
2396 return 0;
2397}
2398
2399void
2400bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2401{
2402 struct bgp *bgp;
2403 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00002404 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002405 struct prefix p;
2406 struct bgp_info binfo;
2407 struct peer *from;
2408 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002409
Paul Jakmab2497022007-06-14 11:17:58 +00002410 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002411 return;
2412
paul718e3742002-12-13 20:15:29 +00002413 bgp = peer->bgp;
2414 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002415
paul718e3742002-12-13 20:15:29 +00002416 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2417 aspath = attr.aspath;
2418 attr.local_pref = bgp->default_local_pref;
2419 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2420
2421 if (afi == AFI_IP)
2422 str2prefix ("0.0.0.0/0", &p);
2423#ifdef HAVE_IPV6
2424 else if (afi == AFI_IP6)
2425 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002426 struct attr_extra *ae;
2427 attr.extra = NULL;
2428
2429 ae = bgp_attr_extra_get (&attr);
2430 attr.extra = ae;
2431
paul718e3742002-12-13 20:15:29 +00002432 str2prefix ("::/0", &p);
2433
2434 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002435 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002436 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002437 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002438
2439 /* If the peer is on shared nextwork and we have link-local
2440 nexthop set it. */
2441 if (peer->shared_network
2442 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2443 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002444 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002445 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002446 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002447 }
2448 }
2449#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002450
2451 if (peer->default_rmap[afi][safi].name)
2452 {
2453 binfo.peer = bgp->peer_self;
2454 binfo.attr = &attr;
2455
paulfee0f4c2004-09-13 05:12:46 +00002456 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2457
paul718e3742002-12-13 20:15:29 +00002458 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2459 RMAP_BGP, &binfo);
2460
paulfee0f4c2004-09-13 05:12:46 +00002461 bgp->peer_self->rmap_type = 0;
2462
paul718e3742002-12-13 20:15:29 +00002463 if (ret == RMAP_DENYMATCH)
2464 {
2465 bgp_attr_flush (&attr);
2466 withdraw = 1;
2467 }
2468 }
2469
2470 if (withdraw)
2471 {
2472 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2473 bgp_default_withdraw_send (peer, afi, safi);
2474 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2475 }
2476 else
2477 {
2478 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2479 bgp_default_update_send (peer, &attr, afi, safi, from);
2480 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002481
2482 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002483 aspath_unintern (aspath);
2484}
2485
2486static void
2487bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002488 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002489{
2490 struct bgp_node *rn;
2491 struct bgp_info *ri;
2492 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00002493
2494 memset (&attr, 0, sizeof (struct attr));
2495
paul718e3742002-12-13 20:15:29 +00002496 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002497 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002498
2499 if (safi != SAFI_MPLS_VPN
2500 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2501 bgp_default_originate (peer, afi, safi, 0);
2502
2503 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2504 for (ri = rn->info; ri; ri = ri->next)
2505 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2506 {
paulfee0f4c2004-09-13 05:12:46 +00002507 if ( (rsclient) ?
2508 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2509 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002510 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2511 else
2512 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002513
2514 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002515 }
2516}
2517
2518void
2519bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2520{
2521 struct bgp_node *rn;
2522 struct bgp_table *table;
2523
2524 if (peer->status != Established)
2525 return;
2526
2527 if (! peer->afc_nego[afi][safi])
2528 return;
2529
2530 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2531 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2532 return;
2533
2534 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002535 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002536 else
2537 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2538 rn = bgp_route_next(rn))
2539 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002540 bgp_announce_table (peer, afi, safi, table, 0);
2541
2542 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2543 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002544}
2545
2546void
2547bgp_announce_route_all (struct peer *peer)
2548{
2549 afi_t afi;
2550 safi_t safi;
2551
2552 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2553 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2554 bgp_announce_route (peer, afi, safi);
2555}
2556
2557static void
paulfee0f4c2004-09-13 05:12:46 +00002558bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2559 safi_t safi, struct bgp_table *table)
2560{
2561 struct bgp_node *rn;
2562 struct bgp_adj_in *ain;
2563
2564 if (! table)
2565 table = rsclient->bgp->rib[afi][safi];
2566
2567 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2568 for (ain = rn->adj_in; ain; ain = ain->next)
2569 {
2570 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2571 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2572 }
2573}
2574
2575void
2576bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2577{
2578 struct bgp_table *table;
2579 struct bgp_node *rn;
2580
2581 if (safi != SAFI_MPLS_VPN)
2582 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2583
2584 else
2585 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2586 rn = bgp_route_next (rn))
2587 if ((table = rn->info) != NULL)
2588 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2589}
2590
2591static void
paul718e3742002-12-13 20:15:29 +00002592bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2593 struct bgp_table *table)
2594{
2595 int ret;
2596 struct bgp_node *rn;
2597 struct bgp_adj_in *ain;
2598
2599 if (! table)
2600 table = peer->bgp->rib[afi][safi];
2601
2602 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2603 for (ain = rn->adj_in; ain; ain = ain->next)
2604 {
2605 if (ain->peer == peer)
2606 {
2607 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2608 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2609 NULL, NULL, 1);
2610 if (ret < 0)
2611 {
2612 bgp_unlock_node (rn);
2613 return;
2614 }
2615 continue;
2616 }
2617 }
2618}
2619
2620void
2621bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2622{
2623 struct bgp_node *rn;
2624 struct bgp_table *table;
2625
2626 if (peer->status != Established)
2627 return;
2628
2629 if (safi != SAFI_MPLS_VPN)
2630 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2631 else
2632 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2633 rn = bgp_route_next (rn))
2634 if ((table = rn->info) != NULL)
2635 bgp_soft_reconfig_table (peer, afi, safi, table);
2636}
2637
paul200df112005-06-01 11:17:05 +00002638static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002639bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002640{
Paul Jakma64e580a2006-02-21 01:09:01 +00002641 struct bgp_node *rn = data;
2642 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002643 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002644 afi_t afi = rn->table->afi;
2645 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002646
Paul Jakma64e580a2006-02-21 01:09:01 +00002647 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002648
Paul Jakma64e580a2006-02-21 01:09:01 +00002649 for (ri = rn->info; ri; ri = ri->next)
2650 if (ri->peer == peer)
paul200df112005-06-01 11:17:05 +00002651 {
2652 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002653 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2654 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002655 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002656 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2657 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002658 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002659 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002660 break;
2661 }
paul200df112005-06-01 11:17:05 +00002662 return WQ_SUCCESS;
2663}
2664
2665static void
paul0fb58d52005-11-14 14:31:49 +00002666bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002667{
Paul Jakma64e580a2006-02-21 01:09:01 +00002668 struct bgp_node *rn = data;
2669
2670 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002671}
2672
2673static void
paul94f2b392005-06-28 12:44:16 +00002674bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002675{
Paul Jakma64e580a2006-02-21 01:09:01 +00002676 struct peer *peer = wq->spec.data;
2677
Paul Jakma64e580a2006-02-21 01:09:01 +00002678 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002679
2680 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002681 BGP_EVENT_ADD (peer, Clearing_Completed);
paul200df112005-06-01 11:17:05 +00002682}
2683
2684static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002685bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002686{
Paul Jakma64e580a2006-02-21 01:09:01 +00002687#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2688 char wname[CLEAR_QUEUE_NAME_LEN];
2689
2690 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2691#undef CLEAR_QUEUE_NAME_LEN
2692
2693 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002694 {
2695 zlog_err ("%s: Failed to allocate work queue", __func__);
2696 exit (1);
2697 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002698 peer->clear_node_queue->spec.hold = 10;
2699 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2700 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2701 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2702 peer->clear_node_queue->spec.max_retries = 0;
2703
2704 /* we only 'lock' this peer reference when the queue is actually active */
2705 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002706}
2707
paul718e3742002-12-13 20:15:29 +00002708static void
2709bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002710 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002711{
2712 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002713
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002714
paul718e3742002-12-13 20:15:29 +00002715 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002716 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002717
hasso6cf159b2005-03-21 10:28:14 +00002718 /* If still no table => afi/safi isn't configured at all or smth. */
2719 if (! table)
2720 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002721
2722 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2723 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002724 struct bgp_info *ri;
2725 struct bgp_adj_in *ain;
2726 struct bgp_adj_out *aout;
2727
Paul Jakma65ca75e2006-05-04 08:08:15 +00002728 if (rn->info == NULL)
2729 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002730
2731 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2732 * queued for every clearing peer, regardless of whether it is
2733 * relevant to the peer at hand.
2734 *
2735 * Overview: There are 3 different indices which need to be
2736 * scrubbed, potentially, when a peer is removed:
2737 *
2738 * 1 peer's routes visible via the RIB (ie accepted routes)
2739 * 2 peer's routes visible by the (optional) peer's adj-in index
2740 * 3 other routes visible by the peer's adj-out index
2741 *
2742 * 3 there is no hurry in scrubbing, once the struct peer is
2743 * removed from bgp->peer, we could just GC such deleted peer's
2744 * adj-outs at our leisure.
2745 *
2746 * 1 and 2 must be 'scrubbed' in some way, at least made
2747 * invisible via RIB index before peer session is allowed to be
2748 * brought back up. So one needs to know when such a 'search' is
2749 * complete.
2750 *
2751 * Ideally:
2752 *
2753 * - there'd be a single global queue or a single RIB walker
2754 * - rather than tracking which route_nodes still need to be
2755 * examined on a peer basis, we'd track which peers still
2756 * aren't cleared
2757 *
2758 * Given that our per-peer prefix-counts now should be reliable,
2759 * this may actually be achievable. It doesn't seem to be a huge
2760 * problem at this time,
2761 */
2762 for (ri = rn->info; ri; ri = ri->next)
2763 if (ri->peer == peer)
2764 {
2765 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2766 work_queue_add (peer->clear_node_queue, rn);
2767 }
2768
2769 for (ain = rn->adj_in; ain; ain = ain->next)
2770 if (ain->peer == peer)
2771 {
2772 bgp_adj_in_remove (rn, ain);
2773 bgp_unlock_node (rn);
2774 break;
2775 }
2776 for (aout = rn->adj_out; aout; aout = aout->next)
2777 if (aout->peer == peer)
2778 {
2779 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2780 bgp_unlock_node (rn);
2781 break;
2782 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002783 }
2784 return;
2785}
2786
2787void
2788bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2789{
2790 struct bgp_node *rn;
2791 struct bgp_table *table;
2792 struct peer *rsclient;
2793 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002794
Paul Jakma64e580a2006-02-21 01:09:01 +00002795 if (peer->clear_node_queue == NULL)
2796 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002797
Paul Jakmaca058a32006-09-14 02:58:49 +00002798 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2799 * Idle until it receives a Clearing_Completed event. This protects
2800 * against peers which flap faster than we can we clear, which could
2801 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002802 *
2803 * a) race with routes from the new session being installed before
2804 * clear_route_node visits the node (to delete the route of that
2805 * peer)
2806 * b) resource exhaustion, clear_route_node likely leads to an entry
2807 * on the process_main queue. Fast-flapping could cause that queue
2808 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002809 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002810 if (!peer->clear_node_queue->thread)
2811 peer_lock (peer); /* bgp_clear_node_complete */
paul200df112005-06-01 11:17:05 +00002812
paul718e3742002-12-13 20:15:29 +00002813 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002814 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002815 else
2816 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2817 rn = bgp_route_next (rn))
2818 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002819 bgp_clear_route_table (peer, afi, safi, table, NULL);
2820
paul1eb8ef22005-04-07 07:30:20 +00002821 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002822 {
2823 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2824 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2825 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002826
Paul Jakmaca058a32006-09-14 02:58:49 +00002827 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002828 * completion function won't be run by workqueue code - call it here.
2829 * XXX: Actually, this assumption doesn't hold, see
2830 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002831 *
2832 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002833 * really needed if peer state is Established - peers in
2834 * pre-Established states shouldn't have any route-update state
2835 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002836 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002837 * We still can get here in pre-Established though, through
2838 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2839 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002840 *
2841 * At some future point, this check could be move to the top of the
2842 * function, and do a quick early-return when state is
2843 * pre-Established, avoiding above list and table scans. Once we're
2844 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002845 */
2846 if (!peer->clear_node_queue->thread)
2847 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002848}
2849
2850void
2851bgp_clear_route_all (struct peer *peer)
2852{
2853 afi_t afi;
2854 safi_t safi;
2855
2856 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2857 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2858 bgp_clear_route (peer, afi, safi);
2859}
2860
2861void
2862bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2863{
2864 struct bgp_table *table;
2865 struct bgp_node *rn;
2866 struct bgp_adj_in *ain;
2867
2868 table = peer->bgp->rib[afi][safi];
2869
2870 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2871 for (ain = rn->adj_in; ain ; ain = ain->next)
2872 if (ain->peer == peer)
2873 {
2874 bgp_adj_in_remove (rn, ain);
2875 bgp_unlock_node (rn);
2876 break;
2877 }
2878}
hasso93406d82005-02-02 14:40:33 +00002879
2880void
2881bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2882{
2883 struct bgp_node *rn;
2884 struct bgp_info *ri;
2885 struct bgp_table *table;
2886
2887 table = peer->bgp->rib[afi][safi];
2888
2889 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2890 {
2891 for (ri = rn->info; ri; ri = ri->next)
2892 if (ri->peer == peer)
2893 {
2894 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2895 bgp_rib_remove (rn, ri, peer, afi, safi);
2896 break;
2897 }
2898 }
2899}
paul718e3742002-12-13 20:15:29 +00002900
2901/* Delete all kernel routes. */
2902void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002903bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002904{
2905 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002906 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002907 struct bgp_node *rn;
2908 struct bgp_table *table;
2909 struct bgp_info *ri;
2910
paul1eb8ef22005-04-07 07:30:20 +00002911 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002912 {
2913 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2914
2915 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2916 for (ri = rn->info; ri; ri = ri->next)
2917 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2918 && ri->type == ZEBRA_ROUTE_BGP
2919 && ri->sub_type == BGP_ROUTE_NORMAL)
2920 bgp_zebra_withdraw (&rn->p, ri);
2921
2922 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2923
2924 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2925 for (ri = rn->info; ri; ri = ri->next)
2926 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2927 && ri->type == ZEBRA_ROUTE_BGP
2928 && ri->sub_type == BGP_ROUTE_NORMAL)
2929 bgp_zebra_withdraw (&rn->p, ri);
2930 }
2931}
2932
2933void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002934bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00002935{
2936 vty_reset ();
2937 bgp_zclient_reset ();
2938 access_list_reset ();
2939 prefix_list_reset ();
2940}
2941
2942/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2943 value. */
2944int
2945bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2946{
2947 u_char *pnt;
2948 u_char *lim;
2949 struct prefix p;
2950 int psize;
2951 int ret;
2952
2953 /* Check peer status. */
2954 if (peer->status != Established)
2955 return 0;
2956
2957 pnt = packet->nlri;
2958 lim = pnt + packet->length;
2959
2960 for (; pnt < lim; pnt += psize)
2961 {
2962 /* Clear prefix structure. */
2963 memset (&p, 0, sizeof (struct prefix));
2964
2965 /* Fetch prefix length. */
2966 p.prefixlen = *pnt++;
2967 p.family = afi2family (packet->afi);
2968
2969 /* Already checked in nlri_sanity_check(). We do double check
2970 here. */
2971 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2972 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2973 return -1;
2974
2975 /* Packet size overflow check. */
2976 psize = PSIZE (p.prefixlen);
2977
2978 /* When packet overflow occur return immediately. */
2979 if (pnt + psize > lim)
2980 return -1;
2981
2982 /* Fetch prefix from NLRI packet. */
2983 memcpy (&p.u.prefix, pnt, psize);
2984
2985 /* Check address. */
2986 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2987 {
2988 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2989 {
paulf5ba3872004-07-09 12:11:31 +00002990 /*
2991 * From draft-ietf-idr-bgp4-22, Section 6.3:
2992 * If a BGP router receives an UPDATE message with a
2993 * semantically incorrect NLRI field, in which a prefix is
2994 * semantically incorrect (eg. an unexpected multicast IP
2995 * address), it should ignore the prefix.
2996 */
paul718e3742002-12-13 20:15:29 +00002997 zlog (peer->log, LOG_ERR,
2998 "IPv4 unicast NLRI is multicast address %s",
2999 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003000
paul718e3742002-12-13 20:15:29 +00003001 return -1;
3002 }
3003 }
3004
3005#ifdef HAVE_IPV6
3006 /* Check address. */
3007 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3008 {
3009 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3010 {
3011 char buf[BUFSIZ];
3012
3013 zlog (peer->log, LOG_WARNING,
3014 "IPv6 link-local NLRI received %s ignore this NLRI",
3015 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3016
3017 continue;
3018 }
3019 }
3020#endif /* HAVE_IPV6 */
3021
3022 /* Normal process. */
3023 if (attr)
3024 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3025 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3026 else
3027 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3028 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3029
3030 /* Address family configuration mismatch or maximum-prefix count
3031 overflow. */
3032 if (ret < 0)
3033 return -1;
3034 }
3035
3036 /* Packet length consistency check. */
3037 if (pnt != lim)
3038 return -1;
3039
3040 return 0;
3041}
3042
3043/* NLRI encode syntax check routine. */
3044int
3045bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3046 bgp_size_t length)
3047{
3048 u_char *end;
3049 u_char prefixlen;
3050 int psize;
3051
3052 end = pnt + length;
3053
3054 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3055 syntactic validity. If the field is syntactically incorrect,
3056 then the Error Subcode is set to Invalid Network Field. */
3057
3058 while (pnt < end)
3059 {
3060 prefixlen = *pnt++;
3061
3062 /* Prefix length check. */
3063 if ((afi == AFI_IP && prefixlen > 32)
3064 || (afi == AFI_IP6 && prefixlen > 128))
3065 {
3066 plog_err (peer->log,
3067 "%s [Error] Update packet error (wrong prefix length %d)",
3068 peer->host, prefixlen);
3069 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3070 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3071 return -1;
3072 }
3073
3074 /* Packet size overflow check. */
3075 psize = PSIZE (prefixlen);
3076
3077 if (pnt + psize > end)
3078 {
3079 plog_err (peer->log,
3080 "%s [Error] Update packet error"
3081 " (prefix data overflow prefix size is %d)",
3082 peer->host, psize);
3083 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3084 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3085 return -1;
3086 }
3087
3088 pnt += psize;
3089 }
3090
3091 /* Packet length consistency check. */
3092 if (pnt != end)
3093 {
3094 plog_err (peer->log,
3095 "%s [Error] Update packet error"
3096 " (prefix length mismatch with total length)",
3097 peer->host);
3098 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3099 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3100 return -1;
3101 }
3102 return 0;
3103}
3104
paul94f2b392005-06-28 12:44:16 +00003105static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003106bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003107{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003108 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003109}
3110
paul94f2b392005-06-28 12:44:16 +00003111static void
paul718e3742002-12-13 20:15:29 +00003112bgp_static_free (struct bgp_static *bgp_static)
3113{
3114 if (bgp_static->rmap.name)
3115 free (bgp_static->rmap.name);
3116 XFREE (MTYPE_BGP_STATIC, bgp_static);
3117}
3118
paul94f2b392005-06-28 12:44:16 +00003119static void
paulfee0f4c2004-09-13 05:12:46 +00003120bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3121 struct prefix *p, afi_t afi, safi_t safi)
3122{
3123 struct bgp_node *rn;
3124 struct bgp_info *ri;
3125
3126 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3127
3128 /* Check selected route and self inserted route. */
3129 for (ri = rn->info; ri; ri = ri->next)
3130 if (ri->peer == bgp->peer_self
3131 && ri->type == ZEBRA_ROUTE_BGP
3132 && ri->sub_type == BGP_ROUTE_STATIC)
3133 break;
3134
3135 /* Withdraw static BGP route from routing table. */
3136 if (ri)
3137 {
paulfee0f4c2004-09-13 05:12:46 +00003138 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003139 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003140 }
3141
3142 /* Unlock bgp_node_lookup. */
3143 bgp_unlock_node (rn);
3144}
3145
paul94f2b392005-06-28 12:44:16 +00003146static void
paulfee0f4c2004-09-13 05:12:46 +00003147bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003148 struct bgp_static *bgp_static,
3149 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003150{
3151 struct bgp_node *rn;
3152 struct bgp_info *ri;
3153 struct bgp_info *new;
3154 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003155 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003156 struct attr attr = {0 };
3157 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003158 struct bgp *bgp;
3159 int ret;
3160 char buf[SU_ADDRSTRLEN];
3161
3162 bgp = rsclient->bgp;
3163
Paul Jakma06e110f2006-05-12 23:29:22 +00003164 assert (bgp_static);
3165 if (!bgp_static)
3166 return;
3167
paulfee0f4c2004-09-13 05:12:46 +00003168 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3169
3170 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003171
3172 attr.nexthop = bgp_static->igpnexthop;
3173 attr.med = bgp_static->igpmetric;
3174 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003175
3176 if (bgp_static->ttl)
3177 {
3178 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3179 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3180 attr.pathlimit.as = 0;
3181 attr.pathlimit.ttl = bgp_static->ttl;
3182 }
3183
3184 if (bgp_static->atomic)
3185 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3186
paulfee0f4c2004-09-13 05:12:46 +00003187 /* Apply network route-map for export to this rsclient. */
3188 if (bgp_static->rmap.name)
3189 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003190 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003191 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003192 info.attr = &attr_tmp;
3193
paulfee0f4c2004-09-13 05:12:46 +00003194 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3195 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3196
3197 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3198
3199 rsclient->rmap_type = 0;
3200
3201 if (ret == RMAP_DENYMATCH)
3202 {
3203 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003204 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003205
3206 /* Unintern original. */
3207 aspath_unintern (attr.aspath);
3208 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003209 bgp_attr_extra_free (&attr);
3210
paulfee0f4c2004-09-13 05:12:46 +00003211 return;
3212 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003213 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003214 }
3215 else
3216 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003217
paulfee0f4c2004-09-13 05:12:46 +00003218 new_attr = *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003219
paulfee0f4c2004-09-13 05:12:46 +00003220 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3221
Paul Jakmafb982c22007-05-04 20:15:47 +00003222 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3223 == RMAP_DENY)
3224 {
paulfee0f4c2004-09-13 05:12:46 +00003225 /* This BGP update is filtered. Log the reason then update BGP entry. */
3226 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003227 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003228 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3229 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3230 p->prefixlen, rsclient->host);
3231
3232 bgp->peer_self->rmap_type = 0;
3233
3234 bgp_attr_unintern (attr_new);
3235 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003236 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003237
3238 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3239
3240 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003241 }
paulfee0f4c2004-09-13 05:12:46 +00003242
3243 bgp->peer_self->rmap_type = 0;
3244
3245 bgp_attr_unintern (attr_new);
3246 attr_new = bgp_attr_intern (&new_attr);
3247
3248 for (ri = rn->info; ri; ri = ri->next)
3249 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3250 && ri->sub_type == BGP_ROUTE_STATIC)
3251 break;
3252
3253 if (ri)
3254 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003255 if (attrhash_cmp (ri->attr, attr_new) &&
3256 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003257 {
3258 bgp_unlock_node (rn);
3259 bgp_attr_unintern (attr_new);
3260 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003261 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003262 return;
3263 }
3264 else
3265 {
3266 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003267 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003268
3269 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003270 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3271 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003272 bgp_attr_unintern (ri->attr);
3273 ri->attr = attr_new;
3274 ri->uptime = time (NULL);
3275
3276 /* Process change. */
3277 bgp_process (bgp, rn, afi, safi);
3278 bgp_unlock_node (rn);
3279 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003280 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003281 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003282 }
paulfee0f4c2004-09-13 05:12:46 +00003283 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003284
paulfee0f4c2004-09-13 05:12:46 +00003285 /* Make new BGP info. */
3286 new = bgp_info_new ();
3287 new->type = ZEBRA_ROUTE_BGP;
3288 new->sub_type = BGP_ROUTE_STATIC;
3289 new->peer = bgp->peer_self;
3290 SET_FLAG (new->flags, BGP_INFO_VALID);
3291 new->attr = attr_new;
3292 new->uptime = time (NULL);
3293
3294 /* Register new BGP information. */
3295 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003296
3297 /* route_node_get lock */
3298 bgp_unlock_node (rn);
3299
paulfee0f4c2004-09-13 05:12:46 +00003300 /* Process change. */
3301 bgp_process (bgp, rn, afi, safi);
3302
3303 /* Unintern original. */
3304 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003305 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003306}
3307
paul94f2b392005-06-28 12:44:16 +00003308static void
paulfee0f4c2004-09-13 05:12:46 +00003309bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003310 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3311{
3312 struct bgp_node *rn;
3313 struct bgp_info *ri;
3314 struct bgp_info *new;
3315 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003316 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003317 struct attr *attr_new;
3318 int ret;
3319
Paul Jakmadd8103a2006-05-12 23:27:30 +00003320 assert (bgp_static);
3321 if (!bgp_static)
3322 return;
3323
paulfee0f4c2004-09-13 05:12:46 +00003324 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003325
3326 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003327
3328 attr.nexthop = bgp_static->igpnexthop;
3329 attr.med = bgp_static->igpmetric;
3330 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003331
Paul Jakma41367172007-08-06 15:24:51 +00003332 if (bgp_static->ttl)
3333 {
3334 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3335 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3336 attr.pathlimit.as = 0;
3337 attr.pathlimit.ttl = bgp_static->ttl;
3338 }
3339
3340 if (bgp_static->atomic)
3341 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3342
paul718e3742002-12-13 20:15:29 +00003343 /* Apply route-map. */
3344 if (bgp_static->rmap.name)
3345 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003346 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003347 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003348 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003349
paulfee0f4c2004-09-13 05:12:46 +00003350 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3351
paul718e3742002-12-13 20:15:29 +00003352 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003353
paulfee0f4c2004-09-13 05:12:46 +00003354 bgp->peer_self->rmap_type = 0;
3355
paul718e3742002-12-13 20:15:29 +00003356 if (ret == RMAP_DENYMATCH)
3357 {
3358 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003359 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003360
3361 /* Unintern original. */
3362 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003363 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003364 bgp_static_withdraw (bgp, p, afi, safi);
3365 return;
3366 }
paul286e1e72003-08-08 00:24:31 +00003367 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003368 }
paul286e1e72003-08-08 00:24:31 +00003369 else
3370 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003371
3372 for (ri = rn->info; ri; ri = ri->next)
3373 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3374 && ri->sub_type == BGP_ROUTE_STATIC)
3375 break;
3376
3377 if (ri)
3378 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003379 if (attrhash_cmp (ri->attr, attr_new) &&
3380 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003381 {
3382 bgp_unlock_node (rn);
3383 bgp_attr_unintern (attr_new);
3384 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003385 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003386 return;
3387 }
3388 else
3389 {
3390 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003391 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003392
3393 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003394 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3395 bgp_info_restore(rn, ri);
3396 else
3397 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003398 bgp_attr_unintern (ri->attr);
3399 ri->attr = attr_new;
3400 ri->uptime = time (NULL);
3401
3402 /* Process change. */
3403 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3404 bgp_process (bgp, rn, afi, safi);
3405 bgp_unlock_node (rn);
3406 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003407 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003408 return;
3409 }
3410 }
3411
3412 /* Make new BGP info. */
3413 new = bgp_info_new ();
3414 new->type = ZEBRA_ROUTE_BGP;
3415 new->sub_type = BGP_ROUTE_STATIC;
3416 new->peer = bgp->peer_self;
3417 SET_FLAG (new->flags, BGP_INFO_VALID);
3418 new->attr = attr_new;
3419 new->uptime = time (NULL);
3420
3421 /* Aggregate address increment. */
3422 bgp_aggregate_increment (bgp, p, new, afi, safi);
3423
3424 /* Register new BGP information. */
3425 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003426
3427 /* route_node_get lock */
3428 bgp_unlock_node (rn);
3429
paul718e3742002-12-13 20:15:29 +00003430 /* Process change. */
3431 bgp_process (bgp, rn, afi, safi);
3432
3433 /* Unintern original. */
3434 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003435 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003436}
3437
3438void
paulfee0f4c2004-09-13 05:12:46 +00003439bgp_static_update (struct bgp *bgp, struct prefix *p,
3440 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3441{
3442 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003443 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003444
3445 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3446
paul1eb8ef22005-04-07 07:30:20 +00003447 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003448 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003449 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3450 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003451 }
3452}
3453
paul94f2b392005-06-28 12:44:16 +00003454static void
paul718e3742002-12-13 20:15:29 +00003455bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3456 u_char safi, struct prefix_rd *prd, u_char *tag)
3457{
3458 struct bgp_node *rn;
3459 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003460
paulfee0f4c2004-09-13 05:12:46 +00003461 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003462
3463 /* Make new BGP info. */
3464 new = bgp_info_new ();
3465 new->type = ZEBRA_ROUTE_BGP;
3466 new->sub_type = BGP_ROUTE_STATIC;
3467 new->peer = bgp->peer_self;
3468 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3469 SET_FLAG (new->flags, BGP_INFO_VALID);
3470 new->uptime = time (NULL);
Paul Jakmafb982c22007-05-04 20:15:47 +00003471 new->extra = bgp_info_extra_new();
3472 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003473
3474 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003475 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003476
3477 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003478 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003479
paul200df112005-06-01 11:17:05 +00003480 /* route_node_get lock */
3481 bgp_unlock_node (rn);
3482
paul718e3742002-12-13 20:15:29 +00003483 /* Process change. */
3484 bgp_process (bgp, rn, afi, safi);
3485}
3486
3487void
3488bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3489 safi_t safi)
3490{
3491 struct bgp_node *rn;
3492 struct bgp_info *ri;
3493
paulfee0f4c2004-09-13 05:12:46 +00003494 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003495
3496 /* Check selected route and self inserted route. */
3497 for (ri = rn->info; ri; ri = ri->next)
3498 if (ri->peer == bgp->peer_self
3499 && ri->type == ZEBRA_ROUTE_BGP
3500 && ri->sub_type == BGP_ROUTE_STATIC)
3501 break;
3502
3503 /* Withdraw static BGP route from routing table. */
3504 if (ri)
3505 {
3506 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003507 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003508 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003509 }
3510
3511 /* Unlock bgp_node_lookup. */
3512 bgp_unlock_node (rn);
3513}
3514
3515void
paulfee0f4c2004-09-13 05:12:46 +00003516bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3517{
3518 struct bgp_static *bgp_static;
3519 struct bgp *bgp;
3520 struct bgp_node *rn;
3521 struct prefix *p;
3522
3523 bgp = rsclient->bgp;
3524
3525 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3526 if ((bgp_static = rn->info) != NULL)
3527 {
3528 p = &rn->p;
3529
3530 bgp_static_update_rsclient (rsclient, p, bgp_static,
3531 afi, safi);
3532 }
3533}
3534
paul94f2b392005-06-28 12:44:16 +00003535static void
paul718e3742002-12-13 20:15:29 +00003536bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3537 u_char safi, struct prefix_rd *prd, u_char *tag)
3538{
3539 struct bgp_node *rn;
3540 struct bgp_info *ri;
3541
paulfee0f4c2004-09-13 05:12:46 +00003542 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003543
3544 /* Check selected route and self inserted route. */
3545 for (ri = rn->info; ri; ri = ri->next)
3546 if (ri->peer == bgp->peer_self
3547 && ri->type == ZEBRA_ROUTE_BGP
3548 && ri->sub_type == BGP_ROUTE_STATIC)
3549 break;
3550
3551 /* Withdraw static BGP route from routing table. */
3552 if (ri)
3553 {
3554 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003555 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003556 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003557 }
3558
3559 /* Unlock bgp_node_lookup. */
3560 bgp_unlock_node (rn);
3561}
3562
Paul Jakma41367172007-08-06 15:24:51 +00003563static void
3564bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3565 int ttl_edge)
3566{
3567 struct bgp_node *parent = rn;
3568 struct bgp_static *sp;
3569
3570 /* Existing static changed TTL, search parents and adjust their atomic */
3571 while ((parent = parent->parent))
3572 if ((sp = parent->info))
3573 {
3574 int sp_level = (sp->atomic ? 1 : 0);
3575 ttl_edge ? sp->atomic++ : sp->atomic--;
3576
3577 /* did we change state of parent whether atomic is set or not? */
3578 if (sp_level != (sp->atomic ? 1 : 0))
3579 {
3580 bgp_static_update (bgp, &parent->p, sp,
3581 rn->table->afi, rn->table->safi);
3582 }
3583 }
3584}
3585
paul718e3742002-12-13 20:15:29 +00003586/* Configure static BGP network. When user don't run zebra, static
3587 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003588static int
paulfd79ac92004-10-13 05:06:08 +00003589bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakma41367172007-08-06 15:24:51 +00003590 u_int16_t afi, u_char safi, const char *rmap, int backdoor,
3591 u_char ttl)
paul718e3742002-12-13 20:15:29 +00003592{
3593 int ret;
3594 struct prefix p;
3595 struct bgp_static *bgp_static;
3596 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003597 u_char need_update = 0;
3598 u_char ttl_change = 0;
3599 u_char ttl_edge = (ttl ? 1 : 0);
3600 u_char new = 0;
paul718e3742002-12-13 20:15:29 +00003601
3602 /* Convert IP prefix string to struct prefix. */
3603 ret = str2prefix (ip_str, &p);
3604 if (! ret)
3605 {
3606 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3607 return CMD_WARNING;
3608 }
3609#ifdef HAVE_IPV6
3610 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3611 {
3612 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3613 VTY_NEWLINE);
3614 return CMD_WARNING;
3615 }
3616#endif /* HAVE_IPV6 */
3617
3618 apply_mask (&p);
3619
3620 /* Set BGP static route configuration. */
3621 rn = bgp_node_get (bgp->route[afi][safi], &p);
3622
3623 if (rn->info)
3624 {
3625 /* Configuration change. */
3626 bgp_static = rn->info;
3627
3628 /* Check previous routes are installed into BGP. */
Paul Jakma41367172007-08-06 15:24:51 +00003629 if (bgp_static->valid)
3630 {
3631 if (bgp_static->backdoor != backdoor
3632 || bgp_static->ttl != ttl)
3633 need_update = 1;
3634 }
3635
3636 /* need to catch TTL set/unset transitions for handling of
3637 * ATOMIC_AGGREGATE
3638 */
3639 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3640 ttl_change = 1;
3641
paul718e3742002-12-13 20:15:29 +00003642 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003643 bgp_static->ttl = ttl;
3644
paul718e3742002-12-13 20:15:29 +00003645 if (rmap)
3646 {
3647 if (bgp_static->rmap.name)
3648 free (bgp_static->rmap.name);
3649 bgp_static->rmap.name = strdup (rmap);
3650 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3651 }
3652 else
3653 {
3654 if (bgp_static->rmap.name)
3655 free (bgp_static->rmap.name);
3656 bgp_static->rmap.name = NULL;
3657 bgp_static->rmap.map = NULL;
3658 bgp_static->valid = 0;
3659 }
3660 bgp_unlock_node (rn);
3661 }
3662 else
3663 {
3664 /* New configuration. */
3665 bgp_static = bgp_static_new ();
3666 bgp_static->backdoor = backdoor;
3667 bgp_static->valid = 0;
3668 bgp_static->igpmetric = 0;
3669 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003670 bgp_static->ttl = ttl;
3671 ttl_change = ttl_edge;
3672 new = 1;
3673
paul718e3742002-12-13 20:15:29 +00003674 if (rmap)
3675 {
3676 if (bgp_static->rmap.name)
3677 free (bgp_static->rmap.name);
3678 bgp_static->rmap.name = strdup (rmap);
3679 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3680 }
3681 rn->info = bgp_static;
3682 }
3683
Paul Jakma41367172007-08-06 15:24:51 +00003684 /* ".. sites that choose to advertise the
3685 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3686 * all less specific covering prefixes as well as the more specific
3687 * prefixes."
3688 *
3689 * So:
3690 * Prefix that has just had pathlimit set/unset:
3691 * - Must bump ATOMIC refcount on all parents.
3692 *
3693 * To catch less specific prefixes:
3694 * - Must search children for ones with TTL, bump atomic refcount
3695 * (we dont care if we're deleting a less specific prefix..)
3696 */
3697 if (ttl_change)
3698 {
3699 /* Existing static changed TTL, search parents and adjust their atomic */
3700 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3701 }
3702
3703 if (new)
3704 {
3705 struct bgp_node *child;
3706 struct bgp_static *sc;
3707
3708 /* New static, search children and bump this statics atomic.. */
3709 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3710 while ((child = bgp_route_next_until (child, rn)))
3711 {
3712 if ((sc = child->info) && sc->ttl)
3713 bgp_static->atomic++;
3714 }
3715 }
3716
paul718e3742002-12-13 20:15:29 +00003717 /* If BGP scan is not enabled, we should install this route here. */
3718 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3719 {
3720 bgp_static->valid = 1;
3721
3722 if (need_update)
3723 bgp_static_withdraw (bgp, &p, afi, safi);
3724
3725 if (! bgp_static->backdoor)
3726 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3727 }
3728
3729 return CMD_SUCCESS;
3730}
3731
3732/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003733static int
paulfd79ac92004-10-13 05:06:08 +00003734bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003735 u_int16_t afi, u_char safi)
3736{
3737 int ret;
3738 struct prefix p;
3739 struct bgp_static *bgp_static;
3740 struct bgp_node *rn;
3741
3742 /* Convert IP prefix string to struct prefix. */
3743 ret = str2prefix (ip_str, &p);
3744 if (! ret)
3745 {
3746 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3747 return CMD_WARNING;
3748 }
3749#ifdef HAVE_IPV6
3750 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3751 {
3752 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3753 VTY_NEWLINE);
3754 return CMD_WARNING;
3755 }
3756#endif /* HAVE_IPV6 */
3757
3758 apply_mask (&p);
3759
3760 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3761 if (! rn)
3762 {
3763 vty_out (vty, "%% Can't find specified static route configuration.%s",
3764 VTY_NEWLINE);
3765 return CMD_WARNING;
3766 }
3767
3768 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003769
3770 /* decrement atomic in parents, see bgp_static_set */
3771 bgp_pathlimit_update_parents (bgp, rn, 0);
3772
paul718e3742002-12-13 20:15:29 +00003773 /* Update BGP RIB. */
3774 if (! bgp_static->backdoor)
3775 bgp_static_withdraw (bgp, &p, afi, safi);
3776
3777 /* Clear configuration. */
3778 bgp_static_free (bgp_static);
3779 rn->info = NULL;
3780 bgp_unlock_node (rn);
3781 bgp_unlock_node (rn);
3782
3783 return CMD_SUCCESS;
3784}
3785
3786/* Called from bgp_delete(). Delete all static routes from the BGP
3787 instance. */
3788void
3789bgp_static_delete (struct bgp *bgp)
3790{
3791 afi_t afi;
3792 safi_t safi;
3793 struct bgp_node *rn;
3794 struct bgp_node *rm;
3795 struct bgp_table *table;
3796 struct bgp_static *bgp_static;
3797
3798 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3799 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3800 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3801 if (rn->info != NULL)
3802 {
3803 if (safi == SAFI_MPLS_VPN)
3804 {
3805 table = rn->info;
3806
3807 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3808 {
3809 bgp_static = rn->info;
3810 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3811 AFI_IP, SAFI_MPLS_VPN,
3812 (struct prefix_rd *)&rn->p,
3813 bgp_static->tag);
3814 bgp_static_free (bgp_static);
3815 rn->info = NULL;
3816 bgp_unlock_node (rn);
3817 }
3818 }
3819 else
3820 {
3821 bgp_static = rn->info;
3822 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3823 bgp_static_free (bgp_static);
3824 rn->info = NULL;
3825 bgp_unlock_node (rn);
3826 }
3827 }
3828}
3829
3830int
paulfd79ac92004-10-13 05:06:08 +00003831bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3832 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003833{
3834 int ret;
3835 struct prefix p;
3836 struct prefix_rd prd;
3837 struct bgp *bgp;
3838 struct bgp_node *prn;
3839 struct bgp_node *rn;
3840 struct bgp_table *table;
3841 struct bgp_static *bgp_static;
3842 u_char tag[3];
3843
3844 bgp = vty->index;
3845
3846 ret = str2prefix (ip_str, &p);
3847 if (! ret)
3848 {
3849 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3850 return CMD_WARNING;
3851 }
3852 apply_mask (&p);
3853
3854 ret = str2prefix_rd (rd_str, &prd);
3855 if (! ret)
3856 {
3857 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3858 return CMD_WARNING;
3859 }
3860
3861 ret = str2tag (tag_str, tag);
3862 if (! ret)
3863 {
3864 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3865 return CMD_WARNING;
3866 }
3867
3868 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3869 (struct prefix *)&prd);
3870 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003871 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003872 else
3873 bgp_unlock_node (prn);
3874 table = prn->info;
3875
3876 rn = bgp_node_get (table, &p);
3877
3878 if (rn->info)
3879 {
3880 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3881 bgp_unlock_node (rn);
3882 }
3883 else
3884 {
3885 /* New configuration. */
3886 bgp_static = bgp_static_new ();
3887 bgp_static->valid = 1;
3888 memcpy (bgp_static->tag, tag, 3);
3889 rn->info = bgp_static;
3890
3891 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3892 }
3893
3894 return CMD_SUCCESS;
3895}
3896
3897/* Configure static BGP network. */
3898int
paulfd79ac92004-10-13 05:06:08 +00003899bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3900 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003901{
3902 int ret;
3903 struct bgp *bgp;
3904 struct prefix p;
3905 struct prefix_rd prd;
3906 struct bgp_node *prn;
3907 struct bgp_node *rn;
3908 struct bgp_table *table;
3909 struct bgp_static *bgp_static;
3910 u_char tag[3];
3911
3912 bgp = vty->index;
3913
3914 /* Convert IP prefix string to struct prefix. */
3915 ret = str2prefix (ip_str, &p);
3916 if (! ret)
3917 {
3918 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3919 return CMD_WARNING;
3920 }
3921 apply_mask (&p);
3922
3923 ret = str2prefix_rd (rd_str, &prd);
3924 if (! ret)
3925 {
3926 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3927 return CMD_WARNING;
3928 }
3929
3930 ret = str2tag (tag_str, tag);
3931 if (! ret)
3932 {
3933 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3934 return CMD_WARNING;
3935 }
3936
3937 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3938 (struct prefix *)&prd);
3939 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003940 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003941 else
3942 bgp_unlock_node (prn);
3943 table = prn->info;
3944
3945 rn = bgp_node_lookup (table, &p);
3946
3947 if (rn)
3948 {
3949 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3950
3951 bgp_static = rn->info;
3952 bgp_static_free (bgp_static);
3953 rn->info = NULL;
3954 bgp_unlock_node (rn);
3955 bgp_unlock_node (rn);
3956 }
3957 else
3958 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3959
3960 return CMD_SUCCESS;
3961}
3962
3963DEFUN (bgp_network,
3964 bgp_network_cmd,
3965 "network A.B.C.D/M",
3966 "Specify a network to announce via BGP\n"
3967 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3968{
Paul Jakma41367172007-08-06 15:24:51 +00003969 u_char ttl = 0;
3970
3971 if (argc == 2)
3972 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
3973
paul718e3742002-12-13 20:15:29 +00003974 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00003975 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00003976}
3977
Paul Jakma41367172007-08-06 15:24:51 +00003978ALIAS (bgp_network,
3979 bgp_network_ttl_cmd,
3980 "network A.B.C.D/M pathlimit <0-255>",
3981 "Specify a network to announce via BGP\n"
3982 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3983 "AS-Path hopcount limit attribute\n"
3984 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3985
paul718e3742002-12-13 20:15:29 +00003986DEFUN (bgp_network_route_map,
3987 bgp_network_route_map_cmd,
3988 "network A.B.C.D/M route-map WORD",
3989 "Specify a network to announce via BGP\n"
3990 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3991 "Route-map to modify the attributes\n"
3992 "Name of the route map\n")
3993{
3994 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00003995 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00003996}
3997
3998DEFUN (bgp_network_backdoor,
3999 bgp_network_backdoor_cmd,
4000 "network A.B.C.D/M backdoor",
4001 "Specify a network to announce via BGP\n"
4002 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4003 "Specify a BGP backdoor route\n")
4004{
Paul Jakma41367172007-08-06 15:24:51 +00004005 u_char ttl = 0;
4006
4007 if (argc == 2)
4008 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4009
4010 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4011 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004012}
4013
Paul Jakma41367172007-08-06 15:24:51 +00004014ALIAS (bgp_network_backdoor,
4015 bgp_network_backdoor_ttl_cmd,
4016 "network A.B.C.D/M backdoor pathlimit <0-255>",
4017 "Specify a network to announce via BGP\n"
4018 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4019 "Specify a BGP backdoor route\n"
4020 "AS-Path hopcount limit attribute\n"
4021 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4022
paul718e3742002-12-13 20:15:29 +00004023DEFUN (bgp_network_mask,
4024 bgp_network_mask_cmd,
4025 "network A.B.C.D mask A.B.C.D",
4026 "Specify a network to announce via BGP\n"
4027 "Network number\n"
4028 "Network mask\n"
4029 "Network mask\n")
4030{
4031 int ret;
4032 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004033 u_char ttl = 0;
4034
4035 if (argc == 3)
4036 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4037
paul718e3742002-12-13 20:15:29 +00004038 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4039 if (! ret)
4040 {
4041 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4042 return CMD_WARNING;
4043 }
4044
4045 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004046 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004047}
4048
Paul Jakma41367172007-08-06 15:24:51 +00004049ALIAS (bgp_network_mask,
4050 bgp_network_mask_ttl_cmd,
4051 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4052 "Specify a network to announce via BGP\n"
4053 "Network number\n"
4054 "Network mask\n"
4055 "Network mask\n"
4056 "AS-Path hopcount limit attribute\n"
4057 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4058
paul718e3742002-12-13 20:15:29 +00004059DEFUN (bgp_network_mask_route_map,
4060 bgp_network_mask_route_map_cmd,
4061 "network A.B.C.D mask A.B.C.D route-map WORD",
4062 "Specify a network to announce via BGP\n"
4063 "Network number\n"
4064 "Network mask\n"
4065 "Network mask\n"
4066 "Route-map to modify the attributes\n"
4067 "Name of the route map\n")
4068{
4069 int ret;
4070 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004071
paul718e3742002-12-13 20:15:29 +00004072 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4073 if (! ret)
4074 {
4075 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4076 return CMD_WARNING;
4077 }
4078
4079 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004080 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
paul718e3742002-12-13 20:15:29 +00004081}
4082
4083DEFUN (bgp_network_mask_backdoor,
4084 bgp_network_mask_backdoor_cmd,
4085 "network A.B.C.D mask A.B.C.D backdoor",
4086 "Specify a network to announce via BGP\n"
4087 "Network number\n"
4088 "Network mask\n"
4089 "Network mask\n"
4090 "Specify a BGP backdoor route\n")
4091{
4092 int ret;
4093 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004094 u_char ttl = 0;
4095
4096 if (argc == 3)
4097 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
paul718e3742002-12-13 20:15:29 +00004098
4099 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4100 if (! ret)
4101 {
4102 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4103 return CMD_WARNING;
4104 }
4105
Paul Jakma41367172007-08-06 15:24:51 +00004106 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4107 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004108}
4109
Paul Jakma41367172007-08-06 15:24:51 +00004110ALIAS (bgp_network_mask_backdoor,
4111 bgp_network_mask_backdoor_ttl_cmd,
4112 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4113 "Specify a network to announce via BGP\n"
4114 "Network number\n"
4115 "Network mask\n"
4116 "Network mask\n"
4117 "Specify a BGP backdoor route\n"
4118 "AS-Path hopcount limit attribute\n"
4119 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4120
paul718e3742002-12-13 20:15:29 +00004121DEFUN (bgp_network_mask_natural,
4122 bgp_network_mask_natural_cmd,
4123 "network A.B.C.D",
4124 "Specify a network to announce via BGP\n"
4125 "Network number\n")
4126{
4127 int ret;
4128 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004129 u_char ttl = 0;
4130
4131 if (argc == 2)
4132 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004133
4134 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4135 if (! ret)
4136 {
4137 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4138 return CMD_WARNING;
4139 }
4140
4141 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004142 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004143}
4144
Paul Jakma41367172007-08-06 15:24:51 +00004145ALIAS (bgp_network_mask_natural,
4146 bgp_network_mask_natural_ttl_cmd,
4147 "network A.B.C.D pathlimit <0-255>",
4148 "Specify a network to announce via BGP\n"
4149 "Network number\n"
4150 "AS-Path hopcount limit attribute\n"
4151 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4152
paul718e3742002-12-13 20:15:29 +00004153DEFUN (bgp_network_mask_natural_route_map,
4154 bgp_network_mask_natural_route_map_cmd,
4155 "network A.B.C.D route-map WORD",
4156 "Specify a network to announce via BGP\n"
4157 "Network number\n"
4158 "Route-map to modify the attributes\n"
4159 "Name of the route map\n")
4160{
4161 int ret;
4162 char prefix_str[BUFSIZ];
4163
4164 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4165 if (! ret)
4166 {
4167 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4168 return CMD_WARNING;
4169 }
4170
4171 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004172 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004173}
4174
4175DEFUN (bgp_network_mask_natural_backdoor,
4176 bgp_network_mask_natural_backdoor_cmd,
4177 "network A.B.C.D backdoor",
4178 "Specify a network to announce via BGP\n"
4179 "Network number\n"
4180 "Specify a BGP backdoor route\n")
4181{
4182 int ret;
4183 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004184 u_char ttl = 0;
4185
4186 if (argc == 2)
4187 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004188
4189 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4190 if (! ret)
4191 {
4192 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4193 return CMD_WARNING;
4194 }
4195
Paul Jakma41367172007-08-06 15:24:51 +00004196 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4197 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004198}
4199
Paul Jakma41367172007-08-06 15:24:51 +00004200ALIAS (bgp_network_mask_natural_backdoor,
4201 bgp_network_mask_natural_backdoor_ttl_cmd,
4202 "network A.B.C.D backdoor pathlimit (1-255>",
4203 "Specify a network to announce via BGP\n"
4204 "Network number\n"
4205 "Specify a BGP backdoor route\n"
4206 "AS-Path hopcount limit attribute\n"
4207 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4208
paul718e3742002-12-13 20:15:29 +00004209DEFUN (no_bgp_network,
4210 no_bgp_network_cmd,
4211 "no network A.B.C.D/M",
4212 NO_STR
4213 "Specify a network to announce via BGP\n"
4214 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4215{
4216 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4217 bgp_node_safi (vty));
4218}
4219
4220ALIAS (no_bgp_network,
Paul Jakma41367172007-08-06 15:24:51 +00004221 no_bgp_network_ttl_cmd,
4222 "no network A.B.C.D/M pathlimit <0-255>",
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 "AS-Path hopcount limit attribute\n"
4227 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4228
4229ALIAS (no_bgp_network,
paul718e3742002-12-13 20:15:29 +00004230 no_bgp_network_route_map_cmd,
4231 "no network A.B.C.D/M route-map WORD",
4232 NO_STR
4233 "Specify a network to announce via BGP\n"
4234 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4235 "Route-map to modify the attributes\n"
4236 "Name of the route map\n")
4237
4238ALIAS (no_bgp_network,
4239 no_bgp_network_backdoor_cmd,
4240 "no network A.B.C.D/M backdoor",
4241 NO_STR
4242 "Specify a network to announce via BGP\n"
4243 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4244 "Specify a BGP backdoor route\n")
4245
Paul Jakma41367172007-08-06 15:24:51 +00004246ALIAS (no_bgp_network,
4247 no_bgp_network_backdoor_ttl_cmd,
4248 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4249 NO_STR
4250 "Specify a network to announce via BGP\n"
4251 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4252 "Specify a BGP backdoor route\n"
4253 "AS-Path hopcount limit attribute\n"
4254 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4255
paul718e3742002-12-13 20:15:29 +00004256DEFUN (no_bgp_network_mask,
4257 no_bgp_network_mask_cmd,
4258 "no network A.B.C.D mask A.B.C.D",
4259 NO_STR
4260 "Specify a network to announce via BGP\n"
4261 "Network number\n"
4262 "Network mask\n"
4263 "Network mask\n")
4264{
4265 int ret;
4266 char prefix_str[BUFSIZ];
4267
4268 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4269 if (! ret)
4270 {
4271 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4272 return CMD_WARNING;
4273 }
4274
4275 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4276 bgp_node_safi (vty));
4277}
4278
Paul Jakma41367172007-08-06 15:24:51 +00004279ALIAS (no_bgp_network,
4280 no_bgp_network_mask_ttl_cmd,
4281 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4282 NO_STR
4283 "Specify a network to announce via BGP\n"
4284 "Network number\n"
4285 "Network mask\n"
4286 "Network mask\n"
4287 "AS-Path hopcount limit attribute\n"
4288 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4289
paul718e3742002-12-13 20:15:29 +00004290ALIAS (no_bgp_network_mask,
4291 no_bgp_network_mask_route_map_cmd,
4292 "no network A.B.C.D mask A.B.C.D route-map WORD",
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 "Route-map to modify the attributes\n"
4299 "Name of the route map\n")
4300
4301ALIAS (no_bgp_network_mask,
4302 no_bgp_network_mask_backdoor_cmd,
4303 "no network A.B.C.D mask A.B.C.D backdoor",
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 "Specify a BGP backdoor route\n")
4310
Paul Jakma41367172007-08-06 15:24:51 +00004311ALIAS (no_bgp_network_mask,
4312 no_bgp_network_mask_backdoor_ttl_cmd,
4313 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4314 NO_STR
4315 "Specify a network to announce via BGP\n"
4316 "Network number\n"
4317 "Network mask\n"
4318 "Network mask\n"
4319 "Specify a BGP backdoor route\n"
4320 "AS-Path hopcount limit attribute\n"
4321 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4322
paul718e3742002-12-13 20:15:29 +00004323DEFUN (no_bgp_network_mask_natural,
4324 no_bgp_network_mask_natural_cmd,
4325 "no network A.B.C.D",
4326 NO_STR
4327 "Specify a network to announce via BGP\n"
4328 "Network number\n")
4329{
4330 int ret;
4331 char prefix_str[BUFSIZ];
4332
4333 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4334 if (! ret)
4335 {
4336 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4337 return CMD_WARNING;
4338 }
4339
4340 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4341 bgp_node_safi (vty));
4342}
4343
4344ALIAS (no_bgp_network_mask_natural,
4345 no_bgp_network_mask_natural_route_map_cmd,
4346 "no network A.B.C.D route-map WORD",
4347 NO_STR
4348 "Specify a network to announce via BGP\n"
4349 "Network number\n"
4350 "Route-map to modify the attributes\n"
4351 "Name of the route map\n")
4352
4353ALIAS (no_bgp_network_mask_natural,
4354 no_bgp_network_mask_natural_backdoor_cmd,
4355 "no network A.B.C.D backdoor",
4356 NO_STR
4357 "Specify a network to announce via BGP\n"
4358 "Network number\n"
4359 "Specify a BGP backdoor route\n")
4360
Paul Jakma41367172007-08-06 15:24:51 +00004361ALIAS (no_bgp_network_mask_natural,
4362 no_bgp_network_mask_natural_ttl_cmd,
4363 "no network A.B.C.D pathlimit <0-255>",
4364 NO_STR
4365 "Specify a network to announce via BGP\n"
4366 "Network number\n"
4367 "AS-Path hopcount limit attribute\n"
4368 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4369
4370ALIAS (no_bgp_network_mask_natural,
4371 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4372 "no network A.B.C.D backdoor pathlimit <0-255>",
4373 NO_STR
4374 "Specify a network to announce via BGP\n"
4375 "Network number\n"
4376 "Specify a BGP backdoor route\n"
4377 "AS-Path hopcount limit attribute\n"
4378 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4379
paul718e3742002-12-13 20:15:29 +00004380#ifdef HAVE_IPV6
4381DEFUN (ipv6_bgp_network,
4382 ipv6_bgp_network_cmd,
4383 "network X:X::X:X/M",
4384 "Specify a network to announce via BGP\n"
4385 "IPv6 prefix <network>/<length>\n")
4386{
Paul Jakma41367172007-08-06 15:24:51 +00004387 u_char ttl = 0;
4388
4389 if (argc == 2)
4390 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4391
4392 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4393 NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004394}
4395
Paul Jakma41367172007-08-06 15:24:51 +00004396ALIAS (ipv6_bgp_network,
4397 ipv6_bgp_network_ttl_cmd,
4398 "network X:X::X:X/M pathlimit <0-255>",
4399 "Specify a network to announce via BGP\n"
4400 "IPv6 prefix <network>/<length>\n"
4401 "AS-Path hopcount limit attribute\n"
4402 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4403
paul718e3742002-12-13 20:15:29 +00004404DEFUN (ipv6_bgp_network_route_map,
4405 ipv6_bgp_network_route_map_cmd,
4406 "network X:X::X:X/M route-map WORD",
4407 "Specify a network to announce via BGP\n"
4408 "IPv6 prefix <network>/<length>\n"
4409 "Route-map to modify the attributes\n"
4410 "Name of the route map\n")
4411{
4412 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakma41367172007-08-06 15:24:51 +00004413 bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004414}
4415
4416DEFUN (no_ipv6_bgp_network,
4417 no_ipv6_bgp_network_cmd,
4418 "no network X:X::X:X/M",
4419 NO_STR
4420 "Specify a network to announce via BGP\n"
4421 "IPv6 prefix <network>/<length>\n")
4422{
4423 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4424}
4425
4426ALIAS (no_ipv6_bgp_network,
4427 no_ipv6_bgp_network_route_map_cmd,
4428 "no network X:X::X:X/M route-map WORD",
4429 NO_STR
4430 "Specify a network to announce via BGP\n"
4431 "IPv6 prefix <network>/<length>\n"
4432 "Route-map to modify the attributes\n"
4433 "Name of the route map\n")
4434
Paul Jakma41367172007-08-06 15:24:51 +00004435ALIAS (no_ipv6_bgp_network,
4436 no_ipv6_bgp_network_ttl_cmd,
4437 "no network X:X::X:X/M pathlimit <0-255>",
4438 NO_STR
4439 "Specify a network to announce via BGP\n"
4440 "IPv6 prefix <network>/<length>\n"
4441 "AS-Path hopcount limit attribute\n"
4442 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4443
paul718e3742002-12-13 20:15:29 +00004444ALIAS (ipv6_bgp_network,
4445 old_ipv6_bgp_network_cmd,
4446 "ipv6 bgp network X:X::X:X/M",
4447 IPV6_STR
4448 BGP_STR
4449 "Specify a network to announce via BGP\n"
4450 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4451
4452ALIAS (no_ipv6_bgp_network,
4453 old_no_ipv6_bgp_network_cmd,
4454 "no ipv6 bgp network X:X::X:X/M",
4455 NO_STR
4456 IPV6_STR
4457 BGP_STR
4458 "Specify a network to announce via BGP\n"
4459 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4460#endif /* HAVE_IPV6 */
4461
4462/* Aggreagete address:
4463
4464 advertise-map Set condition to advertise attribute
4465 as-set Generate AS set path information
4466 attribute-map Set attributes of aggregate
4467 route-map Set parameters of aggregate
4468 summary-only Filter more specific routes from updates
4469 suppress-map Conditionally filter more specific routes from updates
4470 <cr>
4471 */
4472struct bgp_aggregate
4473{
4474 /* Summary-only flag. */
4475 u_char summary_only;
4476
4477 /* AS set generation. */
4478 u_char as_set;
4479
4480 /* Route-map for aggregated route. */
4481 struct route_map *map;
4482
4483 /* Suppress-count. */
4484 unsigned long count;
4485
4486 /* SAFI configuration. */
4487 safi_t safi;
4488};
4489
paul94f2b392005-06-28 12:44:16 +00004490static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004491bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004492{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004493 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004494}
4495
paul94f2b392005-06-28 12:44:16 +00004496static void
paul718e3742002-12-13 20:15:29 +00004497bgp_aggregate_free (struct bgp_aggregate *aggregate)
4498{
4499 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4500}
4501
paul94f2b392005-06-28 12:44:16 +00004502static void
paul718e3742002-12-13 20:15:29 +00004503bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4504 afi_t afi, safi_t safi, struct bgp_info *del,
4505 struct bgp_aggregate *aggregate)
4506{
4507 struct bgp_table *table;
4508 struct bgp_node *top;
4509 struct bgp_node *rn;
4510 u_char origin;
4511 struct aspath *aspath = NULL;
4512 struct aspath *asmerge = NULL;
4513 struct community *community = NULL;
4514 struct community *commerge = NULL;
4515 struct in_addr nexthop;
4516 u_int32_t med = 0;
4517 struct bgp_info *ri;
4518 struct bgp_info *new;
4519 int first = 1;
4520 unsigned long match = 0;
4521
4522 /* Record adding route's nexthop and med. */
4523 if (rinew)
4524 {
4525 nexthop = rinew->attr->nexthop;
4526 med = rinew->attr->med;
4527 }
4528
4529 /* ORIGIN attribute: If at least one route among routes that are
4530 aggregated has ORIGIN with the value INCOMPLETE, then the
4531 aggregated route must have the ORIGIN attribute with the value
4532 INCOMPLETE. Otherwise, if at least one route among routes that
4533 are aggregated has ORIGIN with the value EGP, then the aggregated
4534 route must have the origin attribute with the value EGP. In all
4535 other case the value of the ORIGIN attribute of the aggregated
4536 route is INTERNAL. */
4537 origin = BGP_ORIGIN_IGP;
4538
4539 table = bgp->rib[afi][safi];
4540
4541 top = bgp_node_get (table, p);
4542 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4543 if (rn->p.prefixlen > p->prefixlen)
4544 {
4545 match = 0;
4546
4547 for (ri = rn->info; ri; ri = ri->next)
4548 {
4549 if (BGP_INFO_HOLDDOWN (ri))
4550 continue;
4551
4552 if (del && ri == del)
4553 continue;
4554
4555 if (! rinew && first)
4556 {
4557 nexthop = ri->attr->nexthop;
4558 med = ri->attr->med;
4559 first = 0;
4560 }
4561
4562#ifdef AGGREGATE_NEXTHOP_CHECK
4563 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4564 || ri->attr->med != med)
4565 {
4566 if (aspath)
4567 aspath_free (aspath);
4568 if (community)
4569 community_free (community);
4570 bgp_unlock_node (rn);
4571 bgp_unlock_node (top);
4572 return;
4573 }
4574#endif /* AGGREGATE_NEXTHOP_CHECK */
4575
4576 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4577 {
4578 if (aggregate->summary_only)
4579 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004580 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004581 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004582 match++;
4583 }
4584
4585 aggregate->count++;
4586
4587 if (aggregate->as_set)
4588 {
4589 if (origin < ri->attr->origin)
4590 origin = ri->attr->origin;
4591
4592 if (aspath)
4593 {
4594 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4595 aspath_free (aspath);
4596 aspath = asmerge;
4597 }
4598 else
4599 aspath = aspath_dup (ri->attr->aspath);
4600
4601 if (ri->attr->community)
4602 {
4603 if (community)
4604 {
4605 commerge = community_merge (community,
4606 ri->attr->community);
4607 community = community_uniq_sort (commerge);
4608 community_free (commerge);
4609 }
4610 else
4611 community = community_dup (ri->attr->community);
4612 }
4613 }
4614 }
4615 }
4616 if (match)
4617 bgp_process (bgp, rn, afi, safi);
4618 }
4619 bgp_unlock_node (top);
4620
4621 if (rinew)
4622 {
4623 aggregate->count++;
4624
4625 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004626 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004627
4628 if (aggregate->as_set)
4629 {
4630 if (origin < rinew->attr->origin)
4631 origin = rinew->attr->origin;
4632
4633 if (aspath)
4634 {
4635 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4636 aspath_free (aspath);
4637 aspath = asmerge;
4638 }
4639 else
4640 aspath = aspath_dup (rinew->attr->aspath);
4641
4642 if (rinew->attr->community)
4643 {
4644 if (community)
4645 {
4646 commerge = community_merge (community,
4647 rinew->attr->community);
4648 community = community_uniq_sort (commerge);
4649 community_free (commerge);
4650 }
4651 else
4652 community = community_dup (rinew->attr->community);
4653 }
4654 }
4655 }
4656
4657 if (aggregate->count > 0)
4658 {
4659 rn = bgp_node_get (table, p);
4660 new = bgp_info_new ();
4661 new->type = ZEBRA_ROUTE_BGP;
4662 new->sub_type = BGP_ROUTE_AGGREGATE;
4663 new->peer = bgp->peer_self;
4664 SET_FLAG (new->flags, BGP_INFO_VALID);
4665 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4666 new->uptime = time (NULL);
4667
4668 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004669 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004670 bgp_process (bgp, rn, afi, safi);
4671 }
4672 else
4673 {
4674 if (aspath)
4675 aspath_free (aspath);
4676 if (community)
4677 community_free (community);
4678 }
4679}
4680
4681void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4682 struct bgp_aggregate *);
4683
4684void
4685bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4686 struct bgp_info *ri, afi_t afi, safi_t safi)
4687{
4688 struct bgp_node *child;
4689 struct bgp_node *rn;
4690 struct bgp_aggregate *aggregate;
4691
4692 /* MPLS-VPN aggregation is not yet supported. */
4693 if (safi == SAFI_MPLS_VPN)
4694 return;
4695
4696 if (p->prefixlen == 0)
4697 return;
4698
4699 if (BGP_INFO_HOLDDOWN (ri))
4700 return;
4701
4702 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4703
4704 /* Aggregate address configuration check. */
4705 for (rn = child; rn; rn = rn->parent)
4706 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4707 {
4708 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004709 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004710 }
4711 bgp_unlock_node (child);
4712}
4713
4714void
4715bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4716 struct bgp_info *del, afi_t afi, safi_t safi)
4717{
4718 struct bgp_node *child;
4719 struct bgp_node *rn;
4720 struct bgp_aggregate *aggregate;
4721
4722 /* MPLS-VPN aggregation is not yet supported. */
4723 if (safi == SAFI_MPLS_VPN)
4724 return;
4725
4726 if (p->prefixlen == 0)
4727 return;
4728
4729 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4730
4731 /* Aggregate address configuration check. */
4732 for (rn = child; rn; rn = rn->parent)
4733 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4734 {
4735 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004736 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004737 }
4738 bgp_unlock_node (child);
4739}
4740
paul94f2b392005-06-28 12:44:16 +00004741static void
paul718e3742002-12-13 20:15:29 +00004742bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4743 struct bgp_aggregate *aggregate)
4744{
4745 struct bgp_table *table;
4746 struct bgp_node *top;
4747 struct bgp_node *rn;
4748 struct bgp_info *new;
4749 struct bgp_info *ri;
4750 unsigned long match;
4751 u_char origin = BGP_ORIGIN_IGP;
4752 struct aspath *aspath = NULL;
4753 struct aspath *asmerge = NULL;
4754 struct community *community = NULL;
4755 struct community *commerge = NULL;
4756
4757 table = bgp->rib[afi][safi];
4758
4759 /* Sanity check. */
4760 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4761 return;
4762 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4763 return;
4764
4765 /* If routes exists below this node, generate aggregate routes. */
4766 top = bgp_node_get (table, p);
4767 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4768 if (rn->p.prefixlen > p->prefixlen)
4769 {
4770 match = 0;
4771
4772 for (ri = rn->info; ri; ri = ri->next)
4773 {
4774 if (BGP_INFO_HOLDDOWN (ri))
4775 continue;
4776
4777 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4778 {
4779 /* summary-only aggregate route suppress aggregated
4780 route announcement. */
4781 if (aggregate->summary_only)
4782 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004783 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004784 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004785 match++;
4786 }
4787 /* as-set aggregate route generate origin, as path,
4788 community aggregation. */
4789 if (aggregate->as_set)
4790 {
4791 if (origin < ri->attr->origin)
4792 origin = ri->attr->origin;
4793
4794 if (aspath)
4795 {
4796 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4797 aspath_free (aspath);
4798 aspath = asmerge;
4799 }
4800 else
4801 aspath = aspath_dup (ri->attr->aspath);
4802
4803 if (ri->attr->community)
4804 {
4805 if (community)
4806 {
4807 commerge = community_merge (community,
4808 ri->attr->community);
4809 community = community_uniq_sort (commerge);
4810 community_free (commerge);
4811 }
4812 else
4813 community = community_dup (ri->attr->community);
4814 }
4815 }
4816 aggregate->count++;
4817 }
4818 }
4819
4820 /* If this node is suppressed, process the change. */
4821 if (match)
4822 bgp_process (bgp, rn, afi, safi);
4823 }
4824 bgp_unlock_node (top);
4825
4826 /* Add aggregate route to BGP table. */
4827 if (aggregate->count)
4828 {
4829 rn = bgp_node_get (table, p);
4830
4831 new = bgp_info_new ();
4832 new->type = ZEBRA_ROUTE_BGP;
4833 new->sub_type = BGP_ROUTE_AGGREGATE;
4834 new->peer = bgp->peer_self;
4835 SET_FLAG (new->flags, BGP_INFO_VALID);
4836 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4837 new->uptime = time (NULL);
4838
4839 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004840 bgp_unlock_node (rn);
4841
paul718e3742002-12-13 20:15:29 +00004842 /* Process change. */
4843 bgp_process (bgp, rn, afi, safi);
4844 }
4845}
4846
4847void
4848bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4849 safi_t safi, struct bgp_aggregate *aggregate)
4850{
4851 struct bgp_table *table;
4852 struct bgp_node *top;
4853 struct bgp_node *rn;
4854 struct bgp_info *ri;
4855 unsigned long match;
4856
4857 table = bgp->rib[afi][safi];
4858
4859 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4860 return;
4861 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4862 return;
4863
4864 /* If routes exists below this node, generate aggregate routes. */
4865 top = bgp_node_get (table, p);
4866 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4867 if (rn->p.prefixlen > p->prefixlen)
4868 {
4869 match = 0;
4870
4871 for (ri = rn->info; ri; ri = ri->next)
4872 {
4873 if (BGP_INFO_HOLDDOWN (ri))
4874 continue;
4875
4876 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4877 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004878 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004879 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004880 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004881
Paul Jakmafb982c22007-05-04 20:15:47 +00004882 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004883 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004884 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004885 match++;
4886 }
4887 }
4888 aggregate->count--;
4889 }
4890 }
4891
Paul Jakmafb982c22007-05-04 20:15:47 +00004892 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004893 if (match)
4894 bgp_process (bgp, rn, afi, safi);
4895 }
4896 bgp_unlock_node (top);
4897
4898 /* Delete aggregate route from BGP table. */
4899 rn = bgp_node_get (table, p);
4900
4901 for (ri = rn->info; ri; ri = ri->next)
4902 if (ri->peer == bgp->peer_self
4903 && ri->type == ZEBRA_ROUTE_BGP
4904 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4905 break;
4906
4907 /* Withdraw static BGP route from routing table. */
4908 if (ri)
4909 {
paul718e3742002-12-13 20:15:29 +00004910 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004911 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004912 }
4913
4914 /* Unlock bgp_node_lookup. */
4915 bgp_unlock_node (rn);
4916}
4917
4918/* Aggregate route attribute. */
4919#define AGGREGATE_SUMMARY_ONLY 1
4920#define AGGREGATE_AS_SET 1
4921
paul94f2b392005-06-28 12:44:16 +00004922static int
paulfd79ac92004-10-13 05:06:08 +00004923bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4924 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004925 u_char summary_only, u_char as_set)
4926{
4927 int ret;
4928 struct prefix p;
4929 struct bgp_node *rn;
4930 struct bgp *bgp;
4931 struct bgp_aggregate *aggregate;
4932
4933 /* Convert string to prefix structure. */
4934 ret = str2prefix (prefix_str, &p);
4935 if (!ret)
4936 {
4937 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4938 return CMD_WARNING;
4939 }
4940 apply_mask (&p);
4941
4942 /* Get BGP structure. */
4943 bgp = vty->index;
4944
4945 /* Old configuration check. */
4946 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4947
4948 if (rn->info)
4949 {
4950 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4951 bgp_unlock_node (rn);
4952 return CMD_WARNING;
4953 }
4954
4955 /* Make aggregate address structure. */
4956 aggregate = bgp_aggregate_new ();
4957 aggregate->summary_only = summary_only;
4958 aggregate->as_set = as_set;
4959 aggregate->safi = safi;
4960 rn->info = aggregate;
4961
4962 /* Aggregate address insert into BGP routing table. */
4963 if (safi & SAFI_UNICAST)
4964 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4965 if (safi & SAFI_MULTICAST)
4966 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4967
4968 return CMD_SUCCESS;
4969}
4970
paul94f2b392005-06-28 12:44:16 +00004971static int
paulfd79ac92004-10-13 05:06:08 +00004972bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4973 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004974{
4975 int ret;
4976 struct prefix p;
4977 struct bgp_node *rn;
4978 struct bgp *bgp;
4979 struct bgp_aggregate *aggregate;
4980
4981 /* Convert string to prefix structure. */
4982 ret = str2prefix (prefix_str, &p);
4983 if (!ret)
4984 {
4985 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4986 return CMD_WARNING;
4987 }
4988 apply_mask (&p);
4989
4990 /* Get BGP structure. */
4991 bgp = vty->index;
4992
4993 /* Old configuration check. */
4994 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4995 if (! rn)
4996 {
4997 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4998 VTY_NEWLINE);
4999 return CMD_WARNING;
5000 }
5001
5002 aggregate = rn->info;
5003 if (aggregate->safi & SAFI_UNICAST)
5004 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5005 if (aggregate->safi & SAFI_MULTICAST)
5006 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5007
5008 /* Unlock aggregate address configuration. */
5009 rn->info = NULL;
5010 bgp_aggregate_free (aggregate);
5011 bgp_unlock_node (rn);
5012 bgp_unlock_node (rn);
5013
5014 return CMD_SUCCESS;
5015}
5016
5017DEFUN (aggregate_address,
5018 aggregate_address_cmd,
5019 "aggregate-address A.B.C.D/M",
5020 "Configure BGP aggregate entries\n"
5021 "Aggregate prefix\n")
5022{
5023 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5024}
5025
5026DEFUN (aggregate_address_mask,
5027 aggregate_address_mask_cmd,
5028 "aggregate-address A.B.C.D A.B.C.D",
5029 "Configure BGP aggregate entries\n"
5030 "Aggregate address\n"
5031 "Aggregate mask\n")
5032{
5033 int ret;
5034 char prefix_str[BUFSIZ];
5035
5036 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5037
5038 if (! ret)
5039 {
5040 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5041 return CMD_WARNING;
5042 }
5043
5044 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5045 0, 0);
5046}
5047
5048DEFUN (aggregate_address_summary_only,
5049 aggregate_address_summary_only_cmd,
5050 "aggregate-address A.B.C.D/M summary-only",
5051 "Configure BGP aggregate entries\n"
5052 "Aggregate prefix\n"
5053 "Filter more specific routes from updates\n")
5054{
5055 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5056 AGGREGATE_SUMMARY_ONLY, 0);
5057}
5058
5059DEFUN (aggregate_address_mask_summary_only,
5060 aggregate_address_mask_summary_only_cmd,
5061 "aggregate-address A.B.C.D A.B.C.D summary-only",
5062 "Configure BGP aggregate entries\n"
5063 "Aggregate address\n"
5064 "Aggregate mask\n"
5065 "Filter more specific routes from updates\n")
5066{
5067 int ret;
5068 char prefix_str[BUFSIZ];
5069
5070 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5071
5072 if (! ret)
5073 {
5074 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5075 return CMD_WARNING;
5076 }
5077
5078 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5079 AGGREGATE_SUMMARY_ONLY, 0);
5080}
5081
5082DEFUN (aggregate_address_as_set,
5083 aggregate_address_as_set_cmd,
5084 "aggregate-address A.B.C.D/M as-set",
5085 "Configure BGP aggregate entries\n"
5086 "Aggregate prefix\n"
5087 "Generate AS set path information\n")
5088{
5089 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5090 0, AGGREGATE_AS_SET);
5091}
5092
5093DEFUN (aggregate_address_mask_as_set,
5094 aggregate_address_mask_as_set_cmd,
5095 "aggregate-address A.B.C.D A.B.C.D as-set",
5096 "Configure BGP aggregate entries\n"
5097 "Aggregate address\n"
5098 "Aggregate mask\n"
5099 "Generate AS set path information\n")
5100{
5101 int ret;
5102 char prefix_str[BUFSIZ];
5103
5104 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5105
5106 if (! ret)
5107 {
5108 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5109 return CMD_WARNING;
5110 }
5111
5112 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5113 0, AGGREGATE_AS_SET);
5114}
5115
5116
5117DEFUN (aggregate_address_as_set_summary,
5118 aggregate_address_as_set_summary_cmd,
5119 "aggregate-address A.B.C.D/M as-set summary-only",
5120 "Configure BGP aggregate entries\n"
5121 "Aggregate prefix\n"
5122 "Generate AS set path information\n"
5123 "Filter more specific routes from updates\n")
5124{
5125 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5126 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5127}
5128
5129ALIAS (aggregate_address_as_set_summary,
5130 aggregate_address_summary_as_set_cmd,
5131 "aggregate-address A.B.C.D/M summary-only as-set",
5132 "Configure BGP aggregate entries\n"
5133 "Aggregate prefix\n"
5134 "Filter more specific routes from updates\n"
5135 "Generate AS set path information\n")
5136
5137DEFUN (aggregate_address_mask_as_set_summary,
5138 aggregate_address_mask_as_set_summary_cmd,
5139 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5140 "Configure BGP aggregate entries\n"
5141 "Aggregate address\n"
5142 "Aggregate mask\n"
5143 "Generate AS set path information\n"
5144 "Filter more specific routes from updates\n")
5145{
5146 int ret;
5147 char prefix_str[BUFSIZ];
5148
5149 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5150
5151 if (! ret)
5152 {
5153 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5154 return CMD_WARNING;
5155 }
5156
5157 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5158 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5159}
5160
5161ALIAS (aggregate_address_mask_as_set_summary,
5162 aggregate_address_mask_summary_as_set_cmd,
5163 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5164 "Configure BGP aggregate entries\n"
5165 "Aggregate address\n"
5166 "Aggregate mask\n"
5167 "Filter more specific routes from updates\n"
5168 "Generate AS set path information\n")
5169
5170DEFUN (no_aggregate_address,
5171 no_aggregate_address_cmd,
5172 "no aggregate-address A.B.C.D/M",
5173 NO_STR
5174 "Configure BGP aggregate entries\n"
5175 "Aggregate prefix\n")
5176{
5177 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5178}
5179
5180ALIAS (no_aggregate_address,
5181 no_aggregate_address_summary_only_cmd,
5182 "no aggregate-address A.B.C.D/M summary-only",
5183 NO_STR
5184 "Configure BGP aggregate entries\n"
5185 "Aggregate prefix\n"
5186 "Filter more specific routes from updates\n")
5187
5188ALIAS (no_aggregate_address,
5189 no_aggregate_address_as_set_cmd,
5190 "no aggregate-address A.B.C.D/M as-set",
5191 NO_STR
5192 "Configure BGP aggregate entries\n"
5193 "Aggregate prefix\n"
5194 "Generate AS set path information\n")
5195
5196ALIAS (no_aggregate_address,
5197 no_aggregate_address_as_set_summary_cmd,
5198 "no aggregate-address A.B.C.D/M as-set summary-only",
5199 NO_STR
5200 "Configure BGP aggregate entries\n"
5201 "Aggregate prefix\n"
5202 "Generate AS set path information\n"
5203 "Filter more specific routes from updates\n")
5204
5205ALIAS (no_aggregate_address,
5206 no_aggregate_address_summary_as_set_cmd,
5207 "no aggregate-address A.B.C.D/M summary-only as-set",
5208 NO_STR
5209 "Configure BGP aggregate entries\n"
5210 "Aggregate prefix\n"
5211 "Filter more specific routes from updates\n"
5212 "Generate AS set path information\n")
5213
5214DEFUN (no_aggregate_address_mask,
5215 no_aggregate_address_mask_cmd,
5216 "no aggregate-address A.B.C.D A.B.C.D",
5217 NO_STR
5218 "Configure BGP aggregate entries\n"
5219 "Aggregate address\n"
5220 "Aggregate mask\n")
5221{
5222 int ret;
5223 char prefix_str[BUFSIZ];
5224
5225 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5226
5227 if (! ret)
5228 {
5229 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5230 return CMD_WARNING;
5231 }
5232
5233 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5234}
5235
5236ALIAS (no_aggregate_address_mask,
5237 no_aggregate_address_mask_summary_only_cmd,
5238 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5239 NO_STR
5240 "Configure BGP aggregate entries\n"
5241 "Aggregate address\n"
5242 "Aggregate mask\n"
5243 "Filter more specific routes from updates\n")
5244
5245ALIAS (no_aggregate_address_mask,
5246 no_aggregate_address_mask_as_set_cmd,
5247 "no aggregate-address A.B.C.D A.B.C.D as-set",
5248 NO_STR
5249 "Configure BGP aggregate entries\n"
5250 "Aggregate address\n"
5251 "Aggregate mask\n"
5252 "Generate AS set path information\n")
5253
5254ALIAS (no_aggregate_address_mask,
5255 no_aggregate_address_mask_as_set_summary_cmd,
5256 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5257 NO_STR
5258 "Configure BGP aggregate entries\n"
5259 "Aggregate address\n"
5260 "Aggregate mask\n"
5261 "Generate AS set path information\n"
5262 "Filter more specific routes from updates\n")
5263
5264ALIAS (no_aggregate_address_mask,
5265 no_aggregate_address_mask_summary_as_set_cmd,
5266 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5267 NO_STR
5268 "Configure BGP aggregate entries\n"
5269 "Aggregate address\n"
5270 "Aggregate mask\n"
5271 "Filter more specific routes from updates\n"
5272 "Generate AS set path information\n")
5273
5274#ifdef HAVE_IPV6
5275DEFUN (ipv6_aggregate_address,
5276 ipv6_aggregate_address_cmd,
5277 "aggregate-address X:X::X:X/M",
5278 "Configure BGP aggregate entries\n"
5279 "Aggregate prefix\n")
5280{
5281 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5282}
5283
5284DEFUN (ipv6_aggregate_address_summary_only,
5285 ipv6_aggregate_address_summary_only_cmd,
5286 "aggregate-address X:X::X:X/M summary-only",
5287 "Configure BGP aggregate entries\n"
5288 "Aggregate prefix\n"
5289 "Filter more specific routes from updates\n")
5290{
5291 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5292 AGGREGATE_SUMMARY_ONLY, 0);
5293}
5294
5295DEFUN (no_ipv6_aggregate_address,
5296 no_ipv6_aggregate_address_cmd,
5297 "no aggregate-address X:X::X:X/M",
5298 NO_STR
5299 "Configure BGP aggregate entries\n"
5300 "Aggregate prefix\n")
5301{
5302 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5303}
5304
5305DEFUN (no_ipv6_aggregate_address_summary_only,
5306 no_ipv6_aggregate_address_summary_only_cmd,
5307 "no aggregate-address X:X::X:X/M summary-only",
5308 NO_STR
5309 "Configure BGP aggregate entries\n"
5310 "Aggregate prefix\n"
5311 "Filter more specific routes from updates\n")
5312{
5313 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5314}
5315
5316ALIAS (ipv6_aggregate_address,
5317 old_ipv6_aggregate_address_cmd,
5318 "ipv6 bgp aggregate-address X:X::X:X/M",
5319 IPV6_STR
5320 BGP_STR
5321 "Configure BGP aggregate entries\n"
5322 "Aggregate prefix\n")
5323
5324ALIAS (ipv6_aggregate_address_summary_only,
5325 old_ipv6_aggregate_address_summary_only_cmd,
5326 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5327 IPV6_STR
5328 BGP_STR
5329 "Configure BGP aggregate entries\n"
5330 "Aggregate prefix\n"
5331 "Filter more specific routes from updates\n")
5332
5333ALIAS (no_ipv6_aggregate_address,
5334 old_no_ipv6_aggregate_address_cmd,
5335 "no ipv6 bgp aggregate-address X:X::X:X/M",
5336 NO_STR
5337 IPV6_STR
5338 BGP_STR
5339 "Configure BGP aggregate entries\n"
5340 "Aggregate prefix\n")
5341
5342ALIAS (no_ipv6_aggregate_address_summary_only,
5343 old_no_ipv6_aggregate_address_summary_only_cmd,
5344 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5345 NO_STR
5346 IPV6_STR
5347 BGP_STR
5348 "Configure BGP aggregate entries\n"
5349 "Aggregate prefix\n"
5350 "Filter more specific routes from updates\n")
5351#endif /* HAVE_IPV6 */
5352
5353/* Redistribute route treatment. */
5354void
5355bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5356 u_int32_t metric, u_char type)
5357{
5358 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005359 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005360 struct bgp_info *new;
5361 struct bgp_info *bi;
5362 struct bgp_info info;
5363 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005364 struct attr attr = { 0 };
5365 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005366 struct attr *new_attr;
5367 afi_t afi;
5368 int ret;
5369
5370 /* Make default attribute. */
5371 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5372 if (nexthop)
5373 attr.nexthop = *nexthop;
5374
5375 attr.med = metric;
5376 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5377
paul1eb8ef22005-04-07 07:30:20 +00005378 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005379 {
5380 afi = family2afi (p->family);
5381
5382 if (bgp->redist[afi][type])
5383 {
5384 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005385 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005386
5387 if (bgp->redist_metric_flag[afi][type])
5388 attr_new.med = bgp->redist_metric[afi][type];
5389
5390 /* Apply route-map. */
5391 if (bgp->rmap[afi][type].map)
5392 {
5393 info.peer = bgp->peer_self;
5394 info.attr = &attr_new;
5395
paulfee0f4c2004-09-13 05:12:46 +00005396 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5397
paul718e3742002-12-13 20:15:29 +00005398 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5399 &info);
paulfee0f4c2004-09-13 05:12:46 +00005400
5401 bgp->peer_self->rmap_type = 0;
5402
paul718e3742002-12-13 20:15:29 +00005403 if (ret == RMAP_DENYMATCH)
5404 {
5405 /* Free uninterned attribute. */
5406 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005407 bgp_attr_extra_free (&attr_new);
5408
paul718e3742002-12-13 20:15:29 +00005409 /* Unintern original. */
5410 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005411 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005412 bgp_redistribute_delete (p, type);
5413 return;
5414 }
5415 }
5416
Paul Jakmafb982c22007-05-04 20:15:47 +00005417 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5418 afi, SAFI_UNICAST, p, NULL);
5419
paul718e3742002-12-13 20:15:29 +00005420 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005421 bgp_attr_extra_free (&attr_new);
5422
paul718e3742002-12-13 20:15:29 +00005423 for (bi = bn->info; bi; bi = bi->next)
5424 if (bi->peer == bgp->peer_self
5425 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5426 break;
5427
5428 if (bi)
5429 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005430 if (attrhash_cmp (bi->attr, new_attr) &&
5431 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005432 {
5433 bgp_attr_unintern (new_attr);
5434 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005435 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005436 bgp_unlock_node (bn);
5437 return;
5438 }
5439 else
5440 {
5441 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005442 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005443
5444 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005445 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5446 bgp_info_restore(bn, bi);
5447 else
5448 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005449 bgp_attr_unintern (bi->attr);
5450 bi->attr = new_attr;
5451 bi->uptime = time (NULL);
5452
5453 /* Process change. */
5454 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5455 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5456 bgp_unlock_node (bn);
5457 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005458 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005459 return;
5460 }
5461 }
5462
5463 new = bgp_info_new ();
5464 new->type = type;
5465 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5466 new->peer = bgp->peer_self;
5467 SET_FLAG (new->flags, BGP_INFO_VALID);
5468 new->attr = new_attr;
5469 new->uptime = time (NULL);
5470
5471 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5472 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005473 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005474 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5475 }
5476 }
5477
5478 /* Unintern original. */
5479 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005480 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005481}
5482
5483void
5484bgp_redistribute_delete (struct prefix *p, u_char type)
5485{
5486 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005487 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005488 afi_t afi;
5489 struct bgp_node *rn;
5490 struct bgp_info *ri;
5491
paul1eb8ef22005-04-07 07:30:20 +00005492 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005493 {
5494 afi = family2afi (p->family);
5495
5496 if (bgp->redist[afi][type])
5497 {
paulfee0f4c2004-09-13 05:12:46 +00005498 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005499
5500 for (ri = rn->info; ri; ri = ri->next)
5501 if (ri->peer == bgp->peer_self
5502 && ri->type == type)
5503 break;
5504
5505 if (ri)
5506 {
5507 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005508 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005509 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005510 }
5511 bgp_unlock_node (rn);
5512 }
5513 }
5514}
5515
5516/* Withdraw specified route type's route. */
5517void
5518bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5519{
5520 struct bgp_node *rn;
5521 struct bgp_info *ri;
5522 struct bgp_table *table;
5523
5524 table = bgp->rib[afi][SAFI_UNICAST];
5525
5526 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5527 {
5528 for (ri = rn->info; ri; ri = ri->next)
5529 if (ri->peer == bgp->peer_self
5530 && ri->type == type)
5531 break;
5532
5533 if (ri)
5534 {
5535 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005536 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005537 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005538 }
5539 }
5540}
5541
5542/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005543static void
paul718e3742002-12-13 20:15:29 +00005544route_vty_out_route (struct prefix *p, struct vty *vty)
5545{
5546 int len;
5547 u_int32_t destination;
5548 char buf[BUFSIZ];
5549
5550 if (p->family == AF_INET)
5551 {
5552 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5553 destination = ntohl (p->u.prefix4.s_addr);
5554
5555 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5556 || (IN_CLASSB (destination) && p->prefixlen == 16)
5557 || (IN_CLASSA (destination) && p->prefixlen == 8)
5558 || p->u.prefix4.s_addr == 0)
5559 {
5560 /* When mask is natural, mask is not displayed. */
5561 }
5562 else
5563 len += vty_out (vty, "/%d", p->prefixlen);
5564 }
5565 else
5566 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5567 p->prefixlen);
5568
5569 len = 17 - len;
5570 if (len < 1)
5571 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5572 else
5573 vty_out (vty, "%*s", len, " ");
5574}
5575
paul718e3742002-12-13 20:15:29 +00005576enum bgp_display_type
5577{
5578 normal_list,
5579};
5580
paulb40d9392005-08-22 22:34:41 +00005581/* Print the short form route status for a bgp_info */
5582static void
5583route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005584{
paulb40d9392005-08-22 22:34:41 +00005585 /* Route status display. */
5586 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5587 vty_out (vty, "R");
5588 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005589 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005590 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005591 vty_out (vty, "s");
5592 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5593 vty_out (vty, "*");
5594 else
5595 vty_out (vty, " ");
5596
5597 /* Selected */
5598 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5599 vty_out (vty, "h");
5600 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5601 vty_out (vty, "d");
5602 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5603 vty_out (vty, ">");
5604 else
5605 vty_out (vty, " ");
5606
5607 /* Internal route. */
5608 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5609 vty_out (vty, "i");
5610 else
paulb40d9392005-08-22 22:34:41 +00005611 vty_out (vty, " ");
5612}
5613
5614/* called from terminal list command */
5615void
5616route_vty_out (struct vty *vty, struct prefix *p,
5617 struct bgp_info *binfo, int display, safi_t safi)
5618{
5619 struct attr *attr;
5620
5621 /* short status lead text */
5622 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005623
5624 /* print prefix and mask */
5625 if (! display)
5626 route_vty_out_route (p, vty);
5627 else
5628 vty_out (vty, "%*s", 17, " ");
5629
5630 /* Print attribute */
5631 attr = binfo->attr;
5632 if (attr)
5633 {
5634 if (p->family == AF_INET)
5635 {
5636 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005637 vty_out (vty, "%-16s",
5638 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005639 else
5640 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5641 }
5642#ifdef HAVE_IPV6
5643 else if (p->family == AF_INET6)
5644 {
5645 int len;
5646 char buf[BUFSIZ];
5647
5648 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005649 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5650 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005651 len = 16 - len;
5652 if (len < 1)
5653 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5654 else
5655 vty_out (vty, "%*s", len, " ");
5656 }
5657#endif /* HAVE_IPV6 */
5658
5659 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5660 vty_out (vty, "%10d", attr->med);
5661 else
5662 vty_out (vty, " ");
5663
5664 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5665 vty_out (vty, "%7d", attr->local_pref);
5666 else
5667 vty_out (vty, " ");
5668
Paul Jakmafb982c22007-05-04 20:15:47 +00005669 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005670
Paul Jakmab2518c12006-05-12 23:48:40 +00005671 /* Print aspath */
5672 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005673 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005674
Paul Jakmab2518c12006-05-12 23:48:40 +00005675 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005676 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005677 }
paul718e3742002-12-13 20:15:29 +00005678 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005679}
5680
5681/* called from terminal list command */
5682void
5683route_vty_out_tmp (struct vty *vty, struct prefix *p,
5684 struct attr *attr, safi_t safi)
5685{
5686 /* Route status display. */
5687 vty_out (vty, "*");
5688 vty_out (vty, ">");
5689 vty_out (vty, " ");
5690
5691 /* print prefix and mask */
5692 route_vty_out_route (p, vty);
5693
5694 /* Print attribute */
5695 if (attr)
5696 {
5697 if (p->family == AF_INET)
5698 {
5699 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005700 vty_out (vty, "%-16s",
5701 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005702 else
5703 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5704 }
5705#ifdef HAVE_IPV6
5706 else if (p->family == AF_INET6)
5707 {
5708 int len;
5709 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005710
5711 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005712
5713 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005714 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5715 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005716 len = 16 - len;
5717 if (len < 1)
5718 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5719 else
5720 vty_out (vty, "%*s", len, " ");
5721 }
5722#endif /* HAVE_IPV6 */
5723
5724 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5725 vty_out (vty, "%10d", attr->med);
5726 else
5727 vty_out (vty, " ");
5728
5729 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5730 vty_out (vty, "%7d", attr->local_pref);
5731 else
5732 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005733
5734 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5735
Paul Jakmab2518c12006-05-12 23:48:40 +00005736 /* Print aspath */
5737 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005738 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005739
Paul Jakmab2518c12006-05-12 23:48:40 +00005740 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005741 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005742 }
paul718e3742002-12-13 20:15:29 +00005743
5744 vty_out (vty, "%s", VTY_NEWLINE);
5745}
5746
ajs5a646652004-11-05 01:25:55 +00005747void
paul718e3742002-12-13 20:15:29 +00005748route_vty_out_tag (struct vty *vty, struct prefix *p,
5749 struct bgp_info *binfo, int display, safi_t safi)
5750{
5751 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005752 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005753
5754 if (!binfo->extra)
5755 return;
5756
paulb40d9392005-08-22 22:34:41 +00005757 /* short status lead text */
5758 route_vty_short_status_out (vty, binfo);
5759
paul718e3742002-12-13 20:15:29 +00005760 /* print prefix and mask */
5761 if (! display)
5762 route_vty_out_route (p, vty);
5763 else
5764 vty_out (vty, "%*s", 17, " ");
5765
5766 /* Print attribute */
5767 attr = binfo->attr;
5768 if (attr)
5769 {
5770 if (p->family == AF_INET)
5771 {
5772 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005773 vty_out (vty, "%-16s",
5774 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005775 else
5776 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5777 }
5778#ifdef HAVE_IPV6
5779 else if (p->family == AF_INET6)
5780 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005781 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005782 char buf[BUFSIZ];
5783 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005784 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005785 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005786 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5787 buf, BUFSIZ));
5788 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005789 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005790 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5791 buf, BUFSIZ),
5792 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5793 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005794
5795 }
5796#endif /* HAVE_IPV6 */
5797 }
5798
Paul Jakmafb982c22007-05-04 20:15:47 +00005799 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005800
5801 vty_out (vty, "notag/%d", label);
5802
5803 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005804}
5805
5806/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005807static void
paul718e3742002-12-13 20:15:29 +00005808damp_route_vty_out (struct vty *vty, struct prefix *p,
5809 struct bgp_info *binfo, int display, safi_t safi)
5810{
5811 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005812 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005813 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005814
paulb40d9392005-08-22 22:34:41 +00005815 /* short status lead text */
5816 route_vty_short_status_out (vty, binfo);
5817
paul718e3742002-12-13 20:15:29 +00005818 /* print prefix and mask */
5819 if (! display)
5820 route_vty_out_route (p, vty);
5821 else
5822 vty_out (vty, "%*s", 17, " ");
5823
5824 len = vty_out (vty, "%s", binfo->peer->host);
5825 len = 17 - len;
5826 if (len < 1)
5827 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5828 else
5829 vty_out (vty, "%*s", len, " ");
5830
Chris Caputo50aef6f2009-06-23 06:06:49 +00005831 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005832
5833 /* Print attribute */
5834 attr = binfo->attr;
5835 if (attr)
5836 {
5837 /* Print aspath */
5838 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005839 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005840
5841 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005842 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005843 }
5844 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005845}
5846
paul718e3742002-12-13 20:15:29 +00005847/* flap route */
ajs5a646652004-11-05 01:25:55 +00005848static void
paul718e3742002-12-13 20:15:29 +00005849flap_route_vty_out (struct vty *vty, struct prefix *p,
5850 struct bgp_info *binfo, int display, safi_t safi)
5851{
5852 struct attr *attr;
5853 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005854 char timebuf[BGP_UPTIME_LEN];
5855 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005856
5857 if (!binfo->extra)
5858 return;
5859
5860 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005861
paulb40d9392005-08-22 22:34:41 +00005862 /* short status lead text */
5863 route_vty_short_status_out (vty, binfo);
5864
paul718e3742002-12-13 20:15:29 +00005865 /* print prefix and mask */
5866 if (! display)
5867 route_vty_out_route (p, vty);
5868 else
5869 vty_out (vty, "%*s", 17, " ");
5870
5871 len = vty_out (vty, "%s", binfo->peer->host);
5872 len = 16 - len;
5873 if (len < 1)
5874 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5875 else
5876 vty_out (vty, "%*s", len, " ");
5877
5878 len = vty_out (vty, "%d", bdi->flap);
5879 len = 5 - len;
5880 if (len < 1)
5881 vty_out (vty, " ");
5882 else
5883 vty_out (vty, "%*s ", len, " ");
5884
5885 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5886 timebuf, BGP_UPTIME_LEN));
5887
5888 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5889 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005890 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005891 else
5892 vty_out (vty, "%*s ", 8, " ");
5893
5894 /* Print attribute */
5895 attr = binfo->attr;
5896 if (attr)
5897 {
5898 /* Print aspath */
5899 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005900 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005901
5902 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005903 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005904 }
5905 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005906}
5907
paul94f2b392005-06-28 12:44:16 +00005908static void
paul718e3742002-12-13 20:15:29 +00005909route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5910 struct bgp_info *binfo, afi_t afi, safi_t safi)
5911{
5912 char buf[INET6_ADDRSTRLEN];
5913 char buf1[BUFSIZ];
5914 struct attr *attr;
5915 int sockunion_vty_out (struct vty *, union sockunion *);
5916
5917 attr = binfo->attr;
5918
5919 if (attr)
5920 {
5921 /* Line1 display AS-path, Aggregator */
5922 if (attr->aspath)
5923 {
5924 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005925 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005926 vty_out (vty, "Local");
5927 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005928 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005929 }
5930
paulb40d9392005-08-22 22:34:41 +00005931 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5932 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005933 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5934 vty_out (vty, ", (stale)");
5935 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005936 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005937 attr->extra->aggregator_as,
5938 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005939 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5940 vty_out (vty, ", (Received from a RR-client)");
5941 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5942 vty_out (vty, ", (Received from a RS-client)");
5943 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5944 vty_out (vty, ", (history entry)");
5945 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5946 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005947 vty_out (vty, "%s", VTY_NEWLINE);
5948
5949 /* Line2 display Next-hop, Neighbor, Router-id */
5950 if (p->family == AF_INET)
5951 {
5952 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005953 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005954 inet_ntoa (attr->nexthop));
5955 }
5956#ifdef HAVE_IPV6
5957 else
5958 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005959 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005960 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005961 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005962 buf, INET6_ADDRSTRLEN));
5963 }
5964#endif /* HAVE_IPV6 */
5965
5966 if (binfo->peer == bgp->peer_self)
5967 {
5968 vty_out (vty, " from %s ",
5969 p->family == AF_INET ? "0.0.0.0" : "::");
5970 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5971 }
5972 else
5973 {
5974 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5975 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005976 else if (binfo->extra && binfo->extra->igpmetric)
5977 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005978 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005979 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005980 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005981 else
5982 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5983 }
5984 vty_out (vty, "%s", VTY_NEWLINE);
5985
5986#ifdef HAVE_IPV6
5987 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005988 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005989 {
5990 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005991 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005992 buf, INET6_ADDRSTRLEN),
5993 VTY_NEWLINE);
5994 }
5995#endif /* HAVE_IPV6 */
5996
5997 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5998 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5999
6000 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6001 vty_out (vty, ", metric %d", attr->med);
6002
6003 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6004 vty_out (vty, ", localpref %d", attr->local_pref);
6005 else
6006 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6007
Paul Jakmafb982c22007-05-04 20:15:47 +00006008 if (attr->extra && attr->extra->weight != 0)
6009 vty_out (vty, ", weight %d", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006010
6011 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6012 vty_out (vty, ", valid");
6013
6014 if (binfo->peer != bgp->peer_self)
6015 {
6016 if (binfo->peer->as == binfo->peer->local_as)
6017 vty_out (vty, ", internal");
6018 else
6019 vty_out (vty, ", %s",
6020 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6021 }
6022 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6023 vty_out (vty, ", aggregated, local");
6024 else if (binfo->type != ZEBRA_ROUTE_BGP)
6025 vty_out (vty, ", sourced");
6026 else
6027 vty_out (vty, ", sourced, local");
6028
6029 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6030 vty_out (vty, ", atomic-aggregate");
6031
6032 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6033 vty_out (vty, ", best");
6034
6035 vty_out (vty, "%s", VTY_NEWLINE);
6036
6037 /* Line 4 display Community */
6038 if (attr->community)
6039 vty_out (vty, " Community: %s%s", attr->community->str,
6040 VTY_NEWLINE);
6041
6042 /* Line 5 display Extended-community */
6043 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006044 vty_out (vty, " Extended Community: %s%s",
6045 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006046
6047 /* Line 6 display Originator, Cluster-id */
6048 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6049 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6050 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006051 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006052 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006053 vty_out (vty, " Originator: %s",
6054 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006055
6056 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6057 {
6058 int i;
6059 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006060 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6061 vty_out (vty, "%s ",
6062 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006063 }
6064 vty_out (vty, "%s", VTY_NEWLINE);
6065 }
Paul Jakma41367172007-08-06 15:24:51 +00006066
6067 /* 7: AS Pathlimit */
6068 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6069 {
6070
6071 vty_out (vty, " AS-Pathlimit: %u",
6072 attr->pathlimit.ttl);
6073 if (attr->pathlimit.as)
6074 vty_out (vty, " (%u)", attr->pathlimit.as);
6075 vty_out (vty, "%s", VTY_NEWLINE);
6076 }
6077
Paul Jakmafb982c22007-05-04 20:15:47 +00006078 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006079 bgp_damp_info_vty (vty, binfo);
6080
6081 /* Line 7 display Uptime */
6082 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
6083 }
6084 vty_out (vty, "%s", VTY_NEWLINE);
6085}
6086
paulb40d9392005-08-22 22:34:41 +00006087#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 +00006088#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006089#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6090#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6091#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6092
6093enum bgp_show_type
6094{
6095 bgp_show_type_normal,
6096 bgp_show_type_regexp,
6097 bgp_show_type_prefix_list,
6098 bgp_show_type_filter_list,
6099 bgp_show_type_route_map,
6100 bgp_show_type_neighbor,
6101 bgp_show_type_cidr_only,
6102 bgp_show_type_prefix_longer,
6103 bgp_show_type_community_all,
6104 bgp_show_type_community,
6105 bgp_show_type_community_exact,
6106 bgp_show_type_community_list,
6107 bgp_show_type_community_list_exact,
6108 bgp_show_type_flap_statistics,
6109 bgp_show_type_flap_address,
6110 bgp_show_type_flap_prefix,
6111 bgp_show_type_flap_cidr_only,
6112 bgp_show_type_flap_regexp,
6113 bgp_show_type_flap_filter_list,
6114 bgp_show_type_flap_prefix_list,
6115 bgp_show_type_flap_prefix_longer,
6116 bgp_show_type_flap_route_map,
6117 bgp_show_type_flap_neighbor,
6118 bgp_show_type_dampend_paths,
6119 bgp_show_type_damp_neighbor
6120};
6121
ajs5a646652004-11-05 01:25:55 +00006122static int
paulfee0f4c2004-09-13 05:12:46 +00006123bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006124 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006125{
paul718e3742002-12-13 20:15:29 +00006126 struct bgp_info *ri;
6127 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006128 int header = 1;
paul718e3742002-12-13 20:15:29 +00006129 int display;
ajs5a646652004-11-05 01:25:55 +00006130 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006131
6132 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006133 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006134
paul718e3742002-12-13 20:15:29 +00006135 /* Start processing of routes. */
6136 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6137 if (rn->info != NULL)
6138 {
6139 display = 0;
6140
6141 for (ri = rn->info; ri; ri = ri->next)
6142 {
ajs5a646652004-11-05 01:25:55 +00006143 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006144 || type == bgp_show_type_flap_address
6145 || type == bgp_show_type_flap_prefix
6146 || type == bgp_show_type_flap_cidr_only
6147 || type == bgp_show_type_flap_regexp
6148 || type == bgp_show_type_flap_filter_list
6149 || type == bgp_show_type_flap_prefix_list
6150 || type == bgp_show_type_flap_prefix_longer
6151 || type == bgp_show_type_flap_route_map
6152 || type == bgp_show_type_flap_neighbor
6153 || type == bgp_show_type_dampend_paths
6154 || type == bgp_show_type_damp_neighbor)
6155 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006156 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006157 continue;
6158 }
6159 if (type == bgp_show_type_regexp
6160 || type == bgp_show_type_flap_regexp)
6161 {
ajs5a646652004-11-05 01:25:55 +00006162 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006163
6164 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6165 continue;
6166 }
6167 if (type == bgp_show_type_prefix_list
6168 || type == bgp_show_type_flap_prefix_list)
6169 {
ajs5a646652004-11-05 01:25:55 +00006170 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006171
6172 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6173 continue;
6174 }
6175 if (type == bgp_show_type_filter_list
6176 || type == bgp_show_type_flap_filter_list)
6177 {
ajs5a646652004-11-05 01:25:55 +00006178 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006179
6180 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6181 continue;
6182 }
6183 if (type == bgp_show_type_route_map
6184 || type == bgp_show_type_flap_route_map)
6185 {
ajs5a646652004-11-05 01:25:55 +00006186 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006187 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006188 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006189 int ret;
6190
Paul Jakmafb982c22007-05-04 20:15:47 +00006191 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006192 binfo.peer = ri->peer;
6193 binfo.attr = &dummy_attr;
6194
6195 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006196
6197 bgp_attr_extra_free (&dummy_attr);
6198
paul718e3742002-12-13 20:15:29 +00006199 if (ret == RMAP_DENYMATCH)
6200 continue;
6201 }
6202 if (type == bgp_show_type_neighbor
6203 || type == bgp_show_type_flap_neighbor
6204 || type == bgp_show_type_damp_neighbor)
6205 {
ajs5a646652004-11-05 01:25:55 +00006206 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006207
6208 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6209 continue;
6210 }
6211 if (type == bgp_show_type_cidr_only
6212 || type == bgp_show_type_flap_cidr_only)
6213 {
6214 u_int32_t destination;
6215
6216 destination = ntohl (rn->p.u.prefix4.s_addr);
6217 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6218 continue;
6219 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6220 continue;
6221 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6222 continue;
6223 }
6224 if (type == bgp_show_type_prefix_longer
6225 || type == bgp_show_type_flap_prefix_longer)
6226 {
ajs5a646652004-11-05 01:25:55 +00006227 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006228
6229 if (! prefix_match (p, &rn->p))
6230 continue;
6231 }
6232 if (type == bgp_show_type_community_all)
6233 {
6234 if (! ri->attr->community)
6235 continue;
6236 }
6237 if (type == bgp_show_type_community)
6238 {
ajs5a646652004-11-05 01:25:55 +00006239 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006240
6241 if (! ri->attr->community ||
6242 ! community_match (ri->attr->community, com))
6243 continue;
6244 }
6245 if (type == bgp_show_type_community_exact)
6246 {
ajs5a646652004-11-05 01:25:55 +00006247 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006248
6249 if (! ri->attr->community ||
6250 ! community_cmp (ri->attr->community, com))
6251 continue;
6252 }
6253 if (type == bgp_show_type_community_list)
6254 {
ajs5a646652004-11-05 01:25:55 +00006255 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006256
6257 if (! community_list_match (ri->attr->community, list))
6258 continue;
6259 }
6260 if (type == bgp_show_type_community_list_exact)
6261 {
ajs5a646652004-11-05 01:25:55 +00006262 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006263
6264 if (! community_list_exact_match (ri->attr->community, list))
6265 continue;
6266 }
6267 if (type == bgp_show_type_flap_address
6268 || type == bgp_show_type_flap_prefix)
6269 {
ajs5a646652004-11-05 01:25:55 +00006270 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006271
6272 if (! prefix_match (&rn->p, p))
6273 continue;
6274
6275 if (type == bgp_show_type_flap_prefix)
6276 if (p->prefixlen != rn->p.prefixlen)
6277 continue;
6278 }
6279 if (type == bgp_show_type_dampend_paths
6280 || type == bgp_show_type_damp_neighbor)
6281 {
6282 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6283 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6284 continue;
6285 }
6286
6287 if (header)
6288 {
hasso93406d82005-02-02 14:40:33 +00006289 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6290 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6291 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006292 if (type == bgp_show_type_dampend_paths
6293 || type == bgp_show_type_damp_neighbor)
6294 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6295 else if (type == bgp_show_type_flap_statistics
6296 || type == bgp_show_type_flap_address
6297 || type == bgp_show_type_flap_prefix
6298 || type == bgp_show_type_flap_cidr_only
6299 || type == bgp_show_type_flap_regexp
6300 || type == bgp_show_type_flap_filter_list
6301 || type == bgp_show_type_flap_prefix_list
6302 || type == bgp_show_type_flap_prefix_longer
6303 || type == bgp_show_type_flap_route_map
6304 || type == bgp_show_type_flap_neighbor)
6305 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6306 else
6307 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006308 header = 0;
6309 }
6310
6311 if (type == bgp_show_type_dampend_paths
6312 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006313 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006314 else if (type == bgp_show_type_flap_statistics
6315 || type == bgp_show_type_flap_address
6316 || type == bgp_show_type_flap_prefix
6317 || type == bgp_show_type_flap_cidr_only
6318 || type == bgp_show_type_flap_regexp
6319 || type == bgp_show_type_flap_filter_list
6320 || type == bgp_show_type_flap_prefix_list
6321 || type == bgp_show_type_flap_prefix_longer
6322 || type == bgp_show_type_flap_route_map
6323 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006324 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006325 else
ajs5a646652004-11-05 01:25:55 +00006326 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006327 display++;
6328 }
6329 if (display)
ajs5a646652004-11-05 01:25:55 +00006330 output_count++;
paul718e3742002-12-13 20:15:29 +00006331 }
6332
6333 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006334 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006335 {
6336 if (type == bgp_show_type_normal)
6337 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6338 }
6339 else
6340 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006341 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006342
6343 return CMD_SUCCESS;
6344}
6345
ajs5a646652004-11-05 01:25:55 +00006346static int
paulfee0f4c2004-09-13 05:12:46 +00006347bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006348 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006349{
6350 struct bgp_table *table;
6351
6352 if (bgp == NULL) {
6353 bgp = bgp_get_default ();
6354 }
6355
6356 if (bgp == NULL)
6357 {
6358 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6359 return CMD_WARNING;
6360 }
6361
6362
6363 table = bgp->rib[afi][safi];
6364
ajs5a646652004-11-05 01:25:55 +00006365 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006366}
6367
paul718e3742002-12-13 20:15:29 +00006368/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006369static void
paul718e3742002-12-13 20:15:29 +00006370route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6371 struct bgp_node *rn,
6372 struct prefix_rd *prd, afi_t afi, safi_t safi)
6373{
6374 struct bgp_info *ri;
6375 struct prefix *p;
6376 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006377 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006378 char buf1[INET6_ADDRSTRLEN];
6379 char buf2[INET6_ADDRSTRLEN];
6380 int count = 0;
6381 int best = 0;
6382 int suppress = 0;
6383 int no_export = 0;
6384 int no_advertise = 0;
6385 int local_as = 0;
6386 int first = 0;
6387
6388 p = &rn->p;
6389 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6390 (safi == SAFI_MPLS_VPN ?
6391 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6392 safi == SAFI_MPLS_VPN ? ":" : "",
6393 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6394 p->prefixlen, VTY_NEWLINE);
6395
6396 for (ri = rn->info; ri; ri = ri->next)
6397 {
6398 count++;
6399 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6400 {
6401 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006402 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006403 suppress = 1;
6404 if (ri->attr->community != NULL)
6405 {
6406 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6407 no_advertise = 1;
6408 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6409 no_export = 1;
6410 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6411 local_as = 1;
6412 }
6413 }
6414 }
6415
6416 vty_out (vty, "Paths: (%d available", count);
6417 if (best)
6418 {
6419 vty_out (vty, ", best #%d", best);
6420 if (safi == SAFI_UNICAST)
6421 vty_out (vty, ", table Default-IP-Routing-Table");
6422 }
6423 else
6424 vty_out (vty, ", no best path");
6425 if (no_advertise)
6426 vty_out (vty, ", not advertised to any peer");
6427 else if (no_export)
6428 vty_out (vty, ", not advertised to EBGP peer");
6429 else if (local_as)
6430 vty_out (vty, ", not advertised outside local AS");
6431 if (suppress)
6432 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6433 vty_out (vty, ")%s", VTY_NEWLINE);
6434
6435 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006436 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006437 {
6438 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6439 {
6440 if (! first)
6441 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6442 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6443 first = 1;
6444 }
6445 }
6446 if (! first)
6447 vty_out (vty, " Not advertised to any peer");
6448 vty_out (vty, "%s", VTY_NEWLINE);
6449}
6450
6451/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006452static int
paulfee0f4c2004-09-13 05:12:46 +00006453bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006454 struct bgp_table *rib, const char *ip_str,
6455 afi_t afi, safi_t safi, struct prefix_rd *prd,
6456 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006457{
6458 int ret;
6459 int header;
6460 int display = 0;
6461 struct prefix match;
6462 struct bgp_node *rn;
6463 struct bgp_node *rm;
6464 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006465 struct bgp_table *table;
6466
paul718e3742002-12-13 20:15:29 +00006467 /* Check IP address argument. */
6468 ret = str2prefix (ip_str, &match);
6469 if (! ret)
6470 {
6471 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6472 return CMD_WARNING;
6473 }
6474
6475 match.family = afi2family (afi);
6476
6477 if (safi == SAFI_MPLS_VPN)
6478 {
paulfee0f4c2004-09-13 05:12:46 +00006479 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006480 {
6481 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6482 continue;
6483
6484 if ((table = rn->info) != NULL)
6485 {
6486 header = 1;
6487
6488 if ((rm = bgp_node_match (table, &match)) != NULL)
6489 {
6490 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6491 continue;
6492
6493 for (ri = rm->info; ri; ri = ri->next)
6494 {
6495 if (header)
6496 {
6497 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6498 AFI_IP, SAFI_MPLS_VPN);
6499
6500 header = 0;
6501 }
6502 display++;
6503 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6504 }
6505 }
6506 }
6507 }
6508 }
6509 else
6510 {
6511 header = 1;
6512
paulfee0f4c2004-09-13 05:12:46 +00006513 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006514 {
6515 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6516 {
6517 for (ri = rn->info; ri; ri = ri->next)
6518 {
6519 if (header)
6520 {
6521 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6522 header = 0;
6523 }
6524 display++;
6525 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6526 }
6527 }
6528 }
6529 }
6530
6531 if (! display)
6532 {
6533 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6534 return CMD_WARNING;
6535 }
6536
6537 return CMD_SUCCESS;
6538}
6539
paulfee0f4c2004-09-13 05:12:46 +00006540/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006541static int
paulfd79ac92004-10-13 05:06:08 +00006542bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006543 afi_t afi, safi_t safi, struct prefix_rd *prd,
6544 int prefix_check)
6545{
6546 struct bgp *bgp;
6547
6548 /* BGP structure lookup. */
6549 if (view_name)
6550 {
6551 bgp = bgp_lookup_by_name (view_name);
6552 if (bgp == NULL)
6553 {
6554 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6555 return CMD_WARNING;
6556 }
6557 }
6558 else
6559 {
6560 bgp = bgp_get_default ();
6561 if (bgp == NULL)
6562 {
6563 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6564 return CMD_WARNING;
6565 }
6566 }
6567
6568 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6569 afi, safi, prd, prefix_check);
6570}
6571
paul718e3742002-12-13 20:15:29 +00006572/* BGP route print out function. */
6573DEFUN (show_ip_bgp,
6574 show_ip_bgp_cmd,
6575 "show ip bgp",
6576 SHOW_STR
6577 IP_STR
6578 BGP_STR)
6579{
ajs5a646652004-11-05 01:25:55 +00006580 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006581}
6582
6583DEFUN (show_ip_bgp_ipv4,
6584 show_ip_bgp_ipv4_cmd,
6585 "show ip bgp ipv4 (unicast|multicast)",
6586 SHOW_STR
6587 IP_STR
6588 BGP_STR
6589 "Address family\n"
6590 "Address Family modifier\n"
6591 "Address Family modifier\n")
6592{
6593 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006594 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6595 NULL);
paul718e3742002-12-13 20:15:29 +00006596
ajs5a646652004-11-05 01:25:55 +00006597 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006598}
6599
6600DEFUN (show_ip_bgp_route,
6601 show_ip_bgp_route_cmd,
6602 "show ip bgp A.B.C.D",
6603 SHOW_STR
6604 IP_STR
6605 BGP_STR
6606 "Network in the BGP routing table to display\n")
6607{
6608 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6609}
6610
6611DEFUN (show_ip_bgp_ipv4_route,
6612 show_ip_bgp_ipv4_route_cmd,
6613 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6614 SHOW_STR
6615 IP_STR
6616 BGP_STR
6617 "Address family\n"
6618 "Address Family modifier\n"
6619 "Address Family modifier\n"
6620 "Network in the BGP routing table to display\n")
6621{
6622 if (strncmp (argv[0], "m", 1) == 0)
6623 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6624
6625 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6626}
6627
6628DEFUN (show_ip_bgp_vpnv4_all_route,
6629 show_ip_bgp_vpnv4_all_route_cmd,
6630 "show ip bgp vpnv4 all A.B.C.D",
6631 SHOW_STR
6632 IP_STR
6633 BGP_STR
6634 "Display VPNv4 NLRI specific information\n"
6635 "Display information about all VPNv4 NLRIs\n"
6636 "Network in the BGP routing table to display\n")
6637{
6638 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6639}
6640
6641DEFUN (show_ip_bgp_vpnv4_rd_route,
6642 show_ip_bgp_vpnv4_rd_route_cmd,
6643 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6644 SHOW_STR
6645 IP_STR
6646 BGP_STR
6647 "Display VPNv4 NLRI specific information\n"
6648 "Display information for a route distinguisher\n"
6649 "VPN Route Distinguisher\n"
6650 "Network in the BGP routing table to display\n")
6651{
6652 int ret;
6653 struct prefix_rd prd;
6654
6655 ret = str2prefix_rd (argv[0], &prd);
6656 if (! ret)
6657 {
6658 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6659 return CMD_WARNING;
6660 }
6661 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6662}
6663
6664DEFUN (show_ip_bgp_prefix,
6665 show_ip_bgp_prefix_cmd,
6666 "show ip bgp A.B.C.D/M",
6667 SHOW_STR
6668 IP_STR
6669 BGP_STR
6670 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6671{
6672 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6673}
6674
6675DEFUN (show_ip_bgp_ipv4_prefix,
6676 show_ip_bgp_ipv4_prefix_cmd,
6677 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6678 SHOW_STR
6679 IP_STR
6680 BGP_STR
6681 "Address family\n"
6682 "Address Family modifier\n"
6683 "Address Family modifier\n"
6684 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6685{
6686 if (strncmp (argv[0], "m", 1) == 0)
6687 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6688
6689 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6690}
6691
6692DEFUN (show_ip_bgp_vpnv4_all_prefix,
6693 show_ip_bgp_vpnv4_all_prefix_cmd,
6694 "show ip bgp vpnv4 all A.B.C.D/M",
6695 SHOW_STR
6696 IP_STR
6697 BGP_STR
6698 "Display VPNv4 NLRI specific information\n"
6699 "Display information about all VPNv4 NLRIs\n"
6700 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6701{
6702 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6703}
6704
6705DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6706 show_ip_bgp_vpnv4_rd_prefix_cmd,
6707 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6708 SHOW_STR
6709 IP_STR
6710 BGP_STR
6711 "Display VPNv4 NLRI specific information\n"
6712 "Display information for a route distinguisher\n"
6713 "VPN Route Distinguisher\n"
6714 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6715{
6716 int ret;
6717 struct prefix_rd prd;
6718
6719 ret = str2prefix_rd (argv[0], &prd);
6720 if (! ret)
6721 {
6722 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6723 return CMD_WARNING;
6724 }
6725 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6726}
6727
6728DEFUN (show_ip_bgp_view,
6729 show_ip_bgp_view_cmd,
6730 "show ip bgp view WORD",
6731 SHOW_STR
6732 IP_STR
6733 BGP_STR
6734 "BGP view\n"
6735 "BGP view name\n")
6736{
paulbb46e942003-10-24 19:02:03 +00006737 struct bgp *bgp;
6738
6739 /* BGP structure lookup. */
6740 bgp = bgp_lookup_by_name (argv[0]);
6741 if (bgp == NULL)
6742 {
6743 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6744 return CMD_WARNING;
6745 }
6746
ajs5a646652004-11-05 01:25:55 +00006747 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006748}
6749
6750DEFUN (show_ip_bgp_view_route,
6751 show_ip_bgp_view_route_cmd,
6752 "show ip bgp view WORD A.B.C.D",
6753 SHOW_STR
6754 IP_STR
6755 BGP_STR
6756 "BGP view\n"
6757 "BGP view name\n"
6758 "Network in the BGP routing table to display\n")
6759{
6760 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6761}
6762
6763DEFUN (show_ip_bgp_view_prefix,
6764 show_ip_bgp_view_prefix_cmd,
6765 "show ip bgp view WORD A.B.C.D/M",
6766 SHOW_STR
6767 IP_STR
6768 BGP_STR
6769 "BGP view\n"
6770 "BGP view name\n"
6771 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6772{
6773 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6774}
6775
6776#ifdef HAVE_IPV6
6777DEFUN (show_bgp,
6778 show_bgp_cmd,
6779 "show bgp",
6780 SHOW_STR
6781 BGP_STR)
6782{
ajs5a646652004-11-05 01:25:55 +00006783 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6784 NULL);
paul718e3742002-12-13 20:15:29 +00006785}
6786
6787ALIAS (show_bgp,
6788 show_bgp_ipv6_cmd,
6789 "show bgp ipv6",
6790 SHOW_STR
6791 BGP_STR
6792 "Address family\n")
6793
6794/* old command */
6795DEFUN (show_ipv6_bgp,
6796 show_ipv6_bgp_cmd,
6797 "show ipv6 bgp",
6798 SHOW_STR
6799 IP_STR
6800 BGP_STR)
6801{
ajs5a646652004-11-05 01:25:55 +00006802 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6803 NULL);
paul718e3742002-12-13 20:15:29 +00006804}
6805
6806DEFUN (show_bgp_route,
6807 show_bgp_route_cmd,
6808 "show bgp X:X::X:X",
6809 SHOW_STR
6810 BGP_STR
6811 "Network in the BGP routing table to display\n")
6812{
6813 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6814}
6815
6816ALIAS (show_bgp_route,
6817 show_bgp_ipv6_route_cmd,
6818 "show bgp ipv6 X:X::X:X",
6819 SHOW_STR
6820 BGP_STR
6821 "Address family\n"
6822 "Network in the BGP routing table to display\n")
6823
6824/* old command */
6825DEFUN (show_ipv6_bgp_route,
6826 show_ipv6_bgp_route_cmd,
6827 "show ipv6 bgp X:X::X:X",
6828 SHOW_STR
6829 IP_STR
6830 BGP_STR
6831 "Network in the BGP routing table to display\n")
6832{
6833 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6834}
6835
6836DEFUN (show_bgp_prefix,
6837 show_bgp_prefix_cmd,
6838 "show bgp X:X::X:X/M",
6839 SHOW_STR
6840 BGP_STR
6841 "IPv6 prefix <network>/<length>\n")
6842{
6843 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6844}
6845
6846ALIAS (show_bgp_prefix,
6847 show_bgp_ipv6_prefix_cmd,
6848 "show bgp ipv6 X:X::X:X/M",
6849 SHOW_STR
6850 BGP_STR
6851 "Address family\n"
6852 "IPv6 prefix <network>/<length>\n")
6853
6854/* old command */
6855DEFUN (show_ipv6_bgp_prefix,
6856 show_ipv6_bgp_prefix_cmd,
6857 "show ipv6 bgp X:X::X:X/M",
6858 SHOW_STR
6859 IP_STR
6860 BGP_STR
6861 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6862{
6863 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6864}
6865
paulbb46e942003-10-24 19:02:03 +00006866DEFUN (show_bgp_view,
6867 show_bgp_view_cmd,
6868 "show bgp view WORD",
6869 SHOW_STR
6870 BGP_STR
6871 "BGP view\n"
6872 "View name\n")
6873{
6874 struct bgp *bgp;
6875
6876 /* BGP structure lookup. */
6877 bgp = bgp_lookup_by_name (argv[0]);
6878 if (bgp == NULL)
6879 {
6880 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6881 return CMD_WARNING;
6882 }
6883
ajs5a646652004-11-05 01:25:55 +00006884 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006885}
6886
6887ALIAS (show_bgp_view,
6888 show_bgp_view_ipv6_cmd,
6889 "show bgp view WORD ipv6",
6890 SHOW_STR
6891 BGP_STR
6892 "BGP view\n"
6893 "View name\n"
6894 "Address family\n")
6895
6896DEFUN (show_bgp_view_route,
6897 show_bgp_view_route_cmd,
6898 "show bgp view WORD X:X::X:X",
6899 SHOW_STR
6900 BGP_STR
6901 "BGP view\n"
6902 "View name\n"
6903 "Network in the BGP routing table to display\n")
6904{
6905 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6906}
6907
6908ALIAS (show_bgp_view_route,
6909 show_bgp_view_ipv6_route_cmd,
6910 "show bgp view WORD ipv6 X:X::X:X",
6911 SHOW_STR
6912 BGP_STR
6913 "BGP view\n"
6914 "View name\n"
6915 "Address family\n"
6916 "Network in the BGP routing table to display\n")
6917
6918DEFUN (show_bgp_view_prefix,
6919 show_bgp_view_prefix_cmd,
6920 "show bgp view WORD X:X::X:X/M",
6921 SHOW_STR
6922 BGP_STR
6923 "BGP view\n"
6924 "View name\n"
6925 "IPv6 prefix <network>/<length>\n")
6926{
6927 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6928}
6929
6930ALIAS (show_bgp_view_prefix,
6931 show_bgp_view_ipv6_prefix_cmd,
6932 "show bgp view WORD ipv6 X:X::X:X/M",
6933 SHOW_STR
6934 BGP_STR
6935 "BGP view\n"
6936 "View name\n"
6937 "Address family\n"
6938 "IPv6 prefix <network>/<length>\n")
6939
paul718e3742002-12-13 20:15:29 +00006940/* old command */
6941DEFUN (show_ipv6_mbgp,
6942 show_ipv6_mbgp_cmd,
6943 "show ipv6 mbgp",
6944 SHOW_STR
6945 IP_STR
6946 MBGP_STR)
6947{
ajs5a646652004-11-05 01:25:55 +00006948 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6949 NULL);
paul718e3742002-12-13 20:15:29 +00006950}
6951
6952/* old command */
6953DEFUN (show_ipv6_mbgp_route,
6954 show_ipv6_mbgp_route_cmd,
6955 "show ipv6 mbgp X:X::X:X",
6956 SHOW_STR
6957 IP_STR
6958 MBGP_STR
6959 "Network in the MBGP routing table to display\n")
6960{
6961 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6962}
6963
6964/* old command */
6965DEFUN (show_ipv6_mbgp_prefix,
6966 show_ipv6_mbgp_prefix_cmd,
6967 "show ipv6 mbgp X:X::X:X/M",
6968 SHOW_STR
6969 IP_STR
6970 MBGP_STR
6971 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6972{
6973 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6974}
6975#endif
6976
paul718e3742002-12-13 20:15:29 +00006977
paul94f2b392005-06-28 12:44:16 +00006978static int
paulfd79ac92004-10-13 05:06:08 +00006979bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006980 safi_t safi, enum bgp_show_type type)
6981{
6982 int i;
6983 struct buffer *b;
6984 char *regstr;
6985 int first;
6986 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006987 int rc;
paul718e3742002-12-13 20:15:29 +00006988
6989 first = 0;
6990 b = buffer_new (1024);
6991 for (i = 0; i < argc; i++)
6992 {
6993 if (first)
6994 buffer_putc (b, ' ');
6995 else
6996 {
6997 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6998 continue;
6999 first = 1;
7000 }
7001
7002 buffer_putstr (b, argv[i]);
7003 }
7004 buffer_putc (b, '\0');
7005
7006 regstr = buffer_getstr (b);
7007 buffer_free (b);
7008
7009 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007010 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007011 if (! regex)
7012 {
7013 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7014 VTY_NEWLINE);
7015 return CMD_WARNING;
7016 }
7017
ajs5a646652004-11-05 01:25:55 +00007018 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7019 bgp_regex_free (regex);
7020 return rc;
paul718e3742002-12-13 20:15:29 +00007021}
7022
7023DEFUN (show_ip_bgp_regexp,
7024 show_ip_bgp_regexp_cmd,
7025 "show ip bgp regexp .LINE",
7026 SHOW_STR
7027 IP_STR
7028 BGP_STR
7029 "Display routes matching the AS path regular expression\n"
7030 "A regular-expression to match the BGP AS paths\n")
7031{
7032 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7033 bgp_show_type_regexp);
7034}
7035
7036DEFUN (show_ip_bgp_flap_regexp,
7037 show_ip_bgp_flap_regexp_cmd,
7038 "show ip bgp flap-statistics regexp .LINE",
7039 SHOW_STR
7040 IP_STR
7041 BGP_STR
7042 "Display flap statistics of routes\n"
7043 "Display routes matching the AS path regular expression\n"
7044 "A regular-expression to match the BGP AS paths\n")
7045{
7046 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7047 bgp_show_type_flap_regexp);
7048}
7049
7050DEFUN (show_ip_bgp_ipv4_regexp,
7051 show_ip_bgp_ipv4_regexp_cmd,
7052 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7053 SHOW_STR
7054 IP_STR
7055 BGP_STR
7056 "Address family\n"
7057 "Address Family modifier\n"
7058 "Address Family modifier\n"
7059 "Display routes matching the AS path regular expression\n"
7060 "A regular-expression to match the BGP AS paths\n")
7061{
7062 if (strncmp (argv[0], "m", 1) == 0)
7063 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7064 bgp_show_type_regexp);
7065
7066 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7067 bgp_show_type_regexp);
7068}
7069
7070#ifdef HAVE_IPV6
7071DEFUN (show_bgp_regexp,
7072 show_bgp_regexp_cmd,
7073 "show bgp regexp .LINE",
7074 SHOW_STR
7075 BGP_STR
7076 "Display routes matching the AS path regular expression\n"
7077 "A regular-expression to match the BGP AS paths\n")
7078{
7079 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7080 bgp_show_type_regexp);
7081}
7082
7083ALIAS (show_bgp_regexp,
7084 show_bgp_ipv6_regexp_cmd,
7085 "show bgp ipv6 regexp .LINE",
7086 SHOW_STR
7087 BGP_STR
7088 "Address family\n"
7089 "Display routes matching the AS path regular expression\n"
7090 "A regular-expression to match the BGP AS paths\n")
7091
7092/* old command */
7093DEFUN (show_ipv6_bgp_regexp,
7094 show_ipv6_bgp_regexp_cmd,
7095 "show ipv6 bgp regexp .LINE",
7096 SHOW_STR
7097 IP_STR
7098 BGP_STR
7099 "Display routes matching the AS path regular expression\n"
7100 "A regular-expression to match the BGP AS paths\n")
7101{
7102 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7103 bgp_show_type_regexp);
7104}
7105
7106/* old command */
7107DEFUN (show_ipv6_mbgp_regexp,
7108 show_ipv6_mbgp_regexp_cmd,
7109 "show ipv6 mbgp regexp .LINE",
7110 SHOW_STR
7111 IP_STR
7112 BGP_STR
7113 "Display routes matching the AS path regular expression\n"
7114 "A regular-expression to match the MBGP AS paths\n")
7115{
7116 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7117 bgp_show_type_regexp);
7118}
7119#endif /* HAVE_IPV6 */
7120
paul94f2b392005-06-28 12:44:16 +00007121static int
paulfd79ac92004-10-13 05:06:08 +00007122bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007123 safi_t safi, enum bgp_show_type type)
7124{
7125 struct prefix_list *plist;
7126
7127 plist = prefix_list_lookup (afi, prefix_list_str);
7128 if (plist == NULL)
7129 {
7130 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7131 prefix_list_str, VTY_NEWLINE);
7132 return CMD_WARNING;
7133 }
7134
ajs5a646652004-11-05 01:25:55 +00007135 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007136}
7137
7138DEFUN (show_ip_bgp_prefix_list,
7139 show_ip_bgp_prefix_list_cmd,
7140 "show ip bgp prefix-list WORD",
7141 SHOW_STR
7142 IP_STR
7143 BGP_STR
7144 "Display routes conforming to the prefix-list\n"
7145 "IP prefix-list name\n")
7146{
7147 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7148 bgp_show_type_prefix_list);
7149}
7150
7151DEFUN (show_ip_bgp_flap_prefix_list,
7152 show_ip_bgp_flap_prefix_list_cmd,
7153 "show ip bgp flap-statistics prefix-list WORD",
7154 SHOW_STR
7155 IP_STR
7156 BGP_STR
7157 "Display flap statistics of routes\n"
7158 "Display routes conforming to the prefix-list\n"
7159 "IP prefix-list name\n")
7160{
7161 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7162 bgp_show_type_flap_prefix_list);
7163}
7164
7165DEFUN (show_ip_bgp_ipv4_prefix_list,
7166 show_ip_bgp_ipv4_prefix_list_cmd,
7167 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7168 SHOW_STR
7169 IP_STR
7170 BGP_STR
7171 "Address family\n"
7172 "Address Family modifier\n"
7173 "Address Family modifier\n"
7174 "Display routes conforming to the prefix-list\n"
7175 "IP prefix-list name\n")
7176{
7177 if (strncmp (argv[0], "m", 1) == 0)
7178 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7179 bgp_show_type_prefix_list);
7180
7181 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7182 bgp_show_type_prefix_list);
7183}
7184
7185#ifdef HAVE_IPV6
7186DEFUN (show_bgp_prefix_list,
7187 show_bgp_prefix_list_cmd,
7188 "show bgp prefix-list WORD",
7189 SHOW_STR
7190 BGP_STR
7191 "Display routes conforming to the prefix-list\n"
7192 "IPv6 prefix-list name\n")
7193{
7194 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7195 bgp_show_type_prefix_list);
7196}
7197
7198ALIAS (show_bgp_prefix_list,
7199 show_bgp_ipv6_prefix_list_cmd,
7200 "show bgp ipv6 prefix-list WORD",
7201 SHOW_STR
7202 BGP_STR
7203 "Address family\n"
7204 "Display routes conforming to the prefix-list\n"
7205 "IPv6 prefix-list name\n")
7206
7207/* old command */
7208DEFUN (show_ipv6_bgp_prefix_list,
7209 show_ipv6_bgp_prefix_list_cmd,
7210 "show ipv6 bgp prefix-list WORD",
7211 SHOW_STR
7212 IPV6_STR
7213 BGP_STR
7214 "Display routes matching the prefix-list\n"
7215 "IPv6 prefix-list name\n")
7216{
7217 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7218 bgp_show_type_prefix_list);
7219}
7220
7221/* old command */
7222DEFUN (show_ipv6_mbgp_prefix_list,
7223 show_ipv6_mbgp_prefix_list_cmd,
7224 "show ipv6 mbgp prefix-list WORD",
7225 SHOW_STR
7226 IPV6_STR
7227 MBGP_STR
7228 "Display routes matching the prefix-list\n"
7229 "IPv6 prefix-list name\n")
7230{
7231 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7232 bgp_show_type_prefix_list);
7233}
7234#endif /* HAVE_IPV6 */
7235
paul94f2b392005-06-28 12:44:16 +00007236static int
paulfd79ac92004-10-13 05:06:08 +00007237bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007238 safi_t safi, enum bgp_show_type type)
7239{
7240 struct as_list *as_list;
7241
7242 as_list = as_list_lookup (filter);
7243 if (as_list == NULL)
7244 {
7245 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7246 return CMD_WARNING;
7247 }
7248
ajs5a646652004-11-05 01:25:55 +00007249 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007250}
7251
7252DEFUN (show_ip_bgp_filter_list,
7253 show_ip_bgp_filter_list_cmd,
7254 "show ip bgp filter-list WORD",
7255 SHOW_STR
7256 IP_STR
7257 BGP_STR
7258 "Display routes conforming to the filter-list\n"
7259 "Regular expression access list name\n")
7260{
7261 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7262 bgp_show_type_filter_list);
7263}
7264
7265DEFUN (show_ip_bgp_flap_filter_list,
7266 show_ip_bgp_flap_filter_list_cmd,
7267 "show ip bgp flap-statistics filter-list WORD",
7268 SHOW_STR
7269 IP_STR
7270 BGP_STR
7271 "Display flap statistics of routes\n"
7272 "Display routes conforming to the filter-list\n"
7273 "Regular expression access list name\n")
7274{
7275 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7276 bgp_show_type_flap_filter_list);
7277}
7278
7279DEFUN (show_ip_bgp_ipv4_filter_list,
7280 show_ip_bgp_ipv4_filter_list_cmd,
7281 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7282 SHOW_STR
7283 IP_STR
7284 BGP_STR
7285 "Address family\n"
7286 "Address Family modifier\n"
7287 "Address Family modifier\n"
7288 "Display routes conforming to the filter-list\n"
7289 "Regular expression access list name\n")
7290{
7291 if (strncmp (argv[0], "m", 1) == 0)
7292 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7293 bgp_show_type_filter_list);
7294
7295 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7296 bgp_show_type_filter_list);
7297}
7298
7299#ifdef HAVE_IPV6
7300DEFUN (show_bgp_filter_list,
7301 show_bgp_filter_list_cmd,
7302 "show bgp filter-list WORD",
7303 SHOW_STR
7304 BGP_STR
7305 "Display routes conforming to the filter-list\n"
7306 "Regular expression access list name\n")
7307{
7308 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7309 bgp_show_type_filter_list);
7310}
7311
7312ALIAS (show_bgp_filter_list,
7313 show_bgp_ipv6_filter_list_cmd,
7314 "show bgp ipv6 filter-list WORD",
7315 SHOW_STR
7316 BGP_STR
7317 "Address family\n"
7318 "Display routes conforming to the filter-list\n"
7319 "Regular expression access list name\n")
7320
7321/* old command */
7322DEFUN (show_ipv6_bgp_filter_list,
7323 show_ipv6_bgp_filter_list_cmd,
7324 "show ipv6 bgp filter-list WORD",
7325 SHOW_STR
7326 IPV6_STR
7327 BGP_STR
7328 "Display routes conforming to the filter-list\n"
7329 "Regular expression access list name\n")
7330{
7331 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7332 bgp_show_type_filter_list);
7333}
7334
7335/* old command */
7336DEFUN (show_ipv6_mbgp_filter_list,
7337 show_ipv6_mbgp_filter_list_cmd,
7338 "show ipv6 mbgp filter-list WORD",
7339 SHOW_STR
7340 IPV6_STR
7341 MBGP_STR
7342 "Display routes conforming to the filter-list\n"
7343 "Regular expression access list name\n")
7344{
7345 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7346 bgp_show_type_filter_list);
7347}
7348#endif /* HAVE_IPV6 */
7349
paul94f2b392005-06-28 12:44:16 +00007350static int
paulfd79ac92004-10-13 05:06:08 +00007351bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007352 safi_t safi, enum bgp_show_type type)
7353{
7354 struct route_map *rmap;
7355
7356 rmap = route_map_lookup_by_name (rmap_str);
7357 if (! rmap)
7358 {
7359 vty_out (vty, "%% %s is not a valid route-map name%s",
7360 rmap_str, VTY_NEWLINE);
7361 return CMD_WARNING;
7362 }
7363
ajs5a646652004-11-05 01:25:55 +00007364 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007365}
7366
7367DEFUN (show_ip_bgp_route_map,
7368 show_ip_bgp_route_map_cmd,
7369 "show ip bgp route-map WORD",
7370 SHOW_STR
7371 IP_STR
7372 BGP_STR
7373 "Display routes matching the route-map\n"
7374 "A route-map to match on\n")
7375{
7376 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7377 bgp_show_type_route_map);
7378}
7379
7380DEFUN (show_ip_bgp_flap_route_map,
7381 show_ip_bgp_flap_route_map_cmd,
7382 "show ip bgp flap-statistics route-map WORD",
7383 SHOW_STR
7384 IP_STR
7385 BGP_STR
7386 "Display flap statistics of routes\n"
7387 "Display routes matching the route-map\n"
7388 "A route-map to match on\n")
7389{
7390 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7391 bgp_show_type_flap_route_map);
7392}
7393
7394DEFUN (show_ip_bgp_ipv4_route_map,
7395 show_ip_bgp_ipv4_route_map_cmd,
7396 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7397 SHOW_STR
7398 IP_STR
7399 BGP_STR
7400 "Address family\n"
7401 "Address Family modifier\n"
7402 "Address Family modifier\n"
7403 "Display routes matching the route-map\n"
7404 "A route-map to match on\n")
7405{
7406 if (strncmp (argv[0], "m", 1) == 0)
7407 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7408 bgp_show_type_route_map);
7409
7410 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7411 bgp_show_type_route_map);
7412}
7413
7414DEFUN (show_bgp_route_map,
7415 show_bgp_route_map_cmd,
7416 "show bgp route-map WORD",
7417 SHOW_STR
7418 BGP_STR
7419 "Display routes matching the route-map\n"
7420 "A route-map to match on\n")
7421{
7422 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7423 bgp_show_type_route_map);
7424}
7425
7426ALIAS (show_bgp_route_map,
7427 show_bgp_ipv6_route_map_cmd,
7428 "show bgp ipv6 route-map WORD",
7429 SHOW_STR
7430 BGP_STR
7431 "Address family\n"
7432 "Display routes matching the route-map\n"
7433 "A route-map to match on\n")
7434
7435DEFUN (show_ip_bgp_cidr_only,
7436 show_ip_bgp_cidr_only_cmd,
7437 "show ip bgp cidr-only",
7438 SHOW_STR
7439 IP_STR
7440 BGP_STR
7441 "Display only routes with non-natural netmasks\n")
7442{
7443 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007444 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007445}
7446
7447DEFUN (show_ip_bgp_flap_cidr_only,
7448 show_ip_bgp_flap_cidr_only_cmd,
7449 "show ip bgp flap-statistics cidr-only",
7450 SHOW_STR
7451 IP_STR
7452 BGP_STR
7453 "Display flap statistics of routes\n"
7454 "Display only routes with non-natural netmasks\n")
7455{
7456 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007457 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007458}
7459
7460DEFUN (show_ip_bgp_ipv4_cidr_only,
7461 show_ip_bgp_ipv4_cidr_only_cmd,
7462 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7463 SHOW_STR
7464 IP_STR
7465 BGP_STR
7466 "Address family\n"
7467 "Address Family modifier\n"
7468 "Address Family modifier\n"
7469 "Display only routes with non-natural netmasks\n")
7470{
7471 if (strncmp (argv[0], "m", 1) == 0)
7472 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007473 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007474
7475 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007476 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007477}
7478
7479DEFUN (show_ip_bgp_community_all,
7480 show_ip_bgp_community_all_cmd,
7481 "show ip bgp community",
7482 SHOW_STR
7483 IP_STR
7484 BGP_STR
7485 "Display routes matching the communities\n")
7486{
7487 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007488 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007489}
7490
7491DEFUN (show_ip_bgp_ipv4_community_all,
7492 show_ip_bgp_ipv4_community_all_cmd,
7493 "show ip bgp ipv4 (unicast|multicast) community",
7494 SHOW_STR
7495 IP_STR
7496 BGP_STR
7497 "Address family\n"
7498 "Address Family modifier\n"
7499 "Address Family modifier\n"
7500 "Display routes matching the communities\n")
7501{
7502 if (strncmp (argv[0], "m", 1) == 0)
7503 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007504 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007505
7506 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007507 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007508}
7509
7510#ifdef HAVE_IPV6
7511DEFUN (show_bgp_community_all,
7512 show_bgp_community_all_cmd,
7513 "show bgp community",
7514 SHOW_STR
7515 BGP_STR
7516 "Display routes matching the communities\n")
7517{
7518 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007519 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007520}
7521
7522ALIAS (show_bgp_community_all,
7523 show_bgp_ipv6_community_all_cmd,
7524 "show bgp ipv6 community",
7525 SHOW_STR
7526 BGP_STR
7527 "Address family\n"
7528 "Display routes matching the communities\n")
7529
7530/* old command */
7531DEFUN (show_ipv6_bgp_community_all,
7532 show_ipv6_bgp_community_all_cmd,
7533 "show ipv6 bgp community",
7534 SHOW_STR
7535 IPV6_STR
7536 BGP_STR
7537 "Display routes matching the communities\n")
7538{
7539 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007540 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007541}
7542
7543/* old command */
7544DEFUN (show_ipv6_mbgp_community_all,
7545 show_ipv6_mbgp_community_all_cmd,
7546 "show ipv6 mbgp community",
7547 SHOW_STR
7548 IPV6_STR
7549 MBGP_STR
7550 "Display routes matching the communities\n")
7551{
7552 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007553 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007554}
7555#endif /* HAVE_IPV6 */
7556
paul94f2b392005-06-28 12:44:16 +00007557static int
paulfd79ac92004-10-13 05:06:08 +00007558bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7559 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007560{
7561 struct community *com;
7562 struct buffer *b;
7563 int i;
7564 char *str;
7565 int first = 0;
7566
7567 b = buffer_new (1024);
7568 for (i = 0; i < argc; i++)
7569 {
7570 if (first)
7571 buffer_putc (b, ' ');
7572 else
7573 {
7574 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7575 continue;
7576 first = 1;
7577 }
7578
7579 buffer_putstr (b, argv[i]);
7580 }
7581 buffer_putc (b, '\0');
7582
7583 str = buffer_getstr (b);
7584 buffer_free (b);
7585
7586 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007587 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007588 if (! com)
7589 {
7590 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7591 return CMD_WARNING;
7592 }
7593
ajs5a646652004-11-05 01:25:55 +00007594 return bgp_show (vty, NULL, afi, safi,
7595 (exact ? bgp_show_type_community_exact :
7596 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007597}
7598
7599DEFUN (show_ip_bgp_community,
7600 show_ip_bgp_community_cmd,
7601 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7602 SHOW_STR
7603 IP_STR
7604 BGP_STR
7605 "Display routes matching the communities\n"
7606 "community number\n"
7607 "Do not send outside local AS (well-known community)\n"
7608 "Do not advertise to any peer (well-known community)\n"
7609 "Do not export to next AS (well-known community)\n")
7610{
7611 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7612}
7613
7614ALIAS (show_ip_bgp_community,
7615 show_ip_bgp_community2_cmd,
7616 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7617 SHOW_STR
7618 IP_STR
7619 BGP_STR
7620 "Display routes matching the communities\n"
7621 "community number\n"
7622 "Do not send outside local AS (well-known community)\n"
7623 "Do not advertise to any peer (well-known community)\n"
7624 "Do not export to next AS (well-known community)\n"
7625 "community number\n"
7626 "Do not send outside local AS (well-known community)\n"
7627 "Do not advertise to any peer (well-known community)\n"
7628 "Do not export to next AS (well-known community)\n")
7629
7630ALIAS (show_ip_bgp_community,
7631 show_ip_bgp_community3_cmd,
7632 "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)",
7633 SHOW_STR
7634 IP_STR
7635 BGP_STR
7636 "Display routes matching the communities\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 "community number\n"
7642 "Do not send outside local AS (well-known community)\n"
7643 "Do not advertise to any peer (well-known community)\n"
7644 "Do not export to next AS (well-known community)\n"
7645 "community number\n"
7646 "Do not send outside local AS (well-known community)\n"
7647 "Do not advertise to any peer (well-known community)\n"
7648 "Do not export to next AS (well-known community)\n")
7649
7650ALIAS (show_ip_bgp_community,
7651 show_ip_bgp_community4_cmd,
7652 "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)",
7653 SHOW_STR
7654 IP_STR
7655 BGP_STR
7656 "Display routes matching the communities\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 "community number\n"
7662 "Do not send outside local AS (well-known community)\n"
7663 "Do not advertise to any peer (well-known community)\n"
7664 "Do not export to next AS (well-known community)\n"
7665 "community number\n"
7666 "Do not send outside local AS (well-known community)\n"
7667 "Do not advertise to any peer (well-known community)\n"
7668 "Do not export to next AS (well-known community)\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
7674DEFUN (show_ip_bgp_ipv4_community,
7675 show_ip_bgp_ipv4_community_cmd,
7676 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7677 SHOW_STR
7678 IP_STR
7679 BGP_STR
7680 "Address family\n"
7681 "Address Family modifier\n"
7682 "Address Family modifier\n"
7683 "Display routes matching the communities\n"
7684 "community number\n"
7685 "Do not send outside local AS (well-known community)\n"
7686 "Do not advertise to any peer (well-known community)\n"
7687 "Do not export to next AS (well-known community)\n")
7688{
7689 if (strncmp (argv[0], "m", 1) == 0)
7690 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7691
7692 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7693}
7694
7695ALIAS (show_ip_bgp_ipv4_community,
7696 show_ip_bgp_ipv4_community2_cmd,
7697 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7698 SHOW_STR
7699 IP_STR
7700 BGP_STR
7701 "Address family\n"
7702 "Address Family modifier\n"
7703 "Address Family modifier\n"
7704 "Display routes matching the communities\n"
7705 "community number\n"
7706 "Do not send outside local AS (well-known community)\n"
7707 "Do not advertise to any peer (well-known community)\n"
7708 "Do not export to next AS (well-known community)\n"
7709 "community number\n"
7710 "Do not send outside local AS (well-known community)\n"
7711 "Do not advertise to any peer (well-known community)\n"
7712 "Do not export to next AS (well-known community)\n")
7713
7714ALIAS (show_ip_bgp_ipv4_community,
7715 show_ip_bgp_ipv4_community3_cmd,
7716 "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)",
7717 SHOW_STR
7718 IP_STR
7719 BGP_STR
7720 "Address family\n"
7721 "Address Family modifier\n"
7722 "Address Family modifier\n"
7723 "Display routes matching the communities\n"
7724 "community number\n"
7725 "Do not send outside local AS (well-known community)\n"
7726 "Do not advertise to any peer (well-known community)\n"
7727 "Do not export to next AS (well-known community)\n"
7728 "community number\n"
7729 "Do not send outside local AS (well-known community)\n"
7730 "Do not advertise to any peer (well-known community)\n"
7731 "Do not export to next AS (well-known community)\n"
7732 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\n")
7736
7737ALIAS (show_ip_bgp_ipv4_community,
7738 show_ip_bgp_ipv4_community4_cmd,
7739 "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)",
7740 SHOW_STR
7741 IP_STR
7742 BGP_STR
7743 "Address family\n"
7744 "Address Family modifier\n"
7745 "Address Family modifier\n"
7746 "Display routes matching the communities\n"
7747 "community number\n"
7748 "Do not send outside local AS (well-known community)\n"
7749 "Do not advertise to any peer (well-known community)\n"
7750 "Do not export to next AS (well-known community)\n"
7751 "community number\n"
7752 "Do not send outside local AS (well-known community)\n"
7753 "Do not advertise to any peer (well-known community)\n"
7754 "Do not export to next AS (well-known community)\n"
7755 "community number\n"
7756 "Do not send outside local AS (well-known community)\n"
7757 "Do not advertise to any peer (well-known community)\n"
7758 "Do not export to next AS (well-known community)\n"
7759 "community number\n"
7760 "Do not send outside local AS (well-known community)\n"
7761 "Do not advertise to any peer (well-known community)\n"
7762 "Do not export to next AS (well-known community)\n")
7763
7764DEFUN (show_ip_bgp_community_exact,
7765 show_ip_bgp_community_exact_cmd,
7766 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7767 SHOW_STR
7768 IP_STR
7769 BGP_STR
7770 "Display routes matching the communities\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 "Exact match of the communities")
7776{
7777 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7778}
7779
7780ALIAS (show_ip_bgp_community_exact,
7781 show_ip_bgp_community2_exact_cmd,
7782 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7783 SHOW_STR
7784 IP_STR
7785 BGP_STR
7786 "Display routes matching the communities\n"
7787 "community number\n"
7788 "Do not send outside local AS (well-known community)\n"
7789 "Do not advertise to any peer (well-known community)\n"
7790 "Do not export to next AS (well-known community)\n"
7791 "community number\n"
7792 "Do not send outside local AS (well-known community)\n"
7793 "Do not advertise to any peer (well-known community)\n"
7794 "Do not export to next AS (well-known community)\n"
7795 "Exact match of the communities")
7796
7797ALIAS (show_ip_bgp_community_exact,
7798 show_ip_bgp_community3_exact_cmd,
7799 "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",
7800 SHOW_STR
7801 IP_STR
7802 BGP_STR
7803 "Display routes matching the communities\n"
7804 "community number\n"
7805 "Do not send outside local AS (well-known community)\n"
7806 "Do not advertise to any peer (well-known community)\n"
7807 "Do not export to next AS (well-known community)\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "Exact match of the communities")
7817
7818ALIAS (show_ip_bgp_community_exact,
7819 show_ip_bgp_community4_exact_cmd,
7820 "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",
7821 SHOW_STR
7822 IP_STR
7823 BGP_STR
7824 "Display routes matching the communities\n"
7825 "community number\n"
7826 "Do not send outside local AS (well-known community)\n"
7827 "Do not advertise to any peer (well-known community)\n"
7828 "Do not export to next AS (well-known community)\n"
7829 "community number\n"
7830 "Do not send outside local AS (well-known community)\n"
7831 "Do not advertise to any peer (well-known community)\n"
7832 "Do not export to next AS (well-known community)\n"
7833 "community number\n"
7834 "Do not send outside local AS (well-known community)\n"
7835 "Do not advertise to any peer (well-known community)\n"
7836 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7842
7843DEFUN (show_ip_bgp_ipv4_community_exact,
7844 show_ip_bgp_ipv4_community_exact_cmd,
7845 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7846 SHOW_STR
7847 IP_STR
7848 BGP_STR
7849 "Address family\n"
7850 "Address Family modifier\n"
7851 "Address Family modifier\n"
7852 "Display routes matching the communities\n"
7853 "community number\n"
7854 "Do not send outside local AS (well-known community)\n"
7855 "Do not advertise to any peer (well-known community)\n"
7856 "Do not export to next AS (well-known community)\n"
7857 "Exact match of the communities")
7858{
7859 if (strncmp (argv[0], "m", 1) == 0)
7860 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7861
7862 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7863}
7864
7865ALIAS (show_ip_bgp_ipv4_community_exact,
7866 show_ip_bgp_ipv4_community2_exact_cmd,
7867 "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",
7868 SHOW_STR
7869 IP_STR
7870 BGP_STR
7871 "Address family\n"
7872 "Address Family modifier\n"
7873 "Address Family modifier\n"
7874 "Display routes matching the communities\n"
7875 "community number\n"
7876 "Do not send outside local AS (well-known community)\n"
7877 "Do not advertise to any peer (well-known community)\n"
7878 "Do not export to next AS (well-known community)\n"
7879 "community number\n"
7880 "Do not send outside local AS (well-known community)\n"
7881 "Do not advertise to any peer (well-known community)\n"
7882 "Do not export to next AS (well-known community)\n"
7883 "Exact match of the communities")
7884
7885ALIAS (show_ip_bgp_ipv4_community_exact,
7886 show_ip_bgp_ipv4_community3_exact_cmd,
7887 "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",
7888 SHOW_STR
7889 IP_STR
7890 BGP_STR
7891 "Address family\n"
7892 "Address Family modifier\n"
7893 "Address Family modifier\n"
7894 "Display routes matching the communities\n"
7895 "community number\n"
7896 "Do not send outside local AS (well-known community)\n"
7897 "Do not advertise to any peer (well-known community)\n"
7898 "Do not export to next AS (well-known community)\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n"
7903 "community number\n"
7904 "Do not send outside local AS (well-known community)\n"
7905 "Do not advertise to any peer (well-known community)\n"
7906 "Do not export to next AS (well-known community)\n"
7907 "Exact match of the communities")
7908
7909ALIAS (show_ip_bgp_ipv4_community_exact,
7910 show_ip_bgp_ipv4_community4_exact_cmd,
7911 "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",
7912 SHOW_STR
7913 IP_STR
7914 BGP_STR
7915 "Address family\n"
7916 "Address Family modifier\n"
7917 "Address Family modifier\n"
7918 "Display routes matching the communities\n"
7919 "community number\n"
7920 "Do not send outside local AS (well-known community)\n"
7921 "Do not advertise to any peer (well-known community)\n"
7922 "Do not export to next AS (well-known community)\n"
7923 "community number\n"
7924 "Do not send outside local AS (well-known community)\n"
7925 "Do not advertise to any peer (well-known community)\n"
7926 "Do not export to next AS (well-known community)\n"
7927 "community number\n"
7928 "Do not send outside local AS (well-known community)\n"
7929 "Do not advertise to any peer (well-known community)\n"
7930 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7936
7937#ifdef HAVE_IPV6
7938DEFUN (show_bgp_community,
7939 show_bgp_community_cmd,
7940 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7941 SHOW_STR
7942 BGP_STR
7943 "Display routes matching the communities\n"
7944 "community number\n"
7945 "Do not send outside local AS (well-known community)\n"
7946 "Do not advertise to any peer (well-known community)\n"
7947 "Do not export to next AS (well-known community)\n")
7948{
7949 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7950}
7951
7952ALIAS (show_bgp_community,
7953 show_bgp_ipv6_community_cmd,
7954 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7955 SHOW_STR
7956 BGP_STR
7957 "Address family\n"
7958 "Display routes matching the communities\n"
7959 "community number\n"
7960 "Do not send outside local AS (well-known community)\n"
7961 "Do not advertise to any peer (well-known community)\n"
7962 "Do not export to next AS (well-known community)\n")
7963
7964ALIAS (show_bgp_community,
7965 show_bgp_community2_cmd,
7966 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7967 SHOW_STR
7968 BGP_STR
7969 "Display routes matching the communities\n"
7970 "community number\n"
7971 "Do not send outside local AS (well-known community)\n"
7972 "Do not advertise to any peer (well-known community)\n"
7973 "Do not export to next AS (well-known community)\n"
7974 "community number\n"
7975 "Do not send outside local AS (well-known community)\n"
7976 "Do not advertise to any peer (well-known community)\n"
7977 "Do not export to next AS (well-known community)\n")
7978
7979ALIAS (show_bgp_community,
7980 show_bgp_ipv6_community2_cmd,
7981 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7982 SHOW_STR
7983 BGP_STR
7984 "Address family\n"
7985 "Display routes matching the communities\n"
7986 "community number\n"
7987 "Do not send outside local AS (well-known community)\n"
7988 "Do not advertise to any peer (well-known community)\n"
7989 "Do not export to next AS (well-known community)\n"
7990 "community number\n"
7991 "Do not send outside local AS (well-known community)\n"
7992 "Do not advertise to any peer (well-known community)\n"
7993 "Do not export to next AS (well-known community)\n")
7994
7995ALIAS (show_bgp_community,
7996 show_bgp_community3_cmd,
7997 "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)",
7998 SHOW_STR
7999 BGP_STR
8000 "Display routes matching the communities\n"
8001 "community number\n"
8002 "Do not send outside local AS (well-known community)\n"
8003 "Do not advertise to any peer (well-known community)\n"
8004 "Do not export to next AS (well-known community)\n"
8005 "community number\n"
8006 "Do not send outside local AS (well-known community)\n"
8007 "Do not advertise to any peer (well-known community)\n"
8008 "Do not export to next AS (well-known community)\n"
8009 "community number\n"
8010 "Do not send outside local AS (well-known community)\n"
8011 "Do not advertise to any peer (well-known community)\n"
8012 "Do not export to next AS (well-known community)\n")
8013
8014ALIAS (show_bgp_community,
8015 show_bgp_ipv6_community3_cmd,
8016 "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)",
8017 SHOW_STR
8018 BGP_STR
8019 "Address family\n"
8020 "Display routes matching the communities\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 "community number\n"
8026 "Do not send outside local AS (well-known community)\n"
8027 "Do not advertise to any peer (well-known community)\n"
8028 "Do not export to next AS (well-known community)\n"
8029 "community number\n"
8030 "Do not send outside local AS (well-known community)\n"
8031 "Do not advertise to any peer (well-known community)\n"
8032 "Do not export to next AS (well-known community)\n")
8033
8034ALIAS (show_bgp_community,
8035 show_bgp_community4_cmd,
8036 "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)",
8037 SHOW_STR
8038 BGP_STR
8039 "Display routes matching the communities\n"
8040 "community number\n"
8041 "Do not send outside local AS (well-known community)\n"
8042 "Do not advertise to any peer (well-known community)\n"
8043 "Do not export to next AS (well-known community)\n"
8044 "community number\n"
8045 "Do not send outside local AS (well-known community)\n"
8046 "Do not advertise to any peer (well-known community)\n"
8047 "Do not export to next AS (well-known community)\n"
8048 "community number\n"
8049 "Do not send outside local AS (well-known community)\n"
8050 "Do not advertise to any peer (well-known community)\n"
8051 "Do not export to next AS (well-known community)\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
8057ALIAS (show_bgp_community,
8058 show_bgp_ipv6_community4_cmd,
8059 "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)",
8060 SHOW_STR
8061 BGP_STR
8062 "Address family\n"
8063 "Display routes matching the communities\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 "community number\n"
8069 "Do not send outside local AS (well-known community)\n"
8070 "Do not advertise to any peer (well-known community)\n"
8071 "Do not export to next AS (well-known community)\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\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
8081/* old command */
8082DEFUN (show_ipv6_bgp_community,
8083 show_ipv6_bgp_community_cmd,
8084 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8085 SHOW_STR
8086 IPV6_STR
8087 BGP_STR
8088 "Display routes matching the communities\n"
8089 "community number\n"
8090 "Do not send outside local AS (well-known community)\n"
8091 "Do not advertise to any peer (well-known community)\n"
8092 "Do not export to next AS (well-known community)\n")
8093{
8094 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8095}
8096
8097/* old command */
8098ALIAS (show_ipv6_bgp_community,
8099 show_ipv6_bgp_community2_cmd,
8100 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8101 SHOW_STR
8102 IPV6_STR
8103 BGP_STR
8104 "Display routes matching the communities\n"
8105 "community number\n"
8106 "Do not send outside local AS (well-known community)\n"
8107 "Do not advertise to any peer (well-known community)\n"
8108 "Do not export to next AS (well-known community)\n"
8109 "community number\n"
8110 "Do not send outside local AS (well-known community)\n"
8111 "Do not advertise to any peer (well-known community)\n"
8112 "Do not export to next AS (well-known community)\n")
8113
8114/* old command */
8115ALIAS (show_ipv6_bgp_community,
8116 show_ipv6_bgp_community3_cmd,
8117 "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)",
8118 SHOW_STR
8119 IPV6_STR
8120 BGP_STR
8121 "Display routes matching the communities\n"
8122 "community number\n"
8123 "Do not send outside local AS (well-known community)\n"
8124 "Do not advertise to any peer (well-known community)\n"
8125 "Do not export to next AS (well-known community)\n"
8126 "community number\n"
8127 "Do not send outside local AS (well-known community)\n"
8128 "Do not advertise to any peer (well-known community)\n"
8129 "Do not export to next AS (well-known community)\n"
8130 "community number\n"
8131 "Do not send outside local AS (well-known community)\n"
8132 "Do not advertise to any peer (well-known community)\n"
8133 "Do not export to next AS (well-known community)\n")
8134
8135/* old command */
8136ALIAS (show_ipv6_bgp_community,
8137 show_ipv6_bgp_community4_cmd,
8138 "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)",
8139 SHOW_STR
8140 IPV6_STR
8141 BGP_STR
8142 "Display routes matching the communities\n"
8143 "community number\n"
8144 "Do not send outside local AS (well-known community)\n"
8145 "Do not advertise to any peer (well-known community)\n"
8146 "Do not export to next AS (well-known community)\n"
8147 "community number\n"
8148 "Do not send outside local AS (well-known community)\n"
8149 "Do not advertise to any peer (well-known community)\n"
8150 "Do not export to next AS (well-known community)\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\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
8160DEFUN (show_bgp_community_exact,
8161 show_bgp_community_exact_cmd,
8162 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8163 SHOW_STR
8164 BGP_STR
8165 "Display routes matching the communities\n"
8166 "community number\n"
8167 "Do not send outside local AS (well-known community)\n"
8168 "Do not advertise to any peer (well-known community)\n"
8169 "Do not export to next AS (well-known community)\n"
8170 "Exact match of the communities")
8171{
8172 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8173}
8174
8175ALIAS (show_bgp_community_exact,
8176 show_bgp_ipv6_community_exact_cmd,
8177 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8178 SHOW_STR
8179 BGP_STR
8180 "Address family\n"
8181 "Display routes matching the communities\n"
8182 "community number\n"
8183 "Do not send outside local AS (well-known community)\n"
8184 "Do not advertise to any peer (well-known community)\n"
8185 "Do not export to next AS (well-known community)\n"
8186 "Exact match of the communities")
8187
8188ALIAS (show_bgp_community_exact,
8189 show_bgp_community2_exact_cmd,
8190 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8191 SHOW_STR
8192 BGP_STR
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 "community number\n"
8199 "Do not send outside local AS (well-known community)\n"
8200 "Do not advertise to any peer (well-known community)\n"
8201 "Do not export to next AS (well-known community)\n"
8202 "Exact match of the communities")
8203
8204ALIAS (show_bgp_community_exact,
8205 show_bgp_ipv6_community2_exact_cmd,
8206 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8207 SHOW_STR
8208 BGP_STR
8209 "Address family\n"
8210 "Display routes matching the communities\n"
8211 "community number\n"
8212 "Do not send outside local AS (well-known community)\n"
8213 "Do not advertise to any peer (well-known community)\n"
8214 "Do not export to next AS (well-known community)\n"
8215 "community number\n"
8216 "Do not send outside local AS (well-known community)\n"
8217 "Do not advertise to any peer (well-known community)\n"
8218 "Do not export to next AS (well-known community)\n"
8219 "Exact match of the communities")
8220
8221ALIAS (show_bgp_community_exact,
8222 show_bgp_community3_exact_cmd,
8223 "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",
8224 SHOW_STR
8225 BGP_STR
8226 "Display routes matching the communities\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 "community number\n"
8232 "Do not send outside local AS (well-known community)\n"
8233 "Do not advertise to any peer (well-known community)\n"
8234 "Do not export to next AS (well-known community)\n"
8235 "community number\n"
8236 "Do not send outside local AS (well-known community)\n"
8237 "Do not advertise to any peer (well-known community)\n"
8238 "Do not export to next AS (well-known community)\n"
8239 "Exact match of the communities")
8240
8241ALIAS (show_bgp_community_exact,
8242 show_bgp_ipv6_community3_exact_cmd,
8243 "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",
8244 SHOW_STR
8245 BGP_STR
8246 "Address family\n"
8247 "Display routes matching the communities\n"
8248 "community number\n"
8249 "Do not send outside local AS (well-known community)\n"
8250 "Do not advertise to any peer (well-known community)\n"
8251 "Do not export to next AS (well-known community)\n"
8252 "community number\n"
8253 "Do not send outside local AS (well-known community)\n"
8254 "Do not advertise to any peer (well-known community)\n"
8255 "Do not export to next AS (well-known community)\n"
8256 "community number\n"
8257 "Do not send outside local AS (well-known community)\n"
8258 "Do not advertise to any peer (well-known community)\n"
8259 "Do not export to next AS (well-known community)\n"
8260 "Exact match of the communities")
8261
8262ALIAS (show_bgp_community_exact,
8263 show_bgp_community4_exact_cmd,
8264 "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",
8265 SHOW_STR
8266 BGP_STR
8267 "Display routes matching the communities\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 "community number\n"
8273 "Do not send outside local AS (well-known community)\n"
8274 "Do not advertise to any peer (well-known community)\n"
8275 "Do not export to next AS (well-known community)\n"
8276 "community number\n"
8277 "Do not send outside local AS (well-known community)\n"
8278 "Do not advertise to any peer (well-known community)\n"
8279 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8285
8286ALIAS (show_bgp_community_exact,
8287 show_bgp_ipv6_community4_exact_cmd,
8288 "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",
8289 SHOW_STR
8290 BGP_STR
8291 "Address family\n"
8292 "Display routes matching the communities\n"
8293 "community number\n"
8294 "Do not send outside local AS (well-known community)\n"
8295 "Do not advertise to any peer (well-known community)\n"
8296 "Do not export to next AS (well-known community)\n"
8297 "community number\n"
8298 "Do not send outside local AS (well-known community)\n"
8299 "Do not advertise to any peer (well-known community)\n"
8300 "Do not export to next AS (well-known community)\n"
8301 "community number\n"
8302 "Do not send outside local AS (well-known community)\n"
8303 "Do not advertise to any peer (well-known community)\n"
8304 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8310
8311/* old command */
8312DEFUN (show_ipv6_bgp_community_exact,
8313 show_ipv6_bgp_community_exact_cmd,
8314 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8315 SHOW_STR
8316 IPV6_STR
8317 BGP_STR
8318 "Display routes matching the communities\n"
8319 "community number\n"
8320 "Do not send outside local AS (well-known community)\n"
8321 "Do not advertise to any peer (well-known community)\n"
8322 "Do not export to next AS (well-known community)\n"
8323 "Exact match of the communities")
8324{
8325 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8326}
8327
8328/* old command */
8329ALIAS (show_ipv6_bgp_community_exact,
8330 show_ipv6_bgp_community2_exact_cmd,
8331 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8332 SHOW_STR
8333 IPV6_STR
8334 BGP_STR
8335 "Display routes matching the communities\n"
8336 "community number\n"
8337 "Do not send outside local AS (well-known community)\n"
8338 "Do not advertise to any peer (well-known community)\n"
8339 "Do not export to next AS (well-known community)\n"
8340 "community number\n"
8341 "Do not send outside local AS (well-known community)\n"
8342 "Do not advertise to any peer (well-known community)\n"
8343 "Do not export to next AS (well-known community)\n"
8344 "Exact match of the communities")
8345
8346/* old command */
8347ALIAS (show_ipv6_bgp_community_exact,
8348 show_ipv6_bgp_community3_exact_cmd,
8349 "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",
8350 SHOW_STR
8351 IPV6_STR
8352 BGP_STR
8353 "Display routes matching the communities\n"
8354 "community number\n"
8355 "Do not send outside local AS (well-known community)\n"
8356 "Do not advertise to any peer (well-known community)\n"
8357 "Do not export to next AS (well-known community)\n"
8358 "community number\n"
8359 "Do not send outside local AS (well-known community)\n"
8360 "Do not advertise to any peer (well-known community)\n"
8361 "Do not export to next AS (well-known community)\n"
8362 "community number\n"
8363 "Do not send outside local AS (well-known community)\n"
8364 "Do not advertise to any peer (well-known community)\n"
8365 "Do not export to next AS (well-known community)\n"
8366 "Exact match of the communities")
8367
8368/* old command */
8369ALIAS (show_ipv6_bgp_community_exact,
8370 show_ipv6_bgp_community4_exact_cmd,
8371 "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",
8372 SHOW_STR
8373 IPV6_STR
8374 BGP_STR
8375 "Display routes matching the communities\n"
8376 "community number\n"
8377 "Do not send outside local AS (well-known community)\n"
8378 "Do not advertise to any peer (well-known community)\n"
8379 "Do not export to next AS (well-known community)\n"
8380 "community number\n"
8381 "Do not send outside local AS (well-known community)\n"
8382 "Do not advertise to any peer (well-known community)\n"
8383 "Do not export to next AS (well-known community)\n"
8384 "community number\n"
8385 "Do not send outside local AS (well-known community)\n"
8386 "Do not advertise to any peer (well-known community)\n"
8387 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8393
8394/* old command */
8395DEFUN (show_ipv6_mbgp_community,
8396 show_ipv6_mbgp_community_cmd,
8397 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8398 SHOW_STR
8399 IPV6_STR
8400 MBGP_STR
8401 "Display routes matching the communities\n"
8402 "community number\n"
8403 "Do not send outside local AS (well-known community)\n"
8404 "Do not advertise to any peer (well-known community)\n"
8405 "Do not export to next AS (well-known community)\n")
8406{
8407 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8408}
8409
8410/* old command */
8411ALIAS (show_ipv6_mbgp_community,
8412 show_ipv6_mbgp_community2_cmd,
8413 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8414 SHOW_STR
8415 IPV6_STR
8416 MBGP_STR
8417 "Display routes matching the communities\n"
8418 "community number\n"
8419 "Do not send outside local AS (well-known community)\n"
8420 "Do not advertise to any peer (well-known community)\n"
8421 "Do not export to next AS (well-known community)\n"
8422 "community number\n"
8423 "Do not send outside local AS (well-known community)\n"
8424 "Do not advertise to any peer (well-known community)\n"
8425 "Do not export to next AS (well-known community)\n")
8426
8427/* old command */
8428ALIAS (show_ipv6_mbgp_community,
8429 show_ipv6_mbgp_community3_cmd,
8430 "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)",
8431 SHOW_STR
8432 IPV6_STR
8433 MBGP_STR
8434 "Display routes matching the communities\n"
8435 "community number\n"
8436 "Do not send outside local AS (well-known community)\n"
8437 "Do not advertise to any peer (well-known community)\n"
8438 "Do not export to next AS (well-known community)\n"
8439 "community number\n"
8440 "Do not send outside local AS (well-known community)\n"
8441 "Do not advertise to any peer (well-known community)\n"
8442 "Do not export to next AS (well-known community)\n"
8443 "community number\n"
8444 "Do not send outside local AS (well-known community)\n"
8445 "Do not advertise to any peer (well-known community)\n"
8446 "Do not export to next AS (well-known community)\n")
8447
8448/* old command */
8449ALIAS (show_ipv6_mbgp_community,
8450 show_ipv6_mbgp_community4_cmd,
8451 "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)",
8452 SHOW_STR
8453 IPV6_STR
8454 MBGP_STR
8455 "Display routes matching the communities\n"
8456 "community number\n"
8457 "Do not send outside local AS (well-known community)\n"
8458 "Do not advertise to any peer (well-known community)\n"
8459 "Do not export to next AS (well-known community)\n"
8460 "community number\n"
8461 "Do not send outside local AS (well-known community)\n"
8462 "Do not advertise to any peer (well-known community)\n"
8463 "Do not export to next AS (well-known community)\n"
8464 "community number\n"
8465 "Do not send outside local AS (well-known community)\n"
8466 "Do not advertise to any peer (well-known community)\n"
8467 "Do not export to next AS (well-known community)\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
8473/* old command */
8474DEFUN (show_ipv6_mbgp_community_exact,
8475 show_ipv6_mbgp_community_exact_cmd,
8476 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8477 SHOW_STR
8478 IPV6_STR
8479 MBGP_STR
8480 "Display routes matching the communities\n"
8481 "community number\n"
8482 "Do not send outside local AS (well-known community)\n"
8483 "Do not advertise to any peer (well-known community)\n"
8484 "Do not export to next AS (well-known community)\n"
8485 "Exact match of the communities")
8486{
8487 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8488}
8489
8490/* old command */
8491ALIAS (show_ipv6_mbgp_community_exact,
8492 show_ipv6_mbgp_community2_exact_cmd,
8493 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8494 SHOW_STR
8495 IPV6_STR
8496 MBGP_STR
8497 "Display routes matching the communities\n"
8498 "community number\n"
8499 "Do not send outside local AS (well-known community)\n"
8500 "Do not advertise to any peer (well-known community)\n"
8501 "Do not export to next AS (well-known community)\n"
8502 "community number\n"
8503 "Do not send outside local AS (well-known community)\n"
8504 "Do not advertise to any peer (well-known community)\n"
8505 "Do not export to next AS (well-known community)\n"
8506 "Exact match of the communities")
8507
8508/* old command */
8509ALIAS (show_ipv6_mbgp_community_exact,
8510 show_ipv6_mbgp_community3_exact_cmd,
8511 "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",
8512 SHOW_STR
8513 IPV6_STR
8514 MBGP_STR
8515 "Display routes matching the communities\n"
8516 "community number\n"
8517 "Do not send outside local AS (well-known community)\n"
8518 "Do not advertise to any peer (well-known community)\n"
8519 "Do not export to next AS (well-known community)\n"
8520 "community number\n"
8521 "Do not send outside local AS (well-known community)\n"
8522 "Do not advertise to any peer (well-known community)\n"
8523 "Do not export to next AS (well-known community)\n"
8524 "community number\n"
8525 "Do not send outside local AS (well-known community)\n"
8526 "Do not advertise to any peer (well-known community)\n"
8527 "Do not export to next AS (well-known community)\n"
8528 "Exact match of the communities")
8529
8530/* old command */
8531ALIAS (show_ipv6_mbgp_community_exact,
8532 show_ipv6_mbgp_community4_exact_cmd,
8533 "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",
8534 SHOW_STR
8535 IPV6_STR
8536 MBGP_STR
8537 "Display routes matching the communities\n"
8538 "community number\n"
8539 "Do not send outside local AS (well-known community)\n"
8540 "Do not advertise to any peer (well-known community)\n"
8541 "Do not export to next AS (well-known community)\n"
8542 "community number\n"
8543 "Do not send outside local AS (well-known community)\n"
8544 "Do not advertise to any peer (well-known community)\n"
8545 "Do not export to next AS (well-known community)\n"
8546 "community number\n"
8547 "Do not send outside local AS (well-known community)\n"
8548 "Do not advertise to any peer (well-known community)\n"
8549 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8555#endif /* HAVE_IPV6 */
8556
paul94f2b392005-06-28 12:44:16 +00008557static int
paulfd79ac92004-10-13 05:06:08 +00008558bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008559 u_int16_t afi, u_char safi)
8560{
8561 struct community_list *list;
8562
hassofee6e4e2005-02-02 16:29:31 +00008563 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008564 if (list == NULL)
8565 {
8566 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8567 VTY_NEWLINE);
8568 return CMD_WARNING;
8569 }
8570
ajs5a646652004-11-05 01:25:55 +00008571 return bgp_show (vty, NULL, afi, safi,
8572 (exact ? bgp_show_type_community_list_exact :
8573 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008574}
8575
8576DEFUN (show_ip_bgp_community_list,
8577 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008578 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008579 SHOW_STR
8580 IP_STR
8581 BGP_STR
8582 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008583 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008584 "community-list name\n")
8585{
8586 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8587}
8588
8589DEFUN (show_ip_bgp_ipv4_community_list,
8590 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008591 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008592 SHOW_STR
8593 IP_STR
8594 BGP_STR
8595 "Address family\n"
8596 "Address Family modifier\n"
8597 "Address Family modifier\n"
8598 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008599 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008600 "community-list name\n")
8601{
8602 if (strncmp (argv[0], "m", 1) == 0)
8603 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8604
8605 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8606}
8607
8608DEFUN (show_ip_bgp_community_list_exact,
8609 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008610 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008611 SHOW_STR
8612 IP_STR
8613 BGP_STR
8614 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008615 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008616 "community-list name\n"
8617 "Exact match of the communities\n")
8618{
8619 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8620}
8621
8622DEFUN (show_ip_bgp_ipv4_community_list_exact,
8623 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008624 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008625 SHOW_STR
8626 IP_STR
8627 BGP_STR
8628 "Address family\n"
8629 "Address Family modifier\n"
8630 "Address Family modifier\n"
8631 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008632 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008633 "community-list name\n"
8634 "Exact match of the communities\n")
8635{
8636 if (strncmp (argv[0], "m", 1) == 0)
8637 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8638
8639 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8640}
8641
8642#ifdef HAVE_IPV6
8643DEFUN (show_bgp_community_list,
8644 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008645 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008646 SHOW_STR
8647 BGP_STR
8648 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008649 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008650 "community-list name\n")
8651{
8652 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8653}
8654
8655ALIAS (show_bgp_community_list,
8656 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008657 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008658 SHOW_STR
8659 BGP_STR
8660 "Address family\n"
8661 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008662 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008663 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008664
8665/* old command */
8666DEFUN (show_ipv6_bgp_community_list,
8667 show_ipv6_bgp_community_list_cmd,
8668 "show ipv6 bgp community-list WORD",
8669 SHOW_STR
8670 IPV6_STR
8671 BGP_STR
8672 "Display routes matching the community-list\n"
8673 "community-list name\n")
8674{
8675 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8676}
8677
8678/* old command */
8679DEFUN (show_ipv6_mbgp_community_list,
8680 show_ipv6_mbgp_community_list_cmd,
8681 "show ipv6 mbgp community-list WORD",
8682 SHOW_STR
8683 IPV6_STR
8684 MBGP_STR
8685 "Display routes matching the community-list\n"
8686 "community-list name\n")
8687{
8688 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8689}
8690
8691DEFUN (show_bgp_community_list_exact,
8692 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008693 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008694 SHOW_STR
8695 BGP_STR
8696 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008697 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008698 "community-list name\n"
8699 "Exact match of the communities\n")
8700{
8701 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8702}
8703
8704ALIAS (show_bgp_community_list_exact,
8705 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008706 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008707 SHOW_STR
8708 BGP_STR
8709 "Address family\n"
8710 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008711 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008712 "community-list name\n"
8713 "Exact match of the communities\n")
8714
8715/* old command */
8716DEFUN (show_ipv6_bgp_community_list_exact,
8717 show_ipv6_bgp_community_list_exact_cmd,
8718 "show ipv6 bgp community-list WORD exact-match",
8719 SHOW_STR
8720 IPV6_STR
8721 BGP_STR
8722 "Display routes matching the community-list\n"
8723 "community-list name\n"
8724 "Exact match of the communities\n")
8725{
8726 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8727}
8728
8729/* old command */
8730DEFUN (show_ipv6_mbgp_community_list_exact,
8731 show_ipv6_mbgp_community_list_exact_cmd,
8732 "show ipv6 mbgp community-list WORD exact-match",
8733 SHOW_STR
8734 IPV6_STR
8735 MBGP_STR
8736 "Display routes matching the community-list\n"
8737 "community-list name\n"
8738 "Exact match of the communities\n")
8739{
8740 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8741}
8742#endif /* HAVE_IPV6 */
8743
paul94f2b392005-06-28 12:44:16 +00008744static int
paulfd79ac92004-10-13 05:06:08 +00008745bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008746 safi_t safi, enum bgp_show_type type)
8747{
8748 int ret;
8749 struct prefix *p;
8750
8751 p = prefix_new();
8752
8753 ret = str2prefix (prefix, p);
8754 if (! ret)
8755 {
8756 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8757 return CMD_WARNING;
8758 }
8759
ajs5a646652004-11-05 01:25:55 +00008760 ret = bgp_show (vty, NULL, afi, safi, type, p);
8761 prefix_free(p);
8762 return ret;
paul718e3742002-12-13 20:15:29 +00008763}
8764
8765DEFUN (show_ip_bgp_prefix_longer,
8766 show_ip_bgp_prefix_longer_cmd,
8767 "show ip bgp A.B.C.D/M longer-prefixes",
8768 SHOW_STR
8769 IP_STR
8770 BGP_STR
8771 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8772 "Display route and more specific routes\n")
8773{
8774 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8775 bgp_show_type_prefix_longer);
8776}
8777
8778DEFUN (show_ip_bgp_flap_prefix_longer,
8779 show_ip_bgp_flap_prefix_longer_cmd,
8780 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8781 SHOW_STR
8782 IP_STR
8783 BGP_STR
8784 "Display flap statistics of routes\n"
8785 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8786 "Display route and more specific routes\n")
8787{
8788 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8789 bgp_show_type_flap_prefix_longer);
8790}
8791
8792DEFUN (show_ip_bgp_ipv4_prefix_longer,
8793 show_ip_bgp_ipv4_prefix_longer_cmd,
8794 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8795 SHOW_STR
8796 IP_STR
8797 BGP_STR
8798 "Address family\n"
8799 "Address Family modifier\n"
8800 "Address Family modifier\n"
8801 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8802 "Display route and more specific routes\n")
8803{
8804 if (strncmp (argv[0], "m", 1) == 0)
8805 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8806 bgp_show_type_prefix_longer);
8807
8808 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8809 bgp_show_type_prefix_longer);
8810}
8811
8812DEFUN (show_ip_bgp_flap_address,
8813 show_ip_bgp_flap_address_cmd,
8814 "show ip bgp flap-statistics A.B.C.D",
8815 SHOW_STR
8816 IP_STR
8817 BGP_STR
8818 "Display flap statistics of routes\n"
8819 "Network in the BGP routing table to display\n")
8820{
8821 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8822 bgp_show_type_flap_address);
8823}
8824
8825DEFUN (show_ip_bgp_flap_prefix,
8826 show_ip_bgp_flap_prefix_cmd,
8827 "show ip bgp flap-statistics A.B.C.D/M",
8828 SHOW_STR
8829 IP_STR
8830 BGP_STR
8831 "Display flap statistics of routes\n"
8832 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8833{
8834 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8835 bgp_show_type_flap_prefix);
8836}
8837#ifdef HAVE_IPV6
8838DEFUN (show_bgp_prefix_longer,
8839 show_bgp_prefix_longer_cmd,
8840 "show bgp X:X::X:X/M longer-prefixes",
8841 SHOW_STR
8842 BGP_STR
8843 "IPv6 prefix <network>/<length>\n"
8844 "Display route and more specific routes\n")
8845{
8846 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8847 bgp_show_type_prefix_longer);
8848}
8849
8850ALIAS (show_bgp_prefix_longer,
8851 show_bgp_ipv6_prefix_longer_cmd,
8852 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8853 SHOW_STR
8854 BGP_STR
8855 "Address family\n"
8856 "IPv6 prefix <network>/<length>\n"
8857 "Display route and more specific routes\n")
8858
8859/* old command */
8860DEFUN (show_ipv6_bgp_prefix_longer,
8861 show_ipv6_bgp_prefix_longer_cmd,
8862 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8863 SHOW_STR
8864 IPV6_STR
8865 BGP_STR
8866 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8867 "Display route and more specific routes\n")
8868{
8869 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8870 bgp_show_type_prefix_longer);
8871}
8872
8873/* old command */
8874DEFUN (show_ipv6_mbgp_prefix_longer,
8875 show_ipv6_mbgp_prefix_longer_cmd,
8876 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8877 SHOW_STR
8878 IPV6_STR
8879 MBGP_STR
8880 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8881 "Display route and more specific routes\n")
8882{
8883 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8884 bgp_show_type_prefix_longer);
8885}
8886#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008887
paul94f2b392005-06-28 12:44:16 +00008888static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008889peer_lookup_in_view (struct vty *vty, const char *view_name,
8890 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008891{
8892 int ret;
8893 struct bgp *bgp;
8894 struct peer *peer;
8895 union sockunion su;
8896
8897 /* BGP structure lookup. */
8898 if (view_name)
8899 {
8900 bgp = bgp_lookup_by_name (view_name);
8901 if (! bgp)
8902 {
8903 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8904 return NULL;
8905 }
8906 }
paul5228ad22004-06-04 17:58:18 +00008907 else
paulbb46e942003-10-24 19:02:03 +00008908 {
8909 bgp = bgp_get_default ();
8910 if (! bgp)
8911 {
8912 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8913 return NULL;
8914 }
8915 }
8916
8917 /* Get peer sockunion. */
8918 ret = str2sockunion (ip_str, &su);
8919 if (ret < 0)
8920 {
8921 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8922 return NULL;
8923 }
8924
8925 /* Peer structure lookup. */
8926 peer = peer_lookup (bgp, &su);
8927 if (! peer)
8928 {
8929 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8930 return NULL;
8931 }
8932
8933 return peer;
8934}
Paul Jakma2815e612006-09-14 02:56:07 +00008935
8936enum bgp_stats
8937{
8938 BGP_STATS_MAXBITLEN = 0,
8939 BGP_STATS_RIB,
8940 BGP_STATS_PREFIXES,
8941 BGP_STATS_TOTPLEN,
8942 BGP_STATS_UNAGGREGATEABLE,
8943 BGP_STATS_MAX_AGGREGATEABLE,
8944 BGP_STATS_AGGREGATES,
8945 BGP_STATS_SPACE,
8946 BGP_STATS_ASPATH_COUNT,
8947 BGP_STATS_ASPATH_MAXHOPS,
8948 BGP_STATS_ASPATH_TOTHOPS,
8949 BGP_STATS_ASPATH_MAXSIZE,
8950 BGP_STATS_ASPATH_TOTSIZE,
8951 BGP_STATS_ASN_HIGHEST,
8952 BGP_STATS_MAX,
8953};
paulbb46e942003-10-24 19:02:03 +00008954
Paul Jakma2815e612006-09-14 02:56:07 +00008955static const char *table_stats_strs[] =
8956{
8957 [BGP_STATS_PREFIXES] = "Total Prefixes",
8958 [BGP_STATS_TOTPLEN] = "Average prefix length",
8959 [BGP_STATS_RIB] = "Total Advertisements",
8960 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8961 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8962 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8963 [BGP_STATS_SPACE] = "Address space advertised",
8964 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8965 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8966 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8967 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8968 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8969 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8970 [BGP_STATS_MAX] = NULL,
8971};
8972
8973struct bgp_table_stats
8974{
8975 struct bgp_table *table;
8976 unsigned long long counts[BGP_STATS_MAX];
8977};
8978
8979#if 0
8980#define TALLY_SIGFIG 100000
8981static unsigned long
8982ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8983{
8984 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8985 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8986 unsigned long ret = newtot / count;
8987
8988 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
8989 return ret + 1;
8990 else
8991 return ret;
8992}
8993#endif
8994
8995static int
8996bgp_table_stats_walker (struct thread *t)
8997{
8998 struct bgp_node *rn;
8999 struct bgp_node *top;
9000 struct bgp_table_stats *ts = THREAD_ARG (t);
9001 unsigned int space = 0;
9002
Paul Jakma53d9f672006-10-15 23:41:16 +00009003 if (!(top = bgp_table_top (ts->table)))
9004 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009005
9006 switch (top->p.family)
9007 {
9008 case AF_INET:
9009 space = IPV4_MAX_BITLEN;
9010 break;
9011 case AF_INET6:
9012 space = IPV6_MAX_BITLEN;
9013 break;
9014 }
9015
9016 ts->counts[BGP_STATS_MAXBITLEN] = space;
9017
9018 for (rn = top; rn; rn = bgp_route_next (rn))
9019 {
9020 struct bgp_info *ri;
9021 struct bgp_node *prn = rn->parent;
9022 unsigned int rinum = 0;
9023
9024 if (rn == top)
9025 continue;
9026
9027 if (!rn->info)
9028 continue;
9029
9030 ts->counts[BGP_STATS_PREFIXES]++;
9031 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9032
9033#if 0
9034 ts->counts[BGP_STATS_AVGPLEN]
9035 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9036 ts->counts[BGP_STATS_AVGPLEN],
9037 rn->p.prefixlen);
9038#endif
9039
9040 /* check if the prefix is included by any other announcements */
9041 while (prn && !prn->info)
9042 prn = prn->parent;
9043
9044 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009045 {
9046 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9047 /* announced address space */
9048 if (space)
9049 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9050 }
Paul Jakma2815e612006-09-14 02:56:07 +00009051 else if (prn->info)
9052 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9053
Paul Jakma2815e612006-09-14 02:56:07 +00009054 for (ri = rn->info; ri; ri = ri->next)
9055 {
9056 rinum++;
9057 ts->counts[BGP_STATS_RIB]++;
9058
9059 if (ri->attr &&
9060 (CHECK_FLAG (ri->attr->flag,
9061 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9062 ts->counts[BGP_STATS_AGGREGATES]++;
9063
9064 /* as-path stats */
9065 if (ri->attr && ri->attr->aspath)
9066 {
9067 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9068 unsigned int size = aspath_size (ri->attr->aspath);
9069 as_t highest = aspath_highest (ri->attr->aspath);
9070
9071 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9072
9073 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9074 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9075
9076 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9077 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9078
9079 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9080 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9081#if 0
9082 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9083 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9084 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9085 hops);
9086 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9087 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9088 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9089 size);
9090#endif
9091 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9092 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9093 }
9094 }
9095 }
9096 return 0;
9097}
9098
9099static int
9100bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9101{
9102 struct bgp_table_stats ts;
9103 unsigned int i;
9104
9105 if (!bgp->rib[afi][safi])
9106 {
9107 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9108 return CMD_WARNING;
9109 }
9110
9111 memset (&ts, 0, sizeof (ts));
9112 ts.table = bgp->rib[afi][safi];
9113 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9114
9115 vty_out (vty, "BGP %s RIB statistics%s%s",
9116 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9117
9118 for (i = 0; i < BGP_STATS_MAX; i++)
9119 {
9120 if (!table_stats_strs[i])
9121 continue;
9122
9123 switch (i)
9124 {
9125#if 0
9126 case BGP_STATS_ASPATH_AVGHOPS:
9127 case BGP_STATS_ASPATH_AVGSIZE:
9128 case BGP_STATS_AVGPLEN:
9129 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9130 vty_out (vty, "%12.2f",
9131 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9132 break;
9133#endif
9134 case BGP_STATS_ASPATH_TOTHOPS:
9135 case BGP_STATS_ASPATH_TOTSIZE:
9136 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9137 vty_out (vty, "%12.2f",
9138 ts.counts[i] ?
9139 (float)ts.counts[i] /
9140 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9141 : 0);
9142 break;
9143 case BGP_STATS_TOTPLEN:
9144 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9145 vty_out (vty, "%12.2f",
9146 ts.counts[i] ?
9147 (float)ts.counts[i] /
9148 (float)ts.counts[BGP_STATS_PREFIXES]
9149 : 0);
9150 break;
9151 case BGP_STATS_SPACE:
9152 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9153 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9154 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9155 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009156 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009157 vty_out (vty, "%12.2f%s",
9158 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009159 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009160 VTY_NEWLINE);
9161 vty_out (vty, "%30s: ", "/8 equivalent ");
9162 vty_out (vty, "%12.2f%s",
9163 (float)ts.counts[BGP_STATS_SPACE] /
9164 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9165 VTY_NEWLINE);
9166 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9167 break;
9168 vty_out (vty, "%30s: ", "/24 equivalent ");
9169 vty_out (vty, "%12.2f",
9170 (float)ts.counts[BGP_STATS_SPACE] /
9171 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9172 break;
9173 default:
9174 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9175 vty_out (vty, "%12llu", ts.counts[i]);
9176 }
9177
9178 vty_out (vty, "%s", VTY_NEWLINE);
9179 }
9180 return CMD_SUCCESS;
9181}
9182
9183static int
9184bgp_table_stats_vty (struct vty *vty, const char *name,
9185 const char *afi_str, const char *safi_str)
9186{
9187 struct bgp *bgp;
9188 afi_t afi;
9189 safi_t safi;
9190
9191 if (name)
9192 bgp = bgp_lookup_by_name (name);
9193 else
9194 bgp = bgp_get_default ();
9195
9196 if (!bgp)
9197 {
9198 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9199 return CMD_WARNING;
9200 }
9201 if (strncmp (afi_str, "ipv", 3) == 0)
9202 {
9203 if (strncmp (afi_str, "ipv4", 4) == 0)
9204 afi = AFI_IP;
9205 else if (strncmp (afi_str, "ipv6", 4) == 0)
9206 afi = AFI_IP6;
9207 else
9208 {
9209 vty_out (vty, "%% Invalid address family %s%s",
9210 afi_str, VTY_NEWLINE);
9211 return CMD_WARNING;
9212 }
9213 if (strncmp (safi_str, "m", 1) == 0)
9214 safi = SAFI_MULTICAST;
9215 else if (strncmp (safi_str, "u", 1) == 0)
9216 safi = SAFI_UNICAST;
9217 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9218 safi = BGP_SAFI_VPNV4;
9219 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9220 safi = BGP_SAFI_VPNV6;
9221 else
9222 {
9223 vty_out (vty, "%% Invalid subsequent address family %s%s",
9224 safi_str, VTY_NEWLINE);
9225 return CMD_WARNING;
9226 }
9227 }
9228 else
9229 {
9230 vty_out (vty, "%% Invalid address family %s%s",
9231 afi_str, VTY_NEWLINE);
9232 return CMD_WARNING;
9233 }
9234
9235 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9236 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9237 {
9238 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9239 afi_str, safi_str, VTY_NEWLINE);
9240 return CMD_WARNING;
9241 }
9242 return bgp_table_stats (vty, bgp, afi, safi);
9243}
9244
9245DEFUN (show_bgp_statistics,
9246 show_bgp_statistics_cmd,
9247 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9248 SHOW_STR
9249 BGP_STR
9250 "Address family\n"
9251 "Address family\n"
9252 "Address Family modifier\n"
9253 "Address Family modifier\n"
9254 "BGP RIB advertisement statistics\n")
9255{
9256 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9257}
9258
9259ALIAS (show_bgp_statistics,
9260 show_bgp_statistics_vpnv4_cmd,
9261 "show bgp (ipv4) (vpnv4) statistics",
9262 SHOW_STR
9263 BGP_STR
9264 "Address family\n"
9265 "Address Family modifier\n"
9266 "BGP RIB advertisement statistics\n")
9267
9268DEFUN (show_bgp_statistics_view,
9269 show_bgp_statistics_view_cmd,
9270 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9271 SHOW_STR
9272 BGP_STR
9273 "BGP view\n"
9274 "Address family\n"
9275 "Address family\n"
9276 "Address Family modifier\n"
9277 "Address Family modifier\n"
9278 "BGP RIB advertisement statistics\n")
9279{
9280 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9281}
9282
9283ALIAS (show_bgp_statistics_view,
9284 show_bgp_statistics_view_vpnv4_cmd,
9285 "show bgp view WORD (ipv4) (vpnv4) statistics",
9286 SHOW_STR
9287 BGP_STR
9288 "BGP view\n"
9289 "Address family\n"
9290 "Address Family modifier\n"
9291 "BGP RIB advertisement statistics\n")
9292
Paul Jakmaff7924f2006-09-04 01:10:36 +00009293enum bgp_pcounts
9294{
9295 PCOUNT_ADJ_IN = 0,
9296 PCOUNT_DAMPED,
9297 PCOUNT_REMOVED,
9298 PCOUNT_HISTORY,
9299 PCOUNT_STALE,
9300 PCOUNT_VALID,
9301 PCOUNT_ALL,
9302 PCOUNT_COUNTED,
9303 PCOUNT_PFCNT, /* the figure we display to users */
9304 PCOUNT_MAX,
9305};
9306
9307static const char *pcount_strs[] =
9308{
9309 [PCOUNT_ADJ_IN] = "Adj-in",
9310 [PCOUNT_DAMPED] = "Damped",
9311 [PCOUNT_REMOVED] = "Removed",
9312 [PCOUNT_HISTORY] = "History",
9313 [PCOUNT_STALE] = "Stale",
9314 [PCOUNT_VALID] = "Valid",
9315 [PCOUNT_ALL] = "All RIB",
9316 [PCOUNT_COUNTED] = "PfxCt counted",
9317 [PCOUNT_PFCNT] = "Useable",
9318 [PCOUNT_MAX] = NULL,
9319};
9320
Paul Jakma2815e612006-09-14 02:56:07 +00009321struct peer_pcounts
9322{
9323 unsigned int count[PCOUNT_MAX];
9324 const struct peer *peer;
9325 const struct bgp_table *table;
9326};
9327
Paul Jakmaff7924f2006-09-04 01:10:36 +00009328static int
Paul Jakma2815e612006-09-14 02:56:07 +00009329bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009330{
9331 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009332 struct peer_pcounts *pc = THREAD_ARG (t);
9333 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009334
Paul Jakma2815e612006-09-14 02:56:07 +00009335 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009336 {
9337 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009338 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009339
9340 for (ain = rn->adj_in; ain; ain = ain->next)
9341 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009342 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009343
Paul Jakmaff7924f2006-09-04 01:10:36 +00009344 for (ri = rn->info; ri; ri = ri->next)
9345 {
9346 char buf[SU_ADDRSTRLEN];
9347
9348 if (ri->peer != peer)
9349 continue;
9350
Paul Jakma2815e612006-09-14 02:56:07 +00009351 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009352
9353 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009354 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009355 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009356 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009357 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009358 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009359 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009360 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009361 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009362 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009363 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009364 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009365
9366 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9367 {
Paul Jakma2815e612006-09-14 02:56:07 +00009368 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009369 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009370 plog_warn (peer->log,
9371 "%s [pcount] %s/%d is counted but flags 0x%x",
9372 peer->host,
9373 inet_ntop(rn->p.family, &rn->p.u.prefix,
9374 buf, SU_ADDRSTRLEN),
9375 rn->p.prefixlen,
9376 ri->flags);
9377 }
9378 else
9379 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009380 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009381 plog_warn (peer->log,
9382 "%s [pcount] %s/%d not counted but flags 0x%x",
9383 peer->host,
9384 inet_ntop(rn->p.family, &rn->p.u.prefix,
9385 buf, SU_ADDRSTRLEN),
9386 rn->p.prefixlen,
9387 ri->flags);
9388 }
9389 }
9390 }
Paul Jakma2815e612006-09-14 02:56:07 +00009391 return 0;
9392}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009393
Paul Jakma2815e612006-09-14 02:56:07 +00009394static int
9395bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9396{
9397 struct peer_pcounts pcounts = { .peer = peer };
9398 unsigned int i;
9399
9400 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9401 || !peer->bgp->rib[afi][safi])
9402 {
9403 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9404 return CMD_WARNING;
9405 }
9406
9407 memset (&pcounts, 0, sizeof(pcounts));
9408 pcounts.peer = peer;
9409 pcounts.table = peer->bgp->rib[afi][safi];
9410
9411 /* in-place call via thread subsystem so as to record execution time
9412 * stats for the thread-walk (i.e. ensure this can't be blamed on
9413 * on just vty_read()).
9414 */
9415 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9416
Paul Jakmaff7924f2006-09-04 01:10:36 +00009417 vty_out (vty, "Prefix counts for %s, %s%s",
9418 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9419 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9420 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9421 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9422
9423 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009424 vty_out (vty, "%20s: %-10d%s",
9425 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009426
Paul Jakma2815e612006-09-14 02:56:07 +00009427 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009428 {
9429 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9430 peer->host, VTY_NEWLINE);
9431 vty_out (vty, "Please report this bug, with the above command output%s",
9432 VTY_NEWLINE);
9433 }
9434
9435 return CMD_SUCCESS;
9436}
9437
9438DEFUN (show_ip_bgp_neighbor_prefix_counts,
9439 show_ip_bgp_neighbor_prefix_counts_cmd,
9440 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9441 SHOW_STR
9442 IP_STR
9443 BGP_STR
9444 "Detailed information on TCP and BGP neighbor connections\n"
9445 "Neighbor to display information about\n"
9446 "Neighbor to display information about\n"
9447 "Display detailed prefix count information\n")
9448{
9449 struct peer *peer;
9450
9451 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9452 if (! peer)
9453 return CMD_WARNING;
9454
9455 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9456}
9457
9458DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9459 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9460 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9461 SHOW_STR
9462 BGP_STR
9463 "Address family\n"
9464 "Detailed information on TCP and BGP neighbor connections\n"
9465 "Neighbor to display information about\n"
9466 "Neighbor to display information about\n"
9467 "Display detailed prefix count information\n")
9468{
9469 struct peer *peer;
9470
9471 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9472 if (! peer)
9473 return CMD_WARNING;
9474
9475 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9476}
9477
9478DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9479 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9480 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9481 SHOW_STR
9482 IP_STR
9483 BGP_STR
9484 "Address family\n"
9485 "Address Family modifier\n"
9486 "Address Family modifier\n"
9487 "Detailed information on TCP and BGP neighbor connections\n"
9488 "Neighbor to display information about\n"
9489 "Neighbor to display information about\n"
9490 "Display detailed prefix count information\n")
9491{
9492 struct peer *peer;
9493
9494 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9495 if (! peer)
9496 return CMD_WARNING;
9497
9498 if (strncmp (argv[0], "m", 1) == 0)
9499 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9500
9501 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9502}
9503
9504DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9505 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9506 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9507 SHOW_STR
9508 IP_STR
9509 BGP_STR
9510 "Address family\n"
9511 "Address Family modifier\n"
9512 "Address Family modifier\n"
9513 "Detailed information on TCP and BGP neighbor connections\n"
9514 "Neighbor to display information about\n"
9515 "Neighbor to display information about\n"
9516 "Display detailed prefix count information\n")
9517{
9518 struct peer *peer;
9519
9520 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9521 if (! peer)
9522 return CMD_WARNING;
9523
9524 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9525}
9526
9527
paul94f2b392005-06-28 12:44:16 +00009528static void
paul718e3742002-12-13 20:15:29 +00009529show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9530 int in)
9531{
9532 struct bgp_table *table;
9533 struct bgp_adj_in *ain;
9534 struct bgp_adj_out *adj;
9535 unsigned long output_count;
9536 struct bgp_node *rn;
9537 int header1 = 1;
9538 struct bgp *bgp;
9539 int header2 = 1;
9540
paulbb46e942003-10-24 19:02:03 +00009541 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009542
9543 if (! bgp)
9544 return;
9545
9546 table = bgp->rib[afi][safi];
9547
9548 output_count = 0;
9549
9550 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9551 PEER_STATUS_DEFAULT_ORIGINATE))
9552 {
9553 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 +00009554 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9555 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009556
9557 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9558 VTY_NEWLINE, VTY_NEWLINE);
9559 header1 = 0;
9560 }
9561
9562 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9563 if (in)
9564 {
9565 for (ain = rn->adj_in; ain; ain = ain->next)
9566 if (ain->peer == peer)
9567 {
9568 if (header1)
9569 {
9570 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 +00009571 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9572 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009573 header1 = 0;
9574 }
9575 if (header2)
9576 {
9577 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9578 header2 = 0;
9579 }
9580 if (ain->attr)
9581 {
9582 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9583 output_count++;
9584 }
9585 }
9586 }
9587 else
9588 {
9589 for (adj = rn->adj_out; adj; adj = adj->next)
9590 if (adj->peer == peer)
9591 {
9592 if (header1)
9593 {
9594 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 +00009595 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9596 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009597 header1 = 0;
9598 }
9599 if (header2)
9600 {
9601 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9602 header2 = 0;
9603 }
9604 if (adj->attr)
9605 {
9606 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9607 output_count++;
9608 }
9609 }
9610 }
9611
9612 if (output_count != 0)
9613 vty_out (vty, "%sTotal number of prefixes %ld%s",
9614 VTY_NEWLINE, output_count, VTY_NEWLINE);
9615}
9616
paul94f2b392005-06-28 12:44:16 +00009617static int
paulbb46e942003-10-24 19:02:03 +00009618peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9619{
paul718e3742002-12-13 20:15:29 +00009620 if (! peer || ! peer->afc[afi][safi])
9621 {
9622 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9623 return CMD_WARNING;
9624 }
9625
9626 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9627 {
9628 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9629 VTY_NEWLINE);
9630 return CMD_WARNING;
9631 }
9632
9633 show_adj_route (vty, peer, afi, safi, in);
9634
9635 return CMD_SUCCESS;
9636}
9637
9638DEFUN (show_ip_bgp_neighbor_advertised_route,
9639 show_ip_bgp_neighbor_advertised_route_cmd,
9640 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9641 SHOW_STR
9642 IP_STR
9643 BGP_STR
9644 "Detailed information on TCP and BGP neighbor connections\n"
9645 "Neighbor to display information about\n"
9646 "Neighbor to display information about\n"
9647 "Display the routes advertised to a BGP neighbor\n")
9648{
paulbb46e942003-10-24 19:02:03 +00009649 struct peer *peer;
9650
9651 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9652 if (! peer)
9653 return CMD_WARNING;
9654
9655 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009656}
9657
9658DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9659 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9660 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9661 SHOW_STR
9662 IP_STR
9663 BGP_STR
9664 "Address family\n"
9665 "Address Family modifier\n"
9666 "Address Family modifier\n"
9667 "Detailed information on TCP and BGP neighbor connections\n"
9668 "Neighbor to display information about\n"
9669 "Neighbor to display information about\n"
9670 "Display the routes advertised to a BGP neighbor\n")
9671{
paulbb46e942003-10-24 19:02:03 +00009672 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009673
paulbb46e942003-10-24 19:02:03 +00009674 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9675 if (! peer)
9676 return CMD_WARNING;
9677
9678 if (strncmp (argv[0], "m", 1) == 0)
9679 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9680
9681 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009682}
9683
9684#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009685DEFUN (show_bgp_view_neighbor_advertised_route,
9686 show_bgp_view_neighbor_advertised_route_cmd,
9687 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9688 SHOW_STR
9689 BGP_STR
9690 "BGP view\n"
9691 "View name\n"
9692 "Detailed information on TCP and BGP neighbor connections\n"
9693 "Neighbor to display information about\n"
9694 "Neighbor to display information about\n"
9695 "Display the routes advertised to a BGP neighbor\n")
9696{
9697 struct peer *peer;
9698
9699 if (argc == 2)
9700 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9701 else
9702 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9703
9704 if (! peer)
9705 return CMD_WARNING;
9706
9707 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9708}
9709
9710ALIAS (show_bgp_view_neighbor_advertised_route,
9711 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9712 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9713 SHOW_STR
9714 BGP_STR
9715 "BGP view\n"
9716 "View name\n"
9717 "Address family\n"
9718 "Detailed information on TCP and BGP neighbor connections\n"
9719 "Neighbor to display information about\n"
9720 "Neighbor to display information about\n"
9721 "Display the routes advertised to a BGP neighbor\n")
9722
9723DEFUN (show_bgp_view_neighbor_received_routes,
9724 show_bgp_view_neighbor_received_routes_cmd,
9725 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9726 SHOW_STR
9727 BGP_STR
9728 "BGP view\n"
9729 "View name\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 received routes from neighbor\n")
9734{
9735 struct peer *peer;
9736
9737 if (argc == 2)
9738 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9739 else
9740 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9741
9742 if (! peer)
9743 return CMD_WARNING;
9744
9745 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9746}
9747
9748ALIAS (show_bgp_view_neighbor_received_routes,
9749 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9750 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9751 SHOW_STR
9752 BGP_STR
9753 "BGP view\n"
9754 "View name\n"
9755 "Address family\n"
9756 "Detailed information on TCP and BGP neighbor connections\n"
9757 "Neighbor to display information about\n"
9758 "Neighbor to display information about\n"
9759 "Display the received routes from neighbor\n")
9760
9761ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009762 show_bgp_neighbor_advertised_route_cmd,
9763 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9764 SHOW_STR
9765 BGP_STR
9766 "Detailed information on TCP and BGP neighbor connections\n"
9767 "Neighbor to display information about\n"
9768 "Neighbor to display information about\n"
9769 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009770
9771ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009772 show_bgp_ipv6_neighbor_advertised_route_cmd,
9773 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9774 SHOW_STR
9775 BGP_STR
9776 "Address family\n"
9777 "Detailed information on TCP and BGP neighbor connections\n"
9778 "Neighbor to display information about\n"
9779 "Neighbor to display information about\n"
9780 "Display the routes advertised to a BGP neighbor\n")
9781
9782/* old command */
paulbb46e942003-10-24 19:02:03 +00009783ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009784 ipv6_bgp_neighbor_advertised_route_cmd,
9785 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9786 SHOW_STR
9787 IPV6_STR
9788 BGP_STR
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")
paulbb46e942003-10-24 19:02:03 +00009793
paul718e3742002-12-13 20:15:29 +00009794/* old command */
9795DEFUN (ipv6_mbgp_neighbor_advertised_route,
9796 ipv6_mbgp_neighbor_advertised_route_cmd,
9797 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9798 SHOW_STR
9799 IPV6_STR
9800 MBGP_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")
9805{
paulbb46e942003-10-24 19:02:03 +00009806 struct peer *peer;
9807
9808 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9809 if (! peer)
9810 return CMD_WARNING;
9811
9812 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009813}
9814#endif /* HAVE_IPV6 */
9815
9816DEFUN (show_ip_bgp_neighbor_received_routes,
9817 show_ip_bgp_neighbor_received_routes_cmd,
9818 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9819 SHOW_STR
9820 IP_STR
9821 BGP_STR
9822 "Detailed information on TCP and BGP neighbor connections\n"
9823 "Neighbor to display information about\n"
9824 "Neighbor to display information about\n"
9825 "Display the received routes from neighbor\n")
9826{
paulbb46e942003-10-24 19:02:03 +00009827 struct peer *peer;
9828
9829 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9830 if (! peer)
9831 return CMD_WARNING;
9832
9833 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009834}
9835
9836DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9837 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9838 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9839 SHOW_STR
9840 IP_STR
9841 BGP_STR
9842 "Address family\n"
9843 "Address Family modifier\n"
9844 "Address Family modifier\n"
9845 "Detailed information on TCP and BGP neighbor connections\n"
9846 "Neighbor to display information about\n"
9847 "Neighbor to display information about\n"
9848 "Display the received routes from neighbor\n")
9849{
paulbb46e942003-10-24 19:02:03 +00009850 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009851
paulbb46e942003-10-24 19:02:03 +00009852 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9853 if (! peer)
9854 return CMD_WARNING;
9855
9856 if (strncmp (argv[0], "m", 1) == 0)
9857 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9858
9859 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009860}
9861
9862DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9863 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9864 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9865 SHOW_STR
9866 IP_STR
9867 BGP_STR
9868 "Detailed information on TCP and BGP neighbor connections\n"
9869 "Neighbor to display information about\n"
9870 "Neighbor to display information about\n"
9871 "Display information received from a BGP neighbor\n"
9872 "Display the prefixlist filter\n")
9873{
9874 char name[BUFSIZ];
9875 union sockunion *su;
9876 struct peer *peer;
9877 int count;
9878
9879 su = sockunion_str2su (argv[0]);
9880 if (su == NULL)
9881 return CMD_WARNING;
9882
9883 peer = peer_lookup (NULL, su);
9884 if (! peer)
9885 return CMD_WARNING;
9886
9887 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9888 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9889 if (count)
9890 {
9891 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9892 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9893 }
9894
9895 return CMD_SUCCESS;
9896}
9897
9898DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9899 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9900 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9901 SHOW_STR
9902 IP_STR
9903 BGP_STR
9904 "Address family\n"
9905 "Address Family modifier\n"
9906 "Address Family modifier\n"
9907 "Detailed information on TCP and BGP neighbor connections\n"
9908 "Neighbor to display information about\n"
9909 "Neighbor to display information about\n"
9910 "Display information received from a BGP neighbor\n"
9911 "Display the prefixlist filter\n")
9912{
9913 char name[BUFSIZ];
9914 union sockunion *su;
9915 struct peer *peer;
9916 int count;
9917
9918 su = sockunion_str2su (argv[1]);
9919 if (su == NULL)
9920 return CMD_WARNING;
9921
9922 peer = peer_lookup (NULL, su);
9923 if (! peer)
9924 return CMD_WARNING;
9925
9926 if (strncmp (argv[0], "m", 1) == 0)
9927 {
9928 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9929 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9930 if (count)
9931 {
9932 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9933 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9934 }
9935 }
9936 else
9937 {
9938 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9939 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9940 if (count)
9941 {
9942 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9943 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9944 }
9945 }
9946
9947 return CMD_SUCCESS;
9948}
9949
9950
9951#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009952ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009953 show_bgp_neighbor_received_routes_cmd,
9954 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9955 SHOW_STR
9956 BGP_STR
9957 "Detailed information on TCP and BGP neighbor connections\n"
9958 "Neighbor to display information about\n"
9959 "Neighbor to display information about\n"
9960 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009961
paulbb46e942003-10-24 19:02:03 +00009962ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009963 show_bgp_ipv6_neighbor_received_routes_cmd,
9964 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9965 SHOW_STR
9966 BGP_STR
9967 "Address family\n"
9968 "Detailed information on TCP and BGP neighbor connections\n"
9969 "Neighbor to display information about\n"
9970 "Neighbor to display information about\n"
9971 "Display the received routes from neighbor\n")
9972
9973DEFUN (show_bgp_neighbor_received_prefix_filter,
9974 show_bgp_neighbor_received_prefix_filter_cmd,
9975 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9976 SHOW_STR
9977 BGP_STR
9978 "Detailed information on TCP and BGP neighbor connections\n"
9979 "Neighbor to display information about\n"
9980 "Neighbor to display information about\n"
9981 "Display information received from a BGP neighbor\n"
9982 "Display the prefixlist filter\n")
9983{
9984 char name[BUFSIZ];
9985 union sockunion *su;
9986 struct peer *peer;
9987 int count;
9988
9989 su = sockunion_str2su (argv[0]);
9990 if (su == NULL)
9991 return CMD_WARNING;
9992
9993 peer = peer_lookup (NULL, su);
9994 if (! peer)
9995 return CMD_WARNING;
9996
9997 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9998 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9999 if (count)
10000 {
10001 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10002 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10003 }
10004
10005 return CMD_SUCCESS;
10006}
10007
10008ALIAS (show_bgp_neighbor_received_prefix_filter,
10009 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10010 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10011 SHOW_STR
10012 BGP_STR
10013 "Address family\n"
10014 "Detailed information on TCP and BGP neighbor connections\n"
10015 "Neighbor to display information about\n"
10016 "Neighbor to display information about\n"
10017 "Display information received from a BGP neighbor\n"
10018 "Display the prefixlist filter\n")
10019
10020/* old command */
paulbb46e942003-10-24 19:02:03 +000010021ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010022 ipv6_bgp_neighbor_received_routes_cmd,
10023 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10024 SHOW_STR
10025 IPV6_STR
10026 BGP_STR
10027 "Detailed information on TCP and BGP neighbor connections\n"
10028 "Neighbor to display information about\n"
10029 "Neighbor to display information about\n"
10030 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010031
10032/* old command */
10033DEFUN (ipv6_mbgp_neighbor_received_routes,
10034 ipv6_mbgp_neighbor_received_routes_cmd,
10035 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10036 SHOW_STR
10037 IPV6_STR
10038 MBGP_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")
10043{
paulbb46e942003-10-24 19:02:03 +000010044 struct peer *peer;
10045
10046 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10047 if (! peer)
10048 return CMD_WARNING;
10049
10050 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010051}
paulbb46e942003-10-24 19:02:03 +000010052
10053DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10054 show_bgp_view_neighbor_received_prefix_filter_cmd,
10055 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10056 SHOW_STR
10057 BGP_STR
10058 "BGP view\n"
10059 "View name\n"
10060 "Detailed information on TCP and BGP neighbor connections\n"
10061 "Neighbor to display information about\n"
10062 "Neighbor to display information about\n"
10063 "Display information received from a BGP neighbor\n"
10064 "Display the prefixlist filter\n")
10065{
10066 char name[BUFSIZ];
10067 union sockunion *su;
10068 struct peer *peer;
10069 struct bgp *bgp;
10070 int count;
10071
10072 /* BGP structure lookup. */
10073 bgp = bgp_lookup_by_name (argv[0]);
10074 if (bgp == NULL)
10075 {
10076 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10077 return CMD_WARNING;
10078 }
10079
10080 su = sockunion_str2su (argv[1]);
10081 if (su == NULL)
10082 return CMD_WARNING;
10083
10084 peer = peer_lookup (bgp, su);
10085 if (! peer)
10086 return CMD_WARNING;
10087
10088 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10089 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10090 if (count)
10091 {
10092 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10093 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10094 }
10095
10096 return CMD_SUCCESS;
10097}
10098
10099ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10100 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10101 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10102 SHOW_STR
10103 BGP_STR
10104 "BGP view\n"
10105 "View name\n"
10106 "Address family\n"
10107 "Detailed information on TCP and BGP neighbor connections\n"
10108 "Neighbor to display information about\n"
10109 "Neighbor to display information about\n"
10110 "Display information received from a BGP neighbor\n"
10111 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010112#endif /* HAVE_IPV6 */
10113
paul94f2b392005-06-28 12:44:16 +000010114static int
paulbb46e942003-10-24 19:02:03 +000010115bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010116 safi_t safi, enum bgp_show_type type)
10117{
paul718e3742002-12-13 20:15:29 +000010118 if (! peer || ! peer->afc[afi][safi])
10119 {
10120 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010121 return CMD_WARNING;
10122 }
10123
ajs5a646652004-11-05 01:25:55 +000010124 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010125}
10126
10127DEFUN (show_ip_bgp_neighbor_routes,
10128 show_ip_bgp_neighbor_routes_cmd,
10129 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10130 SHOW_STR
10131 IP_STR
10132 BGP_STR
10133 "Detailed information on TCP and BGP neighbor connections\n"
10134 "Neighbor to display information about\n"
10135 "Neighbor to display information about\n"
10136 "Display routes learned from neighbor\n")
10137{
paulbb46e942003-10-24 19:02:03 +000010138 struct peer *peer;
10139
10140 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10141 if (! peer)
10142 return CMD_WARNING;
10143
10144 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010145 bgp_show_type_neighbor);
10146}
10147
10148DEFUN (show_ip_bgp_neighbor_flap,
10149 show_ip_bgp_neighbor_flap_cmd,
10150 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10151 SHOW_STR
10152 IP_STR
10153 BGP_STR
10154 "Detailed information on TCP and BGP neighbor connections\n"
10155 "Neighbor to display information about\n"
10156 "Neighbor to display information about\n"
10157 "Display flap statistics of the routes learned from neighbor\n")
10158{
paulbb46e942003-10-24 19:02:03 +000010159 struct peer *peer;
10160
10161 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10162 if (! peer)
10163 return CMD_WARNING;
10164
10165 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010166 bgp_show_type_flap_neighbor);
10167}
10168
10169DEFUN (show_ip_bgp_neighbor_damp,
10170 show_ip_bgp_neighbor_damp_cmd,
10171 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10172 SHOW_STR
10173 IP_STR
10174 BGP_STR
10175 "Detailed information on TCP and BGP neighbor connections\n"
10176 "Neighbor to display information about\n"
10177 "Neighbor to display information about\n"
10178 "Display the dampened routes received from neighbor\n")
10179{
paulbb46e942003-10-24 19:02:03 +000010180 struct peer *peer;
10181
10182 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10183 if (! peer)
10184 return CMD_WARNING;
10185
10186 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010187 bgp_show_type_damp_neighbor);
10188}
10189
10190DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10191 show_ip_bgp_ipv4_neighbor_routes_cmd,
10192 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10193 SHOW_STR
10194 IP_STR
10195 BGP_STR
10196 "Address family\n"
10197 "Address Family modifier\n"
10198 "Address Family modifier\n"
10199 "Detailed information on TCP and BGP neighbor connections\n"
10200 "Neighbor to display information about\n"
10201 "Neighbor to display information about\n"
10202 "Display routes learned from neighbor\n")
10203{
paulbb46e942003-10-24 19:02:03 +000010204 struct peer *peer;
10205
10206 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10207 if (! peer)
10208 return CMD_WARNING;
10209
paul718e3742002-12-13 20:15:29 +000010210 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010211 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010212 bgp_show_type_neighbor);
10213
paulbb46e942003-10-24 19:02:03 +000010214 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010215 bgp_show_type_neighbor);
10216}
paulbb46e942003-10-24 19:02:03 +000010217
paulfee0f4c2004-09-13 05:12:46 +000010218DEFUN (show_ip_bgp_view_rsclient,
10219 show_ip_bgp_view_rsclient_cmd,
10220 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10221 SHOW_STR
10222 IP_STR
10223 BGP_STR
10224 "BGP view\n"
10225 "BGP view name\n"
10226 "Information about Route Server Client\n"
10227 NEIGHBOR_ADDR_STR)
10228{
10229 struct bgp_table *table;
10230 struct peer *peer;
10231
10232 if (argc == 2)
10233 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10234 else
10235 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10236
10237 if (! peer)
10238 return CMD_WARNING;
10239
10240 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10241 {
10242 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10243 VTY_NEWLINE);
10244 return CMD_WARNING;
10245 }
10246
10247 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10248 PEER_FLAG_RSERVER_CLIENT))
10249 {
10250 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10251 VTY_NEWLINE);
10252 return CMD_WARNING;
10253 }
10254
10255 table = peer->rib[AFI_IP][SAFI_UNICAST];
10256
ajs5a646652004-11-05 01:25:55 +000010257 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010258}
10259
10260ALIAS (show_ip_bgp_view_rsclient,
10261 show_ip_bgp_rsclient_cmd,
10262 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10263 SHOW_STR
10264 IP_STR
10265 BGP_STR
10266 "Information about Route Server Client\n"
10267 NEIGHBOR_ADDR_STR)
10268
10269DEFUN (show_ip_bgp_view_rsclient_route,
10270 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010271 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010272 SHOW_STR
10273 IP_STR
10274 BGP_STR
10275 "BGP view\n"
10276 "BGP view name\n"
10277 "Information about Route Server Client\n"
10278 NEIGHBOR_ADDR_STR
10279 "Network in the BGP routing table to display\n")
10280{
10281 struct bgp *bgp;
10282 struct peer *peer;
10283
10284 /* BGP structure lookup. */
10285 if (argc == 3)
10286 {
10287 bgp = bgp_lookup_by_name (argv[0]);
10288 if (bgp == NULL)
10289 {
10290 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10291 return CMD_WARNING;
10292 }
10293 }
10294 else
10295 {
10296 bgp = bgp_get_default ();
10297 if (bgp == NULL)
10298 {
10299 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10300 return CMD_WARNING;
10301 }
10302 }
10303
10304 if (argc == 3)
10305 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10306 else
10307 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10308
10309 if (! peer)
10310 return CMD_WARNING;
10311
10312 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10313 {
10314 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10315 VTY_NEWLINE);
10316 return CMD_WARNING;
10317}
10318
10319 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10320 PEER_FLAG_RSERVER_CLIENT))
10321 {
10322 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10323 VTY_NEWLINE);
10324 return CMD_WARNING;
10325 }
10326
10327 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10328 (argc == 3) ? argv[2] : argv[1],
10329 AFI_IP, SAFI_UNICAST, NULL, 0);
10330}
10331
10332ALIAS (show_ip_bgp_view_rsclient_route,
10333 show_ip_bgp_rsclient_route_cmd,
10334 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10335 SHOW_STR
10336 IP_STR
10337 BGP_STR
10338 "Information about Route Server Client\n"
10339 NEIGHBOR_ADDR_STR
10340 "Network in the BGP routing table to display\n")
10341
10342DEFUN (show_ip_bgp_view_rsclient_prefix,
10343 show_ip_bgp_view_rsclient_prefix_cmd,
10344 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10345 SHOW_STR
10346 IP_STR
10347 BGP_STR
10348 "BGP view\n"
10349 "BGP view name\n"
10350 "Information about Route Server Client\n"
10351 NEIGHBOR_ADDR_STR
10352 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10353{
10354 struct bgp *bgp;
10355 struct peer *peer;
10356
10357 /* BGP structure lookup. */
10358 if (argc == 3)
10359 {
10360 bgp = bgp_lookup_by_name (argv[0]);
10361 if (bgp == NULL)
10362 {
10363 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10364 return CMD_WARNING;
10365 }
10366 }
10367 else
10368 {
10369 bgp = bgp_get_default ();
10370 if (bgp == NULL)
10371 {
10372 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10373 return CMD_WARNING;
10374 }
10375 }
10376
10377 if (argc == 3)
10378 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10379 else
10380 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10381
10382 if (! peer)
10383 return CMD_WARNING;
10384
10385 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10386 {
10387 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10388 VTY_NEWLINE);
10389 return CMD_WARNING;
10390}
10391
10392 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10393 PEER_FLAG_RSERVER_CLIENT))
10394{
10395 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10396 VTY_NEWLINE);
10397 return CMD_WARNING;
10398 }
10399
10400 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10401 (argc == 3) ? argv[2] : argv[1],
10402 AFI_IP, SAFI_UNICAST, NULL, 1);
10403}
10404
10405ALIAS (show_ip_bgp_view_rsclient_prefix,
10406 show_ip_bgp_rsclient_prefix_cmd,
10407 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10408 SHOW_STR
10409 IP_STR
10410 BGP_STR
10411 "Information about Route Server Client\n"
10412 NEIGHBOR_ADDR_STR
10413 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10414
10415
paul718e3742002-12-13 20:15:29 +000010416#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010417DEFUN (show_bgp_view_neighbor_routes,
10418 show_bgp_view_neighbor_routes_cmd,
10419 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10420 SHOW_STR
10421 BGP_STR
10422 "BGP view\n"
10423 "BGP view name\n"
10424 "Detailed information on TCP and BGP neighbor connections\n"
10425 "Neighbor to display information about\n"
10426 "Neighbor to display information about\n"
10427 "Display routes learned from neighbor\n")
10428{
10429 struct peer *peer;
10430
10431 if (argc == 2)
10432 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10433 else
10434 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10435
10436 if (! peer)
10437 return CMD_WARNING;
10438
10439 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10440 bgp_show_type_neighbor);
10441}
10442
10443ALIAS (show_bgp_view_neighbor_routes,
10444 show_bgp_view_ipv6_neighbor_routes_cmd,
10445 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10446 SHOW_STR
10447 BGP_STR
10448 "BGP view\n"
10449 "BGP view name\n"
10450 "Address family\n"
10451 "Detailed information on TCP and BGP neighbor connections\n"
10452 "Neighbor to display information about\n"
10453 "Neighbor to display information about\n"
10454 "Display routes learned from neighbor\n")
10455
10456DEFUN (show_bgp_view_neighbor_damp,
10457 show_bgp_view_neighbor_damp_cmd,
10458 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10459 SHOW_STR
10460 BGP_STR
10461 "BGP view\n"
10462 "BGP view name\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 the dampened routes received from neighbor\n")
10467{
10468 struct peer *peer;
10469
10470 if (argc == 2)
10471 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10472 else
10473 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10474
10475 if (! peer)
10476 return CMD_WARNING;
10477
10478 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10479 bgp_show_type_damp_neighbor);
10480}
10481
10482ALIAS (show_bgp_view_neighbor_damp,
10483 show_bgp_view_ipv6_neighbor_damp_cmd,
10484 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10485 SHOW_STR
10486 BGP_STR
10487 "BGP view\n"
10488 "BGP view name\n"
10489 "Address family\n"
10490 "Detailed information on TCP and BGP neighbor connections\n"
10491 "Neighbor to display information about\n"
10492 "Neighbor to display information about\n"
10493 "Display the dampened routes received from neighbor\n")
10494
10495DEFUN (show_bgp_view_neighbor_flap,
10496 show_bgp_view_neighbor_flap_cmd,
10497 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10498 SHOW_STR
10499 BGP_STR
10500 "BGP view\n"
10501 "BGP view name\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 flap statistics of the routes learned from neighbor\n")
10506{
10507 struct peer *peer;
10508
10509 if (argc == 2)
10510 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10511 else
10512 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10513
10514 if (! peer)
10515 return CMD_WARNING;
10516
10517 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10518 bgp_show_type_flap_neighbor);
10519}
10520
10521ALIAS (show_bgp_view_neighbor_flap,
10522 show_bgp_view_ipv6_neighbor_flap_cmd,
10523 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10524 SHOW_STR
10525 BGP_STR
10526 "BGP view\n"
10527 "BGP view name\n"
10528 "Address family\n"
10529 "Detailed information on TCP and BGP neighbor connections\n"
10530 "Neighbor to display information about\n"
10531 "Neighbor to display information about\n"
10532 "Display flap statistics of the routes learned from neighbor\n")
10533
10534ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010535 show_bgp_neighbor_routes_cmd,
10536 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10537 SHOW_STR
10538 BGP_STR
10539 "Detailed information on TCP and BGP neighbor connections\n"
10540 "Neighbor to display information about\n"
10541 "Neighbor to display information about\n"
10542 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010543
paulbb46e942003-10-24 19:02:03 +000010544
10545ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010546 show_bgp_ipv6_neighbor_routes_cmd,
10547 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10548 SHOW_STR
10549 BGP_STR
10550 "Address family\n"
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")
10555
10556/* old command */
paulbb46e942003-10-24 19:02:03 +000010557ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010558 ipv6_bgp_neighbor_routes_cmd,
10559 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10560 SHOW_STR
10561 IPV6_STR
10562 BGP_STR
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")
paul718e3742002-12-13 20:15:29 +000010567
10568/* old command */
10569DEFUN (ipv6_mbgp_neighbor_routes,
10570 ipv6_mbgp_neighbor_routes_cmd,
10571 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10572 SHOW_STR
10573 IPV6_STR
10574 MBGP_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")
10579{
paulbb46e942003-10-24 19:02:03 +000010580 struct peer *peer;
10581
10582 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10583 if (! peer)
10584 return CMD_WARNING;
10585
10586 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010587 bgp_show_type_neighbor);
10588}
paulbb46e942003-10-24 19:02:03 +000010589
10590ALIAS (show_bgp_view_neighbor_flap,
10591 show_bgp_neighbor_flap_cmd,
10592 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10593 SHOW_STR
10594 BGP_STR
10595 "Detailed information on TCP and BGP neighbor connections\n"
10596 "Neighbor to display information about\n"
10597 "Neighbor to display information about\n"
10598 "Display flap statistics of the routes learned from neighbor\n")
10599
10600ALIAS (show_bgp_view_neighbor_flap,
10601 show_bgp_ipv6_neighbor_flap_cmd,
10602 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10603 SHOW_STR
10604 BGP_STR
10605 "Address family\n"
10606 "Detailed information on TCP and BGP neighbor connections\n"
10607 "Neighbor to display information about\n"
10608 "Neighbor to display information about\n"
10609 "Display flap statistics of the routes learned from neighbor\n")
10610
10611ALIAS (show_bgp_view_neighbor_damp,
10612 show_bgp_neighbor_damp_cmd,
10613 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10614 SHOW_STR
10615 BGP_STR
10616 "Detailed information on TCP and BGP neighbor connections\n"
10617 "Neighbor to display information about\n"
10618 "Neighbor to display information about\n"
10619 "Display the dampened routes received from neighbor\n")
10620
10621ALIAS (show_bgp_view_neighbor_damp,
10622 show_bgp_ipv6_neighbor_damp_cmd,
10623 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10624 SHOW_STR
10625 BGP_STR
10626 "Address family\n"
10627 "Detailed information on TCP and BGP neighbor connections\n"
10628 "Neighbor to display information about\n"
10629 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010630 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010631
10632DEFUN (show_bgp_view_rsclient,
10633 show_bgp_view_rsclient_cmd,
10634 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10635 SHOW_STR
10636 BGP_STR
10637 "BGP view\n"
10638 "BGP view name\n"
10639 "Information about Route Server Client\n"
10640 NEIGHBOR_ADDR_STR)
10641{
10642 struct bgp_table *table;
10643 struct peer *peer;
10644
10645 if (argc == 2)
10646 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10647 else
10648 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10649
10650 if (! peer)
10651 return CMD_WARNING;
10652
10653 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10654 {
10655 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10656 VTY_NEWLINE);
10657 return CMD_WARNING;
10658 }
10659
10660 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10661 PEER_FLAG_RSERVER_CLIENT))
10662 {
10663 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10664 VTY_NEWLINE);
10665 return CMD_WARNING;
10666 }
10667
10668 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10669
ajs5a646652004-11-05 01:25:55 +000010670 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010671}
10672
10673ALIAS (show_bgp_view_rsclient,
10674 show_bgp_rsclient_cmd,
10675 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10676 SHOW_STR
10677 BGP_STR
10678 "Information about Route Server Client\n"
10679 NEIGHBOR_ADDR_STR)
10680
10681DEFUN (show_bgp_view_rsclient_route,
10682 show_bgp_view_rsclient_route_cmd,
10683 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10684 SHOW_STR
10685 BGP_STR
10686 "BGP view\n"
10687 "BGP view name\n"
10688 "Information about Route Server Client\n"
10689 NEIGHBOR_ADDR_STR
10690 "Network in the BGP routing table to display\n")
10691{
10692 struct bgp *bgp;
10693 struct peer *peer;
10694
10695 /* BGP structure lookup. */
10696 if (argc == 3)
10697 {
10698 bgp = bgp_lookup_by_name (argv[0]);
10699 if (bgp == NULL)
10700 {
10701 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10702 return CMD_WARNING;
10703 }
10704 }
10705 else
10706 {
10707 bgp = bgp_get_default ();
10708 if (bgp == NULL)
10709 {
10710 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10711 return CMD_WARNING;
10712 }
10713 }
10714
10715 if (argc == 3)
10716 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10717 else
10718 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10719
10720 if (! peer)
10721 return CMD_WARNING;
10722
10723 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10724 {
10725 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10726 VTY_NEWLINE);
10727 return CMD_WARNING;
10728 }
10729
10730 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10731 PEER_FLAG_RSERVER_CLIENT))
10732 {
10733 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10734 VTY_NEWLINE);
10735 return CMD_WARNING;
10736 }
10737
10738 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10739 (argc == 3) ? argv[2] : argv[1],
10740 AFI_IP6, SAFI_UNICAST, NULL, 0);
10741}
10742
10743ALIAS (show_bgp_view_rsclient_route,
10744 show_bgp_rsclient_route_cmd,
10745 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10746 SHOW_STR
10747 BGP_STR
10748 "Information about Route Server Client\n"
10749 NEIGHBOR_ADDR_STR
10750 "Network in the BGP routing table to display\n")
10751
10752DEFUN (show_bgp_view_rsclient_prefix,
10753 show_bgp_view_rsclient_prefix_cmd,
10754 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10755 SHOW_STR
10756 BGP_STR
10757 "BGP view\n"
10758 "BGP view name\n"
10759 "Information about Route Server Client\n"
10760 NEIGHBOR_ADDR_STR
10761 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10762{
10763 struct bgp *bgp;
10764 struct peer *peer;
10765
10766 /* BGP structure lookup. */
10767 if (argc == 3)
10768 {
10769 bgp = bgp_lookup_by_name (argv[0]);
10770 if (bgp == NULL)
10771 {
10772 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10773 return CMD_WARNING;
10774 }
10775 }
10776 else
10777 {
10778 bgp = bgp_get_default ();
10779 if (bgp == NULL)
10780 {
10781 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10782 return CMD_WARNING;
10783 }
10784 }
10785
10786 if (argc == 3)
10787 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10788 else
10789 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10790
10791 if (! peer)
10792 return CMD_WARNING;
10793
10794 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10795 {
10796 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10797 VTY_NEWLINE);
10798 return CMD_WARNING;
10799 }
10800
10801 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10802 PEER_FLAG_RSERVER_CLIENT))
10803 {
10804 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10805 VTY_NEWLINE);
10806 return CMD_WARNING;
10807 }
10808
10809 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10810 (argc == 3) ? argv[2] : argv[1],
10811 AFI_IP6, SAFI_UNICAST, NULL, 1);
10812}
10813
10814ALIAS (show_bgp_view_rsclient_prefix,
10815 show_bgp_rsclient_prefix_cmd,
10816 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10817 SHOW_STR
10818 BGP_STR
10819 "Information about Route Server Client\n"
10820 NEIGHBOR_ADDR_STR
10821 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10822
paul718e3742002-12-13 20:15:29 +000010823#endif /* HAVE_IPV6 */
10824
10825struct bgp_table *bgp_distance_table;
10826
10827struct bgp_distance
10828{
10829 /* Distance value for the IP source prefix. */
10830 u_char distance;
10831
10832 /* Name of the access-list to be matched. */
10833 char *access_list;
10834};
10835
paul94f2b392005-06-28 12:44:16 +000010836static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010837bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010838{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010839 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010840}
10841
paul94f2b392005-06-28 12:44:16 +000010842static void
paul718e3742002-12-13 20:15:29 +000010843bgp_distance_free (struct bgp_distance *bdistance)
10844{
10845 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10846}
10847
paul94f2b392005-06-28 12:44:16 +000010848static int
paulfd79ac92004-10-13 05:06:08 +000010849bgp_distance_set (struct vty *vty, const char *distance_str,
10850 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010851{
10852 int ret;
10853 struct prefix_ipv4 p;
10854 u_char distance;
10855 struct bgp_node *rn;
10856 struct bgp_distance *bdistance;
10857
10858 ret = str2prefix_ipv4 (ip_str, &p);
10859 if (ret == 0)
10860 {
10861 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10862 return CMD_WARNING;
10863 }
10864
10865 distance = atoi (distance_str);
10866
10867 /* Get BGP distance node. */
10868 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10869 if (rn->info)
10870 {
10871 bdistance = rn->info;
10872 bgp_unlock_node (rn);
10873 }
10874 else
10875 {
10876 bdistance = bgp_distance_new ();
10877 rn->info = bdistance;
10878 }
10879
10880 /* Set distance value. */
10881 bdistance->distance = distance;
10882
10883 /* Reset access-list configuration. */
10884 if (bdistance->access_list)
10885 {
10886 free (bdistance->access_list);
10887 bdistance->access_list = NULL;
10888 }
10889 if (access_list_str)
10890 bdistance->access_list = strdup (access_list_str);
10891
10892 return CMD_SUCCESS;
10893}
10894
paul94f2b392005-06-28 12:44:16 +000010895static int
paulfd79ac92004-10-13 05:06:08 +000010896bgp_distance_unset (struct vty *vty, const char *distance_str,
10897 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010898{
10899 int ret;
10900 struct prefix_ipv4 p;
10901 u_char distance;
10902 struct bgp_node *rn;
10903 struct bgp_distance *bdistance;
10904
10905 ret = str2prefix_ipv4 (ip_str, &p);
10906 if (ret == 0)
10907 {
10908 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10909 return CMD_WARNING;
10910 }
10911
10912 distance = atoi (distance_str);
10913
10914 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10915 if (! rn)
10916 {
10917 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10918 return CMD_WARNING;
10919 }
10920
10921 bdistance = rn->info;
10922
10923 if (bdistance->access_list)
10924 free (bdistance->access_list);
10925 bgp_distance_free (bdistance);
10926
10927 rn->info = NULL;
10928 bgp_unlock_node (rn);
10929 bgp_unlock_node (rn);
10930
10931 return CMD_SUCCESS;
10932}
10933
paul94f2b392005-06-28 12:44:16 +000010934static void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010935bgp_distance_reset (void)
paul718e3742002-12-13 20:15:29 +000010936{
10937 struct bgp_node *rn;
10938 struct bgp_distance *bdistance;
10939
10940 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10941 if ((bdistance = rn->info) != NULL)
10942 {
10943 if (bdistance->access_list)
10944 free (bdistance->access_list);
10945 bgp_distance_free (bdistance);
10946 rn->info = NULL;
10947 bgp_unlock_node (rn);
10948 }
10949}
10950
10951/* Apply BGP information to distance method. */
10952u_char
10953bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10954{
10955 struct bgp_node *rn;
10956 struct prefix_ipv4 q;
10957 struct peer *peer;
10958 struct bgp_distance *bdistance;
10959 struct access_list *alist;
10960 struct bgp_static *bgp_static;
10961
10962 if (! bgp)
10963 return 0;
10964
10965 if (p->family != AF_INET)
10966 return 0;
10967
10968 peer = rinfo->peer;
10969
10970 if (peer->su.sa.sa_family != AF_INET)
10971 return 0;
10972
10973 memset (&q, 0, sizeof (struct prefix_ipv4));
10974 q.family = AF_INET;
10975 q.prefix = peer->su.sin.sin_addr;
10976 q.prefixlen = IPV4_MAX_BITLEN;
10977
10978 /* Check source address. */
10979 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10980 if (rn)
10981 {
10982 bdistance = rn->info;
10983 bgp_unlock_node (rn);
10984
10985 if (bdistance->access_list)
10986 {
10987 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10988 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10989 return bdistance->distance;
10990 }
10991 else
10992 return bdistance->distance;
10993 }
10994
10995 /* Backdoor check. */
10996 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10997 if (rn)
10998 {
10999 bgp_static = rn->info;
11000 bgp_unlock_node (rn);
11001
11002 if (bgp_static->backdoor)
11003 {
11004 if (bgp->distance_local)
11005 return bgp->distance_local;
11006 else
11007 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11008 }
11009 }
11010
11011 if (peer_sort (peer) == BGP_PEER_EBGP)
11012 {
11013 if (bgp->distance_ebgp)
11014 return bgp->distance_ebgp;
11015 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11016 }
11017 else
11018 {
11019 if (bgp->distance_ibgp)
11020 return bgp->distance_ibgp;
11021 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11022 }
11023}
11024
11025DEFUN (bgp_distance,
11026 bgp_distance_cmd,
11027 "distance bgp <1-255> <1-255> <1-255>",
11028 "Define an administrative distance\n"
11029 "BGP distance\n"
11030 "Distance for routes external to the AS\n"
11031 "Distance for routes internal to the AS\n"
11032 "Distance for local routes\n")
11033{
11034 struct bgp *bgp;
11035
11036 bgp = vty->index;
11037
11038 bgp->distance_ebgp = atoi (argv[0]);
11039 bgp->distance_ibgp = atoi (argv[1]);
11040 bgp->distance_local = atoi (argv[2]);
11041 return CMD_SUCCESS;
11042}
11043
11044DEFUN (no_bgp_distance,
11045 no_bgp_distance_cmd,
11046 "no distance bgp <1-255> <1-255> <1-255>",
11047 NO_STR
11048 "Define an administrative distance\n"
11049 "BGP distance\n"
11050 "Distance for routes external to the AS\n"
11051 "Distance for routes internal to the AS\n"
11052 "Distance for local routes\n")
11053{
11054 struct bgp *bgp;
11055
11056 bgp = vty->index;
11057
11058 bgp->distance_ebgp= 0;
11059 bgp->distance_ibgp = 0;
11060 bgp->distance_local = 0;
11061 return CMD_SUCCESS;
11062}
11063
11064ALIAS (no_bgp_distance,
11065 no_bgp_distance2_cmd,
11066 "no distance bgp",
11067 NO_STR
11068 "Define an administrative distance\n"
11069 "BGP distance\n")
11070
11071DEFUN (bgp_distance_source,
11072 bgp_distance_source_cmd,
11073 "distance <1-255> A.B.C.D/M",
11074 "Define an administrative distance\n"
11075 "Administrative distance\n"
11076 "IP source prefix\n")
11077{
11078 bgp_distance_set (vty, argv[0], argv[1], NULL);
11079 return CMD_SUCCESS;
11080}
11081
11082DEFUN (no_bgp_distance_source,
11083 no_bgp_distance_source_cmd,
11084 "no distance <1-255> A.B.C.D/M",
11085 NO_STR
11086 "Define an administrative distance\n"
11087 "Administrative distance\n"
11088 "IP source prefix\n")
11089{
11090 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11091 return CMD_SUCCESS;
11092}
11093
11094DEFUN (bgp_distance_source_access_list,
11095 bgp_distance_source_access_list_cmd,
11096 "distance <1-255> A.B.C.D/M WORD",
11097 "Define an administrative distance\n"
11098 "Administrative distance\n"
11099 "IP source prefix\n"
11100 "Access list name\n")
11101{
11102 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11103 return CMD_SUCCESS;
11104}
11105
11106DEFUN (no_bgp_distance_source_access_list,
11107 no_bgp_distance_source_access_list_cmd,
11108 "no distance <1-255> A.B.C.D/M WORD",
11109 NO_STR
11110 "Define an administrative distance\n"
11111 "Administrative distance\n"
11112 "IP source prefix\n"
11113 "Access list name\n")
11114{
11115 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11116 return CMD_SUCCESS;
11117}
11118
11119DEFUN (bgp_damp_set,
11120 bgp_damp_set_cmd,
11121 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11122 "BGP Specific commands\n"
11123 "Enable route-flap dampening\n"
11124 "Half-life time for the penalty\n"
11125 "Value to start reusing a route\n"
11126 "Value to start suppressing a route\n"
11127 "Maximum duration to suppress a stable route\n")
11128{
11129 struct bgp *bgp;
11130 int half = DEFAULT_HALF_LIFE * 60;
11131 int reuse = DEFAULT_REUSE;
11132 int suppress = DEFAULT_SUPPRESS;
11133 int max = 4 * half;
11134
11135 if (argc == 4)
11136 {
11137 half = atoi (argv[0]) * 60;
11138 reuse = atoi (argv[1]);
11139 suppress = atoi (argv[2]);
11140 max = atoi (argv[3]) * 60;
11141 }
11142 else if (argc == 1)
11143 {
11144 half = atoi (argv[0]) * 60;
11145 max = 4 * half;
11146 }
11147
11148 bgp = vty->index;
11149 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11150 half, reuse, suppress, max);
11151}
11152
11153ALIAS (bgp_damp_set,
11154 bgp_damp_set2_cmd,
11155 "bgp dampening <1-45>",
11156 "BGP Specific commands\n"
11157 "Enable route-flap dampening\n"
11158 "Half-life time for the penalty\n")
11159
11160ALIAS (bgp_damp_set,
11161 bgp_damp_set3_cmd,
11162 "bgp dampening",
11163 "BGP Specific commands\n"
11164 "Enable route-flap dampening\n")
11165
11166DEFUN (bgp_damp_unset,
11167 bgp_damp_unset_cmd,
11168 "no bgp dampening",
11169 NO_STR
11170 "BGP Specific commands\n"
11171 "Enable route-flap dampening\n")
11172{
11173 struct bgp *bgp;
11174
11175 bgp = vty->index;
11176 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11177}
11178
11179ALIAS (bgp_damp_unset,
11180 bgp_damp_unset2_cmd,
11181 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11182 NO_STR
11183 "BGP Specific commands\n"
11184 "Enable route-flap dampening\n"
11185 "Half-life time for the penalty\n"
11186 "Value to start reusing a route\n"
11187 "Value to start suppressing a route\n"
11188 "Maximum duration to suppress a stable route\n")
11189
11190DEFUN (show_ip_bgp_dampened_paths,
11191 show_ip_bgp_dampened_paths_cmd,
11192 "show ip bgp dampened-paths",
11193 SHOW_STR
11194 IP_STR
11195 BGP_STR
11196 "Display paths suppressed due to dampening\n")
11197{
ajs5a646652004-11-05 01:25:55 +000011198 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11199 NULL);
paul718e3742002-12-13 20:15:29 +000011200}
11201
11202DEFUN (show_ip_bgp_flap_statistics,
11203 show_ip_bgp_flap_statistics_cmd,
11204 "show ip bgp flap-statistics",
11205 SHOW_STR
11206 IP_STR
11207 BGP_STR
11208 "Display flap statistics of routes\n")
11209{
ajs5a646652004-11-05 01:25:55 +000011210 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11211 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011212}
11213
11214/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011215static int
paulfd79ac92004-10-13 05:06:08 +000011216bgp_clear_damp_route (struct vty *vty, const char *view_name,
11217 const char *ip_str, afi_t afi, safi_t safi,
11218 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011219{
11220 int ret;
11221 struct prefix match;
11222 struct bgp_node *rn;
11223 struct bgp_node *rm;
11224 struct bgp_info *ri;
11225 struct bgp_info *ri_temp;
11226 struct bgp *bgp;
11227 struct bgp_table *table;
11228
11229 /* BGP structure lookup. */
11230 if (view_name)
11231 {
11232 bgp = bgp_lookup_by_name (view_name);
11233 if (bgp == NULL)
11234 {
11235 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11236 return CMD_WARNING;
11237 }
11238 }
11239 else
11240 {
11241 bgp = bgp_get_default ();
11242 if (bgp == NULL)
11243 {
11244 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11245 return CMD_WARNING;
11246 }
11247 }
11248
11249 /* Check IP address argument. */
11250 ret = str2prefix (ip_str, &match);
11251 if (! ret)
11252 {
11253 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11254 return CMD_WARNING;
11255 }
11256
11257 match.family = afi2family (afi);
11258
11259 if (safi == SAFI_MPLS_VPN)
11260 {
11261 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11262 {
11263 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11264 continue;
11265
11266 if ((table = rn->info) != NULL)
11267 if ((rm = bgp_node_match (table, &match)) != NULL)
11268 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11269 {
11270 ri = rm->info;
11271 while (ri)
11272 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011273 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011274 {
11275 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011276 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011277 ri = ri_temp;
11278 }
11279 else
11280 ri = ri->next;
11281 }
11282 }
11283 }
11284 }
11285 else
11286 {
11287 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11288 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11289 {
11290 ri = rn->info;
11291 while (ri)
11292 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011293 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011294 {
11295 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011296 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011297 ri = ri_temp;
11298 }
11299 else
11300 ri = ri->next;
11301 }
11302 }
11303 }
11304
11305 return CMD_SUCCESS;
11306}
11307
11308DEFUN (clear_ip_bgp_dampening,
11309 clear_ip_bgp_dampening_cmd,
11310 "clear ip bgp dampening",
11311 CLEAR_STR
11312 IP_STR
11313 BGP_STR
11314 "Clear route flap dampening information\n")
11315{
11316 bgp_damp_info_clean ();
11317 return CMD_SUCCESS;
11318}
11319
11320DEFUN (clear_ip_bgp_dampening_prefix,
11321 clear_ip_bgp_dampening_prefix_cmd,
11322 "clear ip bgp dampening A.B.C.D/M",
11323 CLEAR_STR
11324 IP_STR
11325 BGP_STR
11326 "Clear route flap dampening information\n"
11327 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11328{
11329 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11330 SAFI_UNICAST, NULL, 1);
11331}
11332
11333DEFUN (clear_ip_bgp_dampening_address,
11334 clear_ip_bgp_dampening_address_cmd,
11335 "clear ip bgp dampening A.B.C.D",
11336 CLEAR_STR
11337 IP_STR
11338 BGP_STR
11339 "Clear route flap dampening information\n"
11340 "Network to clear damping information\n")
11341{
11342 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11343 SAFI_UNICAST, NULL, 0);
11344}
11345
11346DEFUN (clear_ip_bgp_dampening_address_mask,
11347 clear_ip_bgp_dampening_address_mask_cmd,
11348 "clear ip bgp dampening A.B.C.D A.B.C.D",
11349 CLEAR_STR
11350 IP_STR
11351 BGP_STR
11352 "Clear route flap dampening information\n"
11353 "Network to clear damping information\n"
11354 "Network mask\n")
11355{
11356 int ret;
11357 char prefix_str[BUFSIZ];
11358
11359 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11360 if (! ret)
11361 {
11362 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11363 return CMD_WARNING;
11364 }
11365
11366 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11367 SAFI_UNICAST, NULL, 0);
11368}
11369
paul94f2b392005-06-28 12:44:16 +000011370static int
paul718e3742002-12-13 20:15:29 +000011371bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11372 afi_t afi, safi_t safi, int *write)
11373{
11374 struct bgp_node *prn;
11375 struct bgp_node *rn;
11376 struct bgp_table *table;
11377 struct prefix *p;
11378 struct prefix_rd *prd;
11379 struct bgp_static *bgp_static;
11380 u_int32_t label;
11381 char buf[SU_ADDRSTRLEN];
11382 char rdbuf[RD_ADDRSTRLEN];
11383
11384 /* Network configuration. */
11385 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11386 if ((table = prn->info) != NULL)
11387 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11388 if ((bgp_static = rn->info) != NULL)
11389 {
11390 p = &rn->p;
11391 prd = (struct prefix_rd *) &prn->p;
11392
11393 /* "address-family" display. */
11394 bgp_config_write_family_header (vty, afi, safi, write);
11395
11396 /* "network" configuration display. */
11397 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11398 label = decode_label (bgp_static->tag);
11399
11400 vty_out (vty, " network %s/%d rd %s tag %d",
11401 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11402 p->prefixlen,
11403 rdbuf, label);
11404 vty_out (vty, "%s", VTY_NEWLINE);
11405 }
11406 return 0;
11407}
11408
11409/* Configuration of static route announcement and aggregate
11410 information. */
11411int
11412bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11413 afi_t afi, safi_t safi, int *write)
11414{
11415 struct bgp_node *rn;
11416 struct prefix *p;
11417 struct bgp_static *bgp_static;
11418 struct bgp_aggregate *bgp_aggregate;
11419 char buf[SU_ADDRSTRLEN];
11420
11421 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11422 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11423
11424 /* Network configuration. */
11425 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11426 if ((bgp_static = rn->info) != NULL)
11427 {
11428 p = &rn->p;
11429
11430 /* "address-family" display. */
11431 bgp_config_write_family_header (vty, afi, safi, write);
11432
11433 /* "network" configuration display. */
11434 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11435 {
11436 u_int32_t destination;
11437 struct in_addr netmask;
11438
11439 destination = ntohl (p->u.prefix4.s_addr);
11440 masklen2ip (p->prefixlen, &netmask);
11441 vty_out (vty, " network %s",
11442 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11443
11444 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11445 || (IN_CLASSB (destination) && p->prefixlen == 16)
11446 || (IN_CLASSA (destination) && p->prefixlen == 8)
11447 || p->u.prefix4.s_addr == 0)
11448 {
11449 /* Natural mask is not display. */
11450 }
11451 else
11452 vty_out (vty, " mask %s", inet_ntoa (netmask));
11453 }
11454 else
11455 {
11456 vty_out (vty, " network %s/%d",
11457 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11458 p->prefixlen);
11459 }
11460
11461 if (bgp_static->rmap.name)
11462 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011463 else
11464 {
11465 if (bgp_static->backdoor)
11466 vty_out (vty, " backdoor");
11467 if (bgp_static->ttl)
11468 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11469 }
paul718e3742002-12-13 20:15:29 +000011470
11471 vty_out (vty, "%s", VTY_NEWLINE);
11472 }
11473
11474 /* Aggregate-address configuration. */
11475 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11476 if ((bgp_aggregate = rn->info) != NULL)
11477 {
11478 p = &rn->p;
11479
11480 /* "address-family" display. */
11481 bgp_config_write_family_header (vty, afi, safi, write);
11482
11483 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11484 {
11485 struct in_addr netmask;
11486
11487 masklen2ip (p->prefixlen, &netmask);
11488 vty_out (vty, " aggregate-address %s %s",
11489 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11490 inet_ntoa (netmask));
11491 }
11492 else
11493 {
11494 vty_out (vty, " aggregate-address %s/%d",
11495 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11496 p->prefixlen);
11497 }
11498
11499 if (bgp_aggregate->as_set)
11500 vty_out (vty, " as-set");
11501
11502 if (bgp_aggregate->summary_only)
11503 vty_out (vty, " summary-only");
11504
11505 vty_out (vty, "%s", VTY_NEWLINE);
11506 }
11507
11508 return 0;
11509}
11510
11511int
11512bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11513{
11514 struct bgp_node *rn;
11515 struct bgp_distance *bdistance;
11516
11517 /* Distance configuration. */
11518 if (bgp->distance_ebgp
11519 && bgp->distance_ibgp
11520 && bgp->distance_local
11521 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11522 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11523 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11524 vty_out (vty, " distance bgp %d %d %d%s",
11525 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11526 VTY_NEWLINE);
11527
11528 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11529 if ((bdistance = rn->info) != NULL)
11530 {
11531 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11532 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11533 bdistance->access_list ? bdistance->access_list : "",
11534 VTY_NEWLINE);
11535 }
11536
11537 return 0;
11538}
11539
11540/* Allocate routing table structure and install commands. */
11541void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011542bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011543{
11544 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011545 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011546
11547 /* IPv4 BGP commands. */
11548 install_element (BGP_NODE, &bgp_network_cmd);
11549 install_element (BGP_NODE, &bgp_network_mask_cmd);
11550 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11551 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11552 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11553 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11554 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11555 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11556 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011557 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11558 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11559 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11560 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11561 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11562 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011563 install_element (BGP_NODE, &no_bgp_network_cmd);
11564 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11565 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11566 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11567 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11568 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11569 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11570 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11571 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011572 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11573 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11574 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11575 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11576 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11577 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011578
11579 install_element (BGP_NODE, &aggregate_address_cmd);
11580 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11581 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11582 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11583 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11584 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11585 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11586 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11587 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11588 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11589 install_element (BGP_NODE, &no_aggregate_address_cmd);
11590 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11591 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11592 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11593 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11594 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11595 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11596 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11597 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11598 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11599
11600 /* IPv4 unicast configuration. */
11601 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11602 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11603 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11604 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11605 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11606 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011607 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11608 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11609 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11610 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11611 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11612 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 +000011613 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11614 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11615 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11616 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11617 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011618 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11619 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11620 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11621 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11622 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11623 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 +000011624 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11625 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11626 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11627 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11628 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11629 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11630 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11631 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11632 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11633 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11634 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11635 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11636 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11637 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11638 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11639 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11640 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11641 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11642 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11643 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11644
11645 /* IPv4 multicast configuration. */
11646 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11647 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11648 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11649 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11650 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11651 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011652 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11653 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11654 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11655 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11656 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11657 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 +000011658 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11659 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11660 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11661 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11662 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11663 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011664 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11665 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11666 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11667 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11668 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11669 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 +000011670 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11671 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11672 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11673 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11674 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11675 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11676 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11677 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11678 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11679 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11680 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11681 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11682 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11683 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11684 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11685 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11686 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11687 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11688 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11689 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11690
11691 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11692 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11693 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11694 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11695 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11696 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11697 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11698 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11699 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11700 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11701 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11702 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11703 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11704 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11705 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11706 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11707 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11708 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11709 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11710 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11711 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11712 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11713 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11714 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11715 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11716 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11717 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11718 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11719 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11720 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11721 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11722 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11723 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11724 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11725 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11726 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11727 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11728 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11729 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11730 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11731 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11732 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11733 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11734 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11735 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11736 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11737 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11738 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11739 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11740 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11741 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11742 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11743 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11744 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11745 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11746 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11747 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11748 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11749 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11750 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11751 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11752 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11753 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11754 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11755 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11756 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11757 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011758 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11759 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11760 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11761 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11762 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11763 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011764
11765 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11766 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11767 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11768 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11769 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11770 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11771 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11772 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11773 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11774 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11775 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11776 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11777 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11778 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11779 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11780 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11781 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11782 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11783 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11784 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11785 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11786 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11787 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11788 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11789 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11790 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11791 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11792 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11793 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11794 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011795
11796 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11797 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11798 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11799 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11800 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11801 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11802 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11803 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11804 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11805 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11806 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11807 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11808 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11809 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11810 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11811 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11812 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11813 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11814 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11815 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11816 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11817 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11818 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11819 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11820 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11821 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11822 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11823 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11824 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11825 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11826 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11827 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11828 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11829 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11830 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11831 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11832 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11833 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11834 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11835 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11836 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11837 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11838 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11839 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11840 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11841 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11842 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11843 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11844 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11845 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11846 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11847 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11848 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11849 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11850 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11851 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11852 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11853 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11854 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11855 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11856 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11857 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11858 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11859 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11860 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11861 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11862 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011863 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11864 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11865 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11866 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11867 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11868 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011869
11870 /* BGP dampening clear commands */
11871 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11872 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11873 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11874 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11875
Paul Jakmaff7924f2006-09-04 01:10:36 +000011876 /* prefix count */
11877 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11878 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11879 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011880#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011881 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11882
paul718e3742002-12-13 20:15:29 +000011883 /* New config IPv6 BGP commands. */
11884 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11885 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011886 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011887 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11888 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011889 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011890
11891 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11892 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11893 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11894 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11895
11896 /* Old config IPv6 BGP commands. */
11897 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11898 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11899
11900 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11901 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11902 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11903 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11904
11905 install_element (VIEW_NODE, &show_bgp_cmd);
11906 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11907 install_element (VIEW_NODE, &show_bgp_route_cmd);
11908 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11909 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11910 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11911 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11912 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11913 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11914 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11915 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11916 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11917 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11918 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11919 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11920 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11921 install_element (VIEW_NODE, &show_bgp_community_cmd);
11922 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11923 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11924 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11925 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11926 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11927 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11928 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11929 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11930 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11931 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11932 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11933 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11934 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11935 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11936 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11937 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11938 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11939 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11940 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11941 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11942 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11943 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11944 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11945 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11946 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11947 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11948 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11949 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11950 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011951 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11952 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11953 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11954 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011955 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11956 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11957 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011958 install_element (VIEW_NODE, &show_bgp_view_cmd);
11959 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11960 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11961 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11962 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11963 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11964 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11965 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11966 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11967 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11968 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11969 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11970 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11971 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11972 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11973 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11974 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11975 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011976 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11977 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11978 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011979
11980 /* Restricted:
11981 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
11982 */
11983 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
11984 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
11985 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
11986 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
11987 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
11988 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
11989 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
11990 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
11991 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
11992 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
11993 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
11994 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
11995 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
11996 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
11997 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
11998 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
11999 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12000 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12001 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12002 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12003 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
12004 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
12005 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12006 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12007 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12008 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12009 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12010 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12011 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
12012 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012013
12014 install_element (ENABLE_NODE, &show_bgp_cmd);
12015 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
12016 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12017 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
12018 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12019 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
12020 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12021 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12022 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12023 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12024 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12025 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12026 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12027 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12028 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12029 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12030 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12031 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12032 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12033 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12034 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12035 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12036 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12037 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12038 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12039 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12040 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12041 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12042 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12043 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12044 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12045 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12046 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12047 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12048 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12049 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12050 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12051 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12052 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12053 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12054 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12055 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12056 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12057 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12058 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12059 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012060 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12061 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12062 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12063 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012064 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12065 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12066 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012067 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12068 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12069 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12070 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12071 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12072 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12073 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12074 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12075 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12076 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12077 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12078 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12079 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12080 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12081 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12082 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12083 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12084 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012085 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12086 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12087 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012088
12089 /* Statistics */
12090 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12091 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12092 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12093 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12094
paul718e3742002-12-13 20:15:29 +000012095 /* old command */
12096 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12097 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12098 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12099 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12100 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12101 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12102 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12103 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12104 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12105 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12106 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12107 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12108 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12109 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12110 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12111 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12112 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12113 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12114 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12115 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12116 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12117 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12118 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12119 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12120 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12121 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12122 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12123 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12124 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12125 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12126 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12127 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12128 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12129 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12130 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12131 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012132
paul718e3742002-12-13 20:15:29 +000012133 /* old command */
12134 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12135 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12136 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12137 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12138 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12139 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12140 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12141 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12142 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12143 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12144 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12145 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12146 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12147 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12148 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12149 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12150 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12151 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12152 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12153 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12154 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12155 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12156 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12157 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12158 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12159 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12160 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12161 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12162 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12163 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12164 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12165 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12166 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12167 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12168 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12169 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12170
12171 /* old command */
12172 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12173 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12174 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12175 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12176
12177 /* old command */
12178 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12179 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12180 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12181 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12182
12183 /* old command */
12184 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12185 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12186 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12187 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12188#endif /* HAVE_IPV6 */
12189
12190 install_element (BGP_NODE, &bgp_distance_cmd);
12191 install_element (BGP_NODE, &no_bgp_distance_cmd);
12192 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12193 install_element (BGP_NODE, &bgp_distance_source_cmd);
12194 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12195 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12196 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12197
12198 install_element (BGP_NODE, &bgp_damp_set_cmd);
12199 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12200 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12201 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12202 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12203 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12204 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12205 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12206 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12207 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12208}