blob: a44d47abaadfd6cdd7a38758908390fbe25c99c8 [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;
5813
paulb40d9392005-08-22 22:34:41 +00005814 /* short status lead text */
5815 route_vty_short_status_out (vty, binfo);
5816
paul718e3742002-12-13 20:15:29 +00005817 /* print prefix and mask */
5818 if (! display)
5819 route_vty_out_route (p, vty);
5820 else
5821 vty_out (vty, "%*s", 17, " ");
5822
5823 len = vty_out (vty, "%s", binfo->peer->host);
5824 len = 17 - len;
5825 if (len < 1)
5826 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5827 else
5828 vty_out (vty, "%*s", len, " ");
5829
5830 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5831
5832 /* Print attribute */
5833 attr = binfo->attr;
5834 if (attr)
5835 {
5836 /* Print aspath */
5837 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005838 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005839
5840 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005841 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005842 }
5843 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005844}
5845
5846#define BGP_UPTIME_LEN 25
5847
5848/* flap route */
ajs5a646652004-11-05 01:25:55 +00005849static void
paul718e3742002-12-13 20:15:29 +00005850flap_route_vty_out (struct vty *vty, struct prefix *p,
5851 struct bgp_info *binfo, int display, safi_t safi)
5852{
5853 struct attr *attr;
5854 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005855 char timebuf[BGP_UPTIME_LEN];
5856 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005857
5858 if (!binfo->extra)
5859 return;
5860
5861 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005862
paulb40d9392005-08-22 22:34:41 +00005863 /* short status lead text */
5864 route_vty_short_status_out (vty, binfo);
5865
paul718e3742002-12-13 20:15:29 +00005866 /* print prefix and mask */
5867 if (! display)
5868 route_vty_out_route (p, vty);
5869 else
5870 vty_out (vty, "%*s", 17, " ");
5871
5872 len = vty_out (vty, "%s", binfo->peer->host);
5873 len = 16 - len;
5874 if (len < 1)
5875 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5876 else
5877 vty_out (vty, "%*s", len, " ");
5878
5879 len = vty_out (vty, "%d", bdi->flap);
5880 len = 5 - len;
5881 if (len < 1)
5882 vty_out (vty, " ");
5883 else
5884 vty_out (vty, "%*s ", len, " ");
5885
5886 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5887 timebuf, BGP_UPTIME_LEN));
5888
5889 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5890 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5891 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5892 else
5893 vty_out (vty, "%*s ", 8, " ");
5894
5895 /* Print attribute */
5896 attr = binfo->attr;
5897 if (attr)
5898 {
5899 /* Print aspath */
5900 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005901 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005902
5903 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005904 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005905 }
5906 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005907}
5908
paul94f2b392005-06-28 12:44:16 +00005909static void
paul718e3742002-12-13 20:15:29 +00005910route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5911 struct bgp_info *binfo, afi_t afi, safi_t safi)
5912{
5913 char buf[INET6_ADDRSTRLEN];
5914 char buf1[BUFSIZ];
5915 struct attr *attr;
5916 int sockunion_vty_out (struct vty *, union sockunion *);
5917
5918 attr = binfo->attr;
5919
5920 if (attr)
5921 {
5922 /* Line1 display AS-path, Aggregator */
5923 if (attr->aspath)
5924 {
5925 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005926 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005927 vty_out (vty, "Local");
5928 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005929 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005930 }
5931
paulb40d9392005-08-22 22:34:41 +00005932 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5933 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005934 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5935 vty_out (vty, ", (stale)");
5936 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005937 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005938 attr->extra->aggregator_as,
5939 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005940 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5941 vty_out (vty, ", (Received from a RR-client)");
5942 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5943 vty_out (vty, ", (Received from a RS-client)");
5944 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5945 vty_out (vty, ", (history entry)");
5946 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5947 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005948 vty_out (vty, "%s", VTY_NEWLINE);
5949
5950 /* Line2 display Next-hop, Neighbor, Router-id */
5951 if (p->family == AF_INET)
5952 {
5953 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005954 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005955 inet_ntoa (attr->nexthop));
5956 }
5957#ifdef HAVE_IPV6
5958 else
5959 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005960 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005961 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005962 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005963 buf, INET6_ADDRSTRLEN));
5964 }
5965#endif /* HAVE_IPV6 */
5966
5967 if (binfo->peer == bgp->peer_self)
5968 {
5969 vty_out (vty, " from %s ",
5970 p->family == AF_INET ? "0.0.0.0" : "::");
5971 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5972 }
5973 else
5974 {
5975 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5976 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005977 else if (binfo->extra && binfo->extra->igpmetric)
5978 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005979 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005980 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005981 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005982 else
5983 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5984 }
5985 vty_out (vty, "%s", VTY_NEWLINE);
5986
5987#ifdef HAVE_IPV6
5988 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005989 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005990 {
5991 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005992 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005993 buf, INET6_ADDRSTRLEN),
5994 VTY_NEWLINE);
5995 }
5996#endif /* HAVE_IPV6 */
5997
5998 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5999 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6000
6001 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6002 vty_out (vty, ", metric %d", attr->med);
6003
6004 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6005 vty_out (vty, ", localpref %d", attr->local_pref);
6006 else
6007 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6008
Paul Jakmafb982c22007-05-04 20:15:47 +00006009 if (attr->extra && attr->extra->weight != 0)
6010 vty_out (vty, ", weight %d", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006011
6012 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6013 vty_out (vty, ", valid");
6014
6015 if (binfo->peer != bgp->peer_self)
6016 {
6017 if (binfo->peer->as == binfo->peer->local_as)
6018 vty_out (vty, ", internal");
6019 else
6020 vty_out (vty, ", %s",
6021 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6022 }
6023 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6024 vty_out (vty, ", aggregated, local");
6025 else if (binfo->type != ZEBRA_ROUTE_BGP)
6026 vty_out (vty, ", sourced");
6027 else
6028 vty_out (vty, ", sourced, local");
6029
6030 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6031 vty_out (vty, ", atomic-aggregate");
6032
6033 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6034 vty_out (vty, ", best");
6035
6036 vty_out (vty, "%s", VTY_NEWLINE);
6037
6038 /* Line 4 display Community */
6039 if (attr->community)
6040 vty_out (vty, " Community: %s%s", attr->community->str,
6041 VTY_NEWLINE);
6042
6043 /* Line 5 display Extended-community */
6044 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006045 vty_out (vty, " Extended Community: %s%s",
6046 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006047
6048 /* Line 6 display Originator, Cluster-id */
6049 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6050 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6051 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006052 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006053 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006054 vty_out (vty, " Originator: %s",
6055 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006056
6057 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6058 {
6059 int i;
6060 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006061 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6062 vty_out (vty, "%s ",
6063 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006064 }
6065 vty_out (vty, "%s", VTY_NEWLINE);
6066 }
Paul Jakma41367172007-08-06 15:24:51 +00006067
6068 /* 7: AS Pathlimit */
6069 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6070 {
6071
6072 vty_out (vty, " AS-Pathlimit: %u",
6073 attr->pathlimit.ttl);
6074 if (attr->pathlimit.as)
6075 vty_out (vty, " (%u)", attr->pathlimit.as);
6076 vty_out (vty, "%s", VTY_NEWLINE);
6077 }
6078
Paul Jakmafb982c22007-05-04 20:15:47 +00006079 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006080 bgp_damp_info_vty (vty, binfo);
6081
6082 /* Line 7 display Uptime */
6083 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
6084 }
6085 vty_out (vty, "%s", VTY_NEWLINE);
6086}
6087
paulb40d9392005-08-22 22:34:41 +00006088#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 +00006089#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006090#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6091#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6092#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6093
6094enum bgp_show_type
6095{
6096 bgp_show_type_normal,
6097 bgp_show_type_regexp,
6098 bgp_show_type_prefix_list,
6099 bgp_show_type_filter_list,
6100 bgp_show_type_route_map,
6101 bgp_show_type_neighbor,
6102 bgp_show_type_cidr_only,
6103 bgp_show_type_prefix_longer,
6104 bgp_show_type_community_all,
6105 bgp_show_type_community,
6106 bgp_show_type_community_exact,
6107 bgp_show_type_community_list,
6108 bgp_show_type_community_list_exact,
6109 bgp_show_type_flap_statistics,
6110 bgp_show_type_flap_address,
6111 bgp_show_type_flap_prefix,
6112 bgp_show_type_flap_cidr_only,
6113 bgp_show_type_flap_regexp,
6114 bgp_show_type_flap_filter_list,
6115 bgp_show_type_flap_prefix_list,
6116 bgp_show_type_flap_prefix_longer,
6117 bgp_show_type_flap_route_map,
6118 bgp_show_type_flap_neighbor,
6119 bgp_show_type_dampend_paths,
6120 bgp_show_type_damp_neighbor
6121};
6122
ajs5a646652004-11-05 01:25:55 +00006123static int
paulfee0f4c2004-09-13 05:12:46 +00006124bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006125 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006126{
paul718e3742002-12-13 20:15:29 +00006127 struct bgp_info *ri;
6128 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006129 int header = 1;
paul718e3742002-12-13 20:15:29 +00006130 int display;
ajs5a646652004-11-05 01:25:55 +00006131 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006132
6133 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006134 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006135
paul718e3742002-12-13 20:15:29 +00006136 /* Start processing of routes. */
6137 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6138 if (rn->info != NULL)
6139 {
6140 display = 0;
6141
6142 for (ri = rn->info; ri; ri = ri->next)
6143 {
ajs5a646652004-11-05 01:25:55 +00006144 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006145 || type == bgp_show_type_flap_address
6146 || type == bgp_show_type_flap_prefix
6147 || type == bgp_show_type_flap_cidr_only
6148 || type == bgp_show_type_flap_regexp
6149 || type == bgp_show_type_flap_filter_list
6150 || type == bgp_show_type_flap_prefix_list
6151 || type == bgp_show_type_flap_prefix_longer
6152 || type == bgp_show_type_flap_route_map
6153 || type == bgp_show_type_flap_neighbor
6154 || type == bgp_show_type_dampend_paths
6155 || type == bgp_show_type_damp_neighbor)
6156 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006157 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006158 continue;
6159 }
6160 if (type == bgp_show_type_regexp
6161 || type == bgp_show_type_flap_regexp)
6162 {
ajs5a646652004-11-05 01:25:55 +00006163 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006164
6165 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6166 continue;
6167 }
6168 if (type == bgp_show_type_prefix_list
6169 || type == bgp_show_type_flap_prefix_list)
6170 {
ajs5a646652004-11-05 01:25:55 +00006171 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006172
6173 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6174 continue;
6175 }
6176 if (type == bgp_show_type_filter_list
6177 || type == bgp_show_type_flap_filter_list)
6178 {
ajs5a646652004-11-05 01:25:55 +00006179 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006180
6181 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6182 continue;
6183 }
6184 if (type == bgp_show_type_route_map
6185 || type == bgp_show_type_flap_route_map)
6186 {
ajs5a646652004-11-05 01:25:55 +00006187 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006188 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006189 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006190 int ret;
6191
Paul Jakmafb982c22007-05-04 20:15:47 +00006192 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006193 binfo.peer = ri->peer;
6194 binfo.attr = &dummy_attr;
6195
6196 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006197
6198 bgp_attr_extra_free (&dummy_attr);
6199
paul718e3742002-12-13 20:15:29 +00006200 if (ret == RMAP_DENYMATCH)
6201 continue;
6202 }
6203 if (type == bgp_show_type_neighbor
6204 || type == bgp_show_type_flap_neighbor
6205 || type == bgp_show_type_damp_neighbor)
6206 {
ajs5a646652004-11-05 01:25:55 +00006207 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006208
6209 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6210 continue;
6211 }
6212 if (type == bgp_show_type_cidr_only
6213 || type == bgp_show_type_flap_cidr_only)
6214 {
6215 u_int32_t destination;
6216
6217 destination = ntohl (rn->p.u.prefix4.s_addr);
6218 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6219 continue;
6220 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6221 continue;
6222 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6223 continue;
6224 }
6225 if (type == bgp_show_type_prefix_longer
6226 || type == bgp_show_type_flap_prefix_longer)
6227 {
ajs5a646652004-11-05 01:25:55 +00006228 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006229
6230 if (! prefix_match (p, &rn->p))
6231 continue;
6232 }
6233 if (type == bgp_show_type_community_all)
6234 {
6235 if (! ri->attr->community)
6236 continue;
6237 }
6238 if (type == bgp_show_type_community)
6239 {
ajs5a646652004-11-05 01:25:55 +00006240 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006241
6242 if (! ri->attr->community ||
6243 ! community_match (ri->attr->community, com))
6244 continue;
6245 }
6246 if (type == bgp_show_type_community_exact)
6247 {
ajs5a646652004-11-05 01:25:55 +00006248 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006249
6250 if (! ri->attr->community ||
6251 ! community_cmp (ri->attr->community, com))
6252 continue;
6253 }
6254 if (type == bgp_show_type_community_list)
6255 {
ajs5a646652004-11-05 01:25:55 +00006256 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006257
6258 if (! community_list_match (ri->attr->community, list))
6259 continue;
6260 }
6261 if (type == bgp_show_type_community_list_exact)
6262 {
ajs5a646652004-11-05 01:25:55 +00006263 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006264
6265 if (! community_list_exact_match (ri->attr->community, list))
6266 continue;
6267 }
6268 if (type == bgp_show_type_flap_address
6269 || type == bgp_show_type_flap_prefix)
6270 {
ajs5a646652004-11-05 01:25:55 +00006271 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006272
6273 if (! prefix_match (&rn->p, p))
6274 continue;
6275
6276 if (type == bgp_show_type_flap_prefix)
6277 if (p->prefixlen != rn->p.prefixlen)
6278 continue;
6279 }
6280 if (type == bgp_show_type_dampend_paths
6281 || type == bgp_show_type_damp_neighbor)
6282 {
6283 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6284 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6285 continue;
6286 }
6287
6288 if (header)
6289 {
hasso93406d82005-02-02 14:40:33 +00006290 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6291 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6292 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006293 if (type == bgp_show_type_dampend_paths
6294 || type == bgp_show_type_damp_neighbor)
6295 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6296 else if (type == bgp_show_type_flap_statistics
6297 || type == bgp_show_type_flap_address
6298 || type == bgp_show_type_flap_prefix
6299 || type == bgp_show_type_flap_cidr_only
6300 || type == bgp_show_type_flap_regexp
6301 || type == bgp_show_type_flap_filter_list
6302 || type == bgp_show_type_flap_prefix_list
6303 || type == bgp_show_type_flap_prefix_longer
6304 || type == bgp_show_type_flap_route_map
6305 || type == bgp_show_type_flap_neighbor)
6306 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6307 else
6308 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006309 header = 0;
6310 }
6311
6312 if (type == bgp_show_type_dampend_paths
6313 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006314 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006315 else if (type == bgp_show_type_flap_statistics
6316 || type == bgp_show_type_flap_address
6317 || type == bgp_show_type_flap_prefix
6318 || type == bgp_show_type_flap_cidr_only
6319 || type == bgp_show_type_flap_regexp
6320 || type == bgp_show_type_flap_filter_list
6321 || type == bgp_show_type_flap_prefix_list
6322 || type == bgp_show_type_flap_prefix_longer
6323 || type == bgp_show_type_flap_route_map
6324 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006325 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006326 else
ajs5a646652004-11-05 01:25:55 +00006327 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006328 display++;
6329 }
6330 if (display)
ajs5a646652004-11-05 01:25:55 +00006331 output_count++;
paul718e3742002-12-13 20:15:29 +00006332 }
6333
6334 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006335 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006336 {
6337 if (type == bgp_show_type_normal)
6338 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6339 }
6340 else
6341 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006342 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006343
6344 return CMD_SUCCESS;
6345}
6346
ajs5a646652004-11-05 01:25:55 +00006347static int
paulfee0f4c2004-09-13 05:12:46 +00006348bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006349 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006350{
6351 struct bgp_table *table;
6352
6353 if (bgp == NULL) {
6354 bgp = bgp_get_default ();
6355 }
6356
6357 if (bgp == NULL)
6358 {
6359 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6360 return CMD_WARNING;
6361 }
6362
6363
6364 table = bgp->rib[afi][safi];
6365
ajs5a646652004-11-05 01:25:55 +00006366 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006367}
6368
paul718e3742002-12-13 20:15:29 +00006369/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006370static void
paul718e3742002-12-13 20:15:29 +00006371route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6372 struct bgp_node *rn,
6373 struct prefix_rd *prd, afi_t afi, safi_t safi)
6374{
6375 struct bgp_info *ri;
6376 struct prefix *p;
6377 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006378 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006379 char buf1[INET6_ADDRSTRLEN];
6380 char buf2[INET6_ADDRSTRLEN];
6381 int count = 0;
6382 int best = 0;
6383 int suppress = 0;
6384 int no_export = 0;
6385 int no_advertise = 0;
6386 int local_as = 0;
6387 int first = 0;
6388
6389 p = &rn->p;
6390 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6391 (safi == SAFI_MPLS_VPN ?
6392 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6393 safi == SAFI_MPLS_VPN ? ":" : "",
6394 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6395 p->prefixlen, VTY_NEWLINE);
6396
6397 for (ri = rn->info; ri; ri = ri->next)
6398 {
6399 count++;
6400 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6401 {
6402 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006403 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006404 suppress = 1;
6405 if (ri->attr->community != NULL)
6406 {
6407 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6408 no_advertise = 1;
6409 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6410 no_export = 1;
6411 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6412 local_as = 1;
6413 }
6414 }
6415 }
6416
6417 vty_out (vty, "Paths: (%d available", count);
6418 if (best)
6419 {
6420 vty_out (vty, ", best #%d", best);
6421 if (safi == SAFI_UNICAST)
6422 vty_out (vty, ", table Default-IP-Routing-Table");
6423 }
6424 else
6425 vty_out (vty, ", no best path");
6426 if (no_advertise)
6427 vty_out (vty, ", not advertised to any peer");
6428 else if (no_export)
6429 vty_out (vty, ", not advertised to EBGP peer");
6430 else if (local_as)
6431 vty_out (vty, ", not advertised outside local AS");
6432 if (suppress)
6433 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6434 vty_out (vty, ")%s", VTY_NEWLINE);
6435
6436 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006437 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006438 {
6439 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6440 {
6441 if (! first)
6442 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6443 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6444 first = 1;
6445 }
6446 }
6447 if (! first)
6448 vty_out (vty, " Not advertised to any peer");
6449 vty_out (vty, "%s", VTY_NEWLINE);
6450}
6451
6452/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006453static int
paulfee0f4c2004-09-13 05:12:46 +00006454bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006455 struct bgp_table *rib, const char *ip_str,
6456 afi_t afi, safi_t safi, struct prefix_rd *prd,
6457 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006458{
6459 int ret;
6460 int header;
6461 int display = 0;
6462 struct prefix match;
6463 struct bgp_node *rn;
6464 struct bgp_node *rm;
6465 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006466 struct bgp_table *table;
6467
paul718e3742002-12-13 20:15:29 +00006468 /* Check IP address argument. */
6469 ret = str2prefix (ip_str, &match);
6470 if (! ret)
6471 {
6472 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6473 return CMD_WARNING;
6474 }
6475
6476 match.family = afi2family (afi);
6477
6478 if (safi == SAFI_MPLS_VPN)
6479 {
paulfee0f4c2004-09-13 05:12:46 +00006480 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006481 {
6482 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6483 continue;
6484
6485 if ((table = rn->info) != NULL)
6486 {
6487 header = 1;
6488
6489 if ((rm = bgp_node_match (table, &match)) != NULL)
6490 {
6491 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6492 continue;
6493
6494 for (ri = rm->info; ri; ri = ri->next)
6495 {
6496 if (header)
6497 {
6498 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6499 AFI_IP, SAFI_MPLS_VPN);
6500
6501 header = 0;
6502 }
6503 display++;
6504 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6505 }
6506 }
6507 }
6508 }
6509 }
6510 else
6511 {
6512 header = 1;
6513
paulfee0f4c2004-09-13 05:12:46 +00006514 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006515 {
6516 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6517 {
6518 for (ri = rn->info; ri; ri = ri->next)
6519 {
6520 if (header)
6521 {
6522 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6523 header = 0;
6524 }
6525 display++;
6526 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6527 }
6528 }
6529 }
6530 }
6531
6532 if (! display)
6533 {
6534 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6535 return CMD_WARNING;
6536 }
6537
6538 return CMD_SUCCESS;
6539}
6540
paulfee0f4c2004-09-13 05:12:46 +00006541/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006542static int
paulfd79ac92004-10-13 05:06:08 +00006543bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006544 afi_t afi, safi_t safi, struct prefix_rd *prd,
6545 int prefix_check)
6546{
6547 struct bgp *bgp;
6548
6549 /* BGP structure lookup. */
6550 if (view_name)
6551 {
6552 bgp = bgp_lookup_by_name (view_name);
6553 if (bgp == NULL)
6554 {
6555 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6556 return CMD_WARNING;
6557 }
6558 }
6559 else
6560 {
6561 bgp = bgp_get_default ();
6562 if (bgp == NULL)
6563 {
6564 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6565 return CMD_WARNING;
6566 }
6567 }
6568
6569 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6570 afi, safi, prd, prefix_check);
6571}
6572
paul718e3742002-12-13 20:15:29 +00006573/* BGP route print out function. */
6574DEFUN (show_ip_bgp,
6575 show_ip_bgp_cmd,
6576 "show ip bgp",
6577 SHOW_STR
6578 IP_STR
6579 BGP_STR)
6580{
ajs5a646652004-11-05 01:25:55 +00006581 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006582}
6583
6584DEFUN (show_ip_bgp_ipv4,
6585 show_ip_bgp_ipv4_cmd,
6586 "show ip bgp ipv4 (unicast|multicast)",
6587 SHOW_STR
6588 IP_STR
6589 BGP_STR
6590 "Address family\n"
6591 "Address Family modifier\n"
6592 "Address Family modifier\n")
6593{
6594 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006595 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6596 NULL);
paul718e3742002-12-13 20:15:29 +00006597
ajs5a646652004-11-05 01:25:55 +00006598 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006599}
6600
6601DEFUN (show_ip_bgp_route,
6602 show_ip_bgp_route_cmd,
6603 "show ip bgp A.B.C.D",
6604 SHOW_STR
6605 IP_STR
6606 BGP_STR
6607 "Network in the BGP routing table to display\n")
6608{
6609 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6610}
6611
6612DEFUN (show_ip_bgp_ipv4_route,
6613 show_ip_bgp_ipv4_route_cmd,
6614 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6615 SHOW_STR
6616 IP_STR
6617 BGP_STR
6618 "Address family\n"
6619 "Address Family modifier\n"
6620 "Address Family modifier\n"
6621 "Network in the BGP routing table to display\n")
6622{
6623 if (strncmp (argv[0], "m", 1) == 0)
6624 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6625
6626 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6627}
6628
6629DEFUN (show_ip_bgp_vpnv4_all_route,
6630 show_ip_bgp_vpnv4_all_route_cmd,
6631 "show ip bgp vpnv4 all A.B.C.D",
6632 SHOW_STR
6633 IP_STR
6634 BGP_STR
6635 "Display VPNv4 NLRI specific information\n"
6636 "Display information about all VPNv4 NLRIs\n"
6637 "Network in the BGP routing table to display\n")
6638{
6639 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6640}
6641
6642DEFUN (show_ip_bgp_vpnv4_rd_route,
6643 show_ip_bgp_vpnv4_rd_route_cmd,
6644 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6645 SHOW_STR
6646 IP_STR
6647 BGP_STR
6648 "Display VPNv4 NLRI specific information\n"
6649 "Display information for a route distinguisher\n"
6650 "VPN Route Distinguisher\n"
6651 "Network in the BGP routing table to display\n")
6652{
6653 int ret;
6654 struct prefix_rd prd;
6655
6656 ret = str2prefix_rd (argv[0], &prd);
6657 if (! ret)
6658 {
6659 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6660 return CMD_WARNING;
6661 }
6662 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6663}
6664
6665DEFUN (show_ip_bgp_prefix,
6666 show_ip_bgp_prefix_cmd,
6667 "show ip bgp A.B.C.D/M",
6668 SHOW_STR
6669 IP_STR
6670 BGP_STR
6671 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6672{
6673 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6674}
6675
6676DEFUN (show_ip_bgp_ipv4_prefix,
6677 show_ip_bgp_ipv4_prefix_cmd,
6678 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6679 SHOW_STR
6680 IP_STR
6681 BGP_STR
6682 "Address family\n"
6683 "Address Family modifier\n"
6684 "Address Family modifier\n"
6685 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6686{
6687 if (strncmp (argv[0], "m", 1) == 0)
6688 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6689
6690 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6691}
6692
6693DEFUN (show_ip_bgp_vpnv4_all_prefix,
6694 show_ip_bgp_vpnv4_all_prefix_cmd,
6695 "show ip bgp vpnv4 all A.B.C.D/M",
6696 SHOW_STR
6697 IP_STR
6698 BGP_STR
6699 "Display VPNv4 NLRI specific information\n"
6700 "Display information about all VPNv4 NLRIs\n"
6701 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6702{
6703 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6704}
6705
6706DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6707 show_ip_bgp_vpnv4_rd_prefix_cmd,
6708 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6709 SHOW_STR
6710 IP_STR
6711 BGP_STR
6712 "Display VPNv4 NLRI specific information\n"
6713 "Display information for a route distinguisher\n"
6714 "VPN Route Distinguisher\n"
6715 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6716{
6717 int ret;
6718 struct prefix_rd prd;
6719
6720 ret = str2prefix_rd (argv[0], &prd);
6721 if (! ret)
6722 {
6723 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6724 return CMD_WARNING;
6725 }
6726 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6727}
6728
6729DEFUN (show_ip_bgp_view,
6730 show_ip_bgp_view_cmd,
6731 "show ip bgp view WORD",
6732 SHOW_STR
6733 IP_STR
6734 BGP_STR
6735 "BGP view\n"
6736 "BGP view name\n")
6737{
paulbb46e942003-10-24 19:02:03 +00006738 struct bgp *bgp;
6739
6740 /* BGP structure lookup. */
6741 bgp = bgp_lookup_by_name (argv[0]);
6742 if (bgp == NULL)
6743 {
6744 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6745 return CMD_WARNING;
6746 }
6747
ajs5a646652004-11-05 01:25:55 +00006748 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006749}
6750
6751DEFUN (show_ip_bgp_view_route,
6752 show_ip_bgp_view_route_cmd,
6753 "show ip bgp view WORD A.B.C.D",
6754 SHOW_STR
6755 IP_STR
6756 BGP_STR
6757 "BGP view\n"
6758 "BGP view name\n"
6759 "Network in the BGP routing table to display\n")
6760{
6761 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6762}
6763
6764DEFUN (show_ip_bgp_view_prefix,
6765 show_ip_bgp_view_prefix_cmd,
6766 "show ip bgp view WORD A.B.C.D/M",
6767 SHOW_STR
6768 IP_STR
6769 BGP_STR
6770 "BGP view\n"
6771 "BGP view name\n"
6772 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6773{
6774 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6775}
6776
6777#ifdef HAVE_IPV6
6778DEFUN (show_bgp,
6779 show_bgp_cmd,
6780 "show bgp",
6781 SHOW_STR
6782 BGP_STR)
6783{
ajs5a646652004-11-05 01:25:55 +00006784 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6785 NULL);
paul718e3742002-12-13 20:15:29 +00006786}
6787
6788ALIAS (show_bgp,
6789 show_bgp_ipv6_cmd,
6790 "show bgp ipv6",
6791 SHOW_STR
6792 BGP_STR
6793 "Address family\n")
6794
6795/* old command */
6796DEFUN (show_ipv6_bgp,
6797 show_ipv6_bgp_cmd,
6798 "show ipv6 bgp",
6799 SHOW_STR
6800 IP_STR
6801 BGP_STR)
6802{
ajs5a646652004-11-05 01:25:55 +00006803 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6804 NULL);
paul718e3742002-12-13 20:15:29 +00006805}
6806
6807DEFUN (show_bgp_route,
6808 show_bgp_route_cmd,
6809 "show bgp X:X::X:X",
6810 SHOW_STR
6811 BGP_STR
6812 "Network in the BGP routing table to display\n")
6813{
6814 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6815}
6816
6817ALIAS (show_bgp_route,
6818 show_bgp_ipv6_route_cmd,
6819 "show bgp ipv6 X:X::X:X",
6820 SHOW_STR
6821 BGP_STR
6822 "Address family\n"
6823 "Network in the BGP routing table to display\n")
6824
6825/* old command */
6826DEFUN (show_ipv6_bgp_route,
6827 show_ipv6_bgp_route_cmd,
6828 "show ipv6 bgp X:X::X:X",
6829 SHOW_STR
6830 IP_STR
6831 BGP_STR
6832 "Network in the BGP routing table to display\n")
6833{
6834 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6835}
6836
6837DEFUN (show_bgp_prefix,
6838 show_bgp_prefix_cmd,
6839 "show bgp X:X::X:X/M",
6840 SHOW_STR
6841 BGP_STR
6842 "IPv6 prefix <network>/<length>\n")
6843{
6844 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6845}
6846
6847ALIAS (show_bgp_prefix,
6848 show_bgp_ipv6_prefix_cmd,
6849 "show bgp ipv6 X:X::X:X/M",
6850 SHOW_STR
6851 BGP_STR
6852 "Address family\n"
6853 "IPv6 prefix <network>/<length>\n")
6854
6855/* old command */
6856DEFUN (show_ipv6_bgp_prefix,
6857 show_ipv6_bgp_prefix_cmd,
6858 "show ipv6 bgp X:X::X:X/M",
6859 SHOW_STR
6860 IP_STR
6861 BGP_STR
6862 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6863{
6864 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6865}
6866
paulbb46e942003-10-24 19:02:03 +00006867DEFUN (show_bgp_view,
6868 show_bgp_view_cmd,
6869 "show bgp view WORD",
6870 SHOW_STR
6871 BGP_STR
6872 "BGP view\n"
6873 "View name\n")
6874{
6875 struct bgp *bgp;
6876
6877 /* BGP structure lookup. */
6878 bgp = bgp_lookup_by_name (argv[0]);
6879 if (bgp == NULL)
6880 {
6881 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6882 return CMD_WARNING;
6883 }
6884
ajs5a646652004-11-05 01:25:55 +00006885 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006886}
6887
6888ALIAS (show_bgp_view,
6889 show_bgp_view_ipv6_cmd,
6890 "show bgp view WORD ipv6",
6891 SHOW_STR
6892 BGP_STR
6893 "BGP view\n"
6894 "View name\n"
6895 "Address family\n")
6896
6897DEFUN (show_bgp_view_route,
6898 show_bgp_view_route_cmd,
6899 "show bgp view WORD X:X::X:X",
6900 SHOW_STR
6901 BGP_STR
6902 "BGP view\n"
6903 "View name\n"
6904 "Network in the BGP routing table to display\n")
6905{
6906 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6907}
6908
6909ALIAS (show_bgp_view_route,
6910 show_bgp_view_ipv6_route_cmd,
6911 "show bgp view WORD ipv6 X:X::X:X",
6912 SHOW_STR
6913 BGP_STR
6914 "BGP view\n"
6915 "View name\n"
6916 "Address family\n"
6917 "Network in the BGP routing table to display\n")
6918
6919DEFUN (show_bgp_view_prefix,
6920 show_bgp_view_prefix_cmd,
6921 "show bgp view WORD X:X::X:X/M",
6922 SHOW_STR
6923 BGP_STR
6924 "BGP view\n"
6925 "View name\n"
6926 "IPv6 prefix <network>/<length>\n")
6927{
6928 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6929}
6930
6931ALIAS (show_bgp_view_prefix,
6932 show_bgp_view_ipv6_prefix_cmd,
6933 "show bgp view WORD ipv6 X:X::X:X/M",
6934 SHOW_STR
6935 BGP_STR
6936 "BGP view\n"
6937 "View name\n"
6938 "Address family\n"
6939 "IPv6 prefix <network>/<length>\n")
6940
paul718e3742002-12-13 20:15:29 +00006941/* old command */
6942DEFUN (show_ipv6_mbgp,
6943 show_ipv6_mbgp_cmd,
6944 "show ipv6 mbgp",
6945 SHOW_STR
6946 IP_STR
6947 MBGP_STR)
6948{
ajs5a646652004-11-05 01:25:55 +00006949 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6950 NULL);
paul718e3742002-12-13 20:15:29 +00006951}
6952
6953/* old command */
6954DEFUN (show_ipv6_mbgp_route,
6955 show_ipv6_mbgp_route_cmd,
6956 "show ipv6 mbgp X:X::X:X",
6957 SHOW_STR
6958 IP_STR
6959 MBGP_STR
6960 "Network in the MBGP routing table to display\n")
6961{
6962 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6963}
6964
6965/* old command */
6966DEFUN (show_ipv6_mbgp_prefix,
6967 show_ipv6_mbgp_prefix_cmd,
6968 "show ipv6 mbgp X:X::X:X/M",
6969 SHOW_STR
6970 IP_STR
6971 MBGP_STR
6972 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6973{
6974 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6975}
6976#endif
6977
paul718e3742002-12-13 20:15:29 +00006978
paul94f2b392005-06-28 12:44:16 +00006979static int
paulfd79ac92004-10-13 05:06:08 +00006980bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006981 safi_t safi, enum bgp_show_type type)
6982{
6983 int i;
6984 struct buffer *b;
6985 char *regstr;
6986 int first;
6987 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006988 int rc;
paul718e3742002-12-13 20:15:29 +00006989
6990 first = 0;
6991 b = buffer_new (1024);
6992 for (i = 0; i < argc; i++)
6993 {
6994 if (first)
6995 buffer_putc (b, ' ');
6996 else
6997 {
6998 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6999 continue;
7000 first = 1;
7001 }
7002
7003 buffer_putstr (b, argv[i]);
7004 }
7005 buffer_putc (b, '\0');
7006
7007 regstr = buffer_getstr (b);
7008 buffer_free (b);
7009
7010 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007011 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007012 if (! regex)
7013 {
7014 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7015 VTY_NEWLINE);
7016 return CMD_WARNING;
7017 }
7018
ajs5a646652004-11-05 01:25:55 +00007019 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7020 bgp_regex_free (regex);
7021 return rc;
paul718e3742002-12-13 20:15:29 +00007022}
7023
7024DEFUN (show_ip_bgp_regexp,
7025 show_ip_bgp_regexp_cmd,
7026 "show ip bgp regexp .LINE",
7027 SHOW_STR
7028 IP_STR
7029 BGP_STR
7030 "Display routes matching the AS path regular expression\n"
7031 "A regular-expression to match the BGP AS paths\n")
7032{
7033 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7034 bgp_show_type_regexp);
7035}
7036
7037DEFUN (show_ip_bgp_flap_regexp,
7038 show_ip_bgp_flap_regexp_cmd,
7039 "show ip bgp flap-statistics regexp .LINE",
7040 SHOW_STR
7041 IP_STR
7042 BGP_STR
7043 "Display flap statistics of routes\n"
7044 "Display routes matching the AS path regular expression\n"
7045 "A regular-expression to match the BGP AS paths\n")
7046{
7047 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7048 bgp_show_type_flap_regexp);
7049}
7050
7051DEFUN (show_ip_bgp_ipv4_regexp,
7052 show_ip_bgp_ipv4_regexp_cmd,
7053 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7054 SHOW_STR
7055 IP_STR
7056 BGP_STR
7057 "Address family\n"
7058 "Address Family modifier\n"
7059 "Address Family modifier\n"
7060 "Display routes matching the AS path regular expression\n"
7061 "A regular-expression to match the BGP AS paths\n")
7062{
7063 if (strncmp (argv[0], "m", 1) == 0)
7064 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7065 bgp_show_type_regexp);
7066
7067 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7068 bgp_show_type_regexp);
7069}
7070
7071#ifdef HAVE_IPV6
7072DEFUN (show_bgp_regexp,
7073 show_bgp_regexp_cmd,
7074 "show bgp regexp .LINE",
7075 SHOW_STR
7076 BGP_STR
7077 "Display routes matching the AS path regular expression\n"
7078 "A regular-expression to match the BGP AS paths\n")
7079{
7080 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7081 bgp_show_type_regexp);
7082}
7083
7084ALIAS (show_bgp_regexp,
7085 show_bgp_ipv6_regexp_cmd,
7086 "show bgp ipv6 regexp .LINE",
7087 SHOW_STR
7088 BGP_STR
7089 "Address family\n"
7090 "Display routes matching the AS path regular expression\n"
7091 "A regular-expression to match the BGP AS paths\n")
7092
7093/* old command */
7094DEFUN (show_ipv6_bgp_regexp,
7095 show_ipv6_bgp_regexp_cmd,
7096 "show ipv6 bgp regexp .LINE",
7097 SHOW_STR
7098 IP_STR
7099 BGP_STR
7100 "Display routes matching the AS path regular expression\n"
7101 "A regular-expression to match the BGP AS paths\n")
7102{
7103 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7104 bgp_show_type_regexp);
7105}
7106
7107/* old command */
7108DEFUN (show_ipv6_mbgp_regexp,
7109 show_ipv6_mbgp_regexp_cmd,
7110 "show ipv6 mbgp regexp .LINE",
7111 SHOW_STR
7112 IP_STR
7113 BGP_STR
7114 "Display routes matching the AS path regular expression\n"
7115 "A regular-expression to match the MBGP AS paths\n")
7116{
7117 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7118 bgp_show_type_regexp);
7119}
7120#endif /* HAVE_IPV6 */
7121
paul94f2b392005-06-28 12:44:16 +00007122static int
paulfd79ac92004-10-13 05:06:08 +00007123bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007124 safi_t safi, enum bgp_show_type type)
7125{
7126 struct prefix_list *plist;
7127
7128 plist = prefix_list_lookup (afi, prefix_list_str);
7129 if (plist == NULL)
7130 {
7131 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7132 prefix_list_str, VTY_NEWLINE);
7133 return CMD_WARNING;
7134 }
7135
ajs5a646652004-11-05 01:25:55 +00007136 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007137}
7138
7139DEFUN (show_ip_bgp_prefix_list,
7140 show_ip_bgp_prefix_list_cmd,
7141 "show ip bgp prefix-list WORD",
7142 SHOW_STR
7143 IP_STR
7144 BGP_STR
7145 "Display routes conforming to the prefix-list\n"
7146 "IP prefix-list name\n")
7147{
7148 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7149 bgp_show_type_prefix_list);
7150}
7151
7152DEFUN (show_ip_bgp_flap_prefix_list,
7153 show_ip_bgp_flap_prefix_list_cmd,
7154 "show ip bgp flap-statistics prefix-list WORD",
7155 SHOW_STR
7156 IP_STR
7157 BGP_STR
7158 "Display flap statistics of routes\n"
7159 "Display routes conforming to the prefix-list\n"
7160 "IP prefix-list name\n")
7161{
7162 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7163 bgp_show_type_flap_prefix_list);
7164}
7165
7166DEFUN (show_ip_bgp_ipv4_prefix_list,
7167 show_ip_bgp_ipv4_prefix_list_cmd,
7168 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7169 SHOW_STR
7170 IP_STR
7171 BGP_STR
7172 "Address family\n"
7173 "Address Family modifier\n"
7174 "Address Family modifier\n"
7175 "Display routes conforming to the prefix-list\n"
7176 "IP prefix-list name\n")
7177{
7178 if (strncmp (argv[0], "m", 1) == 0)
7179 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7180 bgp_show_type_prefix_list);
7181
7182 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7183 bgp_show_type_prefix_list);
7184}
7185
7186#ifdef HAVE_IPV6
7187DEFUN (show_bgp_prefix_list,
7188 show_bgp_prefix_list_cmd,
7189 "show bgp prefix-list WORD",
7190 SHOW_STR
7191 BGP_STR
7192 "Display routes conforming to the prefix-list\n"
7193 "IPv6 prefix-list name\n")
7194{
7195 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7196 bgp_show_type_prefix_list);
7197}
7198
7199ALIAS (show_bgp_prefix_list,
7200 show_bgp_ipv6_prefix_list_cmd,
7201 "show bgp ipv6 prefix-list WORD",
7202 SHOW_STR
7203 BGP_STR
7204 "Address family\n"
7205 "Display routes conforming to the prefix-list\n"
7206 "IPv6 prefix-list name\n")
7207
7208/* old command */
7209DEFUN (show_ipv6_bgp_prefix_list,
7210 show_ipv6_bgp_prefix_list_cmd,
7211 "show ipv6 bgp prefix-list WORD",
7212 SHOW_STR
7213 IPV6_STR
7214 BGP_STR
7215 "Display routes matching the prefix-list\n"
7216 "IPv6 prefix-list name\n")
7217{
7218 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7219 bgp_show_type_prefix_list);
7220}
7221
7222/* old command */
7223DEFUN (show_ipv6_mbgp_prefix_list,
7224 show_ipv6_mbgp_prefix_list_cmd,
7225 "show ipv6 mbgp prefix-list WORD",
7226 SHOW_STR
7227 IPV6_STR
7228 MBGP_STR
7229 "Display routes matching the prefix-list\n"
7230 "IPv6 prefix-list name\n")
7231{
7232 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7233 bgp_show_type_prefix_list);
7234}
7235#endif /* HAVE_IPV6 */
7236
paul94f2b392005-06-28 12:44:16 +00007237static int
paulfd79ac92004-10-13 05:06:08 +00007238bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007239 safi_t safi, enum bgp_show_type type)
7240{
7241 struct as_list *as_list;
7242
7243 as_list = as_list_lookup (filter);
7244 if (as_list == NULL)
7245 {
7246 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7247 return CMD_WARNING;
7248 }
7249
ajs5a646652004-11-05 01:25:55 +00007250 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007251}
7252
7253DEFUN (show_ip_bgp_filter_list,
7254 show_ip_bgp_filter_list_cmd,
7255 "show ip bgp filter-list WORD",
7256 SHOW_STR
7257 IP_STR
7258 BGP_STR
7259 "Display routes conforming to the filter-list\n"
7260 "Regular expression access list name\n")
7261{
7262 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7263 bgp_show_type_filter_list);
7264}
7265
7266DEFUN (show_ip_bgp_flap_filter_list,
7267 show_ip_bgp_flap_filter_list_cmd,
7268 "show ip bgp flap-statistics filter-list WORD",
7269 SHOW_STR
7270 IP_STR
7271 BGP_STR
7272 "Display flap statistics of routes\n"
7273 "Display routes conforming to the filter-list\n"
7274 "Regular expression access list name\n")
7275{
7276 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7277 bgp_show_type_flap_filter_list);
7278}
7279
7280DEFUN (show_ip_bgp_ipv4_filter_list,
7281 show_ip_bgp_ipv4_filter_list_cmd,
7282 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7283 SHOW_STR
7284 IP_STR
7285 BGP_STR
7286 "Address family\n"
7287 "Address Family modifier\n"
7288 "Address Family modifier\n"
7289 "Display routes conforming to the filter-list\n"
7290 "Regular expression access list name\n")
7291{
7292 if (strncmp (argv[0], "m", 1) == 0)
7293 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7294 bgp_show_type_filter_list);
7295
7296 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7297 bgp_show_type_filter_list);
7298}
7299
7300#ifdef HAVE_IPV6
7301DEFUN (show_bgp_filter_list,
7302 show_bgp_filter_list_cmd,
7303 "show bgp filter-list WORD",
7304 SHOW_STR
7305 BGP_STR
7306 "Display routes conforming to the filter-list\n"
7307 "Regular expression access list name\n")
7308{
7309 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7310 bgp_show_type_filter_list);
7311}
7312
7313ALIAS (show_bgp_filter_list,
7314 show_bgp_ipv6_filter_list_cmd,
7315 "show bgp ipv6 filter-list WORD",
7316 SHOW_STR
7317 BGP_STR
7318 "Address family\n"
7319 "Display routes conforming to the filter-list\n"
7320 "Regular expression access list name\n")
7321
7322/* old command */
7323DEFUN (show_ipv6_bgp_filter_list,
7324 show_ipv6_bgp_filter_list_cmd,
7325 "show ipv6 bgp filter-list WORD",
7326 SHOW_STR
7327 IPV6_STR
7328 BGP_STR
7329 "Display routes conforming to the filter-list\n"
7330 "Regular expression access list name\n")
7331{
7332 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7333 bgp_show_type_filter_list);
7334}
7335
7336/* old command */
7337DEFUN (show_ipv6_mbgp_filter_list,
7338 show_ipv6_mbgp_filter_list_cmd,
7339 "show ipv6 mbgp filter-list WORD",
7340 SHOW_STR
7341 IPV6_STR
7342 MBGP_STR
7343 "Display routes conforming to the filter-list\n"
7344 "Regular expression access list name\n")
7345{
7346 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7347 bgp_show_type_filter_list);
7348}
7349#endif /* HAVE_IPV6 */
7350
paul94f2b392005-06-28 12:44:16 +00007351static int
paulfd79ac92004-10-13 05:06:08 +00007352bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007353 safi_t safi, enum bgp_show_type type)
7354{
7355 struct route_map *rmap;
7356
7357 rmap = route_map_lookup_by_name (rmap_str);
7358 if (! rmap)
7359 {
7360 vty_out (vty, "%% %s is not a valid route-map name%s",
7361 rmap_str, VTY_NEWLINE);
7362 return CMD_WARNING;
7363 }
7364
ajs5a646652004-11-05 01:25:55 +00007365 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007366}
7367
7368DEFUN (show_ip_bgp_route_map,
7369 show_ip_bgp_route_map_cmd,
7370 "show ip bgp route-map WORD",
7371 SHOW_STR
7372 IP_STR
7373 BGP_STR
7374 "Display routes matching the route-map\n"
7375 "A route-map to match on\n")
7376{
7377 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7378 bgp_show_type_route_map);
7379}
7380
7381DEFUN (show_ip_bgp_flap_route_map,
7382 show_ip_bgp_flap_route_map_cmd,
7383 "show ip bgp flap-statistics route-map WORD",
7384 SHOW_STR
7385 IP_STR
7386 BGP_STR
7387 "Display flap statistics of routes\n"
7388 "Display routes matching the route-map\n"
7389 "A route-map to match on\n")
7390{
7391 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7392 bgp_show_type_flap_route_map);
7393}
7394
7395DEFUN (show_ip_bgp_ipv4_route_map,
7396 show_ip_bgp_ipv4_route_map_cmd,
7397 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7398 SHOW_STR
7399 IP_STR
7400 BGP_STR
7401 "Address family\n"
7402 "Address Family modifier\n"
7403 "Address Family modifier\n"
7404 "Display routes matching the route-map\n"
7405 "A route-map to match on\n")
7406{
7407 if (strncmp (argv[0], "m", 1) == 0)
7408 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7409 bgp_show_type_route_map);
7410
7411 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7412 bgp_show_type_route_map);
7413}
7414
7415DEFUN (show_bgp_route_map,
7416 show_bgp_route_map_cmd,
7417 "show bgp route-map WORD",
7418 SHOW_STR
7419 BGP_STR
7420 "Display routes matching the route-map\n"
7421 "A route-map to match on\n")
7422{
7423 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7424 bgp_show_type_route_map);
7425}
7426
7427ALIAS (show_bgp_route_map,
7428 show_bgp_ipv6_route_map_cmd,
7429 "show bgp ipv6 route-map WORD",
7430 SHOW_STR
7431 BGP_STR
7432 "Address family\n"
7433 "Display routes matching the route-map\n"
7434 "A route-map to match on\n")
7435
7436DEFUN (show_ip_bgp_cidr_only,
7437 show_ip_bgp_cidr_only_cmd,
7438 "show ip bgp cidr-only",
7439 SHOW_STR
7440 IP_STR
7441 BGP_STR
7442 "Display only routes with non-natural netmasks\n")
7443{
7444 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007445 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007446}
7447
7448DEFUN (show_ip_bgp_flap_cidr_only,
7449 show_ip_bgp_flap_cidr_only_cmd,
7450 "show ip bgp flap-statistics cidr-only",
7451 SHOW_STR
7452 IP_STR
7453 BGP_STR
7454 "Display flap statistics of routes\n"
7455 "Display only routes with non-natural netmasks\n")
7456{
7457 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007458 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007459}
7460
7461DEFUN (show_ip_bgp_ipv4_cidr_only,
7462 show_ip_bgp_ipv4_cidr_only_cmd,
7463 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7464 SHOW_STR
7465 IP_STR
7466 BGP_STR
7467 "Address family\n"
7468 "Address Family modifier\n"
7469 "Address Family modifier\n"
7470 "Display only routes with non-natural netmasks\n")
7471{
7472 if (strncmp (argv[0], "m", 1) == 0)
7473 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007474 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007475
7476 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007477 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007478}
7479
7480DEFUN (show_ip_bgp_community_all,
7481 show_ip_bgp_community_all_cmd,
7482 "show ip bgp community",
7483 SHOW_STR
7484 IP_STR
7485 BGP_STR
7486 "Display routes matching the communities\n")
7487{
7488 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007489 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007490}
7491
7492DEFUN (show_ip_bgp_ipv4_community_all,
7493 show_ip_bgp_ipv4_community_all_cmd,
7494 "show ip bgp ipv4 (unicast|multicast) community",
7495 SHOW_STR
7496 IP_STR
7497 BGP_STR
7498 "Address family\n"
7499 "Address Family modifier\n"
7500 "Address Family modifier\n"
7501 "Display routes matching the communities\n")
7502{
7503 if (strncmp (argv[0], "m", 1) == 0)
7504 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007505 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007506
7507 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007508 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007509}
7510
7511#ifdef HAVE_IPV6
7512DEFUN (show_bgp_community_all,
7513 show_bgp_community_all_cmd,
7514 "show bgp community",
7515 SHOW_STR
7516 BGP_STR
7517 "Display routes matching the communities\n")
7518{
7519 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007520 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007521}
7522
7523ALIAS (show_bgp_community_all,
7524 show_bgp_ipv6_community_all_cmd,
7525 "show bgp ipv6 community",
7526 SHOW_STR
7527 BGP_STR
7528 "Address family\n"
7529 "Display routes matching the communities\n")
7530
7531/* old command */
7532DEFUN (show_ipv6_bgp_community_all,
7533 show_ipv6_bgp_community_all_cmd,
7534 "show ipv6 bgp community",
7535 SHOW_STR
7536 IPV6_STR
7537 BGP_STR
7538 "Display routes matching the communities\n")
7539{
7540 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007541 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007542}
7543
7544/* old command */
7545DEFUN (show_ipv6_mbgp_community_all,
7546 show_ipv6_mbgp_community_all_cmd,
7547 "show ipv6 mbgp community",
7548 SHOW_STR
7549 IPV6_STR
7550 MBGP_STR
7551 "Display routes matching the communities\n")
7552{
7553 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007554 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007555}
7556#endif /* HAVE_IPV6 */
7557
paul94f2b392005-06-28 12:44:16 +00007558static int
paulfd79ac92004-10-13 05:06:08 +00007559bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7560 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007561{
7562 struct community *com;
7563 struct buffer *b;
7564 int i;
7565 char *str;
7566 int first = 0;
7567
7568 b = buffer_new (1024);
7569 for (i = 0; i < argc; i++)
7570 {
7571 if (first)
7572 buffer_putc (b, ' ');
7573 else
7574 {
7575 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7576 continue;
7577 first = 1;
7578 }
7579
7580 buffer_putstr (b, argv[i]);
7581 }
7582 buffer_putc (b, '\0');
7583
7584 str = buffer_getstr (b);
7585 buffer_free (b);
7586
7587 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007588 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007589 if (! com)
7590 {
7591 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7592 return CMD_WARNING;
7593 }
7594
ajs5a646652004-11-05 01:25:55 +00007595 return bgp_show (vty, NULL, afi, safi,
7596 (exact ? bgp_show_type_community_exact :
7597 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007598}
7599
7600DEFUN (show_ip_bgp_community,
7601 show_ip_bgp_community_cmd,
7602 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7603 SHOW_STR
7604 IP_STR
7605 BGP_STR
7606 "Display routes matching the communities\n"
7607 "community number\n"
7608 "Do not send outside local AS (well-known community)\n"
7609 "Do not advertise to any peer (well-known community)\n"
7610 "Do not export to next AS (well-known community)\n")
7611{
7612 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7613}
7614
7615ALIAS (show_ip_bgp_community,
7616 show_ip_bgp_community2_cmd,
7617 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7618 SHOW_STR
7619 IP_STR
7620 BGP_STR
7621 "Display routes matching the communities\n"
7622 "community number\n"
7623 "Do not send outside local AS (well-known community)\n"
7624 "Do not advertise to any peer (well-known community)\n"
7625 "Do not export to next AS (well-known community)\n"
7626 "community number\n"
7627 "Do not send outside local AS (well-known community)\n"
7628 "Do not advertise to any peer (well-known community)\n"
7629 "Do not export to next AS (well-known community)\n")
7630
7631ALIAS (show_ip_bgp_community,
7632 show_ip_bgp_community3_cmd,
7633 "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)",
7634 SHOW_STR
7635 IP_STR
7636 BGP_STR
7637 "Display routes matching the communities\n"
7638 "community number\n"
7639 "Do not send outside local AS (well-known community)\n"
7640 "Do not advertise to any peer (well-known community)\n"
7641 "Do not export to next AS (well-known community)\n"
7642 "community number\n"
7643 "Do not send outside local AS (well-known community)\n"
7644 "Do not advertise to any peer (well-known community)\n"
7645 "Do not export to next AS (well-known community)\n"
7646 "community number\n"
7647 "Do not send outside local AS (well-known community)\n"
7648 "Do not advertise to any peer (well-known community)\n"
7649 "Do not export to next AS (well-known community)\n")
7650
7651ALIAS (show_ip_bgp_community,
7652 show_ip_bgp_community4_cmd,
7653 "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)",
7654 SHOW_STR
7655 IP_STR
7656 BGP_STR
7657 "Display routes matching the communities\n"
7658 "community number\n"
7659 "Do not send outside local AS (well-known community)\n"
7660 "Do not advertise to any peer (well-known community)\n"
7661 "Do not export to next AS (well-known community)\n"
7662 "community number\n"
7663 "Do not send outside local AS (well-known community)\n"
7664 "Do not advertise to any peer (well-known community)\n"
7665 "Do not export to next AS (well-known community)\n"
7666 "community number\n"
7667 "Do not send outside local AS (well-known community)\n"
7668 "Do not advertise to any peer (well-known community)\n"
7669 "Do not export to next AS (well-known community)\n"
7670 "community number\n"
7671 "Do not send outside local AS (well-known community)\n"
7672 "Do not advertise to any peer (well-known community)\n"
7673 "Do not export to next AS (well-known community)\n")
7674
7675DEFUN (show_ip_bgp_ipv4_community,
7676 show_ip_bgp_ipv4_community_cmd,
7677 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7678 SHOW_STR
7679 IP_STR
7680 BGP_STR
7681 "Address family\n"
7682 "Address Family modifier\n"
7683 "Address Family modifier\n"
7684 "Display routes matching the communities\n"
7685 "community number\n"
7686 "Do not send outside local AS (well-known community)\n"
7687 "Do not advertise to any peer (well-known community)\n"
7688 "Do not export to next AS (well-known community)\n")
7689{
7690 if (strncmp (argv[0], "m", 1) == 0)
7691 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7692
7693 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7694}
7695
7696ALIAS (show_ip_bgp_ipv4_community,
7697 show_ip_bgp_ipv4_community2_cmd,
7698 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7699 SHOW_STR
7700 IP_STR
7701 BGP_STR
7702 "Address family\n"
7703 "Address Family modifier\n"
7704 "Address Family modifier\n"
7705 "Display routes matching the communities\n"
7706 "community number\n"
7707 "Do not send outside local AS (well-known community)\n"
7708 "Do not advertise to any peer (well-known community)\n"
7709 "Do not export to next AS (well-known community)\n"
7710 "community number\n"
7711 "Do not send outside local AS (well-known community)\n"
7712 "Do not advertise to any peer (well-known community)\n"
7713 "Do not export to next AS (well-known community)\n")
7714
7715ALIAS (show_ip_bgp_ipv4_community,
7716 show_ip_bgp_ipv4_community3_cmd,
7717 "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)",
7718 SHOW_STR
7719 IP_STR
7720 BGP_STR
7721 "Address family\n"
7722 "Address Family modifier\n"
7723 "Address Family modifier\n"
7724 "Display routes matching the communities\n"
7725 "community number\n"
7726 "Do not send outside local AS (well-known community)\n"
7727 "Do not advertise to any peer (well-known community)\n"
7728 "Do not export to next AS (well-known community)\n"
7729 "community number\n"
7730 "Do not send outside local AS (well-known community)\n"
7731 "Do not advertise to any peer (well-known community)\n"
7732 "Do not export to next AS (well-known community)\n"
7733 "community number\n"
7734 "Do not send outside local AS (well-known community)\n"
7735 "Do not advertise to any peer (well-known community)\n"
7736 "Do not export to next AS (well-known community)\n")
7737
7738ALIAS (show_ip_bgp_ipv4_community,
7739 show_ip_bgp_ipv4_community4_cmd,
7740 "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)",
7741 SHOW_STR
7742 IP_STR
7743 BGP_STR
7744 "Address family\n"
7745 "Address Family modifier\n"
7746 "Address Family modifier\n"
7747 "Display routes matching the communities\n"
7748 "community number\n"
7749 "Do not send outside local AS (well-known community)\n"
7750 "Do not advertise to any peer (well-known community)\n"
7751 "Do not export to next AS (well-known community)\n"
7752 "community number\n"
7753 "Do not send outside local AS (well-known community)\n"
7754 "Do not advertise to any peer (well-known community)\n"
7755 "Do not export to next AS (well-known community)\n"
7756 "community number\n"
7757 "Do not send outside local AS (well-known community)\n"
7758 "Do not advertise to any peer (well-known community)\n"
7759 "Do not export to next AS (well-known community)\n"
7760 "community number\n"
7761 "Do not send outside local AS (well-known community)\n"
7762 "Do not advertise to any peer (well-known community)\n"
7763 "Do not export to next AS (well-known community)\n")
7764
7765DEFUN (show_ip_bgp_community_exact,
7766 show_ip_bgp_community_exact_cmd,
7767 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7768 SHOW_STR
7769 IP_STR
7770 BGP_STR
7771 "Display routes matching the communities\n"
7772 "community number\n"
7773 "Do not send outside local AS (well-known community)\n"
7774 "Do not advertise to any peer (well-known community)\n"
7775 "Do not export to next AS (well-known community)\n"
7776 "Exact match of the communities")
7777{
7778 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7779}
7780
7781ALIAS (show_ip_bgp_community_exact,
7782 show_ip_bgp_community2_exact_cmd,
7783 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7784 SHOW_STR
7785 IP_STR
7786 BGP_STR
7787 "Display routes matching the communities\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\n"
7796 "Exact match of the communities")
7797
7798ALIAS (show_ip_bgp_community_exact,
7799 show_ip_bgp_community3_exact_cmd,
7800 "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",
7801 SHOW_STR
7802 IP_STR
7803 BGP_STR
7804 "Display routes matching the communities\n"
7805 "community number\n"
7806 "Do not send outside local AS (well-known community)\n"
7807 "Do not advertise to any peer (well-known community)\n"
7808 "Do not export to next AS (well-known community)\n"
7809 "community number\n"
7810 "Do not send outside local AS (well-known community)\n"
7811 "Do not advertise to any peer (well-known community)\n"
7812 "Do not export to next AS (well-known community)\n"
7813 "community number\n"
7814 "Do not send outside local AS (well-known community)\n"
7815 "Do not advertise to any peer (well-known community)\n"
7816 "Do not export to next AS (well-known community)\n"
7817 "Exact match of the communities")
7818
7819ALIAS (show_ip_bgp_community_exact,
7820 show_ip_bgp_community4_exact_cmd,
7821 "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",
7822 SHOW_STR
7823 IP_STR
7824 BGP_STR
7825 "Display routes matching the communities\n"
7826 "community number\n"
7827 "Do not send outside local AS (well-known community)\n"
7828 "Do not advertise to any peer (well-known community)\n"
7829 "Do not export to next AS (well-known community)\n"
7830 "community number\n"
7831 "Do not send outside local AS (well-known community)\n"
7832 "Do not advertise to any peer (well-known community)\n"
7833 "Do not export to next AS (well-known community)\n"
7834 "community number\n"
7835 "Do not send outside local AS (well-known community)\n"
7836 "Do not advertise to any peer (well-known community)\n"
7837 "Do not export to next AS (well-known community)\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n"
7842 "Exact match of the communities")
7843
7844DEFUN (show_ip_bgp_ipv4_community_exact,
7845 show_ip_bgp_ipv4_community_exact_cmd,
7846 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7847 SHOW_STR
7848 IP_STR
7849 BGP_STR
7850 "Address family\n"
7851 "Address Family modifier\n"
7852 "Address Family modifier\n"
7853 "Display routes matching the communities\n"
7854 "community number\n"
7855 "Do not send outside local AS (well-known community)\n"
7856 "Do not advertise to any peer (well-known community)\n"
7857 "Do not export to next AS (well-known community)\n"
7858 "Exact match of the communities")
7859{
7860 if (strncmp (argv[0], "m", 1) == 0)
7861 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7862
7863 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7864}
7865
7866ALIAS (show_ip_bgp_ipv4_community_exact,
7867 show_ip_bgp_ipv4_community2_exact_cmd,
7868 "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",
7869 SHOW_STR
7870 IP_STR
7871 BGP_STR
7872 "Address family\n"
7873 "Address Family modifier\n"
7874 "Address Family modifier\n"
7875 "Display routes matching the communities\n"
7876 "community number\n"
7877 "Do not send outside local AS (well-known community)\n"
7878 "Do not advertise to any peer (well-known community)\n"
7879 "Do not export to next AS (well-known community)\n"
7880 "community number\n"
7881 "Do not send outside local AS (well-known community)\n"
7882 "Do not advertise to any peer (well-known community)\n"
7883 "Do not export to next AS (well-known community)\n"
7884 "Exact match of the communities")
7885
7886ALIAS (show_ip_bgp_ipv4_community_exact,
7887 show_ip_bgp_ipv4_community3_exact_cmd,
7888 "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",
7889 SHOW_STR
7890 IP_STR
7891 BGP_STR
7892 "Address family\n"
7893 "Address Family modifier\n"
7894 "Address Family modifier\n"
7895 "Display routes matching the communities\n"
7896 "community number\n"
7897 "Do not send outside local AS (well-known community)\n"
7898 "Do not advertise to any peer (well-known community)\n"
7899 "Do not export to next AS (well-known community)\n"
7900 "community number\n"
7901 "Do not send outside local AS (well-known community)\n"
7902 "Do not advertise to any peer (well-known community)\n"
7903 "Do not export to next AS (well-known community)\n"
7904 "community number\n"
7905 "Do not send outside local AS (well-known community)\n"
7906 "Do not advertise to any peer (well-known community)\n"
7907 "Do not export to next AS (well-known community)\n"
7908 "Exact match of the communities")
7909
7910ALIAS (show_ip_bgp_ipv4_community_exact,
7911 show_ip_bgp_ipv4_community4_exact_cmd,
7912 "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",
7913 SHOW_STR
7914 IP_STR
7915 BGP_STR
7916 "Address family\n"
7917 "Address Family modifier\n"
7918 "Address Family modifier\n"
7919 "Display routes matching the communities\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n"
7928 "community number\n"
7929 "Do not send outside local AS (well-known community)\n"
7930 "Do not advertise to any peer (well-known community)\n"
7931 "Do not export to next AS (well-known community)\n"
7932 "community number\n"
7933 "Do not send outside local AS (well-known community)\n"
7934 "Do not advertise to any peer (well-known community)\n"
7935 "Do not export to next AS (well-known community)\n"
7936 "Exact match of the communities")
7937
7938#ifdef HAVE_IPV6
7939DEFUN (show_bgp_community,
7940 show_bgp_community_cmd,
7941 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7942 SHOW_STR
7943 BGP_STR
7944 "Display routes matching the communities\n"
7945 "community number\n"
7946 "Do not send outside local AS (well-known community)\n"
7947 "Do not advertise to any peer (well-known community)\n"
7948 "Do not export to next AS (well-known community)\n")
7949{
7950 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7951}
7952
7953ALIAS (show_bgp_community,
7954 show_bgp_ipv6_community_cmd,
7955 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7956 SHOW_STR
7957 BGP_STR
7958 "Address family\n"
7959 "Display routes matching the communities\n"
7960 "community number\n"
7961 "Do not send outside local AS (well-known community)\n"
7962 "Do not advertise to any peer (well-known community)\n"
7963 "Do not export to next AS (well-known community)\n")
7964
7965ALIAS (show_bgp_community,
7966 show_bgp_community2_cmd,
7967 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7968 SHOW_STR
7969 BGP_STR
7970 "Display routes matching the communities\n"
7971 "community number\n"
7972 "Do not send outside local AS (well-known community)\n"
7973 "Do not advertise to any peer (well-known community)\n"
7974 "Do not export to next AS (well-known community)\n"
7975 "community number\n"
7976 "Do not send outside local AS (well-known community)\n"
7977 "Do not advertise to any peer (well-known community)\n"
7978 "Do not export to next AS (well-known community)\n")
7979
7980ALIAS (show_bgp_community,
7981 show_bgp_ipv6_community2_cmd,
7982 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7983 SHOW_STR
7984 BGP_STR
7985 "Address family\n"
7986 "Display routes matching the communities\n"
7987 "community number\n"
7988 "Do not send outside local AS (well-known community)\n"
7989 "Do not advertise to any peer (well-known community)\n"
7990 "Do not export to next AS (well-known community)\n"
7991 "community number\n"
7992 "Do not send outside local AS (well-known community)\n"
7993 "Do not advertise to any peer (well-known community)\n"
7994 "Do not export to next AS (well-known community)\n")
7995
7996ALIAS (show_bgp_community,
7997 show_bgp_community3_cmd,
7998 "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)",
7999 SHOW_STR
8000 BGP_STR
8001 "Display routes matching the communities\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n"
8010 "community number\n"
8011 "Do not send outside local AS (well-known community)\n"
8012 "Do not advertise to any peer (well-known community)\n"
8013 "Do not export to next AS (well-known community)\n")
8014
8015ALIAS (show_bgp_community,
8016 show_bgp_ipv6_community3_cmd,
8017 "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)",
8018 SHOW_STR
8019 BGP_STR
8020 "Address family\n"
8021 "Display routes matching the communities\n"
8022 "community number\n"
8023 "Do not send outside local AS (well-known community)\n"
8024 "Do not advertise to any peer (well-known community)\n"
8025 "Do not export to next AS (well-known community)\n"
8026 "community number\n"
8027 "Do not send outside local AS (well-known community)\n"
8028 "Do not advertise to any peer (well-known community)\n"
8029 "Do not export to next AS (well-known community)\n"
8030 "community number\n"
8031 "Do not send outside local AS (well-known community)\n"
8032 "Do not advertise to any peer (well-known community)\n"
8033 "Do not export to next AS (well-known community)\n")
8034
8035ALIAS (show_bgp_community,
8036 show_bgp_community4_cmd,
8037 "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)",
8038 SHOW_STR
8039 BGP_STR
8040 "Display routes matching the communities\n"
8041 "community number\n"
8042 "Do not send outside local AS (well-known community)\n"
8043 "Do not advertise to any peer (well-known community)\n"
8044 "Do not export to next AS (well-known community)\n"
8045 "community number\n"
8046 "Do not send outside local AS (well-known community)\n"
8047 "Do not advertise to any peer (well-known community)\n"
8048 "Do not export to next AS (well-known community)\n"
8049 "community number\n"
8050 "Do not send outside local AS (well-known community)\n"
8051 "Do not advertise to any peer (well-known community)\n"
8052 "Do not export to next AS (well-known community)\n"
8053 "community number\n"
8054 "Do not send outside local AS (well-known community)\n"
8055 "Do not advertise to any peer (well-known community)\n"
8056 "Do not export to next AS (well-known community)\n")
8057
8058ALIAS (show_bgp_community,
8059 show_bgp_ipv6_community4_cmd,
8060 "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)",
8061 SHOW_STR
8062 BGP_STR
8063 "Address family\n"
8064 "Display routes matching the communities\n"
8065 "community number\n"
8066 "Do not send outside local AS (well-known community)\n"
8067 "Do not advertise to any peer (well-known community)\n"
8068 "Do not export to next AS (well-known community)\n"
8069 "community number\n"
8070 "Do not send outside local AS (well-known community)\n"
8071 "Do not advertise to any peer (well-known community)\n"
8072 "Do not export to next AS (well-known community)\n"
8073 "community number\n"
8074 "Do not send outside local AS (well-known community)\n"
8075 "Do not advertise to any peer (well-known community)\n"
8076 "Do not export to next AS (well-known community)\n"
8077 "community number\n"
8078 "Do not send outside local AS (well-known community)\n"
8079 "Do not advertise to any peer (well-known community)\n"
8080 "Do not export to next AS (well-known community)\n")
8081
8082/* old command */
8083DEFUN (show_ipv6_bgp_community,
8084 show_ipv6_bgp_community_cmd,
8085 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8086 SHOW_STR
8087 IPV6_STR
8088 BGP_STR
8089 "Display routes matching the communities\n"
8090 "community number\n"
8091 "Do not send outside local AS (well-known community)\n"
8092 "Do not advertise to any peer (well-known community)\n"
8093 "Do not export to next AS (well-known community)\n")
8094{
8095 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8096}
8097
8098/* old command */
8099ALIAS (show_ipv6_bgp_community,
8100 show_ipv6_bgp_community2_cmd,
8101 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8102 SHOW_STR
8103 IPV6_STR
8104 BGP_STR
8105 "Display routes matching the communities\n"
8106 "community number\n"
8107 "Do not send outside local AS (well-known community)\n"
8108 "Do not advertise to any peer (well-known community)\n"
8109 "Do not export to next AS (well-known community)\n"
8110 "community number\n"
8111 "Do not send outside local AS (well-known community)\n"
8112 "Do not advertise to any peer (well-known community)\n"
8113 "Do not export to next AS (well-known community)\n")
8114
8115/* old command */
8116ALIAS (show_ipv6_bgp_community,
8117 show_ipv6_bgp_community3_cmd,
8118 "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)",
8119 SHOW_STR
8120 IPV6_STR
8121 BGP_STR
8122 "Display routes matching the communities\n"
8123 "community number\n"
8124 "Do not send outside local AS (well-known community)\n"
8125 "Do not advertise to any peer (well-known community)\n"
8126 "Do not export to next AS (well-known community)\n"
8127 "community number\n"
8128 "Do not send outside local AS (well-known community)\n"
8129 "Do not advertise to any peer (well-known community)\n"
8130 "Do not export to next AS (well-known community)\n"
8131 "community number\n"
8132 "Do not send outside local AS (well-known community)\n"
8133 "Do not advertise to any peer (well-known community)\n"
8134 "Do not export to next AS (well-known community)\n")
8135
8136/* old command */
8137ALIAS (show_ipv6_bgp_community,
8138 show_ipv6_bgp_community4_cmd,
8139 "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)",
8140 SHOW_STR
8141 IPV6_STR
8142 BGP_STR
8143 "Display routes matching the communities\n"
8144 "community number\n"
8145 "Do not send outside local AS (well-known community)\n"
8146 "Do not advertise to any peer (well-known community)\n"
8147 "Do not export to next AS (well-known community)\n"
8148 "community number\n"
8149 "Do not send outside local AS (well-known community)\n"
8150 "Do not advertise to any peer (well-known community)\n"
8151 "Do not export to next AS (well-known community)\n"
8152 "community number\n"
8153 "Do not send outside local AS (well-known community)\n"
8154 "Do not advertise to any peer (well-known community)\n"
8155 "Do not export to next AS (well-known community)\n"
8156 "community number\n"
8157 "Do not send outside local AS (well-known community)\n"
8158 "Do not advertise to any peer (well-known community)\n"
8159 "Do not export to next AS (well-known community)\n")
8160
8161DEFUN (show_bgp_community_exact,
8162 show_bgp_community_exact_cmd,
8163 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8164 SHOW_STR
8165 BGP_STR
8166 "Display routes matching the communities\n"
8167 "community number\n"
8168 "Do not send outside local AS (well-known community)\n"
8169 "Do not advertise to any peer (well-known community)\n"
8170 "Do not export to next AS (well-known community)\n"
8171 "Exact match of the communities")
8172{
8173 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8174}
8175
8176ALIAS (show_bgp_community_exact,
8177 show_bgp_ipv6_community_exact_cmd,
8178 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8179 SHOW_STR
8180 BGP_STR
8181 "Address family\n"
8182 "Display routes matching the communities\n"
8183 "community number\n"
8184 "Do not send outside local AS (well-known community)\n"
8185 "Do not advertise to any peer (well-known community)\n"
8186 "Do not export to next AS (well-known community)\n"
8187 "Exact match of the communities")
8188
8189ALIAS (show_bgp_community_exact,
8190 show_bgp_community2_exact_cmd,
8191 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8192 SHOW_STR
8193 BGP_STR
8194 "Display routes matching the communities\n"
8195 "community number\n"
8196 "Do not send outside local AS (well-known community)\n"
8197 "Do not advertise to any peer (well-known community)\n"
8198 "Do not export to next AS (well-known community)\n"
8199 "community number\n"
8200 "Do not send outside local AS (well-known community)\n"
8201 "Do not advertise to any peer (well-known community)\n"
8202 "Do not export to next AS (well-known community)\n"
8203 "Exact match of the communities")
8204
8205ALIAS (show_bgp_community_exact,
8206 show_bgp_ipv6_community2_exact_cmd,
8207 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8208 SHOW_STR
8209 BGP_STR
8210 "Address family\n"
8211 "Display routes matching the communities\n"
8212 "community number\n"
8213 "Do not send outside local AS (well-known community)\n"
8214 "Do not advertise to any peer (well-known community)\n"
8215 "Do not export to next AS (well-known community)\n"
8216 "community number\n"
8217 "Do not send outside local AS (well-known community)\n"
8218 "Do not advertise to any peer (well-known community)\n"
8219 "Do not export to next AS (well-known community)\n"
8220 "Exact match of the communities")
8221
8222ALIAS (show_bgp_community_exact,
8223 show_bgp_community3_exact_cmd,
8224 "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",
8225 SHOW_STR
8226 BGP_STR
8227 "Display routes matching the communities\n"
8228 "community number\n"
8229 "Do not send outside local AS (well-known community)\n"
8230 "Do not advertise to any peer (well-known community)\n"
8231 "Do not export to next AS (well-known community)\n"
8232 "community number\n"
8233 "Do not send outside local AS (well-known community)\n"
8234 "Do not advertise to any peer (well-known community)\n"
8235 "Do not export to next AS (well-known community)\n"
8236 "community number\n"
8237 "Do not send outside local AS (well-known community)\n"
8238 "Do not advertise to any peer (well-known community)\n"
8239 "Do not export to next AS (well-known community)\n"
8240 "Exact match of the communities")
8241
8242ALIAS (show_bgp_community_exact,
8243 show_bgp_ipv6_community3_exact_cmd,
8244 "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",
8245 SHOW_STR
8246 BGP_STR
8247 "Address family\n"
8248 "Display routes matching the communities\n"
8249 "community number\n"
8250 "Do not send outside local AS (well-known community)\n"
8251 "Do not advertise to any peer (well-known community)\n"
8252 "Do not export to next AS (well-known community)\n"
8253 "community number\n"
8254 "Do not send outside local AS (well-known community)\n"
8255 "Do not advertise to any peer (well-known community)\n"
8256 "Do not export to next AS (well-known community)\n"
8257 "community number\n"
8258 "Do not send outside local AS (well-known community)\n"
8259 "Do not advertise to any peer (well-known community)\n"
8260 "Do not export to next AS (well-known community)\n"
8261 "Exact match of the communities")
8262
8263ALIAS (show_bgp_community_exact,
8264 show_bgp_community4_exact_cmd,
8265 "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",
8266 SHOW_STR
8267 BGP_STR
8268 "Display routes matching the communities\n"
8269 "community number\n"
8270 "Do not send outside local AS (well-known community)\n"
8271 "Do not advertise to any peer (well-known community)\n"
8272 "Do not export to next AS (well-known community)\n"
8273 "community number\n"
8274 "Do not send outside local AS (well-known community)\n"
8275 "Do not advertise to any peer (well-known community)\n"
8276 "Do not export to next AS (well-known community)\n"
8277 "community number\n"
8278 "Do not send outside local AS (well-known community)\n"
8279 "Do not advertise to any peer (well-known community)\n"
8280 "Do not export to next AS (well-known community)\n"
8281 "community number\n"
8282 "Do not send outside local AS (well-known community)\n"
8283 "Do not advertise to any peer (well-known community)\n"
8284 "Do not export to next AS (well-known community)\n"
8285 "Exact match of the communities")
8286
8287ALIAS (show_bgp_community_exact,
8288 show_bgp_ipv6_community4_exact_cmd,
8289 "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",
8290 SHOW_STR
8291 BGP_STR
8292 "Address family\n"
8293 "Display routes matching the communities\n"
8294 "community number\n"
8295 "Do not send outside local AS (well-known community)\n"
8296 "Do not advertise to any peer (well-known community)\n"
8297 "Do not export to next AS (well-known community)\n"
8298 "community number\n"
8299 "Do not send outside local AS (well-known community)\n"
8300 "Do not advertise to any peer (well-known community)\n"
8301 "Do not export to next AS (well-known community)\n"
8302 "community number\n"
8303 "Do not send outside local AS (well-known community)\n"
8304 "Do not advertise to any peer (well-known community)\n"
8305 "Do not export to next AS (well-known community)\n"
8306 "community number\n"
8307 "Do not send outside local AS (well-known community)\n"
8308 "Do not advertise to any peer (well-known community)\n"
8309 "Do not export to next AS (well-known community)\n"
8310 "Exact match of the communities")
8311
8312/* old command */
8313DEFUN (show_ipv6_bgp_community_exact,
8314 show_ipv6_bgp_community_exact_cmd,
8315 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8316 SHOW_STR
8317 IPV6_STR
8318 BGP_STR
8319 "Display routes matching the communities\n"
8320 "community number\n"
8321 "Do not send outside local AS (well-known community)\n"
8322 "Do not advertise to any peer (well-known community)\n"
8323 "Do not export to next AS (well-known community)\n"
8324 "Exact match of the communities")
8325{
8326 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8327}
8328
8329/* old command */
8330ALIAS (show_ipv6_bgp_community_exact,
8331 show_ipv6_bgp_community2_exact_cmd,
8332 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8333 SHOW_STR
8334 IPV6_STR
8335 BGP_STR
8336 "Display routes matching the communities\n"
8337 "community number\n"
8338 "Do not send outside local AS (well-known community)\n"
8339 "Do not advertise to any peer (well-known community)\n"
8340 "Do not export to next AS (well-known community)\n"
8341 "community number\n"
8342 "Do not send outside local AS (well-known community)\n"
8343 "Do not advertise to any peer (well-known community)\n"
8344 "Do not export to next AS (well-known community)\n"
8345 "Exact match of the communities")
8346
8347/* old command */
8348ALIAS (show_ipv6_bgp_community_exact,
8349 show_ipv6_bgp_community3_exact_cmd,
8350 "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",
8351 SHOW_STR
8352 IPV6_STR
8353 BGP_STR
8354 "Display routes matching the communities\n"
8355 "community number\n"
8356 "Do not send outside local AS (well-known community)\n"
8357 "Do not advertise to any peer (well-known community)\n"
8358 "Do not export to next AS (well-known community)\n"
8359 "community number\n"
8360 "Do not send outside local AS (well-known community)\n"
8361 "Do not advertise to any peer (well-known community)\n"
8362 "Do not export to next AS (well-known community)\n"
8363 "community number\n"
8364 "Do not send outside local AS (well-known community)\n"
8365 "Do not advertise to any peer (well-known community)\n"
8366 "Do not export to next AS (well-known community)\n"
8367 "Exact match of the communities")
8368
8369/* old command */
8370ALIAS (show_ipv6_bgp_community_exact,
8371 show_ipv6_bgp_community4_exact_cmd,
8372 "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",
8373 SHOW_STR
8374 IPV6_STR
8375 BGP_STR
8376 "Display routes matching the communities\n"
8377 "community number\n"
8378 "Do not send outside local AS (well-known community)\n"
8379 "Do not advertise to any peer (well-known community)\n"
8380 "Do not export to next AS (well-known community)\n"
8381 "community number\n"
8382 "Do not send outside local AS (well-known community)\n"
8383 "Do not advertise to any peer (well-known community)\n"
8384 "Do not export to next AS (well-known community)\n"
8385 "community number\n"
8386 "Do not send outside local AS (well-known community)\n"
8387 "Do not advertise to any peer (well-known community)\n"
8388 "Do not export to next AS (well-known community)\n"
8389 "community number\n"
8390 "Do not send outside local AS (well-known community)\n"
8391 "Do not advertise to any peer (well-known community)\n"
8392 "Do not export to next AS (well-known community)\n"
8393 "Exact match of the communities")
8394
8395/* old command */
8396DEFUN (show_ipv6_mbgp_community,
8397 show_ipv6_mbgp_community_cmd,
8398 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8399 SHOW_STR
8400 IPV6_STR
8401 MBGP_STR
8402 "Display routes matching the communities\n"
8403 "community number\n"
8404 "Do not send outside local AS (well-known community)\n"
8405 "Do not advertise to any peer (well-known community)\n"
8406 "Do not export to next AS (well-known community)\n")
8407{
8408 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8409}
8410
8411/* old command */
8412ALIAS (show_ipv6_mbgp_community,
8413 show_ipv6_mbgp_community2_cmd,
8414 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8415 SHOW_STR
8416 IPV6_STR
8417 MBGP_STR
8418 "Display routes matching the communities\n"
8419 "community number\n"
8420 "Do not send outside local AS (well-known community)\n"
8421 "Do not advertise to any peer (well-known community)\n"
8422 "Do not export to next AS (well-known community)\n"
8423 "community number\n"
8424 "Do not send outside local AS (well-known community)\n"
8425 "Do not advertise to any peer (well-known community)\n"
8426 "Do not export to next AS (well-known community)\n")
8427
8428/* old command */
8429ALIAS (show_ipv6_mbgp_community,
8430 show_ipv6_mbgp_community3_cmd,
8431 "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)",
8432 SHOW_STR
8433 IPV6_STR
8434 MBGP_STR
8435 "Display routes matching the communities\n"
8436 "community number\n"
8437 "Do not send outside local AS (well-known community)\n"
8438 "Do not advertise to any peer (well-known community)\n"
8439 "Do not export to next AS (well-known community)\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n")
8448
8449/* old command */
8450ALIAS (show_ipv6_mbgp_community,
8451 show_ipv6_mbgp_community4_cmd,
8452 "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)",
8453 SHOW_STR
8454 IPV6_STR
8455 MBGP_STR
8456 "Display routes matching the communities\n"
8457 "community number\n"
8458 "Do not send outside local AS (well-known community)\n"
8459 "Do not advertise to any peer (well-known community)\n"
8460 "Do not export to next AS (well-known community)\n"
8461 "community number\n"
8462 "Do not send outside local AS (well-known community)\n"
8463 "Do not advertise to any peer (well-known community)\n"
8464 "Do not export to next AS (well-known community)\n"
8465 "community number\n"
8466 "Do not send outside local AS (well-known community)\n"
8467 "Do not advertise to any peer (well-known community)\n"
8468 "Do not export to next AS (well-known community)\n"
8469 "community number\n"
8470 "Do not send outside local AS (well-known community)\n"
8471 "Do not advertise to any peer (well-known community)\n"
8472 "Do not export to next AS (well-known community)\n")
8473
8474/* old command */
8475DEFUN (show_ipv6_mbgp_community_exact,
8476 show_ipv6_mbgp_community_exact_cmd,
8477 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8478 SHOW_STR
8479 IPV6_STR
8480 MBGP_STR
8481 "Display routes matching the communities\n"
8482 "community number\n"
8483 "Do not send outside local AS (well-known community)\n"
8484 "Do not advertise to any peer (well-known community)\n"
8485 "Do not export to next AS (well-known community)\n"
8486 "Exact match of the communities")
8487{
8488 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8489}
8490
8491/* old command */
8492ALIAS (show_ipv6_mbgp_community_exact,
8493 show_ipv6_mbgp_community2_exact_cmd,
8494 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8495 SHOW_STR
8496 IPV6_STR
8497 MBGP_STR
8498 "Display routes matching the communities\n"
8499 "community number\n"
8500 "Do not send outside local AS (well-known community)\n"
8501 "Do not advertise to any peer (well-known community)\n"
8502 "Do not export to next AS (well-known community)\n"
8503 "community number\n"
8504 "Do not send outside local AS (well-known community)\n"
8505 "Do not advertise to any peer (well-known community)\n"
8506 "Do not export to next AS (well-known community)\n"
8507 "Exact match of the communities")
8508
8509/* old command */
8510ALIAS (show_ipv6_mbgp_community_exact,
8511 show_ipv6_mbgp_community3_exact_cmd,
8512 "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",
8513 SHOW_STR
8514 IPV6_STR
8515 MBGP_STR
8516 "Display routes matching the communities\n"
8517 "community number\n"
8518 "Do not send outside local AS (well-known community)\n"
8519 "Do not advertise to any peer (well-known community)\n"
8520 "Do not export to next AS (well-known community)\n"
8521 "community number\n"
8522 "Do not send outside local AS (well-known community)\n"
8523 "Do not advertise to any peer (well-known community)\n"
8524 "Do not export to next AS (well-known community)\n"
8525 "community number\n"
8526 "Do not send outside local AS (well-known community)\n"
8527 "Do not advertise to any peer (well-known community)\n"
8528 "Do not export to next AS (well-known community)\n"
8529 "Exact match of the communities")
8530
8531/* old command */
8532ALIAS (show_ipv6_mbgp_community_exact,
8533 show_ipv6_mbgp_community4_exact_cmd,
8534 "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",
8535 SHOW_STR
8536 IPV6_STR
8537 MBGP_STR
8538 "Display routes matching the communities\n"
8539 "community number\n"
8540 "Do not send outside local AS (well-known community)\n"
8541 "Do not advertise to any peer (well-known community)\n"
8542 "Do not export to next AS (well-known community)\n"
8543 "community number\n"
8544 "Do not send outside local AS (well-known community)\n"
8545 "Do not advertise to any peer (well-known community)\n"
8546 "Do not export to next AS (well-known community)\n"
8547 "community number\n"
8548 "Do not send outside local AS (well-known community)\n"
8549 "Do not advertise to any peer (well-known community)\n"
8550 "Do not export to next AS (well-known community)\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "Exact match of the communities")
8556#endif /* HAVE_IPV6 */
8557
paul94f2b392005-06-28 12:44:16 +00008558static int
paulfd79ac92004-10-13 05:06:08 +00008559bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008560 u_int16_t afi, u_char safi)
8561{
8562 struct community_list *list;
8563
hassofee6e4e2005-02-02 16:29:31 +00008564 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008565 if (list == NULL)
8566 {
8567 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8568 VTY_NEWLINE);
8569 return CMD_WARNING;
8570 }
8571
ajs5a646652004-11-05 01:25:55 +00008572 return bgp_show (vty, NULL, afi, safi,
8573 (exact ? bgp_show_type_community_list_exact :
8574 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008575}
8576
8577DEFUN (show_ip_bgp_community_list,
8578 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008579 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008580 SHOW_STR
8581 IP_STR
8582 BGP_STR
8583 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008584 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008585 "community-list name\n")
8586{
8587 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8588}
8589
8590DEFUN (show_ip_bgp_ipv4_community_list,
8591 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008592 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008593 SHOW_STR
8594 IP_STR
8595 BGP_STR
8596 "Address family\n"
8597 "Address Family modifier\n"
8598 "Address Family modifier\n"
8599 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008600 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008601 "community-list name\n")
8602{
8603 if (strncmp (argv[0], "m", 1) == 0)
8604 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8605
8606 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8607}
8608
8609DEFUN (show_ip_bgp_community_list_exact,
8610 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008611 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008612 SHOW_STR
8613 IP_STR
8614 BGP_STR
8615 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008616 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008617 "community-list name\n"
8618 "Exact match of the communities\n")
8619{
8620 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8621}
8622
8623DEFUN (show_ip_bgp_ipv4_community_list_exact,
8624 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008625 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008626 SHOW_STR
8627 IP_STR
8628 BGP_STR
8629 "Address family\n"
8630 "Address Family modifier\n"
8631 "Address Family modifier\n"
8632 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008633 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008634 "community-list name\n"
8635 "Exact match of the communities\n")
8636{
8637 if (strncmp (argv[0], "m", 1) == 0)
8638 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8639
8640 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8641}
8642
8643#ifdef HAVE_IPV6
8644DEFUN (show_bgp_community_list,
8645 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008646 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008647 SHOW_STR
8648 BGP_STR
8649 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008650 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008651 "community-list name\n")
8652{
8653 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8654}
8655
8656ALIAS (show_bgp_community_list,
8657 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008658 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008659 SHOW_STR
8660 BGP_STR
8661 "Address family\n"
8662 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008663 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008664 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008665
8666/* old command */
8667DEFUN (show_ipv6_bgp_community_list,
8668 show_ipv6_bgp_community_list_cmd,
8669 "show ipv6 bgp community-list WORD",
8670 SHOW_STR
8671 IPV6_STR
8672 BGP_STR
8673 "Display routes matching the community-list\n"
8674 "community-list name\n")
8675{
8676 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8677}
8678
8679/* old command */
8680DEFUN (show_ipv6_mbgp_community_list,
8681 show_ipv6_mbgp_community_list_cmd,
8682 "show ipv6 mbgp community-list WORD",
8683 SHOW_STR
8684 IPV6_STR
8685 MBGP_STR
8686 "Display routes matching the community-list\n"
8687 "community-list name\n")
8688{
8689 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8690}
8691
8692DEFUN (show_bgp_community_list_exact,
8693 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008694 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008695 SHOW_STR
8696 BGP_STR
8697 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008698 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008699 "community-list name\n"
8700 "Exact match of the communities\n")
8701{
8702 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8703}
8704
8705ALIAS (show_bgp_community_list_exact,
8706 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008707 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008708 SHOW_STR
8709 BGP_STR
8710 "Address family\n"
8711 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008712 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008713 "community-list name\n"
8714 "Exact match of the communities\n")
8715
8716/* old command */
8717DEFUN (show_ipv6_bgp_community_list_exact,
8718 show_ipv6_bgp_community_list_exact_cmd,
8719 "show ipv6 bgp community-list WORD exact-match",
8720 SHOW_STR
8721 IPV6_STR
8722 BGP_STR
8723 "Display routes matching the community-list\n"
8724 "community-list name\n"
8725 "Exact match of the communities\n")
8726{
8727 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8728}
8729
8730/* old command */
8731DEFUN (show_ipv6_mbgp_community_list_exact,
8732 show_ipv6_mbgp_community_list_exact_cmd,
8733 "show ipv6 mbgp community-list WORD exact-match",
8734 SHOW_STR
8735 IPV6_STR
8736 MBGP_STR
8737 "Display routes matching the community-list\n"
8738 "community-list name\n"
8739 "Exact match of the communities\n")
8740{
8741 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8742}
8743#endif /* HAVE_IPV6 */
8744
paul94f2b392005-06-28 12:44:16 +00008745static int
paulfd79ac92004-10-13 05:06:08 +00008746bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008747 safi_t safi, enum bgp_show_type type)
8748{
8749 int ret;
8750 struct prefix *p;
8751
8752 p = prefix_new();
8753
8754 ret = str2prefix (prefix, p);
8755 if (! ret)
8756 {
8757 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8758 return CMD_WARNING;
8759 }
8760
ajs5a646652004-11-05 01:25:55 +00008761 ret = bgp_show (vty, NULL, afi, safi, type, p);
8762 prefix_free(p);
8763 return ret;
paul718e3742002-12-13 20:15:29 +00008764}
8765
8766DEFUN (show_ip_bgp_prefix_longer,
8767 show_ip_bgp_prefix_longer_cmd,
8768 "show ip bgp A.B.C.D/M longer-prefixes",
8769 SHOW_STR
8770 IP_STR
8771 BGP_STR
8772 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8773 "Display route and more specific routes\n")
8774{
8775 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8776 bgp_show_type_prefix_longer);
8777}
8778
8779DEFUN (show_ip_bgp_flap_prefix_longer,
8780 show_ip_bgp_flap_prefix_longer_cmd,
8781 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8782 SHOW_STR
8783 IP_STR
8784 BGP_STR
8785 "Display flap statistics of routes\n"
8786 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8787 "Display route and more specific routes\n")
8788{
8789 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8790 bgp_show_type_flap_prefix_longer);
8791}
8792
8793DEFUN (show_ip_bgp_ipv4_prefix_longer,
8794 show_ip_bgp_ipv4_prefix_longer_cmd,
8795 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8796 SHOW_STR
8797 IP_STR
8798 BGP_STR
8799 "Address family\n"
8800 "Address Family modifier\n"
8801 "Address Family modifier\n"
8802 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8803 "Display route and more specific routes\n")
8804{
8805 if (strncmp (argv[0], "m", 1) == 0)
8806 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8807 bgp_show_type_prefix_longer);
8808
8809 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8810 bgp_show_type_prefix_longer);
8811}
8812
8813DEFUN (show_ip_bgp_flap_address,
8814 show_ip_bgp_flap_address_cmd,
8815 "show ip bgp flap-statistics A.B.C.D",
8816 SHOW_STR
8817 IP_STR
8818 BGP_STR
8819 "Display flap statistics of routes\n"
8820 "Network in the BGP routing table to display\n")
8821{
8822 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8823 bgp_show_type_flap_address);
8824}
8825
8826DEFUN (show_ip_bgp_flap_prefix,
8827 show_ip_bgp_flap_prefix_cmd,
8828 "show ip bgp flap-statistics A.B.C.D/M",
8829 SHOW_STR
8830 IP_STR
8831 BGP_STR
8832 "Display flap statistics of routes\n"
8833 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8834{
8835 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8836 bgp_show_type_flap_prefix);
8837}
8838#ifdef HAVE_IPV6
8839DEFUN (show_bgp_prefix_longer,
8840 show_bgp_prefix_longer_cmd,
8841 "show bgp X:X::X:X/M longer-prefixes",
8842 SHOW_STR
8843 BGP_STR
8844 "IPv6 prefix <network>/<length>\n"
8845 "Display route and more specific routes\n")
8846{
8847 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8848 bgp_show_type_prefix_longer);
8849}
8850
8851ALIAS (show_bgp_prefix_longer,
8852 show_bgp_ipv6_prefix_longer_cmd,
8853 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8854 SHOW_STR
8855 BGP_STR
8856 "Address family\n"
8857 "IPv6 prefix <network>/<length>\n"
8858 "Display route and more specific routes\n")
8859
8860/* old command */
8861DEFUN (show_ipv6_bgp_prefix_longer,
8862 show_ipv6_bgp_prefix_longer_cmd,
8863 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8864 SHOW_STR
8865 IPV6_STR
8866 BGP_STR
8867 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8868 "Display route and more specific routes\n")
8869{
8870 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8871 bgp_show_type_prefix_longer);
8872}
8873
8874/* old command */
8875DEFUN (show_ipv6_mbgp_prefix_longer,
8876 show_ipv6_mbgp_prefix_longer_cmd,
8877 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8878 SHOW_STR
8879 IPV6_STR
8880 MBGP_STR
8881 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8882 "Display route and more specific routes\n")
8883{
8884 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8885 bgp_show_type_prefix_longer);
8886}
8887#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008888
paul94f2b392005-06-28 12:44:16 +00008889static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008890peer_lookup_in_view (struct vty *vty, const char *view_name,
8891 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008892{
8893 int ret;
8894 struct bgp *bgp;
8895 struct peer *peer;
8896 union sockunion su;
8897
8898 /* BGP structure lookup. */
8899 if (view_name)
8900 {
8901 bgp = bgp_lookup_by_name (view_name);
8902 if (! bgp)
8903 {
8904 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8905 return NULL;
8906 }
8907 }
paul5228ad22004-06-04 17:58:18 +00008908 else
paulbb46e942003-10-24 19:02:03 +00008909 {
8910 bgp = bgp_get_default ();
8911 if (! bgp)
8912 {
8913 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8914 return NULL;
8915 }
8916 }
8917
8918 /* Get peer sockunion. */
8919 ret = str2sockunion (ip_str, &su);
8920 if (ret < 0)
8921 {
8922 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8923 return NULL;
8924 }
8925
8926 /* Peer structure lookup. */
8927 peer = peer_lookup (bgp, &su);
8928 if (! peer)
8929 {
8930 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8931 return NULL;
8932 }
8933
8934 return peer;
8935}
Paul Jakma2815e612006-09-14 02:56:07 +00008936
8937enum bgp_stats
8938{
8939 BGP_STATS_MAXBITLEN = 0,
8940 BGP_STATS_RIB,
8941 BGP_STATS_PREFIXES,
8942 BGP_STATS_TOTPLEN,
8943 BGP_STATS_UNAGGREGATEABLE,
8944 BGP_STATS_MAX_AGGREGATEABLE,
8945 BGP_STATS_AGGREGATES,
8946 BGP_STATS_SPACE,
8947 BGP_STATS_ASPATH_COUNT,
8948 BGP_STATS_ASPATH_MAXHOPS,
8949 BGP_STATS_ASPATH_TOTHOPS,
8950 BGP_STATS_ASPATH_MAXSIZE,
8951 BGP_STATS_ASPATH_TOTSIZE,
8952 BGP_STATS_ASN_HIGHEST,
8953 BGP_STATS_MAX,
8954};
paulbb46e942003-10-24 19:02:03 +00008955
Paul Jakma2815e612006-09-14 02:56:07 +00008956static const char *table_stats_strs[] =
8957{
8958 [BGP_STATS_PREFIXES] = "Total Prefixes",
8959 [BGP_STATS_TOTPLEN] = "Average prefix length",
8960 [BGP_STATS_RIB] = "Total Advertisements",
8961 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8962 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8963 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8964 [BGP_STATS_SPACE] = "Address space advertised",
8965 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8966 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8967 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8968 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8969 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8970 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8971 [BGP_STATS_MAX] = NULL,
8972};
8973
8974struct bgp_table_stats
8975{
8976 struct bgp_table *table;
8977 unsigned long long counts[BGP_STATS_MAX];
8978};
8979
8980#if 0
8981#define TALLY_SIGFIG 100000
8982static unsigned long
8983ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8984{
8985 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8986 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8987 unsigned long ret = newtot / count;
8988
8989 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
8990 return ret + 1;
8991 else
8992 return ret;
8993}
8994#endif
8995
8996static int
8997bgp_table_stats_walker (struct thread *t)
8998{
8999 struct bgp_node *rn;
9000 struct bgp_node *top;
9001 struct bgp_table_stats *ts = THREAD_ARG (t);
9002 unsigned int space = 0;
9003
Paul Jakma53d9f672006-10-15 23:41:16 +00009004 if (!(top = bgp_table_top (ts->table)))
9005 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009006
9007 switch (top->p.family)
9008 {
9009 case AF_INET:
9010 space = IPV4_MAX_BITLEN;
9011 break;
9012 case AF_INET6:
9013 space = IPV6_MAX_BITLEN;
9014 break;
9015 }
9016
9017 ts->counts[BGP_STATS_MAXBITLEN] = space;
9018
9019 for (rn = top; rn; rn = bgp_route_next (rn))
9020 {
9021 struct bgp_info *ri;
9022 struct bgp_node *prn = rn->parent;
9023 unsigned int rinum = 0;
9024
9025 if (rn == top)
9026 continue;
9027
9028 if (!rn->info)
9029 continue;
9030
9031 ts->counts[BGP_STATS_PREFIXES]++;
9032 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9033
9034#if 0
9035 ts->counts[BGP_STATS_AVGPLEN]
9036 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9037 ts->counts[BGP_STATS_AVGPLEN],
9038 rn->p.prefixlen);
9039#endif
9040
9041 /* check if the prefix is included by any other announcements */
9042 while (prn && !prn->info)
9043 prn = prn->parent;
9044
9045 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009046 {
9047 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9048 /* announced address space */
9049 if (space)
9050 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9051 }
Paul Jakma2815e612006-09-14 02:56:07 +00009052 else if (prn->info)
9053 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9054
Paul Jakma2815e612006-09-14 02:56:07 +00009055 for (ri = rn->info; ri; ri = ri->next)
9056 {
9057 rinum++;
9058 ts->counts[BGP_STATS_RIB]++;
9059
9060 if (ri->attr &&
9061 (CHECK_FLAG (ri->attr->flag,
9062 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9063 ts->counts[BGP_STATS_AGGREGATES]++;
9064
9065 /* as-path stats */
9066 if (ri->attr && ri->attr->aspath)
9067 {
9068 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9069 unsigned int size = aspath_size (ri->attr->aspath);
9070 as_t highest = aspath_highest (ri->attr->aspath);
9071
9072 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9073
9074 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9075 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9076
9077 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9078 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9079
9080 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9081 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9082#if 0
9083 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9084 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9085 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9086 hops);
9087 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9088 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9089 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9090 size);
9091#endif
9092 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9093 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9094 }
9095 }
9096 }
9097 return 0;
9098}
9099
9100static int
9101bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9102{
9103 struct bgp_table_stats ts;
9104 unsigned int i;
9105
9106 if (!bgp->rib[afi][safi])
9107 {
9108 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9109 return CMD_WARNING;
9110 }
9111
9112 memset (&ts, 0, sizeof (ts));
9113 ts.table = bgp->rib[afi][safi];
9114 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9115
9116 vty_out (vty, "BGP %s RIB statistics%s%s",
9117 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9118
9119 for (i = 0; i < BGP_STATS_MAX; i++)
9120 {
9121 if (!table_stats_strs[i])
9122 continue;
9123
9124 switch (i)
9125 {
9126#if 0
9127 case BGP_STATS_ASPATH_AVGHOPS:
9128 case BGP_STATS_ASPATH_AVGSIZE:
9129 case BGP_STATS_AVGPLEN:
9130 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9131 vty_out (vty, "%12.2f",
9132 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9133 break;
9134#endif
9135 case BGP_STATS_ASPATH_TOTHOPS:
9136 case BGP_STATS_ASPATH_TOTSIZE:
9137 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9138 vty_out (vty, "%12.2f",
9139 ts.counts[i] ?
9140 (float)ts.counts[i] /
9141 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9142 : 0);
9143 break;
9144 case BGP_STATS_TOTPLEN:
9145 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9146 vty_out (vty, "%12.2f",
9147 ts.counts[i] ?
9148 (float)ts.counts[i] /
9149 (float)ts.counts[BGP_STATS_PREFIXES]
9150 : 0);
9151 break;
9152 case BGP_STATS_SPACE:
9153 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9154 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9155 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9156 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009157 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009158 vty_out (vty, "%12.2f%s",
9159 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009160 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009161 VTY_NEWLINE);
9162 vty_out (vty, "%30s: ", "/8 equivalent ");
9163 vty_out (vty, "%12.2f%s",
9164 (float)ts.counts[BGP_STATS_SPACE] /
9165 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9166 VTY_NEWLINE);
9167 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9168 break;
9169 vty_out (vty, "%30s: ", "/24 equivalent ");
9170 vty_out (vty, "%12.2f",
9171 (float)ts.counts[BGP_STATS_SPACE] /
9172 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9173 break;
9174 default:
9175 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9176 vty_out (vty, "%12llu", ts.counts[i]);
9177 }
9178
9179 vty_out (vty, "%s", VTY_NEWLINE);
9180 }
9181 return CMD_SUCCESS;
9182}
9183
9184static int
9185bgp_table_stats_vty (struct vty *vty, const char *name,
9186 const char *afi_str, const char *safi_str)
9187{
9188 struct bgp *bgp;
9189 afi_t afi;
9190 safi_t safi;
9191
9192 if (name)
9193 bgp = bgp_lookup_by_name (name);
9194 else
9195 bgp = bgp_get_default ();
9196
9197 if (!bgp)
9198 {
9199 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9200 return CMD_WARNING;
9201 }
9202 if (strncmp (afi_str, "ipv", 3) == 0)
9203 {
9204 if (strncmp (afi_str, "ipv4", 4) == 0)
9205 afi = AFI_IP;
9206 else if (strncmp (afi_str, "ipv6", 4) == 0)
9207 afi = AFI_IP6;
9208 else
9209 {
9210 vty_out (vty, "%% Invalid address family %s%s",
9211 afi_str, VTY_NEWLINE);
9212 return CMD_WARNING;
9213 }
9214 if (strncmp (safi_str, "m", 1) == 0)
9215 safi = SAFI_MULTICAST;
9216 else if (strncmp (safi_str, "u", 1) == 0)
9217 safi = SAFI_UNICAST;
9218 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9219 safi = BGP_SAFI_VPNV4;
9220 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9221 safi = BGP_SAFI_VPNV6;
9222 else
9223 {
9224 vty_out (vty, "%% Invalid subsequent address family %s%s",
9225 safi_str, VTY_NEWLINE);
9226 return CMD_WARNING;
9227 }
9228 }
9229 else
9230 {
9231 vty_out (vty, "%% Invalid address family %s%s",
9232 afi_str, VTY_NEWLINE);
9233 return CMD_WARNING;
9234 }
9235
9236 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9237 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9238 {
9239 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9240 afi_str, safi_str, VTY_NEWLINE);
9241 return CMD_WARNING;
9242 }
9243 return bgp_table_stats (vty, bgp, afi, safi);
9244}
9245
9246DEFUN (show_bgp_statistics,
9247 show_bgp_statistics_cmd,
9248 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9249 SHOW_STR
9250 BGP_STR
9251 "Address family\n"
9252 "Address family\n"
9253 "Address Family modifier\n"
9254 "Address Family modifier\n"
9255 "BGP RIB advertisement statistics\n")
9256{
9257 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9258}
9259
9260ALIAS (show_bgp_statistics,
9261 show_bgp_statistics_vpnv4_cmd,
9262 "show bgp (ipv4) (vpnv4) statistics",
9263 SHOW_STR
9264 BGP_STR
9265 "Address family\n"
9266 "Address Family modifier\n"
9267 "BGP RIB advertisement statistics\n")
9268
9269DEFUN (show_bgp_statistics_view,
9270 show_bgp_statistics_view_cmd,
9271 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9272 SHOW_STR
9273 BGP_STR
9274 "BGP view\n"
9275 "Address family\n"
9276 "Address family\n"
9277 "Address Family modifier\n"
9278 "Address Family modifier\n"
9279 "BGP RIB advertisement statistics\n")
9280{
9281 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9282}
9283
9284ALIAS (show_bgp_statistics_view,
9285 show_bgp_statistics_view_vpnv4_cmd,
9286 "show bgp view WORD (ipv4) (vpnv4) statistics",
9287 SHOW_STR
9288 BGP_STR
9289 "BGP view\n"
9290 "Address family\n"
9291 "Address Family modifier\n"
9292 "BGP RIB advertisement statistics\n")
9293
Paul Jakmaff7924f2006-09-04 01:10:36 +00009294enum bgp_pcounts
9295{
9296 PCOUNT_ADJ_IN = 0,
9297 PCOUNT_DAMPED,
9298 PCOUNT_REMOVED,
9299 PCOUNT_HISTORY,
9300 PCOUNT_STALE,
9301 PCOUNT_VALID,
9302 PCOUNT_ALL,
9303 PCOUNT_COUNTED,
9304 PCOUNT_PFCNT, /* the figure we display to users */
9305 PCOUNT_MAX,
9306};
9307
9308static const char *pcount_strs[] =
9309{
9310 [PCOUNT_ADJ_IN] = "Adj-in",
9311 [PCOUNT_DAMPED] = "Damped",
9312 [PCOUNT_REMOVED] = "Removed",
9313 [PCOUNT_HISTORY] = "History",
9314 [PCOUNT_STALE] = "Stale",
9315 [PCOUNT_VALID] = "Valid",
9316 [PCOUNT_ALL] = "All RIB",
9317 [PCOUNT_COUNTED] = "PfxCt counted",
9318 [PCOUNT_PFCNT] = "Useable",
9319 [PCOUNT_MAX] = NULL,
9320};
9321
Paul Jakma2815e612006-09-14 02:56:07 +00009322struct peer_pcounts
9323{
9324 unsigned int count[PCOUNT_MAX];
9325 const struct peer *peer;
9326 const struct bgp_table *table;
9327};
9328
Paul Jakmaff7924f2006-09-04 01:10:36 +00009329static int
Paul Jakma2815e612006-09-14 02:56:07 +00009330bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009331{
9332 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009333 struct peer_pcounts *pc = THREAD_ARG (t);
9334 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009335
Paul Jakma2815e612006-09-14 02:56:07 +00009336 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009337 {
9338 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009339 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009340
9341 for (ain = rn->adj_in; ain; ain = ain->next)
9342 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009343 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009344
Paul Jakmaff7924f2006-09-04 01:10:36 +00009345 for (ri = rn->info; ri; ri = ri->next)
9346 {
9347 char buf[SU_ADDRSTRLEN];
9348
9349 if (ri->peer != peer)
9350 continue;
9351
Paul Jakma2815e612006-09-14 02:56:07 +00009352 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009353
9354 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009355 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009356 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009357 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009358 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009359 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009360 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009361 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009362 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009363 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009364 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009365 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009366
9367 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9368 {
Paul Jakma2815e612006-09-14 02:56:07 +00009369 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009370 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009371 plog_warn (peer->log,
9372 "%s [pcount] %s/%d is counted but flags 0x%x",
9373 peer->host,
9374 inet_ntop(rn->p.family, &rn->p.u.prefix,
9375 buf, SU_ADDRSTRLEN),
9376 rn->p.prefixlen,
9377 ri->flags);
9378 }
9379 else
9380 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009381 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009382 plog_warn (peer->log,
9383 "%s [pcount] %s/%d not counted but flags 0x%x",
9384 peer->host,
9385 inet_ntop(rn->p.family, &rn->p.u.prefix,
9386 buf, SU_ADDRSTRLEN),
9387 rn->p.prefixlen,
9388 ri->flags);
9389 }
9390 }
9391 }
Paul Jakma2815e612006-09-14 02:56:07 +00009392 return 0;
9393}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009394
Paul Jakma2815e612006-09-14 02:56:07 +00009395static int
9396bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9397{
9398 struct peer_pcounts pcounts = { .peer = peer };
9399 unsigned int i;
9400
9401 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9402 || !peer->bgp->rib[afi][safi])
9403 {
9404 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9405 return CMD_WARNING;
9406 }
9407
9408 memset (&pcounts, 0, sizeof(pcounts));
9409 pcounts.peer = peer;
9410 pcounts.table = peer->bgp->rib[afi][safi];
9411
9412 /* in-place call via thread subsystem so as to record execution time
9413 * stats for the thread-walk (i.e. ensure this can't be blamed on
9414 * on just vty_read()).
9415 */
9416 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9417
Paul Jakmaff7924f2006-09-04 01:10:36 +00009418 vty_out (vty, "Prefix counts for %s, %s%s",
9419 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9420 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9421 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9422 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9423
9424 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009425 vty_out (vty, "%20s: %-10d%s",
9426 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009427
Paul Jakma2815e612006-09-14 02:56:07 +00009428 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009429 {
9430 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9431 peer->host, VTY_NEWLINE);
9432 vty_out (vty, "Please report this bug, with the above command output%s",
9433 VTY_NEWLINE);
9434 }
9435
9436 return CMD_SUCCESS;
9437}
9438
9439DEFUN (show_ip_bgp_neighbor_prefix_counts,
9440 show_ip_bgp_neighbor_prefix_counts_cmd,
9441 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9442 SHOW_STR
9443 IP_STR
9444 BGP_STR
9445 "Detailed information on TCP and BGP neighbor connections\n"
9446 "Neighbor to display information about\n"
9447 "Neighbor to display information about\n"
9448 "Display detailed prefix count information\n")
9449{
9450 struct peer *peer;
9451
9452 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9453 if (! peer)
9454 return CMD_WARNING;
9455
9456 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9457}
9458
9459DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9460 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9461 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9462 SHOW_STR
9463 BGP_STR
9464 "Address family\n"
9465 "Detailed information on TCP and BGP neighbor connections\n"
9466 "Neighbor to display information about\n"
9467 "Neighbor to display information about\n"
9468 "Display detailed prefix count information\n")
9469{
9470 struct peer *peer;
9471
9472 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9473 if (! peer)
9474 return CMD_WARNING;
9475
9476 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9477}
9478
9479DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9480 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9481 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9482 SHOW_STR
9483 IP_STR
9484 BGP_STR
9485 "Address family\n"
9486 "Address Family modifier\n"
9487 "Address Family modifier\n"
9488 "Detailed information on TCP and BGP neighbor connections\n"
9489 "Neighbor to display information about\n"
9490 "Neighbor to display information about\n"
9491 "Display detailed prefix count information\n")
9492{
9493 struct peer *peer;
9494
9495 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9496 if (! peer)
9497 return CMD_WARNING;
9498
9499 if (strncmp (argv[0], "m", 1) == 0)
9500 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9501
9502 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9503}
9504
9505DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9506 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9507 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9508 SHOW_STR
9509 IP_STR
9510 BGP_STR
9511 "Address family\n"
9512 "Address Family modifier\n"
9513 "Address Family modifier\n"
9514 "Detailed information on TCP and BGP neighbor connections\n"
9515 "Neighbor to display information about\n"
9516 "Neighbor to display information about\n"
9517 "Display detailed prefix count information\n")
9518{
9519 struct peer *peer;
9520
9521 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9522 if (! peer)
9523 return CMD_WARNING;
9524
9525 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9526}
9527
9528
paul94f2b392005-06-28 12:44:16 +00009529static void
paul718e3742002-12-13 20:15:29 +00009530show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9531 int in)
9532{
9533 struct bgp_table *table;
9534 struct bgp_adj_in *ain;
9535 struct bgp_adj_out *adj;
9536 unsigned long output_count;
9537 struct bgp_node *rn;
9538 int header1 = 1;
9539 struct bgp *bgp;
9540 int header2 = 1;
9541
paulbb46e942003-10-24 19:02:03 +00009542 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009543
9544 if (! bgp)
9545 return;
9546
9547 table = bgp->rib[afi][safi];
9548
9549 output_count = 0;
9550
9551 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9552 PEER_STATUS_DEFAULT_ORIGINATE))
9553 {
9554 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 +00009555 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9556 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009557
9558 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9559 VTY_NEWLINE, VTY_NEWLINE);
9560 header1 = 0;
9561 }
9562
9563 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9564 if (in)
9565 {
9566 for (ain = rn->adj_in; ain; ain = ain->next)
9567 if (ain->peer == peer)
9568 {
9569 if (header1)
9570 {
9571 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 +00009572 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9573 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009574 header1 = 0;
9575 }
9576 if (header2)
9577 {
9578 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9579 header2 = 0;
9580 }
9581 if (ain->attr)
9582 {
9583 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9584 output_count++;
9585 }
9586 }
9587 }
9588 else
9589 {
9590 for (adj = rn->adj_out; adj; adj = adj->next)
9591 if (adj->peer == peer)
9592 {
9593 if (header1)
9594 {
9595 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 +00009596 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9597 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009598 header1 = 0;
9599 }
9600 if (header2)
9601 {
9602 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9603 header2 = 0;
9604 }
9605 if (adj->attr)
9606 {
9607 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9608 output_count++;
9609 }
9610 }
9611 }
9612
9613 if (output_count != 0)
9614 vty_out (vty, "%sTotal number of prefixes %ld%s",
9615 VTY_NEWLINE, output_count, VTY_NEWLINE);
9616}
9617
paul94f2b392005-06-28 12:44:16 +00009618static int
paulbb46e942003-10-24 19:02:03 +00009619peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9620{
paul718e3742002-12-13 20:15:29 +00009621 if (! peer || ! peer->afc[afi][safi])
9622 {
9623 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9624 return CMD_WARNING;
9625 }
9626
9627 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9628 {
9629 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9630 VTY_NEWLINE);
9631 return CMD_WARNING;
9632 }
9633
9634 show_adj_route (vty, peer, afi, safi, in);
9635
9636 return CMD_SUCCESS;
9637}
9638
9639DEFUN (show_ip_bgp_neighbor_advertised_route,
9640 show_ip_bgp_neighbor_advertised_route_cmd,
9641 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9642 SHOW_STR
9643 IP_STR
9644 BGP_STR
9645 "Detailed information on TCP and BGP neighbor connections\n"
9646 "Neighbor to display information about\n"
9647 "Neighbor to display information about\n"
9648 "Display the routes advertised to a BGP neighbor\n")
9649{
paulbb46e942003-10-24 19:02:03 +00009650 struct peer *peer;
9651
9652 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9653 if (! peer)
9654 return CMD_WARNING;
9655
9656 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009657}
9658
9659DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9660 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9661 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9662 SHOW_STR
9663 IP_STR
9664 BGP_STR
9665 "Address family\n"
9666 "Address Family modifier\n"
9667 "Address Family modifier\n"
9668 "Detailed information on TCP and BGP neighbor connections\n"
9669 "Neighbor to display information about\n"
9670 "Neighbor to display information about\n"
9671 "Display the routes advertised to a BGP neighbor\n")
9672{
paulbb46e942003-10-24 19:02:03 +00009673 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009674
paulbb46e942003-10-24 19:02:03 +00009675 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9676 if (! peer)
9677 return CMD_WARNING;
9678
9679 if (strncmp (argv[0], "m", 1) == 0)
9680 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9681
9682 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009683}
9684
9685#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009686DEFUN (show_bgp_view_neighbor_advertised_route,
9687 show_bgp_view_neighbor_advertised_route_cmd,
9688 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9689 SHOW_STR
9690 BGP_STR
9691 "BGP view\n"
9692 "View name\n"
9693 "Detailed information on TCP and BGP neighbor connections\n"
9694 "Neighbor to display information about\n"
9695 "Neighbor to display information about\n"
9696 "Display the routes advertised to a BGP neighbor\n")
9697{
9698 struct peer *peer;
9699
9700 if (argc == 2)
9701 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9702 else
9703 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9704
9705 if (! peer)
9706 return CMD_WARNING;
9707
9708 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9709}
9710
9711ALIAS (show_bgp_view_neighbor_advertised_route,
9712 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9713 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9714 SHOW_STR
9715 BGP_STR
9716 "BGP view\n"
9717 "View name\n"
9718 "Address family\n"
9719 "Detailed information on TCP and BGP neighbor connections\n"
9720 "Neighbor to display information about\n"
9721 "Neighbor to display information about\n"
9722 "Display the routes advertised to a BGP neighbor\n")
9723
9724DEFUN (show_bgp_view_neighbor_received_routes,
9725 show_bgp_view_neighbor_received_routes_cmd,
9726 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9727 SHOW_STR
9728 BGP_STR
9729 "BGP view\n"
9730 "View name\n"
9731 "Detailed information on TCP and BGP neighbor connections\n"
9732 "Neighbor to display information about\n"
9733 "Neighbor to display information about\n"
9734 "Display the received routes from neighbor\n")
9735{
9736 struct peer *peer;
9737
9738 if (argc == 2)
9739 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9740 else
9741 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9742
9743 if (! peer)
9744 return CMD_WARNING;
9745
9746 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9747}
9748
9749ALIAS (show_bgp_view_neighbor_received_routes,
9750 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9751 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9752 SHOW_STR
9753 BGP_STR
9754 "BGP view\n"
9755 "View name\n"
9756 "Address family\n"
9757 "Detailed information on TCP and BGP neighbor connections\n"
9758 "Neighbor to display information about\n"
9759 "Neighbor to display information about\n"
9760 "Display the received routes from neighbor\n")
9761
9762ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009763 show_bgp_neighbor_advertised_route_cmd,
9764 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9765 SHOW_STR
9766 BGP_STR
9767 "Detailed information on TCP and BGP neighbor connections\n"
9768 "Neighbor to display information about\n"
9769 "Neighbor to display information about\n"
9770 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009771
9772ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009773 show_bgp_ipv6_neighbor_advertised_route_cmd,
9774 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9775 SHOW_STR
9776 BGP_STR
9777 "Address family\n"
9778 "Detailed information on TCP and BGP neighbor connections\n"
9779 "Neighbor to display information about\n"
9780 "Neighbor to display information about\n"
9781 "Display the routes advertised to a BGP neighbor\n")
9782
9783/* old command */
paulbb46e942003-10-24 19:02:03 +00009784ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009785 ipv6_bgp_neighbor_advertised_route_cmd,
9786 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9787 SHOW_STR
9788 IPV6_STR
9789 BGP_STR
9790 "Detailed information on TCP and BGP neighbor connections\n"
9791 "Neighbor to display information about\n"
9792 "Neighbor to display information about\n"
9793 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009794
paul718e3742002-12-13 20:15:29 +00009795/* old command */
9796DEFUN (ipv6_mbgp_neighbor_advertised_route,
9797 ipv6_mbgp_neighbor_advertised_route_cmd,
9798 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9799 SHOW_STR
9800 IPV6_STR
9801 MBGP_STR
9802 "Detailed information on TCP and BGP neighbor connections\n"
9803 "Neighbor to display information about\n"
9804 "Neighbor to display information about\n"
9805 "Display the routes advertised to a BGP neighbor\n")
9806{
paulbb46e942003-10-24 19:02:03 +00009807 struct peer *peer;
9808
9809 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9810 if (! peer)
9811 return CMD_WARNING;
9812
9813 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009814}
9815#endif /* HAVE_IPV6 */
9816
9817DEFUN (show_ip_bgp_neighbor_received_routes,
9818 show_ip_bgp_neighbor_received_routes_cmd,
9819 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9820 SHOW_STR
9821 IP_STR
9822 BGP_STR
9823 "Detailed information on TCP and BGP neighbor connections\n"
9824 "Neighbor to display information about\n"
9825 "Neighbor to display information about\n"
9826 "Display the received routes from neighbor\n")
9827{
paulbb46e942003-10-24 19:02:03 +00009828 struct peer *peer;
9829
9830 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9831 if (! peer)
9832 return CMD_WARNING;
9833
9834 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009835}
9836
9837DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9838 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9839 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9840 SHOW_STR
9841 IP_STR
9842 BGP_STR
9843 "Address family\n"
9844 "Address Family modifier\n"
9845 "Address Family modifier\n"
9846 "Detailed information on TCP and BGP neighbor connections\n"
9847 "Neighbor to display information about\n"
9848 "Neighbor to display information about\n"
9849 "Display the received routes from neighbor\n")
9850{
paulbb46e942003-10-24 19:02:03 +00009851 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009852
paulbb46e942003-10-24 19:02:03 +00009853 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9854 if (! peer)
9855 return CMD_WARNING;
9856
9857 if (strncmp (argv[0], "m", 1) == 0)
9858 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9859
9860 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009861}
9862
9863DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9864 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9865 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9866 SHOW_STR
9867 IP_STR
9868 BGP_STR
9869 "Detailed information on TCP and BGP neighbor connections\n"
9870 "Neighbor to display information about\n"
9871 "Neighbor to display information about\n"
9872 "Display information received from a BGP neighbor\n"
9873 "Display the prefixlist filter\n")
9874{
9875 char name[BUFSIZ];
9876 union sockunion *su;
9877 struct peer *peer;
9878 int count;
9879
9880 su = sockunion_str2su (argv[0]);
9881 if (su == NULL)
9882 return CMD_WARNING;
9883
9884 peer = peer_lookup (NULL, su);
9885 if (! peer)
9886 return CMD_WARNING;
9887
9888 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9889 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9890 if (count)
9891 {
9892 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9893 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9894 }
9895
9896 return CMD_SUCCESS;
9897}
9898
9899DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9900 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9901 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9902 SHOW_STR
9903 IP_STR
9904 BGP_STR
9905 "Address family\n"
9906 "Address Family modifier\n"
9907 "Address Family modifier\n"
9908 "Detailed information on TCP and BGP neighbor connections\n"
9909 "Neighbor to display information about\n"
9910 "Neighbor to display information about\n"
9911 "Display information received from a BGP neighbor\n"
9912 "Display the prefixlist filter\n")
9913{
9914 char name[BUFSIZ];
9915 union sockunion *su;
9916 struct peer *peer;
9917 int count;
9918
9919 su = sockunion_str2su (argv[1]);
9920 if (su == NULL)
9921 return CMD_WARNING;
9922
9923 peer = peer_lookup (NULL, su);
9924 if (! peer)
9925 return CMD_WARNING;
9926
9927 if (strncmp (argv[0], "m", 1) == 0)
9928 {
9929 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9930 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9931 if (count)
9932 {
9933 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9934 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9935 }
9936 }
9937 else
9938 {
9939 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9940 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9941 if (count)
9942 {
9943 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9944 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9945 }
9946 }
9947
9948 return CMD_SUCCESS;
9949}
9950
9951
9952#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009953ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009954 show_bgp_neighbor_received_routes_cmd,
9955 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9956 SHOW_STR
9957 BGP_STR
9958 "Detailed information on TCP and BGP neighbor connections\n"
9959 "Neighbor to display information about\n"
9960 "Neighbor to display information about\n"
9961 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009962
paulbb46e942003-10-24 19:02:03 +00009963ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009964 show_bgp_ipv6_neighbor_received_routes_cmd,
9965 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9966 SHOW_STR
9967 BGP_STR
9968 "Address family\n"
9969 "Detailed information on TCP and BGP neighbor connections\n"
9970 "Neighbor to display information about\n"
9971 "Neighbor to display information about\n"
9972 "Display the received routes from neighbor\n")
9973
9974DEFUN (show_bgp_neighbor_received_prefix_filter,
9975 show_bgp_neighbor_received_prefix_filter_cmd,
9976 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9977 SHOW_STR
9978 BGP_STR
9979 "Detailed information on TCP and BGP neighbor connections\n"
9980 "Neighbor to display information about\n"
9981 "Neighbor to display information about\n"
9982 "Display information received from a BGP neighbor\n"
9983 "Display the prefixlist filter\n")
9984{
9985 char name[BUFSIZ];
9986 union sockunion *su;
9987 struct peer *peer;
9988 int count;
9989
9990 su = sockunion_str2su (argv[0]);
9991 if (su == NULL)
9992 return CMD_WARNING;
9993
9994 peer = peer_lookup (NULL, su);
9995 if (! peer)
9996 return CMD_WARNING;
9997
9998 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9999 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10000 if (count)
10001 {
10002 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10003 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10004 }
10005
10006 return CMD_SUCCESS;
10007}
10008
10009ALIAS (show_bgp_neighbor_received_prefix_filter,
10010 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10011 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10012 SHOW_STR
10013 BGP_STR
10014 "Address family\n"
10015 "Detailed information on TCP and BGP neighbor connections\n"
10016 "Neighbor to display information about\n"
10017 "Neighbor to display information about\n"
10018 "Display information received from a BGP neighbor\n"
10019 "Display the prefixlist filter\n")
10020
10021/* old command */
paulbb46e942003-10-24 19:02:03 +000010022ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010023 ipv6_bgp_neighbor_received_routes_cmd,
10024 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10025 SHOW_STR
10026 IPV6_STR
10027 BGP_STR
10028 "Detailed information on TCP and BGP neighbor connections\n"
10029 "Neighbor to display information about\n"
10030 "Neighbor to display information about\n"
10031 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010032
10033/* old command */
10034DEFUN (ipv6_mbgp_neighbor_received_routes,
10035 ipv6_mbgp_neighbor_received_routes_cmd,
10036 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10037 SHOW_STR
10038 IPV6_STR
10039 MBGP_STR
10040 "Detailed information on TCP and BGP neighbor connections\n"
10041 "Neighbor to display information about\n"
10042 "Neighbor to display information about\n"
10043 "Display the received routes from neighbor\n")
10044{
paulbb46e942003-10-24 19:02:03 +000010045 struct peer *peer;
10046
10047 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10048 if (! peer)
10049 return CMD_WARNING;
10050
10051 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010052}
paulbb46e942003-10-24 19:02:03 +000010053
10054DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10055 show_bgp_view_neighbor_received_prefix_filter_cmd,
10056 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10057 SHOW_STR
10058 BGP_STR
10059 "BGP view\n"
10060 "View name\n"
10061 "Detailed information on TCP and BGP neighbor connections\n"
10062 "Neighbor to display information about\n"
10063 "Neighbor to display information about\n"
10064 "Display information received from a BGP neighbor\n"
10065 "Display the prefixlist filter\n")
10066{
10067 char name[BUFSIZ];
10068 union sockunion *su;
10069 struct peer *peer;
10070 struct bgp *bgp;
10071 int count;
10072
10073 /* BGP structure lookup. */
10074 bgp = bgp_lookup_by_name (argv[0]);
10075 if (bgp == NULL)
10076 {
10077 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10078 return CMD_WARNING;
10079 }
10080
10081 su = sockunion_str2su (argv[1]);
10082 if (su == NULL)
10083 return CMD_WARNING;
10084
10085 peer = peer_lookup (bgp, su);
10086 if (! peer)
10087 return CMD_WARNING;
10088
10089 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10090 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10091 if (count)
10092 {
10093 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10094 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10095 }
10096
10097 return CMD_SUCCESS;
10098}
10099
10100ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10101 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10102 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10103 SHOW_STR
10104 BGP_STR
10105 "BGP view\n"
10106 "View name\n"
10107 "Address family\n"
10108 "Detailed information on TCP and BGP neighbor connections\n"
10109 "Neighbor to display information about\n"
10110 "Neighbor to display information about\n"
10111 "Display information received from a BGP neighbor\n"
10112 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010113#endif /* HAVE_IPV6 */
10114
paul94f2b392005-06-28 12:44:16 +000010115static int
paulbb46e942003-10-24 19:02:03 +000010116bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010117 safi_t safi, enum bgp_show_type type)
10118{
paul718e3742002-12-13 20:15:29 +000010119 if (! peer || ! peer->afc[afi][safi])
10120 {
10121 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010122 return CMD_WARNING;
10123 }
10124
ajs5a646652004-11-05 01:25:55 +000010125 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010126}
10127
10128DEFUN (show_ip_bgp_neighbor_routes,
10129 show_ip_bgp_neighbor_routes_cmd,
10130 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10131 SHOW_STR
10132 IP_STR
10133 BGP_STR
10134 "Detailed information on TCP and BGP neighbor connections\n"
10135 "Neighbor to display information about\n"
10136 "Neighbor to display information about\n"
10137 "Display routes learned from neighbor\n")
10138{
paulbb46e942003-10-24 19:02:03 +000010139 struct peer *peer;
10140
10141 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10142 if (! peer)
10143 return CMD_WARNING;
10144
10145 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010146 bgp_show_type_neighbor);
10147}
10148
10149DEFUN (show_ip_bgp_neighbor_flap,
10150 show_ip_bgp_neighbor_flap_cmd,
10151 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10152 SHOW_STR
10153 IP_STR
10154 BGP_STR
10155 "Detailed information on TCP and BGP neighbor connections\n"
10156 "Neighbor to display information about\n"
10157 "Neighbor to display information about\n"
10158 "Display flap statistics of the routes learned from neighbor\n")
10159{
paulbb46e942003-10-24 19:02:03 +000010160 struct peer *peer;
10161
10162 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10163 if (! peer)
10164 return CMD_WARNING;
10165
10166 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010167 bgp_show_type_flap_neighbor);
10168}
10169
10170DEFUN (show_ip_bgp_neighbor_damp,
10171 show_ip_bgp_neighbor_damp_cmd,
10172 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10173 SHOW_STR
10174 IP_STR
10175 BGP_STR
10176 "Detailed information on TCP and BGP neighbor connections\n"
10177 "Neighbor to display information about\n"
10178 "Neighbor to display information about\n"
10179 "Display the dampened routes received from neighbor\n")
10180{
paulbb46e942003-10-24 19:02:03 +000010181 struct peer *peer;
10182
10183 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10184 if (! peer)
10185 return CMD_WARNING;
10186
10187 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010188 bgp_show_type_damp_neighbor);
10189}
10190
10191DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10192 show_ip_bgp_ipv4_neighbor_routes_cmd,
10193 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10194 SHOW_STR
10195 IP_STR
10196 BGP_STR
10197 "Address family\n"
10198 "Address Family modifier\n"
10199 "Address Family modifier\n"
10200 "Detailed information on TCP and BGP neighbor connections\n"
10201 "Neighbor to display information about\n"
10202 "Neighbor to display information about\n"
10203 "Display routes learned from neighbor\n")
10204{
paulbb46e942003-10-24 19:02:03 +000010205 struct peer *peer;
10206
10207 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10208 if (! peer)
10209 return CMD_WARNING;
10210
paul718e3742002-12-13 20:15:29 +000010211 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010212 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010213 bgp_show_type_neighbor);
10214
paulbb46e942003-10-24 19:02:03 +000010215 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010216 bgp_show_type_neighbor);
10217}
paulbb46e942003-10-24 19:02:03 +000010218
paulfee0f4c2004-09-13 05:12:46 +000010219DEFUN (show_ip_bgp_view_rsclient,
10220 show_ip_bgp_view_rsclient_cmd,
10221 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10222 SHOW_STR
10223 IP_STR
10224 BGP_STR
10225 "BGP view\n"
10226 "BGP view name\n"
10227 "Information about Route Server Client\n"
10228 NEIGHBOR_ADDR_STR)
10229{
10230 struct bgp_table *table;
10231 struct peer *peer;
10232
10233 if (argc == 2)
10234 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10235 else
10236 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10237
10238 if (! peer)
10239 return CMD_WARNING;
10240
10241 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10242 {
10243 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10244 VTY_NEWLINE);
10245 return CMD_WARNING;
10246 }
10247
10248 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10249 PEER_FLAG_RSERVER_CLIENT))
10250 {
10251 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10252 VTY_NEWLINE);
10253 return CMD_WARNING;
10254 }
10255
10256 table = peer->rib[AFI_IP][SAFI_UNICAST];
10257
ajs5a646652004-11-05 01:25:55 +000010258 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010259}
10260
10261ALIAS (show_ip_bgp_view_rsclient,
10262 show_ip_bgp_rsclient_cmd,
10263 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10264 SHOW_STR
10265 IP_STR
10266 BGP_STR
10267 "Information about Route Server Client\n"
10268 NEIGHBOR_ADDR_STR)
10269
10270DEFUN (show_ip_bgp_view_rsclient_route,
10271 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010272 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010273 SHOW_STR
10274 IP_STR
10275 BGP_STR
10276 "BGP view\n"
10277 "BGP view name\n"
10278 "Information about Route Server Client\n"
10279 NEIGHBOR_ADDR_STR
10280 "Network in the BGP routing table to display\n")
10281{
10282 struct bgp *bgp;
10283 struct peer *peer;
10284
10285 /* BGP structure lookup. */
10286 if (argc == 3)
10287 {
10288 bgp = bgp_lookup_by_name (argv[0]);
10289 if (bgp == NULL)
10290 {
10291 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10292 return CMD_WARNING;
10293 }
10294 }
10295 else
10296 {
10297 bgp = bgp_get_default ();
10298 if (bgp == NULL)
10299 {
10300 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10301 return CMD_WARNING;
10302 }
10303 }
10304
10305 if (argc == 3)
10306 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10307 else
10308 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10309
10310 if (! peer)
10311 return CMD_WARNING;
10312
10313 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10314 {
10315 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10316 VTY_NEWLINE);
10317 return CMD_WARNING;
10318}
10319
10320 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10321 PEER_FLAG_RSERVER_CLIENT))
10322 {
10323 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10324 VTY_NEWLINE);
10325 return CMD_WARNING;
10326 }
10327
10328 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10329 (argc == 3) ? argv[2] : argv[1],
10330 AFI_IP, SAFI_UNICAST, NULL, 0);
10331}
10332
10333ALIAS (show_ip_bgp_view_rsclient_route,
10334 show_ip_bgp_rsclient_route_cmd,
10335 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10336 SHOW_STR
10337 IP_STR
10338 BGP_STR
10339 "Information about Route Server Client\n"
10340 NEIGHBOR_ADDR_STR
10341 "Network in the BGP routing table to display\n")
10342
10343DEFUN (show_ip_bgp_view_rsclient_prefix,
10344 show_ip_bgp_view_rsclient_prefix_cmd,
10345 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10346 SHOW_STR
10347 IP_STR
10348 BGP_STR
10349 "BGP view\n"
10350 "BGP view name\n"
10351 "Information about Route Server Client\n"
10352 NEIGHBOR_ADDR_STR
10353 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10354{
10355 struct bgp *bgp;
10356 struct peer *peer;
10357
10358 /* BGP structure lookup. */
10359 if (argc == 3)
10360 {
10361 bgp = bgp_lookup_by_name (argv[0]);
10362 if (bgp == NULL)
10363 {
10364 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10365 return CMD_WARNING;
10366 }
10367 }
10368 else
10369 {
10370 bgp = bgp_get_default ();
10371 if (bgp == NULL)
10372 {
10373 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10374 return CMD_WARNING;
10375 }
10376 }
10377
10378 if (argc == 3)
10379 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10380 else
10381 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10382
10383 if (! peer)
10384 return CMD_WARNING;
10385
10386 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10387 {
10388 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10389 VTY_NEWLINE);
10390 return CMD_WARNING;
10391}
10392
10393 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10394 PEER_FLAG_RSERVER_CLIENT))
10395{
10396 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10397 VTY_NEWLINE);
10398 return CMD_WARNING;
10399 }
10400
10401 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10402 (argc == 3) ? argv[2] : argv[1],
10403 AFI_IP, SAFI_UNICAST, NULL, 1);
10404}
10405
10406ALIAS (show_ip_bgp_view_rsclient_prefix,
10407 show_ip_bgp_rsclient_prefix_cmd,
10408 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10409 SHOW_STR
10410 IP_STR
10411 BGP_STR
10412 "Information about Route Server Client\n"
10413 NEIGHBOR_ADDR_STR
10414 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10415
10416
paul718e3742002-12-13 20:15:29 +000010417#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010418DEFUN (show_bgp_view_neighbor_routes,
10419 show_bgp_view_neighbor_routes_cmd,
10420 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10421 SHOW_STR
10422 BGP_STR
10423 "BGP view\n"
10424 "BGP view name\n"
10425 "Detailed information on TCP and BGP neighbor connections\n"
10426 "Neighbor to display information about\n"
10427 "Neighbor to display information about\n"
10428 "Display routes learned from neighbor\n")
10429{
10430 struct peer *peer;
10431
10432 if (argc == 2)
10433 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10434 else
10435 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10436
10437 if (! peer)
10438 return CMD_WARNING;
10439
10440 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10441 bgp_show_type_neighbor);
10442}
10443
10444ALIAS (show_bgp_view_neighbor_routes,
10445 show_bgp_view_ipv6_neighbor_routes_cmd,
10446 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10447 SHOW_STR
10448 BGP_STR
10449 "BGP view\n"
10450 "BGP view name\n"
10451 "Address family\n"
10452 "Detailed information on TCP and BGP neighbor connections\n"
10453 "Neighbor to display information about\n"
10454 "Neighbor to display information about\n"
10455 "Display routes learned from neighbor\n")
10456
10457DEFUN (show_bgp_view_neighbor_damp,
10458 show_bgp_view_neighbor_damp_cmd,
10459 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10460 SHOW_STR
10461 BGP_STR
10462 "BGP view\n"
10463 "BGP view name\n"
10464 "Detailed information on TCP and BGP neighbor connections\n"
10465 "Neighbor to display information about\n"
10466 "Neighbor to display information about\n"
10467 "Display the dampened routes received from neighbor\n")
10468{
10469 struct peer *peer;
10470
10471 if (argc == 2)
10472 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10473 else
10474 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10475
10476 if (! peer)
10477 return CMD_WARNING;
10478
10479 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10480 bgp_show_type_damp_neighbor);
10481}
10482
10483ALIAS (show_bgp_view_neighbor_damp,
10484 show_bgp_view_ipv6_neighbor_damp_cmd,
10485 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10486 SHOW_STR
10487 BGP_STR
10488 "BGP view\n"
10489 "BGP view name\n"
10490 "Address family\n"
10491 "Detailed information on TCP and BGP neighbor connections\n"
10492 "Neighbor to display information about\n"
10493 "Neighbor to display information about\n"
10494 "Display the dampened routes received from neighbor\n")
10495
10496DEFUN (show_bgp_view_neighbor_flap,
10497 show_bgp_view_neighbor_flap_cmd,
10498 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10499 SHOW_STR
10500 BGP_STR
10501 "BGP view\n"
10502 "BGP view name\n"
10503 "Detailed information on TCP and BGP neighbor connections\n"
10504 "Neighbor to display information about\n"
10505 "Neighbor to display information about\n"
10506 "Display flap statistics of the routes learned from neighbor\n")
10507{
10508 struct peer *peer;
10509
10510 if (argc == 2)
10511 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10512 else
10513 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10514
10515 if (! peer)
10516 return CMD_WARNING;
10517
10518 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10519 bgp_show_type_flap_neighbor);
10520}
10521
10522ALIAS (show_bgp_view_neighbor_flap,
10523 show_bgp_view_ipv6_neighbor_flap_cmd,
10524 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10525 SHOW_STR
10526 BGP_STR
10527 "BGP view\n"
10528 "BGP view name\n"
10529 "Address family\n"
10530 "Detailed information on TCP and BGP neighbor connections\n"
10531 "Neighbor to display information about\n"
10532 "Neighbor to display information about\n"
10533 "Display flap statistics of the routes learned from neighbor\n")
10534
10535ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010536 show_bgp_neighbor_routes_cmd,
10537 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10538 SHOW_STR
10539 BGP_STR
10540 "Detailed information on TCP and BGP neighbor connections\n"
10541 "Neighbor to display information about\n"
10542 "Neighbor to display information about\n"
10543 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010544
paulbb46e942003-10-24 19:02:03 +000010545
10546ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010547 show_bgp_ipv6_neighbor_routes_cmd,
10548 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10549 SHOW_STR
10550 BGP_STR
10551 "Address family\n"
10552 "Detailed information on TCP and BGP neighbor connections\n"
10553 "Neighbor to display information about\n"
10554 "Neighbor to display information about\n"
10555 "Display routes learned from neighbor\n")
10556
10557/* old command */
paulbb46e942003-10-24 19:02:03 +000010558ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010559 ipv6_bgp_neighbor_routes_cmd,
10560 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10561 SHOW_STR
10562 IPV6_STR
10563 BGP_STR
10564 "Detailed information on TCP and BGP neighbor connections\n"
10565 "Neighbor to display information about\n"
10566 "Neighbor to display information about\n"
10567 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010568
10569/* old command */
10570DEFUN (ipv6_mbgp_neighbor_routes,
10571 ipv6_mbgp_neighbor_routes_cmd,
10572 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10573 SHOW_STR
10574 IPV6_STR
10575 MBGP_STR
10576 "Detailed information on TCP and BGP neighbor connections\n"
10577 "Neighbor to display information about\n"
10578 "Neighbor to display information about\n"
10579 "Display routes learned from neighbor\n")
10580{
paulbb46e942003-10-24 19:02:03 +000010581 struct peer *peer;
10582
10583 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10584 if (! peer)
10585 return CMD_WARNING;
10586
10587 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010588 bgp_show_type_neighbor);
10589}
paulbb46e942003-10-24 19:02:03 +000010590
10591ALIAS (show_bgp_view_neighbor_flap,
10592 show_bgp_neighbor_flap_cmd,
10593 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10594 SHOW_STR
10595 BGP_STR
10596 "Detailed information on TCP and BGP neighbor connections\n"
10597 "Neighbor to display information about\n"
10598 "Neighbor to display information about\n"
10599 "Display flap statistics of the routes learned from neighbor\n")
10600
10601ALIAS (show_bgp_view_neighbor_flap,
10602 show_bgp_ipv6_neighbor_flap_cmd,
10603 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10604 SHOW_STR
10605 BGP_STR
10606 "Address family\n"
10607 "Detailed information on TCP and BGP neighbor connections\n"
10608 "Neighbor to display information about\n"
10609 "Neighbor to display information about\n"
10610 "Display flap statistics of the routes learned from neighbor\n")
10611
10612ALIAS (show_bgp_view_neighbor_damp,
10613 show_bgp_neighbor_damp_cmd,
10614 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10615 SHOW_STR
10616 BGP_STR
10617 "Detailed information on TCP and BGP neighbor connections\n"
10618 "Neighbor to display information about\n"
10619 "Neighbor to display information about\n"
10620 "Display the dampened routes received from neighbor\n")
10621
10622ALIAS (show_bgp_view_neighbor_damp,
10623 show_bgp_ipv6_neighbor_damp_cmd,
10624 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10625 SHOW_STR
10626 BGP_STR
10627 "Address family\n"
10628 "Detailed information on TCP and BGP neighbor connections\n"
10629 "Neighbor to display information about\n"
10630 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010631 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010632
10633DEFUN (show_bgp_view_rsclient,
10634 show_bgp_view_rsclient_cmd,
10635 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10636 SHOW_STR
10637 BGP_STR
10638 "BGP view\n"
10639 "BGP view name\n"
10640 "Information about Route Server Client\n"
10641 NEIGHBOR_ADDR_STR)
10642{
10643 struct bgp_table *table;
10644 struct peer *peer;
10645
10646 if (argc == 2)
10647 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10648 else
10649 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10650
10651 if (! peer)
10652 return CMD_WARNING;
10653
10654 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10655 {
10656 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10657 VTY_NEWLINE);
10658 return CMD_WARNING;
10659 }
10660
10661 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10662 PEER_FLAG_RSERVER_CLIENT))
10663 {
10664 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10665 VTY_NEWLINE);
10666 return CMD_WARNING;
10667 }
10668
10669 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10670
ajs5a646652004-11-05 01:25:55 +000010671 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010672}
10673
10674ALIAS (show_bgp_view_rsclient,
10675 show_bgp_rsclient_cmd,
10676 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10677 SHOW_STR
10678 BGP_STR
10679 "Information about Route Server Client\n"
10680 NEIGHBOR_ADDR_STR)
10681
10682DEFUN (show_bgp_view_rsclient_route,
10683 show_bgp_view_rsclient_route_cmd,
10684 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10685 SHOW_STR
10686 BGP_STR
10687 "BGP view\n"
10688 "BGP view name\n"
10689 "Information about Route Server Client\n"
10690 NEIGHBOR_ADDR_STR
10691 "Network in the BGP routing table to display\n")
10692{
10693 struct bgp *bgp;
10694 struct peer *peer;
10695
10696 /* BGP structure lookup. */
10697 if (argc == 3)
10698 {
10699 bgp = bgp_lookup_by_name (argv[0]);
10700 if (bgp == NULL)
10701 {
10702 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10703 return CMD_WARNING;
10704 }
10705 }
10706 else
10707 {
10708 bgp = bgp_get_default ();
10709 if (bgp == NULL)
10710 {
10711 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10712 return CMD_WARNING;
10713 }
10714 }
10715
10716 if (argc == 3)
10717 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10718 else
10719 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10720
10721 if (! peer)
10722 return CMD_WARNING;
10723
10724 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10725 {
10726 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10727 VTY_NEWLINE);
10728 return CMD_WARNING;
10729 }
10730
10731 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10732 PEER_FLAG_RSERVER_CLIENT))
10733 {
10734 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10735 VTY_NEWLINE);
10736 return CMD_WARNING;
10737 }
10738
10739 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10740 (argc == 3) ? argv[2] : argv[1],
10741 AFI_IP6, SAFI_UNICAST, NULL, 0);
10742}
10743
10744ALIAS (show_bgp_view_rsclient_route,
10745 show_bgp_rsclient_route_cmd,
10746 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10747 SHOW_STR
10748 BGP_STR
10749 "Information about Route Server Client\n"
10750 NEIGHBOR_ADDR_STR
10751 "Network in the BGP routing table to display\n")
10752
10753DEFUN (show_bgp_view_rsclient_prefix,
10754 show_bgp_view_rsclient_prefix_cmd,
10755 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10756 SHOW_STR
10757 BGP_STR
10758 "BGP view\n"
10759 "BGP view name\n"
10760 "Information about Route Server Client\n"
10761 NEIGHBOR_ADDR_STR
10762 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10763{
10764 struct bgp *bgp;
10765 struct peer *peer;
10766
10767 /* BGP structure lookup. */
10768 if (argc == 3)
10769 {
10770 bgp = bgp_lookup_by_name (argv[0]);
10771 if (bgp == NULL)
10772 {
10773 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10774 return CMD_WARNING;
10775 }
10776 }
10777 else
10778 {
10779 bgp = bgp_get_default ();
10780 if (bgp == NULL)
10781 {
10782 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10783 return CMD_WARNING;
10784 }
10785 }
10786
10787 if (argc == 3)
10788 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10789 else
10790 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10791
10792 if (! peer)
10793 return CMD_WARNING;
10794
10795 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10796 {
10797 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10798 VTY_NEWLINE);
10799 return CMD_WARNING;
10800 }
10801
10802 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10803 PEER_FLAG_RSERVER_CLIENT))
10804 {
10805 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10806 VTY_NEWLINE);
10807 return CMD_WARNING;
10808 }
10809
10810 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10811 (argc == 3) ? argv[2] : argv[1],
10812 AFI_IP6, SAFI_UNICAST, NULL, 1);
10813}
10814
10815ALIAS (show_bgp_view_rsclient_prefix,
10816 show_bgp_rsclient_prefix_cmd,
10817 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10818 SHOW_STR
10819 BGP_STR
10820 "Information about Route Server Client\n"
10821 NEIGHBOR_ADDR_STR
10822 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10823
paul718e3742002-12-13 20:15:29 +000010824#endif /* HAVE_IPV6 */
10825
10826struct bgp_table *bgp_distance_table;
10827
10828struct bgp_distance
10829{
10830 /* Distance value for the IP source prefix. */
10831 u_char distance;
10832
10833 /* Name of the access-list to be matched. */
10834 char *access_list;
10835};
10836
paul94f2b392005-06-28 12:44:16 +000010837static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010838bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010839{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010840 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010841}
10842
paul94f2b392005-06-28 12:44:16 +000010843static void
paul718e3742002-12-13 20:15:29 +000010844bgp_distance_free (struct bgp_distance *bdistance)
10845{
10846 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10847}
10848
paul94f2b392005-06-28 12:44:16 +000010849static int
paulfd79ac92004-10-13 05:06:08 +000010850bgp_distance_set (struct vty *vty, const char *distance_str,
10851 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010852{
10853 int ret;
10854 struct prefix_ipv4 p;
10855 u_char distance;
10856 struct bgp_node *rn;
10857 struct bgp_distance *bdistance;
10858
10859 ret = str2prefix_ipv4 (ip_str, &p);
10860 if (ret == 0)
10861 {
10862 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10863 return CMD_WARNING;
10864 }
10865
10866 distance = atoi (distance_str);
10867
10868 /* Get BGP distance node. */
10869 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10870 if (rn->info)
10871 {
10872 bdistance = rn->info;
10873 bgp_unlock_node (rn);
10874 }
10875 else
10876 {
10877 bdistance = bgp_distance_new ();
10878 rn->info = bdistance;
10879 }
10880
10881 /* Set distance value. */
10882 bdistance->distance = distance;
10883
10884 /* Reset access-list configuration. */
10885 if (bdistance->access_list)
10886 {
10887 free (bdistance->access_list);
10888 bdistance->access_list = NULL;
10889 }
10890 if (access_list_str)
10891 bdistance->access_list = strdup (access_list_str);
10892
10893 return CMD_SUCCESS;
10894}
10895
paul94f2b392005-06-28 12:44:16 +000010896static int
paulfd79ac92004-10-13 05:06:08 +000010897bgp_distance_unset (struct vty *vty, const char *distance_str,
10898 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010899{
10900 int ret;
10901 struct prefix_ipv4 p;
10902 u_char distance;
10903 struct bgp_node *rn;
10904 struct bgp_distance *bdistance;
10905
10906 ret = str2prefix_ipv4 (ip_str, &p);
10907 if (ret == 0)
10908 {
10909 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10910 return CMD_WARNING;
10911 }
10912
10913 distance = atoi (distance_str);
10914
10915 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10916 if (! rn)
10917 {
10918 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10919 return CMD_WARNING;
10920 }
10921
10922 bdistance = rn->info;
10923
10924 if (bdistance->access_list)
10925 free (bdistance->access_list);
10926 bgp_distance_free (bdistance);
10927
10928 rn->info = NULL;
10929 bgp_unlock_node (rn);
10930 bgp_unlock_node (rn);
10931
10932 return CMD_SUCCESS;
10933}
10934
paul94f2b392005-06-28 12:44:16 +000010935static void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010936bgp_distance_reset (void)
paul718e3742002-12-13 20:15:29 +000010937{
10938 struct bgp_node *rn;
10939 struct bgp_distance *bdistance;
10940
10941 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10942 if ((bdistance = rn->info) != NULL)
10943 {
10944 if (bdistance->access_list)
10945 free (bdistance->access_list);
10946 bgp_distance_free (bdistance);
10947 rn->info = NULL;
10948 bgp_unlock_node (rn);
10949 }
10950}
10951
10952/* Apply BGP information to distance method. */
10953u_char
10954bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10955{
10956 struct bgp_node *rn;
10957 struct prefix_ipv4 q;
10958 struct peer *peer;
10959 struct bgp_distance *bdistance;
10960 struct access_list *alist;
10961 struct bgp_static *bgp_static;
10962
10963 if (! bgp)
10964 return 0;
10965
10966 if (p->family != AF_INET)
10967 return 0;
10968
10969 peer = rinfo->peer;
10970
10971 if (peer->su.sa.sa_family != AF_INET)
10972 return 0;
10973
10974 memset (&q, 0, sizeof (struct prefix_ipv4));
10975 q.family = AF_INET;
10976 q.prefix = peer->su.sin.sin_addr;
10977 q.prefixlen = IPV4_MAX_BITLEN;
10978
10979 /* Check source address. */
10980 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10981 if (rn)
10982 {
10983 bdistance = rn->info;
10984 bgp_unlock_node (rn);
10985
10986 if (bdistance->access_list)
10987 {
10988 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10989 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10990 return bdistance->distance;
10991 }
10992 else
10993 return bdistance->distance;
10994 }
10995
10996 /* Backdoor check. */
10997 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10998 if (rn)
10999 {
11000 bgp_static = rn->info;
11001 bgp_unlock_node (rn);
11002
11003 if (bgp_static->backdoor)
11004 {
11005 if (bgp->distance_local)
11006 return bgp->distance_local;
11007 else
11008 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11009 }
11010 }
11011
11012 if (peer_sort (peer) == BGP_PEER_EBGP)
11013 {
11014 if (bgp->distance_ebgp)
11015 return bgp->distance_ebgp;
11016 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11017 }
11018 else
11019 {
11020 if (bgp->distance_ibgp)
11021 return bgp->distance_ibgp;
11022 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11023 }
11024}
11025
11026DEFUN (bgp_distance,
11027 bgp_distance_cmd,
11028 "distance bgp <1-255> <1-255> <1-255>",
11029 "Define an administrative distance\n"
11030 "BGP distance\n"
11031 "Distance for routes external to the AS\n"
11032 "Distance for routes internal to the AS\n"
11033 "Distance for local routes\n")
11034{
11035 struct bgp *bgp;
11036
11037 bgp = vty->index;
11038
11039 bgp->distance_ebgp = atoi (argv[0]);
11040 bgp->distance_ibgp = atoi (argv[1]);
11041 bgp->distance_local = atoi (argv[2]);
11042 return CMD_SUCCESS;
11043}
11044
11045DEFUN (no_bgp_distance,
11046 no_bgp_distance_cmd,
11047 "no distance bgp <1-255> <1-255> <1-255>",
11048 NO_STR
11049 "Define an administrative distance\n"
11050 "BGP distance\n"
11051 "Distance for routes external to the AS\n"
11052 "Distance for routes internal to the AS\n"
11053 "Distance for local routes\n")
11054{
11055 struct bgp *bgp;
11056
11057 bgp = vty->index;
11058
11059 bgp->distance_ebgp= 0;
11060 bgp->distance_ibgp = 0;
11061 bgp->distance_local = 0;
11062 return CMD_SUCCESS;
11063}
11064
11065ALIAS (no_bgp_distance,
11066 no_bgp_distance2_cmd,
11067 "no distance bgp",
11068 NO_STR
11069 "Define an administrative distance\n"
11070 "BGP distance\n")
11071
11072DEFUN (bgp_distance_source,
11073 bgp_distance_source_cmd,
11074 "distance <1-255> A.B.C.D/M",
11075 "Define an administrative distance\n"
11076 "Administrative distance\n"
11077 "IP source prefix\n")
11078{
11079 bgp_distance_set (vty, argv[0], argv[1], NULL);
11080 return CMD_SUCCESS;
11081}
11082
11083DEFUN (no_bgp_distance_source,
11084 no_bgp_distance_source_cmd,
11085 "no distance <1-255> A.B.C.D/M",
11086 NO_STR
11087 "Define an administrative distance\n"
11088 "Administrative distance\n"
11089 "IP source prefix\n")
11090{
11091 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11092 return CMD_SUCCESS;
11093}
11094
11095DEFUN (bgp_distance_source_access_list,
11096 bgp_distance_source_access_list_cmd,
11097 "distance <1-255> A.B.C.D/M WORD",
11098 "Define an administrative distance\n"
11099 "Administrative distance\n"
11100 "IP source prefix\n"
11101 "Access list name\n")
11102{
11103 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11104 return CMD_SUCCESS;
11105}
11106
11107DEFUN (no_bgp_distance_source_access_list,
11108 no_bgp_distance_source_access_list_cmd,
11109 "no distance <1-255> A.B.C.D/M WORD",
11110 NO_STR
11111 "Define an administrative distance\n"
11112 "Administrative distance\n"
11113 "IP source prefix\n"
11114 "Access list name\n")
11115{
11116 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11117 return CMD_SUCCESS;
11118}
11119
11120DEFUN (bgp_damp_set,
11121 bgp_damp_set_cmd,
11122 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11123 "BGP Specific commands\n"
11124 "Enable route-flap dampening\n"
11125 "Half-life time for the penalty\n"
11126 "Value to start reusing a route\n"
11127 "Value to start suppressing a route\n"
11128 "Maximum duration to suppress a stable route\n")
11129{
11130 struct bgp *bgp;
11131 int half = DEFAULT_HALF_LIFE * 60;
11132 int reuse = DEFAULT_REUSE;
11133 int suppress = DEFAULT_SUPPRESS;
11134 int max = 4 * half;
11135
11136 if (argc == 4)
11137 {
11138 half = atoi (argv[0]) * 60;
11139 reuse = atoi (argv[1]);
11140 suppress = atoi (argv[2]);
11141 max = atoi (argv[3]) * 60;
11142 }
11143 else if (argc == 1)
11144 {
11145 half = atoi (argv[0]) * 60;
11146 max = 4 * half;
11147 }
11148
11149 bgp = vty->index;
11150 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11151 half, reuse, suppress, max);
11152}
11153
11154ALIAS (bgp_damp_set,
11155 bgp_damp_set2_cmd,
11156 "bgp dampening <1-45>",
11157 "BGP Specific commands\n"
11158 "Enable route-flap dampening\n"
11159 "Half-life time for the penalty\n")
11160
11161ALIAS (bgp_damp_set,
11162 bgp_damp_set3_cmd,
11163 "bgp dampening",
11164 "BGP Specific commands\n"
11165 "Enable route-flap dampening\n")
11166
11167DEFUN (bgp_damp_unset,
11168 bgp_damp_unset_cmd,
11169 "no bgp dampening",
11170 NO_STR
11171 "BGP Specific commands\n"
11172 "Enable route-flap dampening\n")
11173{
11174 struct bgp *bgp;
11175
11176 bgp = vty->index;
11177 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11178}
11179
11180ALIAS (bgp_damp_unset,
11181 bgp_damp_unset2_cmd,
11182 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11183 NO_STR
11184 "BGP Specific commands\n"
11185 "Enable route-flap dampening\n"
11186 "Half-life time for the penalty\n"
11187 "Value to start reusing a route\n"
11188 "Value to start suppressing a route\n"
11189 "Maximum duration to suppress a stable route\n")
11190
11191DEFUN (show_ip_bgp_dampened_paths,
11192 show_ip_bgp_dampened_paths_cmd,
11193 "show ip bgp dampened-paths",
11194 SHOW_STR
11195 IP_STR
11196 BGP_STR
11197 "Display paths suppressed due to dampening\n")
11198{
ajs5a646652004-11-05 01:25:55 +000011199 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11200 NULL);
paul718e3742002-12-13 20:15:29 +000011201}
11202
11203DEFUN (show_ip_bgp_flap_statistics,
11204 show_ip_bgp_flap_statistics_cmd,
11205 "show ip bgp flap-statistics",
11206 SHOW_STR
11207 IP_STR
11208 BGP_STR
11209 "Display flap statistics of routes\n")
11210{
ajs5a646652004-11-05 01:25:55 +000011211 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11212 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011213}
11214
11215/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011216static int
paulfd79ac92004-10-13 05:06:08 +000011217bgp_clear_damp_route (struct vty *vty, const char *view_name,
11218 const char *ip_str, afi_t afi, safi_t safi,
11219 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011220{
11221 int ret;
11222 struct prefix match;
11223 struct bgp_node *rn;
11224 struct bgp_node *rm;
11225 struct bgp_info *ri;
11226 struct bgp_info *ri_temp;
11227 struct bgp *bgp;
11228 struct bgp_table *table;
11229
11230 /* BGP structure lookup. */
11231 if (view_name)
11232 {
11233 bgp = bgp_lookup_by_name (view_name);
11234 if (bgp == NULL)
11235 {
11236 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11237 return CMD_WARNING;
11238 }
11239 }
11240 else
11241 {
11242 bgp = bgp_get_default ();
11243 if (bgp == NULL)
11244 {
11245 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11246 return CMD_WARNING;
11247 }
11248 }
11249
11250 /* Check IP address argument. */
11251 ret = str2prefix (ip_str, &match);
11252 if (! ret)
11253 {
11254 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11255 return CMD_WARNING;
11256 }
11257
11258 match.family = afi2family (afi);
11259
11260 if (safi == SAFI_MPLS_VPN)
11261 {
11262 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11263 {
11264 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11265 continue;
11266
11267 if ((table = rn->info) != NULL)
11268 if ((rm = bgp_node_match (table, &match)) != NULL)
11269 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11270 {
11271 ri = rm->info;
11272 while (ri)
11273 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011274 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011275 {
11276 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011277 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011278 ri = ri_temp;
11279 }
11280 else
11281 ri = ri->next;
11282 }
11283 }
11284 }
11285 }
11286 else
11287 {
11288 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11289 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11290 {
11291 ri = rn->info;
11292 while (ri)
11293 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011294 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011295 {
11296 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011297 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011298 ri = ri_temp;
11299 }
11300 else
11301 ri = ri->next;
11302 }
11303 }
11304 }
11305
11306 return CMD_SUCCESS;
11307}
11308
11309DEFUN (clear_ip_bgp_dampening,
11310 clear_ip_bgp_dampening_cmd,
11311 "clear ip bgp dampening",
11312 CLEAR_STR
11313 IP_STR
11314 BGP_STR
11315 "Clear route flap dampening information\n")
11316{
11317 bgp_damp_info_clean ();
11318 return CMD_SUCCESS;
11319}
11320
11321DEFUN (clear_ip_bgp_dampening_prefix,
11322 clear_ip_bgp_dampening_prefix_cmd,
11323 "clear ip bgp dampening A.B.C.D/M",
11324 CLEAR_STR
11325 IP_STR
11326 BGP_STR
11327 "Clear route flap dampening information\n"
11328 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11329{
11330 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11331 SAFI_UNICAST, NULL, 1);
11332}
11333
11334DEFUN (clear_ip_bgp_dampening_address,
11335 clear_ip_bgp_dampening_address_cmd,
11336 "clear ip bgp dampening A.B.C.D",
11337 CLEAR_STR
11338 IP_STR
11339 BGP_STR
11340 "Clear route flap dampening information\n"
11341 "Network to clear damping information\n")
11342{
11343 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11344 SAFI_UNICAST, NULL, 0);
11345}
11346
11347DEFUN (clear_ip_bgp_dampening_address_mask,
11348 clear_ip_bgp_dampening_address_mask_cmd,
11349 "clear ip bgp dampening A.B.C.D A.B.C.D",
11350 CLEAR_STR
11351 IP_STR
11352 BGP_STR
11353 "Clear route flap dampening information\n"
11354 "Network to clear damping information\n"
11355 "Network mask\n")
11356{
11357 int ret;
11358 char prefix_str[BUFSIZ];
11359
11360 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11361 if (! ret)
11362 {
11363 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11364 return CMD_WARNING;
11365 }
11366
11367 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11368 SAFI_UNICAST, NULL, 0);
11369}
11370
paul94f2b392005-06-28 12:44:16 +000011371static int
paul718e3742002-12-13 20:15:29 +000011372bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11373 afi_t afi, safi_t safi, int *write)
11374{
11375 struct bgp_node *prn;
11376 struct bgp_node *rn;
11377 struct bgp_table *table;
11378 struct prefix *p;
11379 struct prefix_rd *prd;
11380 struct bgp_static *bgp_static;
11381 u_int32_t label;
11382 char buf[SU_ADDRSTRLEN];
11383 char rdbuf[RD_ADDRSTRLEN];
11384
11385 /* Network configuration. */
11386 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11387 if ((table = prn->info) != NULL)
11388 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11389 if ((bgp_static = rn->info) != NULL)
11390 {
11391 p = &rn->p;
11392 prd = (struct prefix_rd *) &prn->p;
11393
11394 /* "address-family" display. */
11395 bgp_config_write_family_header (vty, afi, safi, write);
11396
11397 /* "network" configuration display. */
11398 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11399 label = decode_label (bgp_static->tag);
11400
11401 vty_out (vty, " network %s/%d rd %s tag %d",
11402 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11403 p->prefixlen,
11404 rdbuf, label);
11405 vty_out (vty, "%s", VTY_NEWLINE);
11406 }
11407 return 0;
11408}
11409
11410/* Configuration of static route announcement and aggregate
11411 information. */
11412int
11413bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11414 afi_t afi, safi_t safi, int *write)
11415{
11416 struct bgp_node *rn;
11417 struct prefix *p;
11418 struct bgp_static *bgp_static;
11419 struct bgp_aggregate *bgp_aggregate;
11420 char buf[SU_ADDRSTRLEN];
11421
11422 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11423 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11424
11425 /* Network configuration. */
11426 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11427 if ((bgp_static = rn->info) != NULL)
11428 {
11429 p = &rn->p;
11430
11431 /* "address-family" display. */
11432 bgp_config_write_family_header (vty, afi, safi, write);
11433
11434 /* "network" configuration display. */
11435 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11436 {
11437 u_int32_t destination;
11438 struct in_addr netmask;
11439
11440 destination = ntohl (p->u.prefix4.s_addr);
11441 masklen2ip (p->prefixlen, &netmask);
11442 vty_out (vty, " network %s",
11443 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11444
11445 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11446 || (IN_CLASSB (destination) && p->prefixlen == 16)
11447 || (IN_CLASSA (destination) && p->prefixlen == 8)
11448 || p->u.prefix4.s_addr == 0)
11449 {
11450 /* Natural mask is not display. */
11451 }
11452 else
11453 vty_out (vty, " mask %s", inet_ntoa (netmask));
11454 }
11455 else
11456 {
11457 vty_out (vty, " network %s/%d",
11458 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11459 p->prefixlen);
11460 }
11461
11462 if (bgp_static->rmap.name)
11463 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011464 else
11465 {
11466 if (bgp_static->backdoor)
11467 vty_out (vty, " backdoor");
11468 if (bgp_static->ttl)
11469 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11470 }
paul718e3742002-12-13 20:15:29 +000011471
11472 vty_out (vty, "%s", VTY_NEWLINE);
11473 }
11474
11475 /* Aggregate-address configuration. */
11476 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11477 if ((bgp_aggregate = rn->info) != NULL)
11478 {
11479 p = &rn->p;
11480
11481 /* "address-family" display. */
11482 bgp_config_write_family_header (vty, afi, safi, write);
11483
11484 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11485 {
11486 struct in_addr netmask;
11487
11488 masklen2ip (p->prefixlen, &netmask);
11489 vty_out (vty, " aggregate-address %s %s",
11490 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11491 inet_ntoa (netmask));
11492 }
11493 else
11494 {
11495 vty_out (vty, " aggregate-address %s/%d",
11496 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11497 p->prefixlen);
11498 }
11499
11500 if (bgp_aggregate->as_set)
11501 vty_out (vty, " as-set");
11502
11503 if (bgp_aggregate->summary_only)
11504 vty_out (vty, " summary-only");
11505
11506 vty_out (vty, "%s", VTY_NEWLINE);
11507 }
11508
11509 return 0;
11510}
11511
11512int
11513bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11514{
11515 struct bgp_node *rn;
11516 struct bgp_distance *bdistance;
11517
11518 /* Distance configuration. */
11519 if (bgp->distance_ebgp
11520 && bgp->distance_ibgp
11521 && bgp->distance_local
11522 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11523 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11524 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11525 vty_out (vty, " distance bgp %d %d %d%s",
11526 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11527 VTY_NEWLINE);
11528
11529 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11530 if ((bdistance = rn->info) != NULL)
11531 {
11532 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11533 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11534 bdistance->access_list ? bdistance->access_list : "",
11535 VTY_NEWLINE);
11536 }
11537
11538 return 0;
11539}
11540
11541/* Allocate routing table structure and install commands. */
11542void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011543bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011544{
11545 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011546 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011547
11548 /* IPv4 BGP commands. */
11549 install_element (BGP_NODE, &bgp_network_cmd);
11550 install_element (BGP_NODE, &bgp_network_mask_cmd);
11551 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11552 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11553 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11554 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11555 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11556 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11557 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011558 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11559 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11560 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11561 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11562 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11563 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011564 install_element (BGP_NODE, &no_bgp_network_cmd);
11565 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11566 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11567 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11568 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11569 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11570 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11571 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11572 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011573 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11574 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11575 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11576 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11577 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11578 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011579
11580 install_element (BGP_NODE, &aggregate_address_cmd);
11581 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11582 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11583 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11584 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11585 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11586 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11587 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11588 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11589 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11590 install_element (BGP_NODE, &no_aggregate_address_cmd);
11591 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11592 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11593 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11594 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11595 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11596 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11597 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11598 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11599 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11600
11601 /* IPv4 unicast configuration. */
11602 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11603 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11604 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11605 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11606 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11607 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011608 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11609 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11610 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11611 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11612 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11613 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 +000011614 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11615 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11616 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11617 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11618 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011619 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11620 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11621 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11622 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11623 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11624 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 +000011625 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11626 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11627 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11628 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11629 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11630 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11631 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11632 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11633 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11634 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11635 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11636 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11637 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11638 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11639 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11640 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11641 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11642 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11643 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11644 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11645
11646 /* IPv4 multicast configuration. */
11647 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11648 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11649 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11650 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11651 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11652 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011653 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11654 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11655 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11656 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11657 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11658 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 +000011659 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11660 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11661 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11662 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11663 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11664 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011665 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11666 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11667 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11668 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11669 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11670 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 +000011671 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11672 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11673 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11674 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11675 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11676 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11677 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11678 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11679 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11680 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11681 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11682 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11683 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11684 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11685 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11686 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11687 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11688 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11689 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11690 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11691
11692 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11693 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11694 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11695 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11696 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11697 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11698 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11699 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11700 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11701 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11702 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11703 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11704 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11705 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11706 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11707 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11708 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11709 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11710 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11711 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11712 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11713 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11714 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11715 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11716 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11717 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11718 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11719 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11720 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11721 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11722 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11723 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11724 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11725 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11726 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11727 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11728 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11729 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11730 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11731 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11732 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11733 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11734 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11735 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11736 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11737 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11738 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11739 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11740 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11741 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11742 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11743 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11744 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11745 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11746 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11747 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11748 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11749 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11750 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11751 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11752 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11753 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11754 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11755 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11756 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11757 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11758 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011759 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11760 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11761 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11762 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11763 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11764 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011765
11766 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11767 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11768 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11769 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11770 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11771 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11772 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11773 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11774 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11775 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11776 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11777 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11778 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11779 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11780 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11781 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11782 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11783 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11784 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11785 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11786 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11787 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11788 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11789 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11790 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11791 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11792 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11793 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11794 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11795 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011796
11797 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11798 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11799 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11800 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11801 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11802 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11803 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11804 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11805 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11806 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11807 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11808 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11809 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11810 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11811 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11812 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11813 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11814 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11815 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11816 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11817 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11818 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11819 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11820 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11821 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11822 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11823 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11824 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11825 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11826 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11827 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11828 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11829 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11830 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11831 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11832 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11833 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11834 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11835 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11836 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11837 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11838 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11839 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11840 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11841 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11842 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11843 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11844 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11845 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11846 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11847 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11848 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11849 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11850 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11851 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11852 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11853 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11854 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11855 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11856 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11857 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11858 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11859 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11860 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11861 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11862 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11863 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011864 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11865 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11866 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11867 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11868 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11869 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011870
11871 /* BGP dampening clear commands */
11872 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11873 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11874 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11875 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11876
Paul Jakmaff7924f2006-09-04 01:10:36 +000011877 /* prefix count */
11878 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11879 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11880 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011881#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011882 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11883
paul718e3742002-12-13 20:15:29 +000011884 /* New config IPv6 BGP commands. */
11885 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11886 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011887 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011888 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11889 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011890 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011891
11892 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11893 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11894 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11895 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11896
11897 /* Old config IPv6 BGP commands. */
11898 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11899 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11900
11901 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11902 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11903 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11904 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11905
11906 install_element (VIEW_NODE, &show_bgp_cmd);
11907 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11908 install_element (VIEW_NODE, &show_bgp_route_cmd);
11909 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11910 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11911 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11912 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11913 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11914 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11915 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11916 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11917 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11918 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11919 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11920 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11921 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11922 install_element (VIEW_NODE, &show_bgp_community_cmd);
11923 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11924 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11925 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11926 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11927 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11928 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11929 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11930 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11931 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11932 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11933 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11934 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11935 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11936 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11937 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11938 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11939 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11940 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11941 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11942 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11943 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11944 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11945 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11946 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11947 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11948 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11949 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11950 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11951 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011952 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11953 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11954 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11955 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011956 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11957 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11958 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011959 install_element (VIEW_NODE, &show_bgp_view_cmd);
11960 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11961 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11962 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11963 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11964 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11965 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11966 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11967 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11968 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11969 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11970 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11971 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11972 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11973 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11974 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11975 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11976 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011977 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11978 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11979 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011980
11981 /* Restricted:
11982 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
11983 */
11984 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
11985 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
11986 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
11987 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
11988 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
11989 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
11990 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
11991 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
11992 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
11993 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
11994 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
11995 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
11996 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
11997 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
11998 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
11999 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12000 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12001 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12002 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12003 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12004 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
12005 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
12006 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12007 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12008 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12009 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12010 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12011 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12012 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
12013 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012014
12015 install_element (ENABLE_NODE, &show_bgp_cmd);
12016 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
12017 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12018 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
12019 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12020 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
12021 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12022 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12023 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12024 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12025 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12026 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12027 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12028 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12029 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12030 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12031 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12032 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12033 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12034 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12035 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12036 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12037 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12038 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12039 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12040 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12041 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12042 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12043 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12044 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12045 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12046 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12047 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12048 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12049 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12050 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12051 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12052 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12053 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12054 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12055 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12056 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12057 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12058 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12059 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12060 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012061 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12062 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12063 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12064 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012065 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12066 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12067 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012068 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12069 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12070 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12071 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12072 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12073 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12074 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12075 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12076 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12077 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12078 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12079 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12080 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12081 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12082 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12083 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12084 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12085 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012086 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12087 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12088 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012089
12090 /* Statistics */
12091 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12092 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12093 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12094 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12095
paul718e3742002-12-13 20:15:29 +000012096 /* old command */
12097 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12098 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12099 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12100 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12101 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12102 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12103 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12104 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12105 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12106 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12107 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12108 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12109 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12110 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12111 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12112 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12113 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12114 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12115 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12116 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12117 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12118 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12119 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12120 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12121 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12122 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12123 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12124 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12125 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12126 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12127 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12128 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12129 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12130 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12131 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12132 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012133
paul718e3742002-12-13 20:15:29 +000012134 /* old command */
12135 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12136 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12137 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12138 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12139 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12140 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12141 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12142 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12143 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12144 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12145 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12146 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12147 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12148 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12149 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12150 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12151 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12152 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12153 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12154 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12155 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12156 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12157 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12158 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12159 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12160 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12161 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12162 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12163 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12164 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12165 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12166 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12167 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12168 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12169 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12170 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12171
12172 /* old command */
12173 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12174 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12175 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12176 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12177
12178 /* old command */
12179 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12180 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12181 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12182 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12183
12184 /* old command */
12185 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12186 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12187 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12188 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12189#endif /* HAVE_IPV6 */
12190
12191 install_element (BGP_NODE, &bgp_distance_cmd);
12192 install_element (BGP_NODE, &no_bgp_distance_cmd);
12193 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12194 install_element (BGP_NODE, &bgp_distance_source_cmd);
12195 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12196 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12197 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12198
12199 install_element (BGP_NODE, &bgp_damp_set_cmd);
12200 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12201 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12202 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12203 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12204 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12205 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12206 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12207 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12208 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12209}