blob: 1cfc451188894f39c9a66707ba5ab79b700c8e46 [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
Paul Jakma650f76c2009-06-25 18:06:31 +0100533#define FILTER_EXIST_WARN(F,f,filter) \
534 if (BGP_DEBUG (update, UPDATE_IN) \
535 && !(F ## _IN (filter))) \
536 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
537 peer->host, #f, F ## _IN_NAME(filter));
538
539 if (DISTRIBUTE_IN_NAME (filter)) {
540 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
541
paul718e3742002-12-13 20:15:29 +0000542 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
543 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100544 }
paul718e3742002-12-13 20:15:29 +0000545
Paul Jakma650f76c2009-06-25 18:06:31 +0100546 if (PREFIX_LIST_IN_NAME (filter)) {
547 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
548
paul718e3742002-12-13 20:15:29 +0000549 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
550 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100551 }
paul718e3742002-12-13 20:15:29 +0000552
Paul Jakma650f76c2009-06-25 18:06:31 +0100553 if (FILTER_LIST_IN_NAME (filter)) {
554 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
555
paul718e3742002-12-13 20:15:29 +0000556 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
557 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100558 }
559
paul718e3742002-12-13 20:15:29 +0000560 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100561#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000562}
563
paul94f2b392005-06-28 12:44:16 +0000564static enum filter_type
paul718e3742002-12-13 20:15:29 +0000565bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
566 afi_t afi, safi_t safi)
567{
568 struct bgp_filter *filter;
569
570 filter = &peer->filter[afi][safi];
571
Paul Jakma650f76c2009-06-25 18:06:31 +0100572#define FILTER_EXIST_WARN(F,f,filter) \
573 if (BGP_DEBUG (update, UPDATE_OUT) \
574 && !(F ## _OUT (filter))) \
575 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
576 peer->host, #f, F ## _OUT_NAME(filter));
577
578 if (DISTRIBUTE_OUT_NAME (filter)) {
579 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
580
paul718e3742002-12-13 20:15:29 +0000581 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
582 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100583 }
paul718e3742002-12-13 20:15:29 +0000584
Paul Jakma650f76c2009-06-25 18:06:31 +0100585 if (PREFIX_LIST_OUT_NAME (filter)) {
586 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
587
paul718e3742002-12-13 20:15:29 +0000588 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
589 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100590 }
paul718e3742002-12-13 20:15:29 +0000591
Paul Jakma650f76c2009-06-25 18:06:31 +0100592 if (FILTER_LIST_OUT_NAME (filter)) {
593 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
594
paul718e3742002-12-13 20:15:29 +0000595 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
596 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100597 }
paul718e3742002-12-13 20:15:29 +0000598
599 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100600#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000601}
602
603/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000604static int
paul718e3742002-12-13 20:15:29 +0000605bgp_community_filter (struct peer *peer, struct attr *attr)
606{
607 if (attr->community)
608 {
609 /* NO_ADVERTISE check. */
610 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
611 return 1;
612
613 /* NO_EXPORT check. */
614 if (peer_sort (peer) == BGP_PEER_EBGP &&
615 community_include (attr->community, COMMUNITY_NO_EXPORT))
616 return 1;
617
618 /* NO_EXPORT_SUBCONFED check. */
619 if (peer_sort (peer) == BGP_PEER_EBGP
620 || peer_sort (peer) == BGP_PEER_CONFED)
621 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
622 return 1;
623 }
624 return 0;
625}
626
627/* Route reflection loop check. */
628static int
629bgp_cluster_filter (struct peer *peer, struct attr *attr)
630{
631 struct in_addr cluster_id;
632
Paul Jakmafb982c22007-05-04 20:15:47 +0000633 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000634 {
635 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
636 cluster_id = peer->bgp->cluster_id;
637 else
638 cluster_id = peer->bgp->router_id;
639
Paul Jakmafb982c22007-05-04 20:15:47 +0000640 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000641 return 1;
642 }
643 return 0;
644}
645
paul94f2b392005-06-28 12:44:16 +0000646static int
paul718e3742002-12-13 20:15:29 +0000647bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
648 afi_t afi, safi_t safi)
649{
650 struct bgp_filter *filter;
651 struct bgp_info info;
652 route_map_result_t ret;
653
654 filter = &peer->filter[afi][safi];
655
656 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000657 if (peer->weight)
658 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000659
660 /* Route map apply. */
661 if (ROUTE_MAP_IN_NAME (filter))
662 {
663 /* Duplicate current value to new strucutre for modification. */
664 info.peer = peer;
665 info.attr = attr;
666
paulac41b2a2003-08-12 05:32:27 +0000667 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
668
paul718e3742002-12-13 20:15:29 +0000669 /* Apply BGP route map to the attribute. */
670 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000671
672 peer->rmap_type = 0;
673
paul718e3742002-12-13 20:15:29 +0000674 if (ret == RMAP_DENYMATCH)
675 {
676 /* Free newly generated AS path and community by route-map. */
677 bgp_attr_flush (attr);
678 return RMAP_DENY;
679 }
680 }
681 return RMAP_PERMIT;
682}
683
paul94f2b392005-06-28 12:44:16 +0000684static int
paulfee0f4c2004-09-13 05:12:46 +0000685bgp_export_modifier (struct peer *rsclient, struct peer *peer,
686 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
687{
688 struct bgp_filter *filter;
689 struct bgp_info info;
690 route_map_result_t ret;
691
692 filter = &peer->filter[afi][safi];
693
694 /* Route map apply. */
695 if (ROUTE_MAP_EXPORT_NAME (filter))
696 {
697 /* Duplicate current value to new strucutre for modification. */
698 info.peer = rsclient;
699 info.attr = attr;
700
701 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
702
703 /* Apply BGP route map to the attribute. */
704 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
705
706 rsclient->rmap_type = 0;
707
708 if (ret == RMAP_DENYMATCH)
709 {
710 /* Free newly generated AS path and community by route-map. */
711 bgp_attr_flush (attr);
712 return RMAP_DENY;
713 }
714 }
715 return RMAP_PERMIT;
716}
717
paul94f2b392005-06-28 12:44:16 +0000718static int
paulfee0f4c2004-09-13 05:12:46 +0000719bgp_import_modifier (struct peer *rsclient, struct peer *peer,
720 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
721{
722 struct bgp_filter *filter;
723 struct bgp_info info;
724 route_map_result_t ret;
725
726 filter = &rsclient->filter[afi][safi];
727
728 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000729 if (peer->weight)
730 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000731
732 /* Route map apply. */
733 if (ROUTE_MAP_IMPORT_NAME (filter))
734 {
735 /* Duplicate current value to new strucutre for modification. */
736 info.peer = peer;
737 info.attr = attr;
738
739 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
740
741 /* Apply BGP route map to the attribute. */
742 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
743
744 peer->rmap_type = 0;
745
746 if (ret == RMAP_DENYMATCH)
747 {
748 /* Free newly generated AS path and community by route-map. */
749 bgp_attr_flush (attr);
750 return RMAP_DENY;
751 }
752 }
753 return RMAP_PERMIT;
754}
755
paul94f2b392005-06-28 12:44:16 +0000756static int
paul718e3742002-12-13 20:15:29 +0000757bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
758 struct attr *attr, afi_t afi, safi_t safi)
759{
760 int ret;
761 char buf[SU_ADDRSTRLEN];
762 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000763 struct peer *from;
764 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000765 int transparent;
766 int reflect;
767
768 from = ri->peer;
769 filter = &peer->filter[afi][safi];
770 bgp = peer->bgp;
771
Paul Jakma750e8142008-07-22 21:11:48 +0000772 if (DISABLE_BGP_ANNOUNCE)
773 return 0;
paul718e3742002-12-13 20:15:29 +0000774
paulfee0f4c2004-09-13 05:12:46 +0000775 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
776 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
777 return 0;
778
paul718e3742002-12-13 20:15:29 +0000779 /* Do not send back route to sender. */
780 if (from == peer)
781 return 0;
782
paul35be31b2004-05-01 18:17:04 +0000783 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
784 if (p->family == AF_INET
785 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
786 return 0;
787#ifdef HAVE_IPV6
788 if (p->family == AF_INET6
789 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
790 return 0;
791#endif
792
paul718e3742002-12-13 20:15:29 +0000793 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000794 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000795 if (! UNSUPPRESS_MAP_NAME (filter))
796 return 0;
797
798 /* Default route check. */
799 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
800 {
801 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
802 return 0;
803#ifdef HAVE_IPV6
804 else if (p->family == AF_INET6 && p->prefixlen == 0)
805 return 0;
806#endif /* HAVE_IPV6 */
807 }
808
paul286e1e72003-08-08 00:24:31 +0000809 /* Transparency check. */
810 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
811 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
812 transparent = 1;
813 else
814 transparent = 0;
815
paul718e3742002-12-13 20:15:29 +0000816 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000817 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000818 return 0;
819
820 /* If the attribute has originator-id and it is same as remote
821 peer's id. */
822 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
823 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000824 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000825 {
826 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000827 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000828 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
829 peer->host,
830 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
831 p->prefixlen);
832 return 0;
833 }
834 }
835
836 /* ORF prefix-list filter check */
837 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
838 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
839 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
840 if (peer->orf_plist[afi][safi])
841 {
842 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
843 return 0;
844 }
845
846 /* Output filter check. */
847 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
848 {
849 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000850 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000851 "%s [Update:SEND] %s/%d is filtered",
852 peer->host,
853 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
854 p->prefixlen);
855 return 0;
856 }
857
858#ifdef BGP_SEND_ASPATH_CHECK
859 /* AS path loop check. */
860 if (aspath_loop_check (ri->attr->aspath, peer->as))
861 {
862 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000863 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400864 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000865 peer->host, peer->as);
866 return 0;
867 }
868#endif /* BGP_SEND_ASPATH_CHECK */
869
870 /* If we're a CONFED we need to loop check the CONFED ID too */
871 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
872 {
873 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
874 {
875 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000876 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400877 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000878 peer->host,
879 bgp->confed_id);
880 return 0;
881 }
882 }
883
884 /* Route-Reflect check. */
885 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
886 reflect = 1;
887 else
888 reflect = 0;
889
890 /* IBGP reflection check. */
891 if (reflect)
892 {
893 /* A route from a Client peer. */
894 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
895 {
896 /* Reflect to all the Non-Client peers and also to the
897 Client peers other than the originator. Originator check
898 is already done. So there is noting to do. */
899 /* no bgp client-to-client reflection check. */
900 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
901 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
902 return 0;
903 }
904 else
905 {
906 /* A route from a Non-client peer. Reflect to all other
907 clients. */
908 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
909 return 0;
910 }
911 }
Paul Jakma41367172007-08-06 15:24:51 +0000912
913 /* AS-Pathlimit check */
914 if (ri->attr->pathlimit.ttl && peer_sort (peer) == BGP_PEER_EBGP)
915 /* Our ASN has not yet been pre-pended, that's done in packet_attribute
916 * on output. Hence the test here is for >=.
917 */
918 if (aspath_count_hops (ri->attr->aspath) >= ri->attr->pathlimit.ttl)
919 {
920 if (BGP_DEBUG (filter, FILTER))
921 zlog_info ("%s [Update:SEND] suppressed, AS-Pathlimit TTL %u exceeded",
922 peer->host, ri->attr->pathlimit.ttl);
923 return 0;
924 }
925
paul718e3742002-12-13 20:15:29 +0000926 /* For modify attribute, copy it to temporary structure. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000927 bgp_attr_dup (attr, ri->attr);
928
paul718e3742002-12-13 20:15:29 +0000929 /* If local-preference is not set. */
930 if ((peer_sort (peer) == BGP_PEER_IBGP
931 || peer_sort (peer) == BGP_PEER_CONFED)
932 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
933 {
934 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
935 attr->local_pref = bgp->default_local_pref;
936 }
937
paul718e3742002-12-13 20:15:29 +0000938 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
939 if (peer_sort (peer) == BGP_PEER_EBGP
940 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
941 {
942 if (ri->peer != bgp->peer_self && ! transparent
943 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
944 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
945 }
946
947 /* next-hop-set */
948 if (transparent || reflect
949 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
950 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000951#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000952 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000953 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000954#endif /* HAVE_IPV6 */
955 )))
paul718e3742002-12-13 20:15:29 +0000956 {
957 /* NEXT-HOP Unchanged. */
958 }
959 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
960 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
961#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000962 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000963 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000964#endif /* HAVE_IPV6 */
965 || (peer_sort (peer) == BGP_PEER_EBGP
966 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
967 {
968 /* Set IPv4 nexthop. */
969 if (p->family == AF_INET)
970 {
971 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000972 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
973 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000974 else
975 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
976 }
977#ifdef HAVE_IPV6
978 /* Set IPv6 nexthop. */
979 if (p->family == AF_INET6)
980 {
981 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000982 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +0000983 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000984 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000985 }
986#endif /* HAVE_IPV6 */
987 }
988
989#ifdef HAVE_IPV6
990 if (p->family == AF_INET6)
991 {
paulfee0f4c2004-09-13 05:12:46 +0000992 /* Left nexthop_local unchanged if so configured. */
993 if ( CHECK_FLAG (peer->af_flags[afi][safi],
994 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
995 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000996 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
997 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +0000998 else
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001000 }
1001
1002 /* Default nexthop_local treatment for non-RS-Clients */
1003 else
1004 {
paul718e3742002-12-13 20:15:29 +00001005 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001006 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001007
1008 /* Set link-local address for shared network peer. */
1009 if (peer->shared_network
1010 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1011 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001012 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001013 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001014 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001015 }
1016
1017 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1018 address.*/
1019 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001020 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001021
1022 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1023 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001024 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001025 }
paulfee0f4c2004-09-13 05:12:46 +00001026
1027 }
paul718e3742002-12-13 20:15:29 +00001028#endif /* HAVE_IPV6 */
1029
Paul Jakma41367172007-08-06 15:24:51 +00001030 /* AS-Pathlimit: Check ASN for private/confed */
1031 if (attr->pathlimit.ttl)
1032 {
1033 /* locally originated update */
1034 if (!attr->pathlimit.as)
1035 attr->pathlimit.as = peer->local_as;
1036
1037 /* if the AS_PATHLIMIT attribute is attached to a prefix by a
1038 member of a confederation, then when the prefix is advertised outside
1039 of the confederation boundary, then the AS number of the
1040 confederation member inside of the AS_PATHLIMIT attribute should be
1041 replaced by the confederation's AS number. */
1042 if (peer_sort (from) == BGP_PEER_CONFED
1043 && peer_sort (peer) != BGP_PEER_CONFED)
1044 attr->pathlimit.as = peer->local_as;
1045
1046 /* Private ASN should be updated whenever announcement leaves
1047 * private space. This is deliberately done after simple confed
1048 * based update..
1049 */
1050 if (attr->pathlimit.as >= BGP_PRIVATE_AS_MIN
1051 && attr->pathlimit.as <= BGP_PRIVATE_AS_MAX)
1052 {
1053 if (peer->local_as < BGP_PRIVATE_AS_MIN
1054 || peer->local_as > BGP_PRIVATE_AS_MAX)
1055 attr->pathlimit.as = peer->local_as;
1056 /* Ours is private, try using theirs.. */
1057 else if (peer->as < BGP_PRIVATE_AS_MIN
1058 || peer->local_as > BGP_PRIVATE_AS_MAX)
1059 attr->pathlimit.as = peer->as;
1060 }
1061 }
1062
paul718e3742002-12-13 20:15:29 +00001063 /* If this is EBGP peer and remove-private-AS is set. */
1064 if (peer_sort (peer) == BGP_PEER_EBGP
1065 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1066 && aspath_private_as_check (attr->aspath))
1067 attr->aspath = aspath_empty_get ();
1068
1069 /* Route map & unsuppress-map apply. */
1070 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001071 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001072 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001073 struct bgp_info info;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001074 struct attr dummy_attr = { 0 };
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001075
paul718e3742002-12-13 20:15:29 +00001076 info.peer = peer;
1077 info.attr = attr;
1078
1079 /* The route reflector is not allowed to modify the attributes
1080 of the reflected IBGP routes. */
1081 if (peer_sort (from) == BGP_PEER_IBGP
1082 && peer_sort (peer) == BGP_PEER_IBGP)
1083 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001084 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001085 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001086 }
paulac41b2a2003-08-12 05:32:27 +00001087
1088 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1089
Paul Jakmafb982c22007-05-04 20:15:47 +00001090 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001091 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1092 else
1093 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1094
paulac41b2a2003-08-12 05:32:27 +00001095 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001096
Paul Jakma9eda90c2007-08-30 13:36:17 +00001097 if (dummy_attr.extra)
1098 bgp_attr_extra_free (&dummy_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001099
paul718e3742002-12-13 20:15:29 +00001100 if (ret == RMAP_DENYMATCH)
1101 {
1102 bgp_attr_flush (attr);
1103 return 0;
1104 }
1105 }
1106 return 1;
1107}
1108
paul94f2b392005-06-28 12:44:16 +00001109static int
paulfee0f4c2004-09-13 05:12:46 +00001110bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1111 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001112{
paulfee0f4c2004-09-13 05:12:46 +00001113 int ret;
1114 char buf[SU_ADDRSTRLEN];
1115 struct bgp_filter *filter;
1116 struct bgp_info info;
1117 struct peer *from;
1118 struct bgp *bgp;
1119
1120 from = ri->peer;
1121 filter = &rsclient->filter[afi][safi];
1122 bgp = rsclient->bgp;
1123
Paul Jakma750e8142008-07-22 21:11:48 +00001124 if (DISABLE_BGP_ANNOUNCE)
1125 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001126
1127 /* Do not send back route to sender. */
1128 if (from == rsclient)
1129 return 0;
1130
1131 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001132 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001133 if (! UNSUPPRESS_MAP_NAME (filter))
1134 return 0;
1135
1136 /* Default route check. */
1137 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1138 PEER_STATUS_DEFAULT_ORIGINATE))
1139 {
1140 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1141 return 0;
1142#ifdef HAVE_IPV6
1143 else if (p->family == AF_INET6 && p->prefixlen == 0)
1144 return 0;
1145#endif /* HAVE_IPV6 */
1146 }
1147
1148 /* If the attribute has originator-id and it is same as remote
1149 peer's id. */
1150 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1151 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001152 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1153 &ri->attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001154 {
1155 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001156 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001157 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1158 rsclient->host,
1159 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1160 p->prefixlen);
1161 return 0;
1162 }
1163 }
1164
1165 /* ORF prefix-list filter check */
1166 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1167 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1168 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1169 if (rsclient->orf_plist[afi][safi])
1170 {
1171 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1172 return 0;
1173 }
1174
1175 /* Output filter check. */
1176 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1177 {
1178 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001179 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001180 "%s [Update:SEND] %s/%d is filtered",
1181 rsclient->host,
1182 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1183 p->prefixlen);
1184 return 0;
1185 }
1186
1187#ifdef BGP_SEND_ASPATH_CHECK
1188 /* AS path loop check. */
1189 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1190 {
1191 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001192 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001193 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001194 rsclient->host, rsclient->as);
1195 return 0;
1196 }
1197#endif /* BGP_SEND_ASPATH_CHECK */
1198
1199 /* For modify attribute, copy it to temporary structure. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001200 bgp_attr_dup (attr, ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001201
1202 /* next-hop-set */
1203 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1204#ifdef HAVE_IPV6
1205 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001206 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001207#endif /* HAVE_IPV6 */
1208 )
1209 {
1210 /* Set IPv4 nexthop. */
1211 if (p->family == AF_INET)
1212 {
1213 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001214 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001215 IPV4_MAX_BYTELEN);
1216 else
1217 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1218 }
1219#ifdef HAVE_IPV6
1220 /* Set IPv6 nexthop. */
1221 if (p->family == AF_INET6)
1222 {
1223 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001224 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001225 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001226 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001227 }
1228#endif /* HAVE_IPV6 */
1229 }
1230
1231#ifdef HAVE_IPV6
1232 if (p->family == AF_INET6)
1233 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 struct attr_extra *attre = attr->extra;
1235
1236 assert (attr->extra);
1237
paulfee0f4c2004-09-13 05:12:46 +00001238 /* Left nexthop_local unchanged if so configured. */
1239 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1240 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1241 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001242 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1243 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001244 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001245 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001246 }
1247
1248 /* Default nexthop_local treatment for RS-Clients */
1249 else
1250 {
1251 /* Announcer and RS-Client are both in the same network */
1252 if (rsclient->shared_network && from->shared_network &&
1253 (rsclient->ifindex == from->ifindex))
1254 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001255 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1256 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001257 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001258 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001259 }
1260
1261 /* Set link-local address for shared network peer. */
1262 else if (rsclient->shared_network
1263 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1264 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001265 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001266 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001267 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001268 }
1269
1270 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001271 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001272 }
1273
1274 }
1275#endif /* HAVE_IPV6 */
1276
1277
1278 /* If this is EBGP peer and remove-private-AS is set. */
1279 if (peer_sort (rsclient) == BGP_PEER_EBGP
1280 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1281 && aspath_private_as_check (attr->aspath))
1282 attr->aspath = aspath_empty_get ();
1283
1284 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001285 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001286 {
1287 info.peer = rsclient;
1288 info.attr = attr;
1289
1290 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1291
Paul Jakmafb982c22007-05-04 20:15:47 +00001292 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001293 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1294 else
1295 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1296
1297 rsclient->rmap_type = 0;
1298
1299 if (ret == RMAP_DENYMATCH)
1300 {
1301 bgp_attr_flush (attr);
1302 return 0;
1303 }
1304 }
1305
1306 return 1;
1307}
1308
1309struct bgp_info_pair
1310{
1311 struct bgp_info *old;
1312 struct bgp_info *new;
1313};
1314
paul94f2b392005-06-28 12:44:16 +00001315static void
paulfee0f4c2004-09-13 05:12:46 +00001316bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1317{
paul718e3742002-12-13 20:15:29 +00001318 struct bgp_info *new_select;
1319 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001320 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001321 struct bgp_info *ri1;
1322 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001323 struct bgp_info *nextri = NULL;
1324
paul718e3742002-12-13 20:15:29 +00001325 /* bgp deterministic-med */
1326 new_select = NULL;
1327 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1328 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1329 {
1330 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1331 continue;
1332 if (BGP_INFO_HOLDDOWN (ri1))
1333 continue;
1334
1335 new_select = ri1;
1336 if (ri1->next)
1337 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1338 {
1339 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1340 continue;
1341 if (BGP_INFO_HOLDDOWN (ri2))
1342 continue;
1343
1344 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1345 || aspath_cmp_left_confed (ri1->attr->aspath,
1346 ri2->attr->aspath))
1347 {
1348 if (bgp_info_cmp (bgp, ri2, new_select))
1349 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001350 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001351 new_select = ri2;
1352 }
1353
Paul Jakma1a392d42006-09-07 00:24:49 +00001354 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001355 }
1356 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1358 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001359 }
1360
1361 /* Check old selected route and new selected route. */
1362 old_select = NULL;
1363 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001364 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001365 {
1366 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1367 old_select = ri;
1368
1369 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001370 {
1371 /* reap REMOVED routes, if needs be
1372 * selected route must stay for a while longer though
1373 */
1374 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1375 && (ri != old_select))
1376 bgp_info_reap (rn, ri);
1377
1378 continue;
1379 }
paul718e3742002-12-13 20:15:29 +00001380
1381 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1382 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1383 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001384 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001385 continue;
1386 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001387 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1388 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001389
1390 if (bgp_info_cmp (bgp, ri, new_select))
1391 new_select = ri;
1392 }
paulb40d9392005-08-22 22:34:41 +00001393
paulfee0f4c2004-09-13 05:12:46 +00001394 result->old = old_select;
1395 result->new = new_select;
1396
1397 return;
1398}
1399
paul94f2b392005-06-28 12:44:16 +00001400static int
paulfee0f4c2004-09-13 05:12:46 +00001401bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001402 struct bgp_node *rn, afi_t afi, safi_t safi)
1403{
paulfee0f4c2004-09-13 05:12:46 +00001404 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001405 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001406
1407 p = &rn->p;
1408
Paul Jakma9eda90c2007-08-30 13:36:17 +00001409 /* Announce route to Established peer. */
1410 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001411 return 0;
1412
Paul Jakma9eda90c2007-08-30 13:36:17 +00001413 /* Address family configuration check. */
1414 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001415 return 0;
1416
Paul Jakma9eda90c2007-08-30 13:36:17 +00001417 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001418 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1419 PEER_STATUS_ORF_WAIT_REFRESH))
1420 return 0;
1421
1422 switch (rn->table->type)
1423 {
1424 case BGP_TABLE_MAIN:
1425 /* Announcement to peer->conf. If the route is filtered,
1426 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001427 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1428 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001429 else
1430 bgp_adj_out_unset (rn, peer, p, afi, safi);
1431 break;
1432 case BGP_TABLE_RSCLIENT:
1433 /* Announcement to peer->conf. If the route is filtered,
1434 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001435 if (selected &&
1436 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1437 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1438 else
1439 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001440 break;
1441 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001442
1443 bgp_attr_extra_free (&attr);
1444
paulfee0f4c2004-09-13 05:12:46 +00001445 return 0;
paul200df112005-06-01 11:17:05 +00001446}
paulfee0f4c2004-09-13 05:12:46 +00001447
paul200df112005-06-01 11:17:05 +00001448struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001449{
paul200df112005-06-01 11:17:05 +00001450 struct bgp *bgp;
1451 struct bgp_node *rn;
1452 afi_t afi;
1453 safi_t safi;
1454};
1455
1456static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001457bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001458{
paul0fb58d52005-11-14 14:31:49 +00001459 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001460 struct bgp *bgp = pq->bgp;
1461 struct bgp_node *rn = pq->rn;
1462 afi_t afi = pq->afi;
1463 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001464 struct bgp_info *new_select;
1465 struct bgp_info *old_select;
1466 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001467 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001468 struct peer *rsclient = rn->table->owner;
1469
paulfee0f4c2004-09-13 05:12:46 +00001470 /* Best path selection. */
1471 bgp_best_selection (bgp, rn, &old_and_new);
1472 new_select = old_and_new.new;
1473 old_select = old_and_new.old;
1474
paul200df112005-06-01 11:17:05 +00001475 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1476 {
Chris Caputo228da422009-07-18 05:44:03 +00001477 if (rsclient->group)
1478 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1479 {
1480 /* Nothing to do. */
1481 if (old_select && old_select == new_select)
1482 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1483 continue;
paulfee0f4c2004-09-13 05:12:46 +00001484
Chris Caputo228da422009-07-18 05:44:03 +00001485 if (old_select)
1486 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1487 if (new_select)
1488 {
1489 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1490 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1491 }
paulfee0f4c2004-09-13 05:12:46 +00001492
Chris Caputo228da422009-07-18 05:44:03 +00001493 bgp_process_announce_selected (rsclient, new_select, rn,
1494 afi, safi);
1495 }
paul200df112005-06-01 11:17:05 +00001496 }
1497 else
1498 {
hassob7395792005-08-26 12:58:38 +00001499 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001500 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001501 if (new_select)
1502 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001503 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1504 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001505 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001506 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001507 }
paulfee0f4c2004-09-13 05:12:46 +00001508
paulb40d9392005-08-22 22:34:41 +00001509 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1510 bgp_info_reap (rn, old_select);
1511
paul200df112005-06-01 11:17:05 +00001512 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1513 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001514}
1515
paul200df112005-06-01 11:17:05 +00001516static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001517bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001518{
paul0fb58d52005-11-14 14:31:49 +00001519 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001520 struct bgp *bgp = pq->bgp;
1521 struct bgp_node *rn = pq->rn;
1522 afi_t afi = pq->afi;
1523 safi_t safi = pq->safi;
1524 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001525 struct bgp_info *new_select;
1526 struct bgp_info *old_select;
1527 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001528 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001529 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001530
paulfee0f4c2004-09-13 05:12:46 +00001531 /* Best path selection. */
1532 bgp_best_selection (bgp, rn, &old_and_new);
1533 old_select = old_and_new.old;
1534 new_select = old_and_new.new;
1535
1536 /* Nothing to do. */
1537 if (old_select && old_select == new_select)
1538 {
1539 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001540 {
1541 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1542 bgp_zebra_announce (p, old_select, bgp);
1543
1544 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1545 return WQ_SUCCESS;
1546 }
paulfee0f4c2004-09-13 05:12:46 +00001547 }
paul718e3742002-12-13 20:15:29 +00001548
hasso338b3422005-02-23 14:27:24 +00001549 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001550 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001551 if (new_select)
1552 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001553 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1554 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001555 }
1556
1557
paul718e3742002-12-13 20:15:29 +00001558 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001559 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001560 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001561 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001562 }
1563
1564 /* FIB update. */
1565 if (safi == SAFI_UNICAST && ! bgp->name &&
1566 ! bgp_option_check (BGP_OPT_NO_FIB))
1567 {
1568 if (new_select
1569 && new_select->type == ZEBRA_ROUTE_BGP
1570 && new_select->sub_type == BGP_ROUTE_NORMAL)
1571 bgp_zebra_announce (p, new_select, bgp);
1572 else
1573 {
1574 /* Withdraw the route from the kernel. */
1575 if (old_select
1576 && old_select->type == ZEBRA_ROUTE_BGP
1577 && old_select->sub_type == BGP_ROUTE_NORMAL)
1578 bgp_zebra_withdraw (p, old_select);
1579 }
1580 }
paulb40d9392005-08-22 22:34:41 +00001581
1582 /* Reap old select bgp_info, it it has been removed */
1583 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1584 bgp_info_reap (rn, old_select);
1585
paul200df112005-06-01 11:17:05 +00001586 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1587 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001588}
1589
paul200df112005-06-01 11:17:05 +00001590static void
paul0fb58d52005-11-14 14:31:49 +00001591bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001592{
paul0fb58d52005-11-14 14:31:49 +00001593 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001594 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001595
Chris Caputo228da422009-07-18 05:44:03 +00001596 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001597 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001598 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001599 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1600}
1601
1602static void
1603bgp_process_queue_init (void)
1604{
1605 bm->process_main_queue
1606 = work_queue_new (bm->master, "process_main_queue");
1607 bm->process_rsclient_queue
1608 = work_queue_new (bm->master, "process_rsclient_queue");
1609
1610 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1611 {
1612 zlog_err ("%s: Failed to allocate work queue", __func__);
1613 exit (1);
1614 }
1615
1616 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1617 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1618 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1619 bm->process_rsclient_queue->spec.del_item_data
1620 = bm->process_main_queue->spec.del_item_data;
1621 bm->process_main_queue->spec.max_retries
1622 = bm->process_main_queue->spec.max_retries = 0;
1623 bm->process_rsclient_queue->spec.hold
Paul Jakma09dd5612006-09-14 03:38:16 +00001624 = bm->process_main_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001625}
1626
1627void
paulfee0f4c2004-09-13 05:12:46 +00001628bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1629{
paul200df112005-06-01 11:17:05 +00001630 struct bgp_process_queue *pqnode;
1631
1632 /* already scheduled for processing? */
1633 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1634 return;
1635
1636 if ( (bm->process_main_queue == NULL) ||
1637 (bm->process_rsclient_queue == NULL) )
1638 bgp_process_queue_init ();
1639
1640 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1641 sizeof (struct bgp_process_queue));
1642 if (!pqnode)
1643 return;
Chris Caputo228da422009-07-18 05:44:03 +00001644
1645 /* all unlocked in bgp_processq_del */
1646 bgp_table_lock (rn->table);
1647 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001648 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001649 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001650 pqnode->afi = afi;
1651 pqnode->safi = safi;
1652
paulfee0f4c2004-09-13 05:12:46 +00001653 switch (rn->table->type)
1654 {
paul200df112005-06-01 11:17:05 +00001655 case BGP_TABLE_MAIN:
1656 work_queue_add (bm->process_main_queue, pqnode);
1657 break;
1658 case BGP_TABLE_RSCLIENT:
1659 work_queue_add (bm->process_rsclient_queue, pqnode);
1660 break;
paulfee0f4c2004-09-13 05:12:46 +00001661 }
paul200df112005-06-01 11:17:05 +00001662
1663 return;
paulfee0f4c2004-09-13 05:12:46 +00001664}
hasso0a486e52005-02-01 20:57:17 +00001665
paul94f2b392005-06-28 12:44:16 +00001666static int
hasso0a486e52005-02-01 20:57:17 +00001667bgp_maximum_prefix_restart_timer (struct thread *thread)
1668{
1669 struct peer *peer;
1670
1671 peer = THREAD_ARG (thread);
1672 peer->t_pmax_restart = NULL;
1673
1674 if (BGP_DEBUG (events, EVENTS))
1675 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1676 peer->host);
1677
1678 peer_clear (peer);
1679
1680 return 0;
1681}
1682
paulfee0f4c2004-09-13 05:12:46 +00001683int
paul5228ad22004-06-04 17:58:18 +00001684bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1685 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001686{
hassoe0701b72004-05-20 09:19:34 +00001687 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1688 return 0;
1689
1690 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001691 {
hassoe0701b72004-05-20 09:19:34 +00001692 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1693 && ! always)
1694 return 0;
paul718e3742002-12-13 20:15:29 +00001695
hassoe0701b72004-05-20 09:19:34 +00001696 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001697 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1698 "limit %ld", afi_safi_print (afi, safi), peer->host,
1699 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001700 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001701
hassoe0701b72004-05-20 09:19:34 +00001702 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1703 return 0;
paul718e3742002-12-13 20:15:29 +00001704
hassoe0701b72004-05-20 09:19:34 +00001705 {
paul5228ad22004-06-04 17:58:18 +00001706 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001707
1708 if (safi == SAFI_MPLS_VPN)
1709 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001710
1711 ndata[0] = (afi >> 8);
1712 ndata[1] = afi;
1713 ndata[2] = safi;
1714 ndata[3] = (peer->pmax[afi][safi] >> 24);
1715 ndata[4] = (peer->pmax[afi][safi] >> 16);
1716 ndata[5] = (peer->pmax[afi][safi] >> 8);
1717 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001718
1719 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1720 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1721 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1722 }
hasso0a486e52005-02-01 20:57:17 +00001723
1724 /* restart timer start */
1725 if (peer->pmax_restart[afi][safi])
1726 {
1727 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1728
1729 if (BGP_DEBUG (events, EVENTS))
1730 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1731 peer->host, peer->v_pmax_restart);
1732
1733 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1734 peer->v_pmax_restart);
1735 }
1736
hassoe0701b72004-05-20 09:19:34 +00001737 return 1;
paul718e3742002-12-13 20:15:29 +00001738 }
hassoe0701b72004-05-20 09:19:34 +00001739 else
1740 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1741
1742 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1743 {
1744 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1745 && ! always)
1746 return 0;
1747
1748 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001749 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1750 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1751 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001752 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1753 }
1754 else
1755 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001756 return 0;
1757}
1758
paulb40d9392005-08-22 22:34:41 +00001759/* Unconditionally remove the route from the RIB, without taking
1760 * damping into consideration (eg, because the session went down)
1761 */
paul94f2b392005-06-28 12:44:16 +00001762static void
paul718e3742002-12-13 20:15:29 +00001763bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1764 afi_t afi, safi_t safi)
1765{
paul902212c2006-02-05 17:51:19 +00001766 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1767
1768 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1769 bgp_info_delete (rn, ri); /* keep historical info */
1770
paulb40d9392005-08-22 22:34:41 +00001771 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001772}
1773
paul94f2b392005-06-28 12:44:16 +00001774static void
paul718e3742002-12-13 20:15:29 +00001775bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001776 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001777{
paul718e3742002-12-13 20:15:29 +00001778 int status = BGP_DAMP_NONE;
1779
paulb40d9392005-08-22 22:34:41 +00001780 /* apply dampening, if result is suppressed, we'll be retaining
1781 * the bgp_info in the RIB for historical reference.
1782 */
1783 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1784 && peer_sort (peer) == BGP_PEER_EBGP)
1785 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1786 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001787 {
paul902212c2006-02-05 17:51:19 +00001788 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1789 return;
1790 }
1791
1792 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001793}
1794
paul94f2b392005-06-28 12:44:16 +00001795static void
paulfee0f4c2004-09-13 05:12:46 +00001796bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1797 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1798 int sub_type, struct prefix_rd *prd, u_char *tag)
1799{
1800 struct bgp_node *rn;
1801 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001802 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001803 struct attr *attr_new;
1804 struct attr *attr_new2;
1805 struct bgp_info *ri;
1806 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001807 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001808 char buf[SU_ADDRSTRLEN];
1809
1810 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1811 if (peer == rsclient)
1812 return;
1813
1814 bgp = peer->bgp;
1815 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1816
1817 /* Check previously received route. */
1818 for (ri = rn->info; ri; ri = ri->next)
1819 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1820 break;
1821
1822 /* AS path loop check. */
1823 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1824 {
1825 reason = "as-path contains our own AS;";
1826 goto filtered;
1827 }
1828
1829 /* Route reflector originator ID check. */
1830 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001831 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001832 {
1833 reason = "originator is us;";
1834 goto filtered;
1835 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001836
1837 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001838
1839 /* Apply export policy. */
1840 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1841 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1842 {
1843 reason = "export-policy;";
1844 goto filtered;
1845 }
1846
1847 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001848
paulfee0f4c2004-09-13 05:12:46 +00001849 /* Apply import policy. */
1850 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1851 {
1852 bgp_attr_unintern (attr_new2);
1853
1854 reason = "import-policy;";
1855 goto filtered;
1856 }
1857
1858 attr_new = bgp_attr_intern (&new_attr);
1859 bgp_attr_unintern (attr_new2);
1860
1861 /* IPv4 unicast next hop check. */
1862 if (afi == AFI_IP && safi == SAFI_UNICAST)
1863 {
1864 /* Next hop must not be 0.0.0.0 nor Class E address. */
1865 if (new_attr.nexthop.s_addr == 0
1866 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1867 {
1868 bgp_attr_unintern (attr_new);
1869
1870 reason = "martian next-hop;";
1871 goto filtered;
1872 }
1873 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001874
1875 /* new_attr isn't passed to any functions after here */
1876 bgp_attr_extra_free (&new_attr);
1877
paulfee0f4c2004-09-13 05:12:46 +00001878 /* If the update is implicit withdraw. */
1879 if (ri)
1880 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001881 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001882
1883 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001884 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1885 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001886 {
1887
Paul Jakma1a392d42006-09-07 00:24:49 +00001888 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001889
1890 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001891 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001892 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1893 peer->host,
1894 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1895 p->prefixlen, rsclient->host);
1896
Chris Caputo228da422009-07-18 05:44:03 +00001897 bgp_unlock_node (rn);
1898 bgp_attr_unintern (attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001899
Chris Caputo228da422009-07-18 05:44:03 +00001900 return;
paulfee0f4c2004-09-13 05:12:46 +00001901 }
1902
Paul Jakma16d2e242007-04-10 19:32:10 +00001903 /* Withdraw/Announce before we fully processed the withdraw */
1904 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1905 bgp_info_restore (rn, ri);
1906
paulfee0f4c2004-09-13 05:12:46 +00001907 /* Received Logging. */
1908 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001909 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001910 peer->host,
1911 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1912 p->prefixlen, rsclient->host);
1913
1914 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001915 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001916
1917 /* Update to new attribute. */
1918 bgp_attr_unintern (ri->attr);
1919 ri->attr = attr_new;
1920
1921 /* Update MPLS tag. */
1922 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001923 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001924
Paul Jakma1a392d42006-09-07 00:24:49 +00001925 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001926
1927 /* Process change. */
1928 bgp_process (bgp, rn, afi, safi);
1929 bgp_unlock_node (rn);
1930
1931 return;
1932 }
1933
1934 /* Received Logging. */
1935 if (BGP_DEBUG (update, UPDATE_IN))
1936 {
ajsd2c1f162004-12-08 21:10:20 +00001937 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001938 peer->host,
1939 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1940 p->prefixlen, rsclient->host);
1941 }
1942
1943 /* Make new BGP info. */
1944 new = bgp_info_new ();
1945 new->type = type;
1946 new->sub_type = sub_type;
1947 new->peer = peer;
1948 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001949 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001950
1951 /* Update MPLS tag. */
1952 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001953 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001954
Paul Jakma1a392d42006-09-07 00:24:49 +00001955 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001956
1957 /* Register new BGP information. */
1958 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001959
1960 /* route_node_get lock */
1961 bgp_unlock_node (rn);
1962
paulfee0f4c2004-09-13 05:12:46 +00001963 /* Process change. */
1964 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001965
1966 bgp_attr_extra_free (&new_attr);
1967
paulfee0f4c2004-09-13 05:12:46 +00001968 return;
1969
1970 filtered:
1971
1972 /* This BGP update is filtered. Log the reason then update BGP entry. */
1973 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001974 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001975 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1976 peer->host,
1977 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1978 p->prefixlen, rsclient->host, reason);
1979
1980 if (ri)
paulb40d9392005-08-22 22:34:41 +00001981 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001982
1983 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001984
1985 if (new_attr.extra)
1986 bgp_attr_extra_free (&new_attr);
1987
paulfee0f4c2004-09-13 05:12:46 +00001988 return;
1989}
1990
paul94f2b392005-06-28 12:44:16 +00001991static void
paulfee0f4c2004-09-13 05:12:46 +00001992bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1993 struct peer *peer, struct prefix *p, int type, int sub_type,
1994 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00001995{
paulfee0f4c2004-09-13 05:12:46 +00001996 struct bgp_node *rn;
1997 struct bgp_info *ri;
1998 char buf[SU_ADDRSTRLEN];
1999
2000 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002001 return;
paulfee0f4c2004-09-13 05:12:46 +00002002
2003 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2004
2005 /* Lookup withdrawn route. */
2006 for (ri = rn->info; ri; ri = ri->next)
2007 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2008 break;
2009
2010 /* Withdraw specified route from routing table. */
2011 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002012 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002013 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002014 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002015 "%s Can't find the route %s/%d", peer->host,
2016 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2017 p->prefixlen);
2018
2019 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002020 bgp_unlock_node (rn);
2021}
paulfee0f4c2004-09-13 05:12:46 +00002022
paul94f2b392005-06-28 12:44:16 +00002023static int
paulfee0f4c2004-09-13 05:12:46 +00002024bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002025 afi_t afi, safi_t safi, int type, int sub_type,
2026 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2027{
2028 int ret;
2029 int aspath_loop_count = 0;
2030 struct bgp_node *rn;
2031 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002032 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002033 struct attr *attr_new;
2034 struct bgp_info *ri;
2035 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002036 const char *reason;
paul718e3742002-12-13 20:15:29 +00002037 char buf[SU_ADDRSTRLEN];
2038
2039 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002040 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002041
paul718e3742002-12-13 20:15:29 +00002042 /* When peer's soft reconfiguration enabled. Record input packet in
2043 Adj-RIBs-In. */
2044 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2045 && peer != bgp->peer_self && ! soft_reconfig)
2046 bgp_adj_in_set (rn, peer, attr);
2047
2048 /* Check previously received route. */
2049 for (ri = rn->info; ri; ri = ri->next)
2050 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2051 break;
2052
2053 /* AS path local-as loop check. */
2054 if (peer->change_local_as)
2055 {
2056 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2057 aspath_loop_count = 1;
2058
2059 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2060 {
2061 reason = "as-path contains our own AS;";
2062 goto filtered;
2063 }
2064 }
2065
2066 /* AS path loop check. */
2067 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2068 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2069 && aspath_loop_check(attr->aspath, bgp->confed_id)
2070 > peer->allowas_in[afi][safi]))
2071 {
2072 reason = "as-path contains our own AS;";
2073 goto filtered;
2074 }
2075
2076 /* Route reflector originator ID check. */
2077 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002078 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002079 {
2080 reason = "originator is us;";
2081 goto filtered;
2082 }
2083
2084 /* Route reflector cluster ID check. */
2085 if (bgp_cluster_filter (peer, attr))
2086 {
2087 reason = "reflected from the same cluster;";
2088 goto filtered;
2089 }
2090
2091 /* Apply incoming filter. */
2092 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2093 {
2094 reason = "filter;";
2095 goto filtered;
2096 }
2097
2098 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002099 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002100
2101 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2102 {
2103 reason = "route-map;";
2104 goto filtered;
2105 }
2106
2107 /* IPv4 unicast next hop check. */
2108 if (afi == AFI_IP && safi == SAFI_UNICAST)
2109 {
2110 /* If the peer is EBGP and nexthop is not on connected route,
2111 discard it. */
2112 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2113 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002114 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002115 {
2116 reason = "non-connected next-hop;";
2117 goto filtered;
2118 }
2119
2120 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2121 must not be my own address. */
2122 if (bgp_nexthop_self (afi, &new_attr)
2123 || new_attr.nexthop.s_addr == 0
2124 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2125 {
2126 reason = "martian next-hop;";
2127 goto filtered;
2128 }
2129 }
2130
2131 attr_new = bgp_attr_intern (&new_attr);
2132
2133 /* If the update is implicit withdraw. */
2134 if (ri)
2135 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002136 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002137
2138 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002139 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2140 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002141 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002142 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002143
2144 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2145 && peer_sort (peer) == BGP_PEER_EBGP
2146 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2147 {
2148 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002149 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002150 peer->host,
2151 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2152 p->prefixlen);
2153
paul902212c2006-02-05 17:51:19 +00002154 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2155 {
2156 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2157 bgp_process (bgp, rn, afi, safi);
2158 }
paul718e3742002-12-13 20:15:29 +00002159 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002160 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002161 {
2162 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002163 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002164 "%s rcvd %s/%d...duplicate ignored",
2165 peer->host,
2166 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2167 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002168
2169 /* graceful restart STALE flag unset. */
2170 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2171 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002172 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002173 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002174 }
paul718e3742002-12-13 20:15:29 +00002175 }
2176
2177 bgp_unlock_node (rn);
2178 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002179 bgp_attr_extra_free (&new_attr);
2180
paul718e3742002-12-13 20:15:29 +00002181 return 0;
2182 }
2183
Paul Jakma16d2e242007-04-10 19:32:10 +00002184 /* Withdraw/Announce before we fully processed the withdraw */
2185 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2186 {
2187 if (BGP_DEBUG (update, UPDATE_IN))
2188 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2189 peer->host,
2190 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2191 p->prefixlen);
2192 bgp_info_restore (rn, ri);
2193 }
2194
paul718e3742002-12-13 20:15:29 +00002195 /* Received Logging. */
2196 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002197 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002198 peer->host,
2199 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2200 p->prefixlen);
2201
hasso93406d82005-02-02 14:40:33 +00002202 /* graceful restart STALE flag unset. */
2203 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002204 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002205
paul718e3742002-12-13 20:15:29 +00002206 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002207 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002208
2209 /* implicit withdraw, decrement aggregate and pcount here.
2210 * only if update is accepted, they'll increment below.
2211 */
paul902212c2006-02-05 17:51:19 +00002212 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2213
paul718e3742002-12-13 20:15:29 +00002214 /* Update bgp route dampening information. */
2215 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2216 && peer_sort (peer) == BGP_PEER_EBGP)
2217 {
2218 /* This is implicit withdraw so we should update dampening
2219 information. */
2220 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2221 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002222 }
2223
paul718e3742002-12-13 20:15:29 +00002224 /* Update to new attribute. */
2225 bgp_attr_unintern (ri->attr);
2226 ri->attr = attr_new;
2227
2228 /* Update MPLS tag. */
2229 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002230 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002231
2232 /* Update bgp route dampening information. */
2233 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2234 && peer_sort (peer) == BGP_PEER_EBGP)
2235 {
2236 /* Now we do normal update dampening. */
2237 ret = bgp_damp_update (ri, rn, afi, safi);
2238 if (ret == BGP_DAMP_SUPPRESSED)
2239 {
2240 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002241 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002242 return 0;
2243 }
2244 }
2245
2246 /* Nexthop reachability check. */
2247 if ((afi == AFI_IP || afi == AFI_IP6)
2248 && safi == SAFI_UNICAST
2249 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002250 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002251 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002252 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002253 {
2254 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002255 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002256 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002257 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002258 }
2259 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002260 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002261
2262 /* Process change. */
2263 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2264
2265 bgp_process (bgp, rn, afi, safi);
2266 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002267 bgp_attr_extra_free (&new_attr);
2268
paul718e3742002-12-13 20:15:29 +00002269 return 0;
2270 }
2271
2272 /* Received Logging. */
2273 if (BGP_DEBUG (update, UPDATE_IN))
2274 {
ajsd2c1f162004-12-08 21:10:20 +00002275 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002276 peer->host,
2277 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2278 p->prefixlen);
2279 }
2280
paul718e3742002-12-13 20:15:29 +00002281 /* Make new BGP info. */
2282 new = bgp_info_new ();
2283 new->type = type;
2284 new->sub_type = sub_type;
2285 new->peer = peer;
2286 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002287 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002288
2289 /* Update MPLS tag. */
2290 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002291 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002292
2293 /* Nexthop reachability check. */
2294 if ((afi == AFI_IP || afi == AFI_IP6)
2295 && safi == SAFI_UNICAST
2296 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002297 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002298 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002299 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002300 {
2301 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002302 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002303 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002304 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002305 }
2306 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002307 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002308
paul902212c2006-02-05 17:51:19 +00002309 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002310 bgp_aggregate_increment (bgp, p, new, afi, safi);
2311
2312 /* Register new BGP information. */
2313 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002314
2315 /* route_node_get lock */
2316 bgp_unlock_node (rn);
2317
Paul Jakmafb982c22007-05-04 20:15:47 +00002318 bgp_attr_extra_free (&new_attr);
2319
paul718e3742002-12-13 20:15:29 +00002320 /* If maximum prefix count is configured and current prefix
2321 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002322 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2323 return -1;
paul718e3742002-12-13 20:15:29 +00002324
2325 /* Process change. */
2326 bgp_process (bgp, rn, afi, safi);
2327
2328 return 0;
2329
2330 /* This BGP update is filtered. Log the reason then update BGP
2331 entry. */
2332 filtered:
2333 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002334 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002335 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2336 peer->host,
2337 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2338 p->prefixlen, reason);
2339
2340 if (ri)
paulb40d9392005-08-22 22:34:41 +00002341 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002342
2343 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002344
2345 bgp_attr_extra_free (&new_attr);
2346
paul718e3742002-12-13 20:15:29 +00002347 return 0;
2348}
2349
2350int
paulfee0f4c2004-09-13 05:12:46 +00002351bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2352 afi_t afi, safi_t safi, int type, int sub_type,
2353 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2354{
2355 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002356 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002357 struct bgp *bgp;
2358 int ret;
2359
2360 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2361 soft_reconfig);
2362
2363 bgp = peer->bgp;
2364
2365 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002366 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002367 {
2368 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2369 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2370 sub_type, prd, tag);
2371 }
2372
2373 return ret;
2374}
2375
2376int
paul718e3742002-12-13 20:15:29 +00002377bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002378 afi_t afi, safi_t safi, int type, int sub_type,
2379 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002380{
2381 struct bgp *bgp;
2382 char buf[SU_ADDRSTRLEN];
2383 struct bgp_node *rn;
2384 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002385 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002386 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002387
2388 bgp = peer->bgp;
2389
paulfee0f4c2004-09-13 05:12:46 +00002390 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002391 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002392 {
2393 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2394 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2395 }
2396
paul718e3742002-12-13 20:15:29 +00002397 /* Logging. */
2398 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002399 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002400 peer->host,
2401 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2402 p->prefixlen);
2403
2404 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002405 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002406
2407 /* If peer is soft reconfiguration enabled. Record input packet for
2408 further calculation. */
2409 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2410 && peer != bgp->peer_self)
2411 bgp_adj_in_unset (rn, peer);
2412
2413 /* Lookup withdrawn route. */
2414 for (ri = rn->info; ri; ri = ri->next)
2415 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2416 break;
2417
2418 /* Withdraw specified route from routing table. */
2419 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002420 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002421 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002422 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002423 "%s Can't find the route %s/%d", peer->host,
2424 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2425 p->prefixlen);
2426
2427 /* Unlock bgp_node_get() lock. */
2428 bgp_unlock_node (rn);
2429
2430 return 0;
2431}
2432
2433void
2434bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2435{
2436 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002437 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002438 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002439 struct prefix p;
2440 struct bgp_info binfo;
2441 struct peer *from;
2442 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002443
Paul Jakmab2497022007-06-14 11:17:58 +00002444 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002445 return;
2446
paul718e3742002-12-13 20:15:29 +00002447 bgp = peer->bgp;
2448 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002449
paul718e3742002-12-13 20:15:29 +00002450 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2451 aspath = attr.aspath;
2452 attr.local_pref = bgp->default_local_pref;
2453 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2454
2455 if (afi == AFI_IP)
2456 str2prefix ("0.0.0.0/0", &p);
2457#ifdef HAVE_IPV6
2458 else if (afi == AFI_IP6)
2459 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002460 struct attr_extra *ae;
2461 attr.extra = NULL;
2462
2463 ae = bgp_attr_extra_get (&attr);
2464 attr.extra = ae;
2465
paul718e3742002-12-13 20:15:29 +00002466 str2prefix ("::/0", &p);
2467
2468 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002469 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002470 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002471 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002472
2473 /* If the peer is on shared nextwork and we have link-local
2474 nexthop set it. */
2475 if (peer->shared_network
2476 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2477 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002478 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002479 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002480 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002481 }
2482 }
2483#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002484
2485 if (peer->default_rmap[afi][safi].name)
2486 {
2487 binfo.peer = bgp->peer_self;
2488 binfo.attr = &attr;
2489
paulfee0f4c2004-09-13 05:12:46 +00002490 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2491
paul718e3742002-12-13 20:15:29 +00002492 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2493 RMAP_BGP, &binfo);
2494
paulfee0f4c2004-09-13 05:12:46 +00002495 bgp->peer_self->rmap_type = 0;
2496
paul718e3742002-12-13 20:15:29 +00002497 if (ret == RMAP_DENYMATCH)
2498 {
2499 bgp_attr_flush (&attr);
2500 withdraw = 1;
2501 }
2502 }
2503
2504 if (withdraw)
2505 {
2506 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2507 bgp_default_withdraw_send (peer, afi, safi);
2508 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2509 }
2510 else
2511 {
2512 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2513 bgp_default_update_send (peer, &attr, afi, safi, from);
2514 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002515
2516 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002517 aspath_unintern (aspath);
2518}
2519
2520static void
2521bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002522 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002523{
2524 struct bgp_node *rn;
2525 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002526 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002527
paul718e3742002-12-13 20:15:29 +00002528 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002529 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002530
2531 if (safi != SAFI_MPLS_VPN
2532 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2533 bgp_default_originate (peer, afi, safi, 0);
2534
2535 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2536 for (ri = rn->info; ri; ri = ri->next)
2537 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2538 {
paulfee0f4c2004-09-13 05:12:46 +00002539 if ( (rsclient) ?
2540 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2541 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002542 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2543 else
2544 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002545
2546 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002547 }
2548}
2549
2550void
2551bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2552{
2553 struct bgp_node *rn;
2554 struct bgp_table *table;
2555
2556 if (peer->status != Established)
2557 return;
2558
2559 if (! peer->afc_nego[afi][safi])
2560 return;
2561
2562 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2563 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2564 return;
2565
2566 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002567 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002568 else
2569 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2570 rn = bgp_route_next(rn))
2571 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002572 bgp_announce_table (peer, afi, safi, table, 0);
2573
2574 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2575 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002576}
2577
2578void
2579bgp_announce_route_all (struct peer *peer)
2580{
2581 afi_t afi;
2582 safi_t safi;
2583
2584 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2585 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2586 bgp_announce_route (peer, afi, safi);
2587}
2588
2589static void
paulfee0f4c2004-09-13 05:12:46 +00002590bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2591 safi_t safi, struct bgp_table *table)
2592{
2593 struct bgp_node *rn;
2594 struct bgp_adj_in *ain;
2595
2596 if (! table)
2597 table = rsclient->bgp->rib[afi][safi];
2598
2599 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2600 for (ain = rn->adj_in; ain; ain = ain->next)
2601 {
2602 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2603 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2604 }
2605}
2606
2607void
2608bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2609{
2610 struct bgp_table *table;
2611 struct bgp_node *rn;
2612
2613 if (safi != SAFI_MPLS_VPN)
2614 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2615
2616 else
2617 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2618 rn = bgp_route_next (rn))
2619 if ((table = rn->info) != NULL)
2620 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2621}
2622
2623static void
paul718e3742002-12-13 20:15:29 +00002624bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2625 struct bgp_table *table)
2626{
2627 int ret;
2628 struct bgp_node *rn;
2629 struct bgp_adj_in *ain;
2630
2631 if (! table)
2632 table = peer->bgp->rib[afi][safi];
2633
2634 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2635 for (ain = rn->adj_in; ain; ain = ain->next)
2636 {
2637 if (ain->peer == peer)
2638 {
2639 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2640 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2641 NULL, NULL, 1);
2642 if (ret < 0)
2643 {
2644 bgp_unlock_node (rn);
2645 return;
2646 }
2647 continue;
2648 }
2649 }
2650}
2651
2652void
2653bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2654{
2655 struct bgp_node *rn;
2656 struct bgp_table *table;
2657
2658 if (peer->status != Established)
2659 return;
2660
2661 if (safi != SAFI_MPLS_VPN)
2662 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2663 else
2664 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2665 rn = bgp_route_next (rn))
2666 if ((table = rn->info) != NULL)
2667 bgp_soft_reconfig_table (peer, afi, safi, table);
2668}
2669
Chris Caputo228da422009-07-18 05:44:03 +00002670
2671struct bgp_clear_node_queue
2672{
2673 struct bgp_node *rn;
2674 enum bgp_clear_route_type purpose;
2675};
2676
paul200df112005-06-01 11:17:05 +00002677static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002678bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002679{
Chris Caputo228da422009-07-18 05:44:03 +00002680 struct bgp_clear_node_queue *cnq = data;
2681 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002682 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002683 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002684 afi_t afi = rn->table->afi;
2685 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002686
Paul Jakma64e580a2006-02-21 01:09:01 +00002687 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002688
Paul Jakma64e580a2006-02-21 01:09:01 +00002689 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002690 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002691 {
2692 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002693 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2694 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002695 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002696 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2697 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002698 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002699 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002700 break;
2701 }
paul200df112005-06-01 11:17:05 +00002702 return WQ_SUCCESS;
2703}
2704
2705static void
paul0fb58d52005-11-14 14:31:49 +00002706bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002707{
Chris Caputo228da422009-07-18 05:44:03 +00002708 struct bgp_clear_node_queue *cnq = data;
2709 struct bgp_node *rn = cnq->rn;
2710 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002711
2712 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002713 bgp_table_unlock (table);
2714 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002715}
2716
2717static void
paul94f2b392005-06-28 12:44:16 +00002718bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002719{
Paul Jakma64e580a2006-02-21 01:09:01 +00002720 struct peer *peer = wq->spec.data;
2721
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002722 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002723 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002724
2725 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002726}
2727
2728static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002729bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002730{
Paul Jakmaa2943652009-07-21 14:02:04 +01002731 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002732
Paul Jakmaa2943652009-07-21 14:02:04 +01002733 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002734#undef CLEAR_QUEUE_NAME_LEN
2735
2736 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002737 {
2738 zlog_err ("%s: Failed to allocate work queue", __func__);
2739 exit (1);
2740 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002741 peer->clear_node_queue->spec.hold = 10;
2742 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2743 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2744 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2745 peer->clear_node_queue->spec.max_retries = 0;
2746
2747 /* we only 'lock' this peer reference when the queue is actually active */
2748 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002749}
2750
paul718e3742002-12-13 20:15:29 +00002751static void
2752bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002753 struct bgp_table *table, struct peer *rsclient,
2754 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002755{
2756 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002757
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002758
paul718e3742002-12-13 20:15:29 +00002759 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002760 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002761
hasso6cf159b2005-03-21 10:28:14 +00002762 /* If still no table => afi/safi isn't configured at all or smth. */
2763 if (! table)
2764 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002765
2766 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2767 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002768 struct bgp_info *ri;
2769 struct bgp_adj_in *ain;
2770 struct bgp_adj_out *aout;
2771
Paul Jakma65ca75e2006-05-04 08:08:15 +00002772 if (rn->info == NULL)
2773 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002774
2775 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2776 * queued for every clearing peer, regardless of whether it is
2777 * relevant to the peer at hand.
2778 *
2779 * Overview: There are 3 different indices which need to be
2780 * scrubbed, potentially, when a peer is removed:
2781 *
2782 * 1 peer's routes visible via the RIB (ie accepted routes)
2783 * 2 peer's routes visible by the (optional) peer's adj-in index
2784 * 3 other routes visible by the peer's adj-out index
2785 *
2786 * 3 there is no hurry in scrubbing, once the struct peer is
2787 * removed from bgp->peer, we could just GC such deleted peer's
2788 * adj-outs at our leisure.
2789 *
2790 * 1 and 2 must be 'scrubbed' in some way, at least made
2791 * invisible via RIB index before peer session is allowed to be
2792 * brought back up. So one needs to know when such a 'search' is
2793 * complete.
2794 *
2795 * Ideally:
2796 *
2797 * - there'd be a single global queue or a single RIB walker
2798 * - rather than tracking which route_nodes still need to be
2799 * examined on a peer basis, we'd track which peers still
2800 * aren't cleared
2801 *
2802 * Given that our per-peer prefix-counts now should be reliable,
2803 * this may actually be achievable. It doesn't seem to be a huge
2804 * problem at this time,
2805 */
2806 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002807 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002808 {
Chris Caputo228da422009-07-18 05:44:03 +00002809 struct bgp_clear_node_queue *cnq;
2810
2811 /* both unlocked in bgp_clear_node_queue_del */
2812 bgp_table_lock (rn->table);
2813 bgp_lock_node (rn);
2814 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2815 sizeof (struct bgp_clear_node_queue));
2816 cnq->rn = rn;
2817 cnq->purpose = purpose;
2818 work_queue_add (peer->clear_node_queue, cnq);
2819 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002820 }
2821
2822 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002823 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002824 {
2825 bgp_adj_in_remove (rn, ain);
2826 bgp_unlock_node (rn);
2827 break;
2828 }
2829 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002830 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002831 {
2832 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2833 bgp_unlock_node (rn);
2834 break;
2835 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002836 }
2837 return;
2838}
2839
2840void
Chris Caputo228da422009-07-18 05:44:03 +00002841bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2842 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002843{
2844 struct bgp_node *rn;
2845 struct bgp_table *table;
2846 struct peer *rsclient;
2847 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002848
Paul Jakma64e580a2006-02-21 01:09:01 +00002849 if (peer->clear_node_queue == NULL)
2850 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002851
Paul Jakmaca058a32006-09-14 02:58:49 +00002852 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2853 * Idle until it receives a Clearing_Completed event. This protects
2854 * against peers which flap faster than we can we clear, which could
2855 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002856 *
2857 * a) race with routes from the new session being installed before
2858 * clear_route_node visits the node (to delete the route of that
2859 * peer)
2860 * b) resource exhaustion, clear_route_node likely leads to an entry
2861 * on the process_main queue. Fast-flapping could cause that queue
2862 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002863 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002864 if (!peer->clear_node_queue->thread)
2865 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002866
Chris Caputo228da422009-07-18 05:44:03 +00002867 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002868 {
Chris Caputo228da422009-07-18 05:44:03 +00002869 case BGP_CLEAR_ROUTE_NORMAL:
2870 if (safi != SAFI_MPLS_VPN)
2871 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2872 else
2873 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2874 rn = bgp_route_next (rn))
2875 if ((table = rn->info) != NULL)
2876 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2877
2878 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2879 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2880 PEER_FLAG_RSERVER_CLIENT))
2881 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2882 break;
2883
2884 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2885 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2886 break;
2887
2888 default:
2889 assert (0);
2890 break;
paulfee0f4c2004-09-13 05:12:46 +00002891 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002892
Paul Jakmaca058a32006-09-14 02:58:49 +00002893 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002894 * completion function won't be run by workqueue code - call it here.
2895 * XXX: Actually, this assumption doesn't hold, see
2896 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002897 *
2898 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002899 * really needed if peer state is Established - peers in
2900 * pre-Established states shouldn't have any route-update state
2901 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002902 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002903 * We still can get here in pre-Established though, through
2904 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2905 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002906 *
2907 * At some future point, this check could be move to the top of the
2908 * function, and do a quick early-return when state is
2909 * pre-Established, avoiding above list and table scans. Once we're
2910 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002911 */
2912 if (!peer->clear_node_queue->thread)
2913 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002914}
2915
2916void
2917bgp_clear_route_all (struct peer *peer)
2918{
2919 afi_t afi;
2920 safi_t safi;
2921
2922 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2923 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002924 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002925}
2926
2927void
2928bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2929{
2930 struct bgp_table *table;
2931 struct bgp_node *rn;
2932 struct bgp_adj_in *ain;
2933
2934 table = peer->bgp->rib[afi][safi];
2935
2936 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2937 for (ain = rn->adj_in; ain ; ain = ain->next)
2938 if (ain->peer == peer)
2939 {
2940 bgp_adj_in_remove (rn, ain);
2941 bgp_unlock_node (rn);
2942 break;
2943 }
2944}
hasso93406d82005-02-02 14:40:33 +00002945
2946void
2947bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2948{
2949 struct bgp_node *rn;
2950 struct bgp_info *ri;
2951 struct bgp_table *table;
2952
2953 table = peer->bgp->rib[afi][safi];
2954
2955 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2956 {
2957 for (ri = rn->info; ri; ri = ri->next)
2958 if (ri->peer == peer)
2959 {
2960 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2961 bgp_rib_remove (rn, ri, peer, afi, safi);
2962 break;
2963 }
2964 }
2965}
paul718e3742002-12-13 20:15:29 +00002966
2967/* Delete all kernel routes. */
2968void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002969bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002970{
2971 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002972 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002973 struct bgp_node *rn;
2974 struct bgp_table *table;
2975 struct bgp_info *ri;
2976
paul1eb8ef22005-04-07 07:30:20 +00002977 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002978 {
2979 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2980
2981 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2982 for (ri = rn->info; ri; ri = ri->next)
2983 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2984 && ri->type == ZEBRA_ROUTE_BGP
2985 && ri->sub_type == BGP_ROUTE_NORMAL)
2986 bgp_zebra_withdraw (&rn->p, ri);
2987
2988 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2989
2990 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2991 for (ri = rn->info; ri; ri = ri->next)
2992 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2993 && ri->type == ZEBRA_ROUTE_BGP
2994 && ri->sub_type == BGP_ROUTE_NORMAL)
2995 bgp_zebra_withdraw (&rn->p, ri);
2996 }
2997}
2998
2999void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003000bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003001{
3002 vty_reset ();
3003 bgp_zclient_reset ();
3004 access_list_reset ();
3005 prefix_list_reset ();
3006}
3007
3008/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3009 value. */
3010int
3011bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3012{
3013 u_char *pnt;
3014 u_char *lim;
3015 struct prefix p;
3016 int psize;
3017 int ret;
3018
3019 /* Check peer status. */
3020 if (peer->status != Established)
3021 return 0;
3022
3023 pnt = packet->nlri;
3024 lim = pnt + packet->length;
3025
3026 for (; pnt < lim; pnt += psize)
3027 {
3028 /* Clear prefix structure. */
3029 memset (&p, 0, sizeof (struct prefix));
3030
3031 /* Fetch prefix length. */
3032 p.prefixlen = *pnt++;
3033 p.family = afi2family (packet->afi);
3034
3035 /* Already checked in nlri_sanity_check(). We do double check
3036 here. */
3037 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3038 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3039 return -1;
3040
3041 /* Packet size overflow check. */
3042 psize = PSIZE (p.prefixlen);
3043
3044 /* When packet overflow occur return immediately. */
3045 if (pnt + psize > lim)
3046 return -1;
3047
3048 /* Fetch prefix from NLRI packet. */
3049 memcpy (&p.u.prefix, pnt, psize);
3050
3051 /* Check address. */
3052 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3053 {
3054 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3055 {
paulf5ba3872004-07-09 12:11:31 +00003056 /*
3057 * From draft-ietf-idr-bgp4-22, Section 6.3:
3058 * If a BGP router receives an UPDATE message with a
3059 * semantically incorrect NLRI field, in which a prefix is
3060 * semantically incorrect (eg. an unexpected multicast IP
3061 * address), it should ignore the prefix.
3062 */
paul718e3742002-12-13 20:15:29 +00003063 zlog (peer->log, LOG_ERR,
3064 "IPv4 unicast NLRI is multicast address %s",
3065 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003066
paul718e3742002-12-13 20:15:29 +00003067 return -1;
3068 }
3069 }
3070
3071#ifdef HAVE_IPV6
3072 /* Check address. */
3073 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3074 {
3075 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3076 {
3077 char buf[BUFSIZ];
3078
3079 zlog (peer->log, LOG_WARNING,
3080 "IPv6 link-local NLRI received %s ignore this NLRI",
3081 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3082
3083 continue;
3084 }
3085 }
3086#endif /* HAVE_IPV6 */
3087
3088 /* Normal process. */
3089 if (attr)
3090 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3091 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3092 else
3093 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3094 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3095
3096 /* Address family configuration mismatch or maximum-prefix count
3097 overflow. */
3098 if (ret < 0)
3099 return -1;
3100 }
3101
3102 /* Packet length consistency check. */
3103 if (pnt != lim)
3104 return -1;
3105
3106 return 0;
3107}
3108
3109/* NLRI encode syntax check routine. */
3110int
3111bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3112 bgp_size_t length)
3113{
3114 u_char *end;
3115 u_char prefixlen;
3116 int psize;
3117
3118 end = pnt + length;
3119
3120 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3121 syntactic validity. If the field is syntactically incorrect,
3122 then the Error Subcode is set to Invalid Network Field. */
3123
3124 while (pnt < end)
3125 {
3126 prefixlen = *pnt++;
3127
3128 /* Prefix length check. */
3129 if ((afi == AFI_IP && prefixlen > 32)
3130 || (afi == AFI_IP6 && prefixlen > 128))
3131 {
3132 plog_err (peer->log,
3133 "%s [Error] Update packet error (wrong prefix length %d)",
3134 peer->host, prefixlen);
3135 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3136 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3137 return -1;
3138 }
3139
3140 /* Packet size overflow check. */
3141 psize = PSIZE (prefixlen);
3142
3143 if (pnt + psize > end)
3144 {
3145 plog_err (peer->log,
3146 "%s [Error] Update packet error"
3147 " (prefix data overflow prefix size is %d)",
3148 peer->host, psize);
3149 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3150 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3151 return -1;
3152 }
3153
3154 pnt += psize;
3155 }
3156
3157 /* Packet length consistency check. */
3158 if (pnt != end)
3159 {
3160 plog_err (peer->log,
3161 "%s [Error] Update packet error"
3162 " (prefix length mismatch with total length)",
3163 peer->host);
3164 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3165 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3166 return -1;
3167 }
3168 return 0;
3169}
3170
paul94f2b392005-06-28 12:44:16 +00003171static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003172bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003173{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003174 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003175}
3176
paul94f2b392005-06-28 12:44:16 +00003177static void
paul718e3742002-12-13 20:15:29 +00003178bgp_static_free (struct bgp_static *bgp_static)
3179{
3180 if (bgp_static->rmap.name)
3181 free (bgp_static->rmap.name);
3182 XFREE (MTYPE_BGP_STATIC, bgp_static);
3183}
3184
paul94f2b392005-06-28 12:44:16 +00003185static void
paulfee0f4c2004-09-13 05:12:46 +00003186bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3187 struct prefix *p, afi_t afi, safi_t safi)
3188{
3189 struct bgp_node *rn;
3190 struct bgp_info *ri;
3191
3192 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3193
3194 /* Check selected route and self inserted route. */
3195 for (ri = rn->info; ri; ri = ri->next)
3196 if (ri->peer == bgp->peer_self
3197 && ri->type == ZEBRA_ROUTE_BGP
3198 && ri->sub_type == BGP_ROUTE_STATIC)
3199 break;
3200
3201 /* Withdraw static BGP route from routing table. */
3202 if (ri)
3203 {
paulfee0f4c2004-09-13 05:12:46 +00003204 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003205 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003206 }
3207
3208 /* Unlock bgp_node_lookup. */
3209 bgp_unlock_node (rn);
3210}
3211
paul94f2b392005-06-28 12:44:16 +00003212static void
paulfee0f4c2004-09-13 05:12:46 +00003213bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003214 struct bgp_static *bgp_static,
3215 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003216{
3217 struct bgp_node *rn;
3218 struct bgp_info *ri;
3219 struct bgp_info *new;
3220 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003221 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003222 struct attr attr = {0 };
3223 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003224 struct bgp *bgp;
3225 int ret;
3226 char buf[SU_ADDRSTRLEN];
3227
3228 bgp = rsclient->bgp;
3229
Paul Jakma06e110f2006-05-12 23:29:22 +00003230 assert (bgp_static);
3231 if (!bgp_static)
3232 return;
3233
paulfee0f4c2004-09-13 05:12:46 +00003234 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3235
3236 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003237
3238 attr.nexthop = bgp_static->igpnexthop;
3239 attr.med = bgp_static->igpmetric;
3240 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003241
3242 if (bgp_static->ttl)
3243 {
3244 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3245 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3246 attr.pathlimit.as = 0;
3247 attr.pathlimit.ttl = bgp_static->ttl;
3248 }
3249
3250 if (bgp_static->atomic)
3251 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3252
paulfee0f4c2004-09-13 05:12:46 +00003253 /* Apply network route-map for export to this rsclient. */
3254 if (bgp_static->rmap.name)
3255 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003256 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003257 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003258 info.attr = &attr_tmp;
3259
paulfee0f4c2004-09-13 05:12:46 +00003260 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3261 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3262
3263 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3264
3265 rsclient->rmap_type = 0;
3266
3267 if (ret == RMAP_DENYMATCH)
3268 {
3269 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003270 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003271
3272 /* Unintern original. */
3273 aspath_unintern (attr.aspath);
3274 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003275 bgp_attr_extra_free (&attr);
3276
paulfee0f4c2004-09-13 05:12:46 +00003277 return;
3278 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003279 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003280 }
3281 else
3282 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003283
paulfee0f4c2004-09-13 05:12:46 +00003284 new_attr = *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003285
paulfee0f4c2004-09-13 05:12:46 +00003286 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3287
Paul Jakmafb982c22007-05-04 20:15:47 +00003288 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3289 == RMAP_DENY)
3290 {
paulfee0f4c2004-09-13 05:12:46 +00003291 /* This BGP update is filtered. Log the reason then update BGP entry. */
3292 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003293 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003294 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3295 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3296 p->prefixlen, rsclient->host);
3297
3298 bgp->peer_self->rmap_type = 0;
3299
3300 bgp_attr_unintern (attr_new);
3301 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003302 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003303
3304 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3305
3306 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003307 }
paulfee0f4c2004-09-13 05:12:46 +00003308
3309 bgp->peer_self->rmap_type = 0;
3310
3311 bgp_attr_unintern (attr_new);
3312 attr_new = bgp_attr_intern (&new_attr);
3313
3314 for (ri = rn->info; ri; ri = ri->next)
3315 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3316 && ri->sub_type == BGP_ROUTE_STATIC)
3317 break;
3318
3319 if (ri)
3320 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003321 if (attrhash_cmp (ri->attr, attr_new) &&
3322 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003323 {
3324 bgp_unlock_node (rn);
3325 bgp_attr_unintern (attr_new);
3326 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003327 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003328 return;
3329 }
3330 else
3331 {
3332 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003333 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003334
3335 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003336 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3337 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003338 bgp_attr_unintern (ri->attr);
3339 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003340 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003341
3342 /* Process change. */
3343 bgp_process (bgp, rn, afi, safi);
3344 bgp_unlock_node (rn);
3345 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003346 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003347 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003348 }
paulfee0f4c2004-09-13 05:12:46 +00003349 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003350
paulfee0f4c2004-09-13 05:12:46 +00003351 /* Make new BGP info. */
3352 new = bgp_info_new ();
3353 new->type = ZEBRA_ROUTE_BGP;
3354 new->sub_type = BGP_ROUTE_STATIC;
3355 new->peer = bgp->peer_self;
3356 SET_FLAG (new->flags, BGP_INFO_VALID);
3357 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003358 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003359
3360 /* Register new BGP information. */
3361 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003362
3363 /* route_node_get lock */
3364 bgp_unlock_node (rn);
3365
paulfee0f4c2004-09-13 05:12:46 +00003366 /* Process change. */
3367 bgp_process (bgp, rn, afi, safi);
3368
3369 /* Unintern original. */
3370 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003371 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003372}
3373
paul94f2b392005-06-28 12:44:16 +00003374static void
paulfee0f4c2004-09-13 05:12:46 +00003375bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003376 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3377{
3378 struct bgp_node *rn;
3379 struct bgp_info *ri;
3380 struct bgp_info *new;
3381 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003382 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003383 struct attr *attr_new;
3384 int ret;
3385
Paul Jakmadd8103a2006-05-12 23:27:30 +00003386 assert (bgp_static);
3387 if (!bgp_static)
3388 return;
3389
paulfee0f4c2004-09-13 05:12:46 +00003390 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003391
3392 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003393
3394 attr.nexthop = bgp_static->igpnexthop;
3395 attr.med = bgp_static->igpmetric;
3396 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003397
Paul Jakma41367172007-08-06 15:24:51 +00003398 if (bgp_static->ttl)
3399 {
3400 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3401 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3402 attr.pathlimit.as = 0;
3403 attr.pathlimit.ttl = bgp_static->ttl;
3404 }
3405
3406 if (bgp_static->atomic)
3407 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3408
paul718e3742002-12-13 20:15:29 +00003409 /* Apply route-map. */
3410 if (bgp_static->rmap.name)
3411 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003412 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003413 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003414 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003415
paulfee0f4c2004-09-13 05:12:46 +00003416 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3417
paul718e3742002-12-13 20:15:29 +00003418 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003419
paulfee0f4c2004-09-13 05:12:46 +00003420 bgp->peer_self->rmap_type = 0;
3421
paul718e3742002-12-13 20:15:29 +00003422 if (ret == RMAP_DENYMATCH)
3423 {
3424 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003425 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003426
3427 /* Unintern original. */
3428 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003429 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003430 bgp_static_withdraw (bgp, p, afi, safi);
3431 return;
3432 }
paul286e1e72003-08-08 00:24:31 +00003433 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003434 }
paul286e1e72003-08-08 00:24:31 +00003435 else
3436 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003437
3438 for (ri = rn->info; ri; ri = ri->next)
3439 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3440 && ri->sub_type == BGP_ROUTE_STATIC)
3441 break;
3442
3443 if (ri)
3444 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003445 if (attrhash_cmp (ri->attr, attr_new) &&
3446 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003447 {
3448 bgp_unlock_node (rn);
3449 bgp_attr_unintern (attr_new);
3450 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003451 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003452 return;
3453 }
3454 else
3455 {
3456 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003457 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003458
3459 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003460 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3461 bgp_info_restore(rn, ri);
3462 else
3463 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003464 bgp_attr_unintern (ri->attr);
3465 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003466 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003467
3468 /* Process change. */
3469 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3470 bgp_process (bgp, rn, afi, safi);
3471 bgp_unlock_node (rn);
3472 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003473 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003474 return;
3475 }
3476 }
3477
3478 /* Make new BGP info. */
3479 new = bgp_info_new ();
3480 new->type = ZEBRA_ROUTE_BGP;
3481 new->sub_type = BGP_ROUTE_STATIC;
3482 new->peer = bgp->peer_self;
3483 SET_FLAG (new->flags, BGP_INFO_VALID);
3484 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003485 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003486
3487 /* Aggregate address increment. */
3488 bgp_aggregate_increment (bgp, p, new, afi, safi);
3489
3490 /* Register new BGP information. */
3491 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003492
3493 /* route_node_get lock */
3494 bgp_unlock_node (rn);
3495
paul718e3742002-12-13 20:15:29 +00003496 /* Process change. */
3497 bgp_process (bgp, rn, afi, safi);
3498
3499 /* Unintern original. */
3500 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003501 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003502}
3503
3504void
paulfee0f4c2004-09-13 05:12:46 +00003505bgp_static_update (struct bgp *bgp, struct prefix *p,
3506 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3507{
3508 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003509 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003510
3511 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3512
paul1eb8ef22005-04-07 07:30:20 +00003513 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003514 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003515 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3516 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003517 }
3518}
3519
paul94f2b392005-06-28 12:44:16 +00003520static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003521bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3522 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003523{
3524 struct bgp_node *rn;
3525 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003526
paulfee0f4c2004-09-13 05:12:46 +00003527 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003528
3529 /* Make new BGP info. */
3530 new = bgp_info_new ();
3531 new->type = ZEBRA_ROUTE_BGP;
3532 new->sub_type = BGP_ROUTE_STATIC;
3533 new->peer = bgp->peer_self;
3534 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3535 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003536 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003537 new->extra = bgp_info_extra_new();
3538 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003539
3540 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003541 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003542
3543 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003544 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003545
paul200df112005-06-01 11:17:05 +00003546 /* route_node_get lock */
3547 bgp_unlock_node (rn);
3548
paul718e3742002-12-13 20:15:29 +00003549 /* Process change. */
3550 bgp_process (bgp, rn, afi, safi);
3551}
3552
3553void
3554bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3555 safi_t safi)
3556{
3557 struct bgp_node *rn;
3558 struct bgp_info *ri;
3559
paulfee0f4c2004-09-13 05:12:46 +00003560 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003561
3562 /* Check selected route and self inserted route. */
3563 for (ri = rn->info; ri; ri = ri->next)
3564 if (ri->peer == bgp->peer_self
3565 && ri->type == ZEBRA_ROUTE_BGP
3566 && ri->sub_type == BGP_ROUTE_STATIC)
3567 break;
3568
3569 /* Withdraw static BGP route from routing table. */
3570 if (ri)
3571 {
3572 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003573 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003574 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003575 }
3576
3577 /* Unlock bgp_node_lookup. */
3578 bgp_unlock_node (rn);
3579}
3580
3581void
paulfee0f4c2004-09-13 05:12:46 +00003582bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3583{
3584 struct bgp_static *bgp_static;
3585 struct bgp *bgp;
3586 struct bgp_node *rn;
3587 struct prefix *p;
3588
3589 bgp = rsclient->bgp;
3590
3591 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3592 if ((bgp_static = rn->info) != NULL)
3593 {
3594 p = &rn->p;
3595
3596 bgp_static_update_rsclient (rsclient, p, bgp_static,
3597 afi, safi);
3598 }
3599}
3600
paul94f2b392005-06-28 12:44:16 +00003601static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003602bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3603 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003604{
3605 struct bgp_node *rn;
3606 struct bgp_info *ri;
3607
paulfee0f4c2004-09-13 05:12:46 +00003608 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003609
3610 /* Check selected route and self inserted route. */
3611 for (ri = rn->info; ri; ri = ri->next)
3612 if (ri->peer == bgp->peer_self
3613 && ri->type == ZEBRA_ROUTE_BGP
3614 && ri->sub_type == BGP_ROUTE_STATIC)
3615 break;
3616
3617 /* Withdraw static BGP route from routing table. */
3618 if (ri)
3619 {
3620 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003621 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003622 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003623 }
3624
3625 /* Unlock bgp_node_lookup. */
3626 bgp_unlock_node (rn);
3627}
3628
Paul Jakma41367172007-08-06 15:24:51 +00003629static void
3630bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3631 int ttl_edge)
3632{
3633 struct bgp_node *parent = rn;
3634 struct bgp_static *sp;
3635
3636 /* Existing static changed TTL, search parents and adjust their atomic */
3637 while ((parent = parent->parent))
3638 if ((sp = parent->info))
3639 {
3640 int sp_level = (sp->atomic ? 1 : 0);
3641 ttl_edge ? sp->atomic++ : sp->atomic--;
3642
3643 /* did we change state of parent whether atomic is set or not? */
3644 if (sp_level != (sp->atomic ? 1 : 0))
3645 {
3646 bgp_static_update (bgp, &parent->p, sp,
3647 rn->table->afi, rn->table->safi);
3648 }
3649 }
3650}
3651
paul718e3742002-12-13 20:15:29 +00003652/* Configure static BGP network. When user don't run zebra, static
3653 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003654static int
paulfd79ac92004-10-13 05:06:08 +00003655bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003656 afi_t afi, safi_t safi, const char *rmap, int backdoor,
Paul Jakma41367172007-08-06 15:24:51 +00003657 u_char ttl)
paul718e3742002-12-13 20:15:29 +00003658{
3659 int ret;
3660 struct prefix p;
3661 struct bgp_static *bgp_static;
3662 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003663 u_char need_update = 0;
3664 u_char ttl_change = 0;
3665 u_char ttl_edge = (ttl ? 1 : 0);
3666 u_char new = 0;
paul718e3742002-12-13 20:15:29 +00003667
3668 /* Convert IP prefix string to struct prefix. */
3669 ret = str2prefix (ip_str, &p);
3670 if (! ret)
3671 {
3672 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3673 return CMD_WARNING;
3674 }
3675#ifdef HAVE_IPV6
3676 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3677 {
3678 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3679 VTY_NEWLINE);
3680 return CMD_WARNING;
3681 }
3682#endif /* HAVE_IPV6 */
3683
3684 apply_mask (&p);
3685
3686 /* Set BGP static route configuration. */
3687 rn = bgp_node_get (bgp->route[afi][safi], &p);
3688
3689 if (rn->info)
3690 {
3691 /* Configuration change. */
3692 bgp_static = rn->info;
3693
3694 /* Check previous routes are installed into BGP. */
Paul Jakma41367172007-08-06 15:24:51 +00003695 if (bgp_static->valid)
3696 {
3697 if (bgp_static->backdoor != backdoor
3698 || bgp_static->ttl != ttl)
3699 need_update = 1;
3700 }
3701
3702 /* need to catch TTL set/unset transitions for handling of
3703 * ATOMIC_AGGREGATE
3704 */
3705 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3706 ttl_change = 1;
3707
paul718e3742002-12-13 20:15:29 +00003708 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003709 bgp_static->ttl = ttl;
3710
paul718e3742002-12-13 20:15:29 +00003711 if (rmap)
3712 {
3713 if (bgp_static->rmap.name)
3714 free (bgp_static->rmap.name);
3715 bgp_static->rmap.name = strdup (rmap);
3716 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3717 }
3718 else
3719 {
3720 if (bgp_static->rmap.name)
3721 free (bgp_static->rmap.name);
3722 bgp_static->rmap.name = NULL;
3723 bgp_static->rmap.map = NULL;
3724 bgp_static->valid = 0;
3725 }
3726 bgp_unlock_node (rn);
3727 }
3728 else
3729 {
3730 /* New configuration. */
3731 bgp_static = bgp_static_new ();
3732 bgp_static->backdoor = backdoor;
3733 bgp_static->valid = 0;
3734 bgp_static->igpmetric = 0;
3735 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003736 bgp_static->ttl = ttl;
3737 ttl_change = ttl_edge;
3738 new = 1;
3739
paul718e3742002-12-13 20:15:29 +00003740 if (rmap)
3741 {
3742 if (bgp_static->rmap.name)
3743 free (bgp_static->rmap.name);
3744 bgp_static->rmap.name = strdup (rmap);
3745 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3746 }
3747 rn->info = bgp_static;
3748 }
3749
Paul Jakma41367172007-08-06 15:24:51 +00003750 /* ".. sites that choose to advertise the
3751 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3752 * all less specific covering prefixes as well as the more specific
3753 * prefixes."
3754 *
3755 * So:
3756 * Prefix that has just had pathlimit set/unset:
3757 * - Must bump ATOMIC refcount on all parents.
3758 *
3759 * To catch less specific prefixes:
3760 * - Must search children for ones with TTL, bump atomic refcount
3761 * (we dont care if we're deleting a less specific prefix..)
3762 */
3763 if (ttl_change)
3764 {
3765 /* Existing static changed TTL, search parents and adjust their atomic */
3766 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3767 }
3768
3769 if (new)
3770 {
3771 struct bgp_node *child;
3772 struct bgp_static *sc;
3773
3774 /* New static, search children and bump this statics atomic.. */
3775 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3776 while ((child = bgp_route_next_until (child, rn)))
3777 {
3778 if ((sc = child->info) && sc->ttl)
3779 bgp_static->atomic++;
3780 }
3781 }
3782
paul718e3742002-12-13 20:15:29 +00003783 /* If BGP scan is not enabled, we should install this route here. */
3784 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3785 {
3786 bgp_static->valid = 1;
3787
3788 if (need_update)
3789 bgp_static_withdraw (bgp, &p, afi, safi);
3790
3791 if (! bgp_static->backdoor)
3792 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3793 }
3794
3795 return CMD_SUCCESS;
3796}
3797
3798/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003799static int
paulfd79ac92004-10-13 05:06:08 +00003800bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003801 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003802{
3803 int ret;
3804 struct prefix p;
3805 struct bgp_static *bgp_static;
3806 struct bgp_node *rn;
3807
3808 /* Convert IP prefix string to struct prefix. */
3809 ret = str2prefix (ip_str, &p);
3810 if (! ret)
3811 {
3812 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3813 return CMD_WARNING;
3814 }
3815#ifdef HAVE_IPV6
3816 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3817 {
3818 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3819 VTY_NEWLINE);
3820 return CMD_WARNING;
3821 }
3822#endif /* HAVE_IPV6 */
3823
3824 apply_mask (&p);
3825
3826 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3827 if (! rn)
3828 {
3829 vty_out (vty, "%% Can't find specified static route configuration.%s",
3830 VTY_NEWLINE);
3831 return CMD_WARNING;
3832 }
3833
3834 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003835
3836 /* decrement atomic in parents, see bgp_static_set */
3837 bgp_pathlimit_update_parents (bgp, rn, 0);
3838
paul718e3742002-12-13 20:15:29 +00003839 /* Update BGP RIB. */
3840 if (! bgp_static->backdoor)
3841 bgp_static_withdraw (bgp, &p, afi, safi);
3842
3843 /* Clear configuration. */
3844 bgp_static_free (bgp_static);
3845 rn->info = NULL;
3846 bgp_unlock_node (rn);
3847 bgp_unlock_node (rn);
3848
3849 return CMD_SUCCESS;
3850}
3851
3852/* Called from bgp_delete(). Delete all static routes from the BGP
3853 instance. */
3854void
3855bgp_static_delete (struct bgp *bgp)
3856{
3857 afi_t afi;
3858 safi_t safi;
3859 struct bgp_node *rn;
3860 struct bgp_node *rm;
3861 struct bgp_table *table;
3862 struct bgp_static *bgp_static;
3863
3864 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3865 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3866 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3867 if (rn->info != NULL)
3868 {
3869 if (safi == SAFI_MPLS_VPN)
3870 {
3871 table = rn->info;
3872
3873 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3874 {
3875 bgp_static = rn->info;
3876 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3877 AFI_IP, SAFI_MPLS_VPN,
3878 (struct prefix_rd *)&rn->p,
3879 bgp_static->tag);
3880 bgp_static_free (bgp_static);
3881 rn->info = NULL;
3882 bgp_unlock_node (rn);
3883 }
3884 }
3885 else
3886 {
3887 bgp_static = rn->info;
3888 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3889 bgp_static_free (bgp_static);
3890 rn->info = NULL;
3891 bgp_unlock_node (rn);
3892 }
3893 }
3894}
3895
3896int
paulfd79ac92004-10-13 05:06:08 +00003897bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3898 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003899{
3900 int ret;
3901 struct prefix p;
3902 struct prefix_rd prd;
3903 struct bgp *bgp;
3904 struct bgp_node *prn;
3905 struct bgp_node *rn;
3906 struct bgp_table *table;
3907 struct bgp_static *bgp_static;
3908 u_char tag[3];
3909
3910 bgp = vty->index;
3911
3912 ret = str2prefix (ip_str, &p);
3913 if (! ret)
3914 {
3915 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3916 return CMD_WARNING;
3917 }
3918 apply_mask (&p);
3919
3920 ret = str2prefix_rd (rd_str, &prd);
3921 if (! ret)
3922 {
3923 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3924 return CMD_WARNING;
3925 }
3926
3927 ret = str2tag (tag_str, tag);
3928 if (! ret)
3929 {
3930 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3931 return CMD_WARNING;
3932 }
3933
3934 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3935 (struct prefix *)&prd);
3936 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003937 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003938 else
3939 bgp_unlock_node (prn);
3940 table = prn->info;
3941
3942 rn = bgp_node_get (table, &p);
3943
3944 if (rn->info)
3945 {
3946 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3947 bgp_unlock_node (rn);
3948 }
3949 else
3950 {
3951 /* New configuration. */
3952 bgp_static = bgp_static_new ();
3953 bgp_static->valid = 1;
3954 memcpy (bgp_static->tag, tag, 3);
3955 rn->info = bgp_static;
3956
3957 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3958 }
3959
3960 return CMD_SUCCESS;
3961}
3962
3963/* Configure static BGP network. */
3964int
paulfd79ac92004-10-13 05:06:08 +00003965bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3966 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003967{
3968 int ret;
3969 struct bgp *bgp;
3970 struct prefix p;
3971 struct prefix_rd prd;
3972 struct bgp_node *prn;
3973 struct bgp_node *rn;
3974 struct bgp_table *table;
3975 struct bgp_static *bgp_static;
3976 u_char tag[3];
3977
3978 bgp = vty->index;
3979
3980 /* Convert IP prefix string to struct prefix. */
3981 ret = str2prefix (ip_str, &p);
3982 if (! ret)
3983 {
3984 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3985 return CMD_WARNING;
3986 }
3987 apply_mask (&p);
3988
3989 ret = str2prefix_rd (rd_str, &prd);
3990 if (! ret)
3991 {
3992 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3993 return CMD_WARNING;
3994 }
3995
3996 ret = str2tag (tag_str, tag);
3997 if (! ret)
3998 {
3999 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4000 return CMD_WARNING;
4001 }
4002
4003 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4004 (struct prefix *)&prd);
4005 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004006 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004007 else
4008 bgp_unlock_node (prn);
4009 table = prn->info;
4010
4011 rn = bgp_node_lookup (table, &p);
4012
4013 if (rn)
4014 {
4015 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4016
4017 bgp_static = rn->info;
4018 bgp_static_free (bgp_static);
4019 rn->info = NULL;
4020 bgp_unlock_node (rn);
4021 bgp_unlock_node (rn);
4022 }
4023 else
4024 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4025
4026 return CMD_SUCCESS;
4027}
4028
4029DEFUN (bgp_network,
4030 bgp_network_cmd,
4031 "network A.B.C.D/M",
4032 "Specify a network to announce via BGP\n"
4033 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4034{
Paul Jakma41367172007-08-06 15:24:51 +00004035 u_char ttl = 0;
4036
4037 if (argc == 2)
4038 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4039
paul718e3742002-12-13 20:15:29 +00004040 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004041 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004042}
4043
Paul Jakma41367172007-08-06 15:24:51 +00004044ALIAS (bgp_network,
4045 bgp_network_ttl_cmd,
4046 "network A.B.C.D/M pathlimit <0-255>",
4047 "Specify a network to announce via BGP\n"
4048 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4049 "AS-Path hopcount limit attribute\n"
4050 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4051
paul718e3742002-12-13 20:15:29 +00004052DEFUN (bgp_network_route_map,
4053 bgp_network_route_map_cmd,
4054 "network A.B.C.D/M route-map WORD",
4055 "Specify a network to announce via BGP\n"
4056 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4057 "Route-map to modify the attributes\n"
4058 "Name of the route map\n")
4059{
4060 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004061 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004062}
4063
4064DEFUN (bgp_network_backdoor,
4065 bgp_network_backdoor_cmd,
4066 "network A.B.C.D/M backdoor",
4067 "Specify a network to announce via BGP\n"
4068 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4069 "Specify a BGP backdoor route\n")
4070{
Paul Jakma41367172007-08-06 15:24:51 +00004071 u_char ttl = 0;
4072
4073 if (argc == 2)
4074 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4075
4076 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4077 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004078}
4079
Paul Jakma41367172007-08-06 15:24:51 +00004080ALIAS (bgp_network_backdoor,
4081 bgp_network_backdoor_ttl_cmd,
4082 "network A.B.C.D/M backdoor pathlimit <0-255>",
4083 "Specify a network to announce via BGP\n"
4084 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4085 "Specify a BGP backdoor route\n"
4086 "AS-Path hopcount limit attribute\n"
4087 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4088
paul718e3742002-12-13 20:15:29 +00004089DEFUN (bgp_network_mask,
4090 bgp_network_mask_cmd,
4091 "network A.B.C.D mask A.B.C.D",
4092 "Specify a network to announce via BGP\n"
4093 "Network number\n"
4094 "Network mask\n"
4095 "Network mask\n")
4096{
4097 int ret;
4098 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004099 u_char ttl = 0;
4100
4101 if (argc == 3)
4102 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4103
paul718e3742002-12-13 20:15:29 +00004104 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4105 if (! ret)
4106 {
4107 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4108 return CMD_WARNING;
4109 }
4110
4111 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004112 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004113}
4114
Paul Jakma41367172007-08-06 15:24:51 +00004115ALIAS (bgp_network_mask,
4116 bgp_network_mask_ttl_cmd,
4117 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4118 "Specify a network to announce via BGP\n"
4119 "Network number\n"
4120 "Network mask\n"
4121 "Network mask\n"
4122 "AS-Path hopcount limit attribute\n"
4123 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4124
paul718e3742002-12-13 20:15:29 +00004125DEFUN (bgp_network_mask_route_map,
4126 bgp_network_mask_route_map_cmd,
4127 "network A.B.C.D mask A.B.C.D route-map WORD",
4128 "Specify a network to announce via BGP\n"
4129 "Network number\n"
4130 "Network mask\n"
4131 "Network mask\n"
4132 "Route-map to modify the attributes\n"
4133 "Name of the route map\n")
4134{
4135 int ret;
4136 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004137
paul718e3742002-12-13 20:15:29 +00004138 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4139 if (! ret)
4140 {
4141 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4142 return CMD_WARNING;
4143 }
4144
4145 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004146 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
paul718e3742002-12-13 20:15:29 +00004147}
4148
4149DEFUN (bgp_network_mask_backdoor,
4150 bgp_network_mask_backdoor_cmd,
4151 "network A.B.C.D mask A.B.C.D backdoor",
4152 "Specify a network to announce via BGP\n"
4153 "Network number\n"
4154 "Network mask\n"
4155 "Network mask\n"
4156 "Specify a BGP backdoor route\n")
4157{
4158 int ret;
4159 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004160 u_char ttl = 0;
4161
4162 if (argc == 3)
4163 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
paul718e3742002-12-13 20:15:29 +00004164
4165 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4166 if (! ret)
4167 {
4168 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4169 return CMD_WARNING;
4170 }
4171
Paul Jakma41367172007-08-06 15:24:51 +00004172 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4173 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004174}
4175
Paul Jakma41367172007-08-06 15:24:51 +00004176ALIAS (bgp_network_mask_backdoor,
4177 bgp_network_mask_backdoor_ttl_cmd,
4178 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4179 "Specify a network to announce via BGP\n"
4180 "Network number\n"
4181 "Network mask\n"
4182 "Network mask\n"
4183 "Specify a BGP backdoor route\n"
4184 "AS-Path hopcount limit attribute\n"
4185 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4186
paul718e3742002-12-13 20:15:29 +00004187DEFUN (bgp_network_mask_natural,
4188 bgp_network_mask_natural_cmd,
4189 "network A.B.C.D",
4190 "Specify a network to announce via BGP\n"
4191 "Network number\n")
4192{
4193 int ret;
4194 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004195 u_char ttl = 0;
4196
4197 if (argc == 2)
4198 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004199
4200 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4201 if (! ret)
4202 {
4203 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4204 return CMD_WARNING;
4205 }
4206
4207 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004208 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004209}
4210
Paul Jakma41367172007-08-06 15:24:51 +00004211ALIAS (bgp_network_mask_natural,
4212 bgp_network_mask_natural_ttl_cmd,
4213 "network A.B.C.D pathlimit <0-255>",
4214 "Specify a network to announce via BGP\n"
4215 "Network number\n"
4216 "AS-Path hopcount limit attribute\n"
4217 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4218
paul718e3742002-12-13 20:15:29 +00004219DEFUN (bgp_network_mask_natural_route_map,
4220 bgp_network_mask_natural_route_map_cmd,
4221 "network A.B.C.D route-map WORD",
4222 "Specify a network to announce via BGP\n"
4223 "Network number\n"
4224 "Route-map to modify the attributes\n"
4225 "Name of the route map\n")
4226{
4227 int ret;
4228 char prefix_str[BUFSIZ];
4229
4230 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4231 if (! ret)
4232 {
4233 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4234 return CMD_WARNING;
4235 }
4236
4237 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004238 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004239}
4240
4241DEFUN (bgp_network_mask_natural_backdoor,
4242 bgp_network_mask_natural_backdoor_cmd,
4243 "network A.B.C.D backdoor",
4244 "Specify a network to announce via BGP\n"
4245 "Network number\n"
4246 "Specify a BGP backdoor route\n")
4247{
4248 int ret;
4249 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004250 u_char ttl = 0;
4251
4252 if (argc == 2)
4253 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004254
4255 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4256 if (! ret)
4257 {
4258 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4259 return CMD_WARNING;
4260 }
4261
Paul Jakma41367172007-08-06 15:24:51 +00004262 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4263 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004264}
4265
Paul Jakma41367172007-08-06 15:24:51 +00004266ALIAS (bgp_network_mask_natural_backdoor,
4267 bgp_network_mask_natural_backdoor_ttl_cmd,
4268 "network A.B.C.D backdoor pathlimit (1-255>",
4269 "Specify a network to announce via BGP\n"
4270 "Network number\n"
4271 "Specify a BGP backdoor route\n"
4272 "AS-Path hopcount limit attribute\n"
4273 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4274
paul718e3742002-12-13 20:15:29 +00004275DEFUN (no_bgp_network,
4276 no_bgp_network_cmd,
4277 "no network A.B.C.D/M",
4278 NO_STR
4279 "Specify a network to announce via BGP\n"
4280 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4281{
4282 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4283 bgp_node_safi (vty));
4284}
4285
4286ALIAS (no_bgp_network,
Paul Jakma41367172007-08-06 15:24:51 +00004287 no_bgp_network_ttl_cmd,
4288 "no network A.B.C.D/M pathlimit <0-255>",
4289 NO_STR
4290 "Specify a network to announce via BGP\n"
4291 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4292 "AS-Path hopcount limit attribute\n"
4293 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4294
4295ALIAS (no_bgp_network,
paul718e3742002-12-13 20:15:29 +00004296 no_bgp_network_route_map_cmd,
4297 "no network A.B.C.D/M route-map WORD",
4298 NO_STR
4299 "Specify a network to announce via BGP\n"
4300 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4301 "Route-map to modify the attributes\n"
4302 "Name of the route map\n")
4303
4304ALIAS (no_bgp_network,
4305 no_bgp_network_backdoor_cmd,
4306 "no network A.B.C.D/M backdoor",
4307 NO_STR
4308 "Specify a network to announce via BGP\n"
4309 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4310 "Specify a BGP backdoor route\n")
4311
Paul Jakma41367172007-08-06 15:24:51 +00004312ALIAS (no_bgp_network,
4313 no_bgp_network_backdoor_ttl_cmd,
4314 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4315 NO_STR
4316 "Specify a network to announce via BGP\n"
4317 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4318 "Specify a BGP backdoor route\n"
4319 "AS-Path hopcount limit attribute\n"
4320 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4321
paul718e3742002-12-13 20:15:29 +00004322DEFUN (no_bgp_network_mask,
4323 no_bgp_network_mask_cmd,
4324 "no network A.B.C.D mask A.B.C.D",
4325 NO_STR
4326 "Specify a network to announce via BGP\n"
4327 "Network number\n"
4328 "Network mask\n"
4329 "Network mask\n")
4330{
4331 int ret;
4332 char prefix_str[BUFSIZ];
4333
4334 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4335 if (! ret)
4336 {
4337 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4338 return CMD_WARNING;
4339 }
4340
4341 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4342 bgp_node_safi (vty));
4343}
4344
Paul Jakma41367172007-08-06 15:24:51 +00004345ALIAS (no_bgp_network,
4346 no_bgp_network_mask_ttl_cmd,
4347 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4348 NO_STR
4349 "Specify a network to announce via BGP\n"
4350 "Network number\n"
4351 "Network mask\n"
4352 "Network mask\n"
4353 "AS-Path hopcount limit attribute\n"
4354 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4355
paul718e3742002-12-13 20:15:29 +00004356ALIAS (no_bgp_network_mask,
4357 no_bgp_network_mask_route_map_cmd,
4358 "no network A.B.C.D mask A.B.C.D route-map WORD",
4359 NO_STR
4360 "Specify a network to announce via BGP\n"
4361 "Network number\n"
4362 "Network mask\n"
4363 "Network mask\n"
4364 "Route-map to modify the attributes\n"
4365 "Name of the route map\n")
4366
4367ALIAS (no_bgp_network_mask,
4368 no_bgp_network_mask_backdoor_cmd,
4369 "no network A.B.C.D mask A.B.C.D backdoor",
4370 NO_STR
4371 "Specify a network to announce via BGP\n"
4372 "Network number\n"
4373 "Network mask\n"
4374 "Network mask\n"
4375 "Specify a BGP backdoor route\n")
4376
Paul Jakma41367172007-08-06 15:24:51 +00004377ALIAS (no_bgp_network_mask,
4378 no_bgp_network_mask_backdoor_ttl_cmd,
4379 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4380 NO_STR
4381 "Specify a network to announce via BGP\n"
4382 "Network number\n"
4383 "Network mask\n"
4384 "Network mask\n"
4385 "Specify a BGP backdoor route\n"
4386 "AS-Path hopcount limit attribute\n"
4387 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4388
paul718e3742002-12-13 20:15:29 +00004389DEFUN (no_bgp_network_mask_natural,
4390 no_bgp_network_mask_natural_cmd,
4391 "no network A.B.C.D",
4392 NO_STR
4393 "Specify a network to announce via BGP\n"
4394 "Network number\n")
4395{
4396 int ret;
4397 char prefix_str[BUFSIZ];
4398
4399 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4400 if (! ret)
4401 {
4402 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4403 return CMD_WARNING;
4404 }
4405
4406 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4407 bgp_node_safi (vty));
4408}
4409
4410ALIAS (no_bgp_network_mask_natural,
4411 no_bgp_network_mask_natural_route_map_cmd,
4412 "no network A.B.C.D route-map WORD",
4413 NO_STR
4414 "Specify a network to announce via BGP\n"
4415 "Network number\n"
4416 "Route-map to modify the attributes\n"
4417 "Name of the route map\n")
4418
4419ALIAS (no_bgp_network_mask_natural,
4420 no_bgp_network_mask_natural_backdoor_cmd,
4421 "no network A.B.C.D backdoor",
4422 NO_STR
4423 "Specify a network to announce via BGP\n"
4424 "Network number\n"
4425 "Specify a BGP backdoor route\n")
4426
Paul Jakma41367172007-08-06 15:24:51 +00004427ALIAS (no_bgp_network_mask_natural,
4428 no_bgp_network_mask_natural_ttl_cmd,
4429 "no network A.B.C.D pathlimit <0-255>",
4430 NO_STR
4431 "Specify a network to announce via BGP\n"
4432 "Network number\n"
4433 "AS-Path hopcount limit attribute\n"
4434 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4435
4436ALIAS (no_bgp_network_mask_natural,
4437 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4438 "no network A.B.C.D backdoor pathlimit <0-255>",
4439 NO_STR
4440 "Specify a network to announce via BGP\n"
4441 "Network number\n"
4442 "Specify a BGP backdoor route\n"
4443 "AS-Path hopcount limit attribute\n"
4444 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4445
paul718e3742002-12-13 20:15:29 +00004446#ifdef HAVE_IPV6
4447DEFUN (ipv6_bgp_network,
4448 ipv6_bgp_network_cmd,
4449 "network X:X::X:X/M",
4450 "Specify a network to announce via BGP\n"
4451 "IPv6 prefix <network>/<length>\n")
4452{
Paul Jakma41367172007-08-06 15:24:51 +00004453 u_char ttl = 0;
4454
4455 if (argc == 2)
4456 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4457
4458 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4459 NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004460}
4461
Paul Jakma41367172007-08-06 15:24:51 +00004462ALIAS (ipv6_bgp_network,
4463 ipv6_bgp_network_ttl_cmd,
4464 "network X:X::X:X/M pathlimit <0-255>",
4465 "Specify a network to announce via BGP\n"
4466 "IPv6 prefix <network>/<length>\n"
4467 "AS-Path hopcount limit attribute\n"
4468 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4469
paul718e3742002-12-13 20:15:29 +00004470DEFUN (ipv6_bgp_network_route_map,
4471 ipv6_bgp_network_route_map_cmd,
4472 "network X:X::X:X/M route-map WORD",
4473 "Specify a network to announce via BGP\n"
4474 "IPv6 prefix <network>/<length>\n"
4475 "Route-map to modify the attributes\n"
4476 "Name of the route map\n")
4477{
4478 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakma41367172007-08-06 15:24:51 +00004479 bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004480}
4481
4482DEFUN (no_ipv6_bgp_network,
4483 no_ipv6_bgp_network_cmd,
4484 "no network X:X::X:X/M",
4485 NO_STR
4486 "Specify a network to announce via BGP\n"
4487 "IPv6 prefix <network>/<length>\n")
4488{
4489 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4490}
4491
4492ALIAS (no_ipv6_bgp_network,
4493 no_ipv6_bgp_network_route_map_cmd,
4494 "no network X:X::X:X/M route-map WORD",
4495 NO_STR
4496 "Specify a network to announce via BGP\n"
4497 "IPv6 prefix <network>/<length>\n"
4498 "Route-map to modify the attributes\n"
4499 "Name of the route map\n")
4500
Paul Jakma41367172007-08-06 15:24:51 +00004501ALIAS (no_ipv6_bgp_network,
4502 no_ipv6_bgp_network_ttl_cmd,
4503 "no network X:X::X:X/M pathlimit <0-255>",
4504 NO_STR
4505 "Specify a network to announce via BGP\n"
4506 "IPv6 prefix <network>/<length>\n"
4507 "AS-Path hopcount limit attribute\n"
4508 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4509
paul718e3742002-12-13 20:15:29 +00004510ALIAS (ipv6_bgp_network,
4511 old_ipv6_bgp_network_cmd,
4512 "ipv6 bgp network X:X::X:X/M",
4513 IPV6_STR
4514 BGP_STR
4515 "Specify a network to announce via BGP\n"
4516 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4517
4518ALIAS (no_ipv6_bgp_network,
4519 old_no_ipv6_bgp_network_cmd,
4520 "no ipv6 bgp network X:X::X:X/M",
4521 NO_STR
4522 IPV6_STR
4523 BGP_STR
4524 "Specify a network to announce via BGP\n"
4525 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4526#endif /* HAVE_IPV6 */
4527
4528/* Aggreagete address:
4529
4530 advertise-map Set condition to advertise attribute
4531 as-set Generate AS set path information
4532 attribute-map Set attributes of aggregate
4533 route-map Set parameters of aggregate
4534 summary-only Filter more specific routes from updates
4535 suppress-map Conditionally filter more specific routes from updates
4536 <cr>
4537 */
4538struct bgp_aggregate
4539{
4540 /* Summary-only flag. */
4541 u_char summary_only;
4542
4543 /* AS set generation. */
4544 u_char as_set;
4545
4546 /* Route-map for aggregated route. */
4547 struct route_map *map;
4548
4549 /* Suppress-count. */
4550 unsigned long count;
4551
4552 /* SAFI configuration. */
4553 safi_t safi;
4554};
4555
paul94f2b392005-06-28 12:44:16 +00004556static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004557bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004558{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004559 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004560}
4561
paul94f2b392005-06-28 12:44:16 +00004562static void
paul718e3742002-12-13 20:15:29 +00004563bgp_aggregate_free (struct bgp_aggregate *aggregate)
4564{
4565 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4566}
4567
paul94f2b392005-06-28 12:44:16 +00004568static void
paul718e3742002-12-13 20:15:29 +00004569bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4570 afi_t afi, safi_t safi, struct bgp_info *del,
4571 struct bgp_aggregate *aggregate)
4572{
4573 struct bgp_table *table;
4574 struct bgp_node *top;
4575 struct bgp_node *rn;
4576 u_char origin;
4577 struct aspath *aspath = NULL;
4578 struct aspath *asmerge = NULL;
4579 struct community *community = NULL;
4580 struct community *commerge = NULL;
4581 struct in_addr nexthop;
4582 u_int32_t med = 0;
4583 struct bgp_info *ri;
4584 struct bgp_info *new;
4585 int first = 1;
4586 unsigned long match = 0;
4587
4588 /* Record adding route's nexthop and med. */
4589 if (rinew)
4590 {
4591 nexthop = rinew->attr->nexthop;
4592 med = rinew->attr->med;
4593 }
4594
4595 /* ORIGIN attribute: If at least one route among routes that are
4596 aggregated has ORIGIN with the value INCOMPLETE, then the
4597 aggregated route must have the ORIGIN attribute with the value
4598 INCOMPLETE. Otherwise, if at least one route among routes that
4599 are aggregated has ORIGIN with the value EGP, then the aggregated
4600 route must have the origin attribute with the value EGP. In all
4601 other case the value of the ORIGIN attribute of the aggregated
4602 route is INTERNAL. */
4603 origin = BGP_ORIGIN_IGP;
4604
4605 table = bgp->rib[afi][safi];
4606
4607 top = bgp_node_get (table, p);
4608 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4609 if (rn->p.prefixlen > p->prefixlen)
4610 {
4611 match = 0;
4612
4613 for (ri = rn->info; ri; ri = ri->next)
4614 {
4615 if (BGP_INFO_HOLDDOWN (ri))
4616 continue;
4617
4618 if (del && ri == del)
4619 continue;
4620
4621 if (! rinew && first)
4622 {
4623 nexthop = ri->attr->nexthop;
4624 med = ri->attr->med;
4625 first = 0;
4626 }
4627
4628#ifdef AGGREGATE_NEXTHOP_CHECK
4629 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4630 || ri->attr->med != med)
4631 {
4632 if (aspath)
4633 aspath_free (aspath);
4634 if (community)
4635 community_free (community);
4636 bgp_unlock_node (rn);
4637 bgp_unlock_node (top);
4638 return;
4639 }
4640#endif /* AGGREGATE_NEXTHOP_CHECK */
4641
4642 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4643 {
4644 if (aggregate->summary_only)
4645 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004646 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004647 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004648 match++;
4649 }
4650
4651 aggregate->count++;
4652
4653 if (aggregate->as_set)
4654 {
4655 if (origin < ri->attr->origin)
4656 origin = ri->attr->origin;
4657
4658 if (aspath)
4659 {
4660 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4661 aspath_free (aspath);
4662 aspath = asmerge;
4663 }
4664 else
4665 aspath = aspath_dup (ri->attr->aspath);
4666
4667 if (ri->attr->community)
4668 {
4669 if (community)
4670 {
4671 commerge = community_merge (community,
4672 ri->attr->community);
4673 community = community_uniq_sort (commerge);
4674 community_free (commerge);
4675 }
4676 else
4677 community = community_dup (ri->attr->community);
4678 }
4679 }
4680 }
4681 }
4682 if (match)
4683 bgp_process (bgp, rn, afi, safi);
4684 }
4685 bgp_unlock_node (top);
4686
4687 if (rinew)
4688 {
4689 aggregate->count++;
4690
4691 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004692 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004693
4694 if (aggregate->as_set)
4695 {
4696 if (origin < rinew->attr->origin)
4697 origin = rinew->attr->origin;
4698
4699 if (aspath)
4700 {
4701 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4702 aspath_free (aspath);
4703 aspath = asmerge;
4704 }
4705 else
4706 aspath = aspath_dup (rinew->attr->aspath);
4707
4708 if (rinew->attr->community)
4709 {
4710 if (community)
4711 {
4712 commerge = community_merge (community,
4713 rinew->attr->community);
4714 community = community_uniq_sort (commerge);
4715 community_free (commerge);
4716 }
4717 else
4718 community = community_dup (rinew->attr->community);
4719 }
4720 }
4721 }
4722
4723 if (aggregate->count > 0)
4724 {
4725 rn = bgp_node_get (table, p);
4726 new = bgp_info_new ();
4727 new->type = ZEBRA_ROUTE_BGP;
4728 new->sub_type = BGP_ROUTE_AGGREGATE;
4729 new->peer = bgp->peer_self;
4730 SET_FLAG (new->flags, BGP_INFO_VALID);
4731 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004732 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004733
4734 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004735 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004736 bgp_process (bgp, rn, afi, safi);
4737 }
4738 else
4739 {
4740 if (aspath)
4741 aspath_free (aspath);
4742 if (community)
4743 community_free (community);
4744 }
4745}
4746
4747void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4748 struct bgp_aggregate *);
4749
4750void
4751bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4752 struct bgp_info *ri, afi_t afi, safi_t safi)
4753{
4754 struct bgp_node *child;
4755 struct bgp_node *rn;
4756 struct bgp_aggregate *aggregate;
4757
4758 /* MPLS-VPN aggregation is not yet supported. */
4759 if (safi == SAFI_MPLS_VPN)
4760 return;
4761
4762 if (p->prefixlen == 0)
4763 return;
4764
4765 if (BGP_INFO_HOLDDOWN (ri))
4766 return;
4767
4768 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4769
4770 /* Aggregate address configuration check. */
4771 for (rn = child; rn; rn = rn->parent)
4772 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4773 {
4774 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004775 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004776 }
4777 bgp_unlock_node (child);
4778}
4779
4780void
4781bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4782 struct bgp_info *del, afi_t afi, safi_t safi)
4783{
4784 struct bgp_node *child;
4785 struct bgp_node *rn;
4786 struct bgp_aggregate *aggregate;
4787
4788 /* MPLS-VPN aggregation is not yet supported. */
4789 if (safi == SAFI_MPLS_VPN)
4790 return;
4791
4792 if (p->prefixlen == 0)
4793 return;
4794
4795 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4796
4797 /* Aggregate address configuration check. */
4798 for (rn = child; rn; rn = rn->parent)
4799 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4800 {
4801 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004802 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004803 }
4804 bgp_unlock_node (child);
4805}
4806
paul94f2b392005-06-28 12:44:16 +00004807static void
paul718e3742002-12-13 20:15:29 +00004808bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4809 struct bgp_aggregate *aggregate)
4810{
4811 struct bgp_table *table;
4812 struct bgp_node *top;
4813 struct bgp_node *rn;
4814 struct bgp_info *new;
4815 struct bgp_info *ri;
4816 unsigned long match;
4817 u_char origin = BGP_ORIGIN_IGP;
4818 struct aspath *aspath = NULL;
4819 struct aspath *asmerge = NULL;
4820 struct community *community = NULL;
4821 struct community *commerge = NULL;
4822
4823 table = bgp->rib[afi][safi];
4824
4825 /* Sanity check. */
4826 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4827 return;
4828 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4829 return;
4830
4831 /* If routes exists below this node, generate aggregate routes. */
4832 top = bgp_node_get (table, p);
4833 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4834 if (rn->p.prefixlen > p->prefixlen)
4835 {
4836 match = 0;
4837
4838 for (ri = rn->info; ri; ri = ri->next)
4839 {
4840 if (BGP_INFO_HOLDDOWN (ri))
4841 continue;
4842
4843 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4844 {
4845 /* summary-only aggregate route suppress aggregated
4846 route announcement. */
4847 if (aggregate->summary_only)
4848 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004849 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004850 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004851 match++;
4852 }
4853 /* as-set aggregate route generate origin, as path,
4854 community aggregation. */
4855 if (aggregate->as_set)
4856 {
4857 if (origin < ri->attr->origin)
4858 origin = ri->attr->origin;
4859
4860 if (aspath)
4861 {
4862 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4863 aspath_free (aspath);
4864 aspath = asmerge;
4865 }
4866 else
4867 aspath = aspath_dup (ri->attr->aspath);
4868
4869 if (ri->attr->community)
4870 {
4871 if (community)
4872 {
4873 commerge = community_merge (community,
4874 ri->attr->community);
4875 community = community_uniq_sort (commerge);
4876 community_free (commerge);
4877 }
4878 else
4879 community = community_dup (ri->attr->community);
4880 }
4881 }
4882 aggregate->count++;
4883 }
4884 }
4885
4886 /* If this node is suppressed, process the change. */
4887 if (match)
4888 bgp_process (bgp, rn, afi, safi);
4889 }
4890 bgp_unlock_node (top);
4891
4892 /* Add aggregate route to BGP table. */
4893 if (aggregate->count)
4894 {
4895 rn = bgp_node_get (table, p);
4896
4897 new = bgp_info_new ();
4898 new->type = ZEBRA_ROUTE_BGP;
4899 new->sub_type = BGP_ROUTE_AGGREGATE;
4900 new->peer = bgp->peer_self;
4901 SET_FLAG (new->flags, BGP_INFO_VALID);
4902 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004903 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004904
4905 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004906 bgp_unlock_node (rn);
4907
paul718e3742002-12-13 20:15:29 +00004908 /* Process change. */
4909 bgp_process (bgp, rn, afi, safi);
4910 }
4911}
4912
4913void
4914bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4915 safi_t safi, struct bgp_aggregate *aggregate)
4916{
4917 struct bgp_table *table;
4918 struct bgp_node *top;
4919 struct bgp_node *rn;
4920 struct bgp_info *ri;
4921 unsigned long match;
4922
4923 table = bgp->rib[afi][safi];
4924
4925 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4926 return;
4927 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4928 return;
4929
4930 /* If routes exists below this node, generate aggregate routes. */
4931 top = bgp_node_get (table, p);
4932 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4933 if (rn->p.prefixlen > p->prefixlen)
4934 {
4935 match = 0;
4936
4937 for (ri = rn->info; ri; ri = ri->next)
4938 {
4939 if (BGP_INFO_HOLDDOWN (ri))
4940 continue;
4941
4942 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4943 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004944 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004945 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004946 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004947
Paul Jakmafb982c22007-05-04 20:15:47 +00004948 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004949 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004950 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004951 match++;
4952 }
4953 }
4954 aggregate->count--;
4955 }
4956 }
4957
Paul Jakmafb982c22007-05-04 20:15:47 +00004958 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004959 if (match)
4960 bgp_process (bgp, rn, afi, safi);
4961 }
4962 bgp_unlock_node (top);
4963
4964 /* Delete aggregate route from BGP table. */
4965 rn = bgp_node_get (table, p);
4966
4967 for (ri = rn->info; ri; ri = ri->next)
4968 if (ri->peer == bgp->peer_self
4969 && ri->type == ZEBRA_ROUTE_BGP
4970 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4971 break;
4972
4973 /* Withdraw static BGP route from routing table. */
4974 if (ri)
4975 {
paul718e3742002-12-13 20:15:29 +00004976 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004977 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004978 }
4979
4980 /* Unlock bgp_node_lookup. */
4981 bgp_unlock_node (rn);
4982}
4983
4984/* Aggregate route attribute. */
4985#define AGGREGATE_SUMMARY_ONLY 1
4986#define AGGREGATE_AS_SET 1
4987
paul94f2b392005-06-28 12:44:16 +00004988static int
paulfd79ac92004-10-13 05:06:08 +00004989bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4990 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004991 u_char summary_only, u_char as_set)
4992{
4993 int ret;
4994 struct prefix p;
4995 struct bgp_node *rn;
4996 struct bgp *bgp;
4997 struct bgp_aggregate *aggregate;
4998
4999 /* Convert string to prefix structure. */
5000 ret = str2prefix (prefix_str, &p);
5001 if (!ret)
5002 {
5003 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5004 return CMD_WARNING;
5005 }
5006 apply_mask (&p);
5007
5008 /* Get BGP structure. */
5009 bgp = vty->index;
5010
5011 /* Old configuration check. */
5012 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5013
5014 if (rn->info)
5015 {
5016 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5017 bgp_unlock_node (rn);
5018 return CMD_WARNING;
5019 }
5020
5021 /* Make aggregate address structure. */
5022 aggregate = bgp_aggregate_new ();
5023 aggregate->summary_only = summary_only;
5024 aggregate->as_set = as_set;
5025 aggregate->safi = safi;
5026 rn->info = aggregate;
5027
5028 /* Aggregate address insert into BGP routing table. */
5029 if (safi & SAFI_UNICAST)
5030 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5031 if (safi & SAFI_MULTICAST)
5032 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5033
5034 return CMD_SUCCESS;
5035}
5036
paul94f2b392005-06-28 12:44:16 +00005037static int
paulfd79ac92004-10-13 05:06:08 +00005038bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5039 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00005040{
5041 int ret;
5042 struct prefix p;
5043 struct bgp_node *rn;
5044 struct bgp *bgp;
5045 struct bgp_aggregate *aggregate;
5046
5047 /* Convert string to prefix structure. */
5048 ret = str2prefix (prefix_str, &p);
5049 if (!ret)
5050 {
5051 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5052 return CMD_WARNING;
5053 }
5054 apply_mask (&p);
5055
5056 /* Get BGP structure. */
5057 bgp = vty->index;
5058
5059 /* Old configuration check. */
5060 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5061 if (! rn)
5062 {
5063 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5064 VTY_NEWLINE);
5065 return CMD_WARNING;
5066 }
5067
5068 aggregate = rn->info;
5069 if (aggregate->safi & SAFI_UNICAST)
5070 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5071 if (aggregate->safi & SAFI_MULTICAST)
5072 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5073
5074 /* Unlock aggregate address configuration. */
5075 rn->info = NULL;
5076 bgp_aggregate_free (aggregate);
5077 bgp_unlock_node (rn);
5078 bgp_unlock_node (rn);
5079
5080 return CMD_SUCCESS;
5081}
5082
5083DEFUN (aggregate_address,
5084 aggregate_address_cmd,
5085 "aggregate-address A.B.C.D/M",
5086 "Configure BGP aggregate entries\n"
5087 "Aggregate prefix\n")
5088{
5089 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5090}
5091
5092DEFUN (aggregate_address_mask,
5093 aggregate_address_mask_cmd,
5094 "aggregate-address A.B.C.D A.B.C.D",
5095 "Configure BGP aggregate entries\n"
5096 "Aggregate address\n"
5097 "Aggregate mask\n")
5098{
5099 int ret;
5100 char prefix_str[BUFSIZ];
5101
5102 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5103
5104 if (! ret)
5105 {
5106 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5107 return CMD_WARNING;
5108 }
5109
5110 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5111 0, 0);
5112}
5113
5114DEFUN (aggregate_address_summary_only,
5115 aggregate_address_summary_only_cmd,
5116 "aggregate-address A.B.C.D/M summary-only",
5117 "Configure BGP aggregate entries\n"
5118 "Aggregate prefix\n"
5119 "Filter more specific routes from updates\n")
5120{
5121 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5122 AGGREGATE_SUMMARY_ONLY, 0);
5123}
5124
5125DEFUN (aggregate_address_mask_summary_only,
5126 aggregate_address_mask_summary_only_cmd,
5127 "aggregate-address A.B.C.D A.B.C.D summary-only",
5128 "Configure BGP aggregate entries\n"
5129 "Aggregate address\n"
5130 "Aggregate mask\n"
5131 "Filter more specific routes from updates\n")
5132{
5133 int ret;
5134 char prefix_str[BUFSIZ];
5135
5136 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5137
5138 if (! ret)
5139 {
5140 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5141 return CMD_WARNING;
5142 }
5143
5144 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5145 AGGREGATE_SUMMARY_ONLY, 0);
5146}
5147
5148DEFUN (aggregate_address_as_set,
5149 aggregate_address_as_set_cmd,
5150 "aggregate-address A.B.C.D/M as-set",
5151 "Configure BGP aggregate entries\n"
5152 "Aggregate prefix\n"
5153 "Generate AS set path information\n")
5154{
5155 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5156 0, AGGREGATE_AS_SET);
5157}
5158
5159DEFUN (aggregate_address_mask_as_set,
5160 aggregate_address_mask_as_set_cmd,
5161 "aggregate-address A.B.C.D A.B.C.D as-set",
5162 "Configure BGP aggregate entries\n"
5163 "Aggregate address\n"
5164 "Aggregate mask\n"
5165 "Generate AS set path information\n")
5166{
5167 int ret;
5168 char prefix_str[BUFSIZ];
5169
5170 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5171
5172 if (! ret)
5173 {
5174 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5175 return CMD_WARNING;
5176 }
5177
5178 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5179 0, AGGREGATE_AS_SET);
5180}
5181
5182
5183DEFUN (aggregate_address_as_set_summary,
5184 aggregate_address_as_set_summary_cmd,
5185 "aggregate-address A.B.C.D/M as-set summary-only",
5186 "Configure BGP aggregate entries\n"
5187 "Aggregate prefix\n"
5188 "Generate AS set path information\n"
5189 "Filter more specific routes from updates\n")
5190{
5191 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5192 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5193}
5194
5195ALIAS (aggregate_address_as_set_summary,
5196 aggregate_address_summary_as_set_cmd,
5197 "aggregate-address A.B.C.D/M summary-only as-set",
5198 "Configure BGP aggregate entries\n"
5199 "Aggregate prefix\n"
5200 "Filter more specific routes from updates\n"
5201 "Generate AS set path information\n")
5202
5203DEFUN (aggregate_address_mask_as_set_summary,
5204 aggregate_address_mask_as_set_summary_cmd,
5205 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5206 "Configure BGP aggregate entries\n"
5207 "Aggregate address\n"
5208 "Aggregate mask\n"
5209 "Generate AS set path information\n"
5210 "Filter more specific routes from updates\n")
5211{
5212 int ret;
5213 char prefix_str[BUFSIZ];
5214
5215 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5216
5217 if (! ret)
5218 {
5219 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5220 return CMD_WARNING;
5221 }
5222
5223 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5224 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5225}
5226
5227ALIAS (aggregate_address_mask_as_set_summary,
5228 aggregate_address_mask_summary_as_set_cmd,
5229 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5230 "Configure BGP aggregate entries\n"
5231 "Aggregate address\n"
5232 "Aggregate mask\n"
5233 "Filter more specific routes from updates\n"
5234 "Generate AS set path information\n")
5235
5236DEFUN (no_aggregate_address,
5237 no_aggregate_address_cmd,
5238 "no aggregate-address A.B.C.D/M",
5239 NO_STR
5240 "Configure BGP aggregate entries\n"
5241 "Aggregate prefix\n")
5242{
5243 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5244}
5245
5246ALIAS (no_aggregate_address,
5247 no_aggregate_address_summary_only_cmd,
5248 "no aggregate-address A.B.C.D/M summary-only",
5249 NO_STR
5250 "Configure BGP aggregate entries\n"
5251 "Aggregate prefix\n"
5252 "Filter more specific routes from updates\n")
5253
5254ALIAS (no_aggregate_address,
5255 no_aggregate_address_as_set_cmd,
5256 "no aggregate-address A.B.C.D/M as-set",
5257 NO_STR
5258 "Configure BGP aggregate entries\n"
5259 "Aggregate prefix\n"
5260 "Generate AS set path information\n")
5261
5262ALIAS (no_aggregate_address,
5263 no_aggregate_address_as_set_summary_cmd,
5264 "no aggregate-address A.B.C.D/M as-set summary-only",
5265 NO_STR
5266 "Configure BGP aggregate entries\n"
5267 "Aggregate prefix\n"
5268 "Generate AS set path information\n"
5269 "Filter more specific routes from updates\n")
5270
5271ALIAS (no_aggregate_address,
5272 no_aggregate_address_summary_as_set_cmd,
5273 "no aggregate-address A.B.C.D/M summary-only as-set",
5274 NO_STR
5275 "Configure BGP aggregate entries\n"
5276 "Aggregate prefix\n"
5277 "Filter more specific routes from updates\n"
5278 "Generate AS set path information\n")
5279
5280DEFUN (no_aggregate_address_mask,
5281 no_aggregate_address_mask_cmd,
5282 "no aggregate-address A.B.C.D A.B.C.D",
5283 NO_STR
5284 "Configure BGP aggregate entries\n"
5285 "Aggregate address\n"
5286 "Aggregate mask\n")
5287{
5288 int ret;
5289 char prefix_str[BUFSIZ];
5290
5291 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5292
5293 if (! ret)
5294 {
5295 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5296 return CMD_WARNING;
5297 }
5298
5299 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5300}
5301
5302ALIAS (no_aggregate_address_mask,
5303 no_aggregate_address_mask_summary_only_cmd,
5304 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5305 NO_STR
5306 "Configure BGP aggregate entries\n"
5307 "Aggregate address\n"
5308 "Aggregate mask\n"
5309 "Filter more specific routes from updates\n")
5310
5311ALIAS (no_aggregate_address_mask,
5312 no_aggregate_address_mask_as_set_cmd,
5313 "no aggregate-address A.B.C.D A.B.C.D as-set",
5314 NO_STR
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate address\n"
5317 "Aggregate mask\n"
5318 "Generate AS set path information\n")
5319
5320ALIAS (no_aggregate_address_mask,
5321 no_aggregate_address_mask_as_set_summary_cmd,
5322 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5323 NO_STR
5324 "Configure BGP aggregate entries\n"
5325 "Aggregate address\n"
5326 "Aggregate mask\n"
5327 "Generate AS set path information\n"
5328 "Filter more specific routes from updates\n")
5329
5330ALIAS (no_aggregate_address_mask,
5331 no_aggregate_address_mask_summary_as_set_cmd,
5332 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5333 NO_STR
5334 "Configure BGP aggregate entries\n"
5335 "Aggregate address\n"
5336 "Aggregate mask\n"
5337 "Filter more specific routes from updates\n"
5338 "Generate AS set path information\n")
5339
5340#ifdef HAVE_IPV6
5341DEFUN (ipv6_aggregate_address,
5342 ipv6_aggregate_address_cmd,
5343 "aggregate-address X:X::X:X/M",
5344 "Configure BGP aggregate entries\n"
5345 "Aggregate prefix\n")
5346{
5347 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5348}
5349
5350DEFUN (ipv6_aggregate_address_summary_only,
5351 ipv6_aggregate_address_summary_only_cmd,
5352 "aggregate-address X:X::X:X/M summary-only",
5353 "Configure BGP aggregate entries\n"
5354 "Aggregate prefix\n"
5355 "Filter more specific routes from updates\n")
5356{
5357 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5358 AGGREGATE_SUMMARY_ONLY, 0);
5359}
5360
5361DEFUN (no_ipv6_aggregate_address,
5362 no_ipv6_aggregate_address_cmd,
5363 "no aggregate-address X:X::X:X/M",
5364 NO_STR
5365 "Configure BGP aggregate entries\n"
5366 "Aggregate prefix\n")
5367{
5368 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5369}
5370
5371DEFUN (no_ipv6_aggregate_address_summary_only,
5372 no_ipv6_aggregate_address_summary_only_cmd,
5373 "no aggregate-address X:X::X:X/M summary-only",
5374 NO_STR
5375 "Configure BGP aggregate entries\n"
5376 "Aggregate prefix\n"
5377 "Filter more specific routes from updates\n")
5378{
5379 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5380}
5381
5382ALIAS (ipv6_aggregate_address,
5383 old_ipv6_aggregate_address_cmd,
5384 "ipv6 bgp aggregate-address X:X::X:X/M",
5385 IPV6_STR
5386 BGP_STR
5387 "Configure BGP aggregate entries\n"
5388 "Aggregate prefix\n")
5389
5390ALIAS (ipv6_aggregate_address_summary_only,
5391 old_ipv6_aggregate_address_summary_only_cmd,
5392 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5393 IPV6_STR
5394 BGP_STR
5395 "Configure BGP aggregate entries\n"
5396 "Aggregate prefix\n"
5397 "Filter more specific routes from updates\n")
5398
5399ALIAS (no_ipv6_aggregate_address,
5400 old_no_ipv6_aggregate_address_cmd,
5401 "no ipv6 bgp aggregate-address X:X::X:X/M",
5402 NO_STR
5403 IPV6_STR
5404 BGP_STR
5405 "Configure BGP aggregate entries\n"
5406 "Aggregate prefix\n")
5407
5408ALIAS (no_ipv6_aggregate_address_summary_only,
5409 old_no_ipv6_aggregate_address_summary_only_cmd,
5410 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5411 NO_STR
5412 IPV6_STR
5413 BGP_STR
5414 "Configure BGP aggregate entries\n"
5415 "Aggregate prefix\n"
5416 "Filter more specific routes from updates\n")
5417#endif /* HAVE_IPV6 */
5418
5419/* Redistribute route treatment. */
5420void
5421bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5422 u_int32_t metric, u_char type)
5423{
5424 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005425 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005426 struct bgp_info *new;
5427 struct bgp_info *bi;
5428 struct bgp_info info;
5429 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005430 struct attr attr = { 0 };
5431 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005432 struct attr *new_attr;
5433 afi_t afi;
5434 int ret;
5435
5436 /* Make default attribute. */
5437 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5438 if (nexthop)
5439 attr.nexthop = *nexthop;
5440
5441 attr.med = metric;
5442 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5443
paul1eb8ef22005-04-07 07:30:20 +00005444 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005445 {
5446 afi = family2afi (p->family);
5447
5448 if (bgp->redist[afi][type])
5449 {
5450 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005451 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005452
5453 if (bgp->redist_metric_flag[afi][type])
5454 attr_new.med = bgp->redist_metric[afi][type];
5455
5456 /* Apply route-map. */
5457 if (bgp->rmap[afi][type].map)
5458 {
5459 info.peer = bgp->peer_self;
5460 info.attr = &attr_new;
5461
paulfee0f4c2004-09-13 05:12:46 +00005462 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5463
paul718e3742002-12-13 20:15:29 +00005464 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5465 &info);
paulfee0f4c2004-09-13 05:12:46 +00005466
5467 bgp->peer_self->rmap_type = 0;
5468
paul718e3742002-12-13 20:15:29 +00005469 if (ret == RMAP_DENYMATCH)
5470 {
5471 /* Free uninterned attribute. */
5472 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005473 bgp_attr_extra_free (&attr_new);
5474
paul718e3742002-12-13 20:15:29 +00005475 /* Unintern original. */
5476 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005477 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005478 bgp_redistribute_delete (p, type);
5479 return;
5480 }
5481 }
5482
Paul Jakmafb982c22007-05-04 20:15:47 +00005483 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5484 afi, SAFI_UNICAST, p, NULL);
5485
paul718e3742002-12-13 20:15:29 +00005486 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005487 bgp_attr_extra_free (&attr_new);
5488
paul718e3742002-12-13 20:15:29 +00005489 for (bi = bn->info; bi; bi = bi->next)
5490 if (bi->peer == bgp->peer_self
5491 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5492 break;
5493
5494 if (bi)
5495 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005496 if (attrhash_cmp (bi->attr, new_attr) &&
5497 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005498 {
5499 bgp_attr_unintern (new_attr);
5500 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005501 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005502 bgp_unlock_node (bn);
5503 return;
5504 }
5505 else
5506 {
5507 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005508 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005509
5510 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005511 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5512 bgp_info_restore(bn, bi);
5513 else
5514 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005515 bgp_attr_unintern (bi->attr);
5516 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005517 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005518
5519 /* Process change. */
5520 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5521 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5522 bgp_unlock_node (bn);
5523 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005524 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005525 return;
5526 }
5527 }
5528
5529 new = bgp_info_new ();
5530 new->type = type;
5531 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5532 new->peer = bgp->peer_self;
5533 SET_FLAG (new->flags, BGP_INFO_VALID);
5534 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005535 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005536
5537 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5538 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005539 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005540 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5541 }
5542 }
5543
5544 /* Unintern original. */
5545 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005546 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005547}
5548
5549void
5550bgp_redistribute_delete (struct prefix *p, u_char type)
5551{
5552 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005553 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005554 afi_t afi;
5555 struct bgp_node *rn;
5556 struct bgp_info *ri;
5557
paul1eb8ef22005-04-07 07:30:20 +00005558 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005559 {
5560 afi = family2afi (p->family);
5561
5562 if (bgp->redist[afi][type])
5563 {
paulfee0f4c2004-09-13 05:12:46 +00005564 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005565
5566 for (ri = rn->info; ri; ri = ri->next)
5567 if (ri->peer == bgp->peer_self
5568 && ri->type == type)
5569 break;
5570
5571 if (ri)
5572 {
5573 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005574 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005575 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005576 }
5577 bgp_unlock_node (rn);
5578 }
5579 }
5580}
5581
5582/* Withdraw specified route type's route. */
5583void
5584bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5585{
5586 struct bgp_node *rn;
5587 struct bgp_info *ri;
5588 struct bgp_table *table;
5589
5590 table = bgp->rib[afi][SAFI_UNICAST];
5591
5592 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5593 {
5594 for (ri = rn->info; ri; ri = ri->next)
5595 if (ri->peer == bgp->peer_self
5596 && ri->type == type)
5597 break;
5598
5599 if (ri)
5600 {
5601 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005602 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005603 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005604 }
5605 }
5606}
5607
5608/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005609static void
paul718e3742002-12-13 20:15:29 +00005610route_vty_out_route (struct prefix *p, struct vty *vty)
5611{
5612 int len;
5613 u_int32_t destination;
5614 char buf[BUFSIZ];
5615
5616 if (p->family == AF_INET)
5617 {
5618 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5619 destination = ntohl (p->u.prefix4.s_addr);
5620
5621 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5622 || (IN_CLASSB (destination) && p->prefixlen == 16)
5623 || (IN_CLASSA (destination) && p->prefixlen == 8)
5624 || p->u.prefix4.s_addr == 0)
5625 {
5626 /* When mask is natural, mask is not displayed. */
5627 }
5628 else
5629 len += vty_out (vty, "/%d", p->prefixlen);
5630 }
5631 else
5632 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5633 p->prefixlen);
5634
5635 len = 17 - len;
5636 if (len < 1)
5637 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5638 else
5639 vty_out (vty, "%*s", len, " ");
5640}
5641
paul718e3742002-12-13 20:15:29 +00005642enum bgp_display_type
5643{
5644 normal_list,
5645};
5646
paulb40d9392005-08-22 22:34:41 +00005647/* Print the short form route status for a bgp_info */
5648static void
5649route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005650{
paulb40d9392005-08-22 22:34:41 +00005651 /* Route status display. */
5652 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5653 vty_out (vty, "R");
5654 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005655 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005656 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005657 vty_out (vty, "s");
5658 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5659 vty_out (vty, "*");
5660 else
5661 vty_out (vty, " ");
5662
5663 /* Selected */
5664 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5665 vty_out (vty, "h");
5666 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5667 vty_out (vty, "d");
5668 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5669 vty_out (vty, ">");
5670 else
5671 vty_out (vty, " ");
5672
5673 /* Internal route. */
5674 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5675 vty_out (vty, "i");
5676 else
paulb40d9392005-08-22 22:34:41 +00005677 vty_out (vty, " ");
5678}
5679
5680/* called from terminal list command */
5681void
5682route_vty_out (struct vty *vty, struct prefix *p,
5683 struct bgp_info *binfo, int display, safi_t safi)
5684{
5685 struct attr *attr;
5686
5687 /* short status lead text */
5688 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005689
5690 /* print prefix and mask */
5691 if (! display)
5692 route_vty_out_route (p, vty);
5693 else
5694 vty_out (vty, "%*s", 17, " ");
5695
5696 /* Print attribute */
5697 attr = binfo->attr;
5698 if (attr)
5699 {
5700 if (p->family == AF_INET)
5701 {
5702 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005703 vty_out (vty, "%-16s",
5704 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005705 else
5706 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5707 }
5708#ifdef HAVE_IPV6
5709 else if (p->family == AF_INET6)
5710 {
5711 int len;
5712 char buf[BUFSIZ];
5713
5714 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005715 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5716 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005717 len = 16 - len;
5718 if (len < 1)
5719 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5720 else
5721 vty_out (vty, "%*s", len, " ");
5722 }
5723#endif /* HAVE_IPV6 */
5724
5725 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5726 vty_out (vty, "%10d", attr->med);
5727 else
5728 vty_out (vty, " ");
5729
5730 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5731 vty_out (vty, "%7d", attr->local_pref);
5732 else
5733 vty_out (vty, " ");
5734
Paul Jakmafb982c22007-05-04 20:15:47 +00005735 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005736
Paul Jakmab2518c12006-05-12 23:48:40 +00005737 /* Print aspath */
5738 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005739 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005740
Paul Jakmab2518c12006-05-12 23:48:40 +00005741 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005742 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005743 }
paul718e3742002-12-13 20:15:29 +00005744 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005745}
5746
5747/* called from terminal list command */
5748void
5749route_vty_out_tmp (struct vty *vty, struct prefix *p,
5750 struct attr *attr, safi_t safi)
5751{
5752 /* Route status display. */
5753 vty_out (vty, "*");
5754 vty_out (vty, ">");
5755 vty_out (vty, " ");
5756
5757 /* print prefix and mask */
5758 route_vty_out_route (p, vty);
5759
5760 /* Print attribute */
5761 if (attr)
5762 {
5763 if (p->family == AF_INET)
5764 {
5765 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005766 vty_out (vty, "%-16s",
5767 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005768 else
5769 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5770 }
5771#ifdef HAVE_IPV6
5772 else if (p->family == AF_INET6)
5773 {
5774 int len;
5775 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005776
5777 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005778
5779 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005780 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5781 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005782 len = 16 - len;
5783 if (len < 1)
5784 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5785 else
5786 vty_out (vty, "%*s", len, " ");
5787 }
5788#endif /* HAVE_IPV6 */
5789
5790 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5791 vty_out (vty, "%10d", attr->med);
5792 else
5793 vty_out (vty, " ");
5794
5795 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5796 vty_out (vty, "%7d", attr->local_pref);
5797 else
5798 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005799
5800 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5801
Paul Jakmab2518c12006-05-12 23:48:40 +00005802 /* Print aspath */
5803 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005804 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005805
Paul Jakmab2518c12006-05-12 23:48:40 +00005806 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005807 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005808 }
paul718e3742002-12-13 20:15:29 +00005809
5810 vty_out (vty, "%s", VTY_NEWLINE);
5811}
5812
ajs5a646652004-11-05 01:25:55 +00005813void
paul718e3742002-12-13 20:15:29 +00005814route_vty_out_tag (struct vty *vty, struct prefix *p,
5815 struct bgp_info *binfo, int display, safi_t safi)
5816{
5817 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005818 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005819
5820 if (!binfo->extra)
5821 return;
5822
paulb40d9392005-08-22 22:34:41 +00005823 /* short status lead text */
5824 route_vty_short_status_out (vty, binfo);
5825
paul718e3742002-12-13 20:15:29 +00005826 /* print prefix and mask */
5827 if (! display)
5828 route_vty_out_route (p, vty);
5829 else
5830 vty_out (vty, "%*s", 17, " ");
5831
5832 /* Print attribute */
5833 attr = binfo->attr;
5834 if (attr)
5835 {
5836 if (p->family == AF_INET)
5837 {
5838 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005839 vty_out (vty, "%-16s",
5840 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005841 else
5842 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5843 }
5844#ifdef HAVE_IPV6
5845 else if (p->family == AF_INET6)
5846 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005847 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005848 char buf[BUFSIZ];
5849 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005850 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005851 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005852 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5853 buf, BUFSIZ));
5854 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005855 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005856 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5857 buf, BUFSIZ),
5858 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5859 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005860
5861 }
5862#endif /* HAVE_IPV6 */
5863 }
5864
Paul Jakmafb982c22007-05-04 20:15:47 +00005865 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005866
5867 vty_out (vty, "notag/%d", label);
5868
5869 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005870}
5871
5872/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005873static void
paul718e3742002-12-13 20:15:29 +00005874damp_route_vty_out (struct vty *vty, struct prefix *p,
5875 struct bgp_info *binfo, int display, safi_t safi)
5876{
5877 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005878 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005879 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005880
paulb40d9392005-08-22 22:34:41 +00005881 /* short status lead text */
5882 route_vty_short_status_out (vty, binfo);
5883
paul718e3742002-12-13 20:15:29 +00005884 /* print prefix and mask */
5885 if (! display)
5886 route_vty_out_route (p, vty);
5887 else
5888 vty_out (vty, "%*s", 17, " ");
5889
5890 len = vty_out (vty, "%s", binfo->peer->host);
5891 len = 17 - len;
5892 if (len < 1)
5893 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5894 else
5895 vty_out (vty, "%*s", len, " ");
5896
Chris Caputo50aef6f2009-06-23 06:06:49 +00005897 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005898
5899 /* Print attribute */
5900 attr = binfo->attr;
5901 if (attr)
5902 {
5903 /* Print aspath */
5904 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005905 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005906
5907 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005908 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005909 }
5910 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005911}
5912
paul718e3742002-12-13 20:15:29 +00005913/* flap route */
ajs5a646652004-11-05 01:25:55 +00005914static void
paul718e3742002-12-13 20:15:29 +00005915flap_route_vty_out (struct vty *vty, struct prefix *p,
5916 struct bgp_info *binfo, int display, safi_t safi)
5917{
5918 struct attr *attr;
5919 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005920 char timebuf[BGP_UPTIME_LEN];
5921 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005922
5923 if (!binfo->extra)
5924 return;
5925
5926 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005927
paulb40d9392005-08-22 22:34:41 +00005928 /* short status lead text */
5929 route_vty_short_status_out (vty, binfo);
5930
paul718e3742002-12-13 20:15:29 +00005931 /* print prefix and mask */
5932 if (! display)
5933 route_vty_out_route (p, vty);
5934 else
5935 vty_out (vty, "%*s", 17, " ");
5936
5937 len = vty_out (vty, "%s", binfo->peer->host);
5938 len = 16 - len;
5939 if (len < 1)
5940 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5941 else
5942 vty_out (vty, "%*s", len, " ");
5943
5944 len = vty_out (vty, "%d", bdi->flap);
5945 len = 5 - len;
5946 if (len < 1)
5947 vty_out (vty, " ");
5948 else
5949 vty_out (vty, "%*s ", len, " ");
5950
5951 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5952 timebuf, BGP_UPTIME_LEN));
5953
5954 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5955 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005956 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005957 else
5958 vty_out (vty, "%*s ", 8, " ");
5959
5960 /* Print attribute */
5961 attr = binfo->attr;
5962 if (attr)
5963 {
5964 /* Print aspath */
5965 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005966 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005967
5968 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005969 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005970 }
5971 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005972}
5973
paul94f2b392005-06-28 12:44:16 +00005974static void
paul718e3742002-12-13 20:15:29 +00005975route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5976 struct bgp_info *binfo, afi_t afi, safi_t safi)
5977{
5978 char buf[INET6_ADDRSTRLEN];
5979 char buf1[BUFSIZ];
5980 struct attr *attr;
5981 int sockunion_vty_out (struct vty *, union sockunion *);
5982
5983 attr = binfo->attr;
5984
5985 if (attr)
5986 {
5987 /* Line1 display AS-path, Aggregator */
5988 if (attr->aspath)
5989 {
5990 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005991 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005992 vty_out (vty, "Local");
5993 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005994 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005995 }
5996
paulb40d9392005-08-22 22:34:41 +00005997 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5998 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005999 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6000 vty_out (vty, ", (stale)");
6001 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006002 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006003 attr->extra->aggregator_as,
6004 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006005 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6006 vty_out (vty, ", (Received from a RR-client)");
6007 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6008 vty_out (vty, ", (Received from a RS-client)");
6009 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6010 vty_out (vty, ", (history entry)");
6011 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6012 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006013 vty_out (vty, "%s", VTY_NEWLINE);
6014
6015 /* Line2 display Next-hop, Neighbor, Router-id */
6016 if (p->family == AF_INET)
6017 {
6018 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006019 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006020 inet_ntoa (attr->nexthop));
6021 }
6022#ifdef HAVE_IPV6
6023 else
6024 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006025 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006026 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006027 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006028 buf, INET6_ADDRSTRLEN));
6029 }
6030#endif /* HAVE_IPV6 */
6031
6032 if (binfo->peer == bgp->peer_self)
6033 {
6034 vty_out (vty, " from %s ",
6035 p->family == AF_INET ? "0.0.0.0" : "::");
6036 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6037 }
6038 else
6039 {
6040 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6041 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006042 else if (binfo->extra && binfo->extra->igpmetric)
6043 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006044 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006045 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006046 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006047 else
6048 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6049 }
6050 vty_out (vty, "%s", VTY_NEWLINE);
6051
6052#ifdef HAVE_IPV6
6053 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006054 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006055 {
6056 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006057 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006058 buf, INET6_ADDRSTRLEN),
6059 VTY_NEWLINE);
6060 }
6061#endif /* HAVE_IPV6 */
6062
6063 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6064 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6065
6066 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6067 vty_out (vty, ", metric %d", attr->med);
6068
6069 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6070 vty_out (vty, ", localpref %d", attr->local_pref);
6071 else
6072 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6073
Paul Jakmafb982c22007-05-04 20:15:47 +00006074 if (attr->extra && attr->extra->weight != 0)
6075 vty_out (vty, ", weight %d", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006076
6077 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6078 vty_out (vty, ", valid");
6079
6080 if (binfo->peer != bgp->peer_self)
6081 {
6082 if (binfo->peer->as == binfo->peer->local_as)
6083 vty_out (vty, ", internal");
6084 else
6085 vty_out (vty, ", %s",
6086 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6087 }
6088 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6089 vty_out (vty, ", aggregated, local");
6090 else if (binfo->type != ZEBRA_ROUTE_BGP)
6091 vty_out (vty, ", sourced");
6092 else
6093 vty_out (vty, ", sourced, local");
6094
6095 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6096 vty_out (vty, ", atomic-aggregate");
6097
6098 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6099 vty_out (vty, ", best");
6100
6101 vty_out (vty, "%s", VTY_NEWLINE);
6102
6103 /* Line 4 display Community */
6104 if (attr->community)
6105 vty_out (vty, " Community: %s%s", attr->community->str,
6106 VTY_NEWLINE);
6107
6108 /* Line 5 display Extended-community */
6109 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006110 vty_out (vty, " Extended Community: %s%s",
6111 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006112
6113 /* Line 6 display Originator, Cluster-id */
6114 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6115 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6116 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006117 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006118 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006119 vty_out (vty, " Originator: %s",
6120 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006121
6122 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6123 {
6124 int i;
6125 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006126 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6127 vty_out (vty, "%s ",
6128 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006129 }
6130 vty_out (vty, "%s", VTY_NEWLINE);
6131 }
Paul Jakma41367172007-08-06 15:24:51 +00006132
6133 /* 7: AS Pathlimit */
6134 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6135 {
6136
6137 vty_out (vty, " AS-Pathlimit: %u",
6138 attr->pathlimit.ttl);
6139 if (attr->pathlimit.as)
6140 vty_out (vty, " (%u)", attr->pathlimit.as);
6141 vty_out (vty, "%s", VTY_NEWLINE);
6142 }
6143
Paul Jakmafb982c22007-05-04 20:15:47 +00006144 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006145 bgp_damp_info_vty (vty, binfo);
6146
6147 /* Line 7 display Uptime */
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006148 time_t tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
6149 vty_out (vty, " Last update: %s", ctime(&tbuf));
paul718e3742002-12-13 20:15:29 +00006150 }
6151 vty_out (vty, "%s", VTY_NEWLINE);
6152}
6153
paulb40d9392005-08-22 22:34:41 +00006154#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 +00006155#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006156#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6157#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6158#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6159
6160enum bgp_show_type
6161{
6162 bgp_show_type_normal,
6163 bgp_show_type_regexp,
6164 bgp_show_type_prefix_list,
6165 bgp_show_type_filter_list,
6166 bgp_show_type_route_map,
6167 bgp_show_type_neighbor,
6168 bgp_show_type_cidr_only,
6169 bgp_show_type_prefix_longer,
6170 bgp_show_type_community_all,
6171 bgp_show_type_community,
6172 bgp_show_type_community_exact,
6173 bgp_show_type_community_list,
6174 bgp_show_type_community_list_exact,
6175 bgp_show_type_flap_statistics,
6176 bgp_show_type_flap_address,
6177 bgp_show_type_flap_prefix,
6178 bgp_show_type_flap_cidr_only,
6179 bgp_show_type_flap_regexp,
6180 bgp_show_type_flap_filter_list,
6181 bgp_show_type_flap_prefix_list,
6182 bgp_show_type_flap_prefix_longer,
6183 bgp_show_type_flap_route_map,
6184 bgp_show_type_flap_neighbor,
6185 bgp_show_type_dampend_paths,
6186 bgp_show_type_damp_neighbor
6187};
6188
ajs5a646652004-11-05 01:25:55 +00006189static int
paulfee0f4c2004-09-13 05:12:46 +00006190bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006191 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006192{
paul718e3742002-12-13 20:15:29 +00006193 struct bgp_info *ri;
6194 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006195 int header = 1;
paul718e3742002-12-13 20:15:29 +00006196 int display;
ajs5a646652004-11-05 01:25:55 +00006197 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006198
6199 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006200 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006201
paul718e3742002-12-13 20:15:29 +00006202 /* Start processing of routes. */
6203 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6204 if (rn->info != NULL)
6205 {
6206 display = 0;
6207
6208 for (ri = rn->info; ri; ri = ri->next)
6209 {
ajs5a646652004-11-05 01:25:55 +00006210 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006211 || type == bgp_show_type_flap_address
6212 || type == bgp_show_type_flap_prefix
6213 || type == bgp_show_type_flap_cidr_only
6214 || type == bgp_show_type_flap_regexp
6215 || type == bgp_show_type_flap_filter_list
6216 || type == bgp_show_type_flap_prefix_list
6217 || type == bgp_show_type_flap_prefix_longer
6218 || type == bgp_show_type_flap_route_map
6219 || type == bgp_show_type_flap_neighbor
6220 || type == bgp_show_type_dampend_paths
6221 || type == bgp_show_type_damp_neighbor)
6222 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006223 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006224 continue;
6225 }
6226 if (type == bgp_show_type_regexp
6227 || type == bgp_show_type_flap_regexp)
6228 {
ajs5a646652004-11-05 01:25:55 +00006229 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006230
6231 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6232 continue;
6233 }
6234 if (type == bgp_show_type_prefix_list
6235 || type == bgp_show_type_flap_prefix_list)
6236 {
ajs5a646652004-11-05 01:25:55 +00006237 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006238
6239 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6240 continue;
6241 }
6242 if (type == bgp_show_type_filter_list
6243 || type == bgp_show_type_flap_filter_list)
6244 {
ajs5a646652004-11-05 01:25:55 +00006245 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006246
6247 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6248 continue;
6249 }
6250 if (type == bgp_show_type_route_map
6251 || type == bgp_show_type_flap_route_map)
6252 {
ajs5a646652004-11-05 01:25:55 +00006253 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006254 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006255 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006256 int ret;
6257
Paul Jakmafb982c22007-05-04 20:15:47 +00006258 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006259 binfo.peer = ri->peer;
6260 binfo.attr = &dummy_attr;
6261
6262 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006263
6264 bgp_attr_extra_free (&dummy_attr);
6265
paul718e3742002-12-13 20:15:29 +00006266 if (ret == RMAP_DENYMATCH)
6267 continue;
6268 }
6269 if (type == bgp_show_type_neighbor
6270 || type == bgp_show_type_flap_neighbor
6271 || type == bgp_show_type_damp_neighbor)
6272 {
ajs5a646652004-11-05 01:25:55 +00006273 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006274
6275 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6276 continue;
6277 }
6278 if (type == bgp_show_type_cidr_only
6279 || type == bgp_show_type_flap_cidr_only)
6280 {
6281 u_int32_t destination;
6282
6283 destination = ntohl (rn->p.u.prefix4.s_addr);
6284 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6285 continue;
6286 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6287 continue;
6288 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6289 continue;
6290 }
6291 if (type == bgp_show_type_prefix_longer
6292 || type == bgp_show_type_flap_prefix_longer)
6293 {
ajs5a646652004-11-05 01:25:55 +00006294 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006295
6296 if (! prefix_match (p, &rn->p))
6297 continue;
6298 }
6299 if (type == bgp_show_type_community_all)
6300 {
6301 if (! ri->attr->community)
6302 continue;
6303 }
6304 if (type == bgp_show_type_community)
6305 {
ajs5a646652004-11-05 01:25:55 +00006306 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006307
6308 if (! ri->attr->community ||
6309 ! community_match (ri->attr->community, com))
6310 continue;
6311 }
6312 if (type == bgp_show_type_community_exact)
6313 {
ajs5a646652004-11-05 01:25:55 +00006314 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006315
6316 if (! ri->attr->community ||
6317 ! community_cmp (ri->attr->community, com))
6318 continue;
6319 }
6320 if (type == bgp_show_type_community_list)
6321 {
ajs5a646652004-11-05 01:25:55 +00006322 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006323
6324 if (! community_list_match (ri->attr->community, list))
6325 continue;
6326 }
6327 if (type == bgp_show_type_community_list_exact)
6328 {
ajs5a646652004-11-05 01:25:55 +00006329 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006330
6331 if (! community_list_exact_match (ri->attr->community, list))
6332 continue;
6333 }
6334 if (type == bgp_show_type_flap_address
6335 || type == bgp_show_type_flap_prefix)
6336 {
ajs5a646652004-11-05 01:25:55 +00006337 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006338
6339 if (! prefix_match (&rn->p, p))
6340 continue;
6341
6342 if (type == bgp_show_type_flap_prefix)
6343 if (p->prefixlen != rn->p.prefixlen)
6344 continue;
6345 }
6346 if (type == bgp_show_type_dampend_paths
6347 || type == bgp_show_type_damp_neighbor)
6348 {
6349 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6350 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6351 continue;
6352 }
6353
6354 if (header)
6355 {
hasso93406d82005-02-02 14:40:33 +00006356 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6357 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6358 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006359 if (type == bgp_show_type_dampend_paths
6360 || type == bgp_show_type_damp_neighbor)
6361 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6362 else if (type == bgp_show_type_flap_statistics
6363 || type == bgp_show_type_flap_address
6364 || type == bgp_show_type_flap_prefix
6365 || type == bgp_show_type_flap_cidr_only
6366 || type == bgp_show_type_flap_regexp
6367 || type == bgp_show_type_flap_filter_list
6368 || type == bgp_show_type_flap_prefix_list
6369 || type == bgp_show_type_flap_prefix_longer
6370 || type == bgp_show_type_flap_route_map
6371 || type == bgp_show_type_flap_neighbor)
6372 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6373 else
6374 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006375 header = 0;
6376 }
6377
6378 if (type == bgp_show_type_dampend_paths
6379 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006380 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006381 else if (type == bgp_show_type_flap_statistics
6382 || type == bgp_show_type_flap_address
6383 || type == bgp_show_type_flap_prefix
6384 || type == bgp_show_type_flap_cidr_only
6385 || type == bgp_show_type_flap_regexp
6386 || type == bgp_show_type_flap_filter_list
6387 || type == bgp_show_type_flap_prefix_list
6388 || type == bgp_show_type_flap_prefix_longer
6389 || type == bgp_show_type_flap_route_map
6390 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006391 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006392 else
ajs5a646652004-11-05 01:25:55 +00006393 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006394 display++;
6395 }
6396 if (display)
ajs5a646652004-11-05 01:25:55 +00006397 output_count++;
paul718e3742002-12-13 20:15:29 +00006398 }
6399
6400 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006401 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006402 {
6403 if (type == bgp_show_type_normal)
6404 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6405 }
6406 else
6407 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006408 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006409
6410 return CMD_SUCCESS;
6411}
6412
ajs5a646652004-11-05 01:25:55 +00006413static int
paulfee0f4c2004-09-13 05:12:46 +00006414bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006415 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006416{
6417 struct bgp_table *table;
6418
6419 if (bgp == NULL) {
6420 bgp = bgp_get_default ();
6421 }
6422
6423 if (bgp == NULL)
6424 {
6425 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6426 return CMD_WARNING;
6427 }
6428
6429
6430 table = bgp->rib[afi][safi];
6431
ajs5a646652004-11-05 01:25:55 +00006432 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006433}
6434
paul718e3742002-12-13 20:15:29 +00006435/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006436static void
paul718e3742002-12-13 20:15:29 +00006437route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6438 struct bgp_node *rn,
6439 struct prefix_rd *prd, afi_t afi, safi_t safi)
6440{
6441 struct bgp_info *ri;
6442 struct prefix *p;
6443 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006444 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006445 char buf1[INET6_ADDRSTRLEN];
6446 char buf2[INET6_ADDRSTRLEN];
6447 int count = 0;
6448 int best = 0;
6449 int suppress = 0;
6450 int no_export = 0;
6451 int no_advertise = 0;
6452 int local_as = 0;
6453 int first = 0;
6454
6455 p = &rn->p;
6456 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6457 (safi == SAFI_MPLS_VPN ?
6458 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6459 safi == SAFI_MPLS_VPN ? ":" : "",
6460 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6461 p->prefixlen, VTY_NEWLINE);
6462
6463 for (ri = rn->info; ri; ri = ri->next)
6464 {
6465 count++;
6466 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6467 {
6468 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006469 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006470 suppress = 1;
6471 if (ri->attr->community != NULL)
6472 {
6473 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6474 no_advertise = 1;
6475 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6476 no_export = 1;
6477 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6478 local_as = 1;
6479 }
6480 }
6481 }
6482
6483 vty_out (vty, "Paths: (%d available", count);
6484 if (best)
6485 {
6486 vty_out (vty, ", best #%d", best);
6487 if (safi == SAFI_UNICAST)
6488 vty_out (vty, ", table Default-IP-Routing-Table");
6489 }
6490 else
6491 vty_out (vty, ", no best path");
6492 if (no_advertise)
6493 vty_out (vty, ", not advertised to any peer");
6494 else if (no_export)
6495 vty_out (vty, ", not advertised to EBGP peer");
6496 else if (local_as)
6497 vty_out (vty, ", not advertised outside local AS");
6498 if (suppress)
6499 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6500 vty_out (vty, ")%s", VTY_NEWLINE);
6501
6502 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006503 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006504 {
6505 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6506 {
6507 if (! first)
6508 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6509 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6510 first = 1;
6511 }
6512 }
6513 if (! first)
6514 vty_out (vty, " Not advertised to any peer");
6515 vty_out (vty, "%s", VTY_NEWLINE);
6516}
6517
6518/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006519static int
paulfee0f4c2004-09-13 05:12:46 +00006520bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006521 struct bgp_table *rib, const char *ip_str,
6522 afi_t afi, safi_t safi, struct prefix_rd *prd,
6523 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006524{
6525 int ret;
6526 int header;
6527 int display = 0;
6528 struct prefix match;
6529 struct bgp_node *rn;
6530 struct bgp_node *rm;
6531 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006532 struct bgp_table *table;
6533
paul718e3742002-12-13 20:15:29 +00006534 /* Check IP address argument. */
6535 ret = str2prefix (ip_str, &match);
6536 if (! ret)
6537 {
6538 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6539 return CMD_WARNING;
6540 }
6541
6542 match.family = afi2family (afi);
6543
6544 if (safi == SAFI_MPLS_VPN)
6545 {
paulfee0f4c2004-09-13 05:12:46 +00006546 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006547 {
6548 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6549 continue;
6550
6551 if ((table = rn->info) != NULL)
6552 {
6553 header = 1;
6554
6555 if ((rm = bgp_node_match (table, &match)) != NULL)
6556 {
6557 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6558 continue;
6559
6560 for (ri = rm->info; ri; ri = ri->next)
6561 {
6562 if (header)
6563 {
6564 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6565 AFI_IP, SAFI_MPLS_VPN);
6566
6567 header = 0;
6568 }
6569 display++;
6570 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6571 }
6572 }
6573 }
6574 }
6575 }
6576 else
6577 {
6578 header = 1;
6579
paulfee0f4c2004-09-13 05:12:46 +00006580 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006581 {
6582 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6583 {
6584 for (ri = rn->info; ri; ri = ri->next)
6585 {
6586 if (header)
6587 {
6588 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6589 header = 0;
6590 }
6591 display++;
6592 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6593 }
6594 }
6595 }
6596 }
6597
6598 if (! display)
6599 {
6600 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6601 return CMD_WARNING;
6602 }
6603
6604 return CMD_SUCCESS;
6605}
6606
paulfee0f4c2004-09-13 05:12:46 +00006607/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006608static int
paulfd79ac92004-10-13 05:06:08 +00006609bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006610 afi_t afi, safi_t safi, struct prefix_rd *prd,
6611 int prefix_check)
6612{
6613 struct bgp *bgp;
6614
6615 /* BGP structure lookup. */
6616 if (view_name)
6617 {
6618 bgp = bgp_lookup_by_name (view_name);
6619 if (bgp == NULL)
6620 {
6621 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6622 return CMD_WARNING;
6623 }
6624 }
6625 else
6626 {
6627 bgp = bgp_get_default ();
6628 if (bgp == NULL)
6629 {
6630 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6631 return CMD_WARNING;
6632 }
6633 }
6634
6635 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6636 afi, safi, prd, prefix_check);
6637}
6638
paul718e3742002-12-13 20:15:29 +00006639/* BGP route print out function. */
6640DEFUN (show_ip_bgp,
6641 show_ip_bgp_cmd,
6642 "show ip bgp",
6643 SHOW_STR
6644 IP_STR
6645 BGP_STR)
6646{
ajs5a646652004-11-05 01:25:55 +00006647 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006648}
6649
6650DEFUN (show_ip_bgp_ipv4,
6651 show_ip_bgp_ipv4_cmd,
6652 "show ip bgp ipv4 (unicast|multicast)",
6653 SHOW_STR
6654 IP_STR
6655 BGP_STR
6656 "Address family\n"
6657 "Address Family modifier\n"
6658 "Address Family modifier\n")
6659{
6660 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006661 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6662 NULL);
paul718e3742002-12-13 20:15:29 +00006663
ajs5a646652004-11-05 01:25:55 +00006664 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006665}
6666
6667DEFUN (show_ip_bgp_route,
6668 show_ip_bgp_route_cmd,
6669 "show ip bgp A.B.C.D",
6670 SHOW_STR
6671 IP_STR
6672 BGP_STR
6673 "Network in the BGP routing table to display\n")
6674{
6675 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6676}
6677
6678DEFUN (show_ip_bgp_ipv4_route,
6679 show_ip_bgp_ipv4_route_cmd,
6680 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6681 SHOW_STR
6682 IP_STR
6683 BGP_STR
6684 "Address family\n"
6685 "Address Family modifier\n"
6686 "Address Family modifier\n"
6687 "Network in the BGP routing table to display\n")
6688{
6689 if (strncmp (argv[0], "m", 1) == 0)
6690 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6691
6692 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6693}
6694
6695DEFUN (show_ip_bgp_vpnv4_all_route,
6696 show_ip_bgp_vpnv4_all_route_cmd,
6697 "show ip bgp vpnv4 all A.B.C.D",
6698 SHOW_STR
6699 IP_STR
6700 BGP_STR
6701 "Display VPNv4 NLRI specific information\n"
6702 "Display information about all VPNv4 NLRIs\n"
6703 "Network in the BGP routing table to display\n")
6704{
6705 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6706}
6707
6708DEFUN (show_ip_bgp_vpnv4_rd_route,
6709 show_ip_bgp_vpnv4_rd_route_cmd,
6710 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6711 SHOW_STR
6712 IP_STR
6713 BGP_STR
6714 "Display VPNv4 NLRI specific information\n"
6715 "Display information for a route distinguisher\n"
6716 "VPN Route Distinguisher\n"
6717 "Network in the BGP routing table to display\n")
6718{
6719 int ret;
6720 struct prefix_rd prd;
6721
6722 ret = str2prefix_rd (argv[0], &prd);
6723 if (! ret)
6724 {
6725 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6726 return CMD_WARNING;
6727 }
6728 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6729}
6730
6731DEFUN (show_ip_bgp_prefix,
6732 show_ip_bgp_prefix_cmd,
6733 "show ip bgp A.B.C.D/M",
6734 SHOW_STR
6735 IP_STR
6736 BGP_STR
6737 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6738{
6739 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6740}
6741
6742DEFUN (show_ip_bgp_ipv4_prefix,
6743 show_ip_bgp_ipv4_prefix_cmd,
6744 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6745 SHOW_STR
6746 IP_STR
6747 BGP_STR
6748 "Address family\n"
6749 "Address Family modifier\n"
6750 "Address Family modifier\n"
6751 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6752{
6753 if (strncmp (argv[0], "m", 1) == 0)
6754 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6755
6756 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6757}
6758
6759DEFUN (show_ip_bgp_vpnv4_all_prefix,
6760 show_ip_bgp_vpnv4_all_prefix_cmd,
6761 "show ip bgp vpnv4 all A.B.C.D/M",
6762 SHOW_STR
6763 IP_STR
6764 BGP_STR
6765 "Display VPNv4 NLRI specific information\n"
6766 "Display information about all VPNv4 NLRIs\n"
6767 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6768{
6769 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6770}
6771
6772DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6773 show_ip_bgp_vpnv4_rd_prefix_cmd,
6774 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6775 SHOW_STR
6776 IP_STR
6777 BGP_STR
6778 "Display VPNv4 NLRI specific information\n"
6779 "Display information for a route distinguisher\n"
6780 "VPN Route Distinguisher\n"
6781 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6782{
6783 int ret;
6784 struct prefix_rd prd;
6785
6786 ret = str2prefix_rd (argv[0], &prd);
6787 if (! ret)
6788 {
6789 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6790 return CMD_WARNING;
6791 }
6792 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6793}
6794
6795DEFUN (show_ip_bgp_view,
6796 show_ip_bgp_view_cmd,
6797 "show ip bgp view WORD",
6798 SHOW_STR
6799 IP_STR
6800 BGP_STR
6801 "BGP view\n"
6802 "BGP view name\n")
6803{
paulbb46e942003-10-24 19:02:03 +00006804 struct bgp *bgp;
6805
6806 /* BGP structure lookup. */
6807 bgp = bgp_lookup_by_name (argv[0]);
6808 if (bgp == NULL)
6809 {
6810 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6811 return CMD_WARNING;
6812 }
6813
ajs5a646652004-11-05 01:25:55 +00006814 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006815}
6816
6817DEFUN (show_ip_bgp_view_route,
6818 show_ip_bgp_view_route_cmd,
6819 "show ip bgp view WORD A.B.C.D",
6820 SHOW_STR
6821 IP_STR
6822 BGP_STR
6823 "BGP view\n"
6824 "BGP view name\n"
6825 "Network in the BGP routing table to display\n")
6826{
6827 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6828}
6829
6830DEFUN (show_ip_bgp_view_prefix,
6831 show_ip_bgp_view_prefix_cmd,
6832 "show ip bgp view WORD A.B.C.D/M",
6833 SHOW_STR
6834 IP_STR
6835 BGP_STR
6836 "BGP view\n"
6837 "BGP view name\n"
6838 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6839{
6840 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6841}
6842
6843#ifdef HAVE_IPV6
6844DEFUN (show_bgp,
6845 show_bgp_cmd,
6846 "show bgp",
6847 SHOW_STR
6848 BGP_STR)
6849{
ajs5a646652004-11-05 01:25:55 +00006850 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6851 NULL);
paul718e3742002-12-13 20:15:29 +00006852}
6853
6854ALIAS (show_bgp,
6855 show_bgp_ipv6_cmd,
6856 "show bgp ipv6",
6857 SHOW_STR
6858 BGP_STR
6859 "Address family\n")
6860
6861/* old command */
6862DEFUN (show_ipv6_bgp,
6863 show_ipv6_bgp_cmd,
6864 "show ipv6 bgp",
6865 SHOW_STR
6866 IP_STR
6867 BGP_STR)
6868{
ajs5a646652004-11-05 01:25:55 +00006869 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6870 NULL);
paul718e3742002-12-13 20:15:29 +00006871}
6872
6873DEFUN (show_bgp_route,
6874 show_bgp_route_cmd,
6875 "show bgp X:X::X:X",
6876 SHOW_STR
6877 BGP_STR
6878 "Network in the BGP routing table to display\n")
6879{
6880 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6881}
6882
6883ALIAS (show_bgp_route,
6884 show_bgp_ipv6_route_cmd,
6885 "show bgp ipv6 X:X::X:X",
6886 SHOW_STR
6887 BGP_STR
6888 "Address family\n"
6889 "Network in the BGP routing table to display\n")
6890
6891/* old command */
6892DEFUN (show_ipv6_bgp_route,
6893 show_ipv6_bgp_route_cmd,
6894 "show ipv6 bgp X:X::X:X",
6895 SHOW_STR
6896 IP_STR
6897 BGP_STR
6898 "Network in the BGP routing table to display\n")
6899{
6900 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6901}
6902
6903DEFUN (show_bgp_prefix,
6904 show_bgp_prefix_cmd,
6905 "show bgp X:X::X:X/M",
6906 SHOW_STR
6907 BGP_STR
6908 "IPv6 prefix <network>/<length>\n")
6909{
6910 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6911}
6912
6913ALIAS (show_bgp_prefix,
6914 show_bgp_ipv6_prefix_cmd,
6915 "show bgp ipv6 X:X::X:X/M",
6916 SHOW_STR
6917 BGP_STR
6918 "Address family\n"
6919 "IPv6 prefix <network>/<length>\n")
6920
6921/* old command */
6922DEFUN (show_ipv6_bgp_prefix,
6923 show_ipv6_bgp_prefix_cmd,
6924 "show ipv6 bgp X:X::X:X/M",
6925 SHOW_STR
6926 IP_STR
6927 BGP_STR
6928 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6929{
6930 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6931}
6932
paulbb46e942003-10-24 19:02:03 +00006933DEFUN (show_bgp_view,
6934 show_bgp_view_cmd,
6935 "show bgp view WORD",
6936 SHOW_STR
6937 BGP_STR
6938 "BGP view\n"
6939 "View name\n")
6940{
6941 struct bgp *bgp;
6942
6943 /* BGP structure lookup. */
6944 bgp = bgp_lookup_by_name (argv[0]);
6945 if (bgp == NULL)
6946 {
6947 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6948 return CMD_WARNING;
6949 }
6950
ajs5a646652004-11-05 01:25:55 +00006951 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006952}
6953
6954ALIAS (show_bgp_view,
6955 show_bgp_view_ipv6_cmd,
6956 "show bgp view WORD ipv6",
6957 SHOW_STR
6958 BGP_STR
6959 "BGP view\n"
6960 "View name\n"
6961 "Address family\n")
6962
6963DEFUN (show_bgp_view_route,
6964 show_bgp_view_route_cmd,
6965 "show bgp view WORD X:X::X:X",
6966 SHOW_STR
6967 BGP_STR
6968 "BGP view\n"
6969 "View name\n"
6970 "Network in the BGP routing table to display\n")
6971{
6972 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6973}
6974
6975ALIAS (show_bgp_view_route,
6976 show_bgp_view_ipv6_route_cmd,
6977 "show bgp view WORD ipv6 X:X::X:X",
6978 SHOW_STR
6979 BGP_STR
6980 "BGP view\n"
6981 "View name\n"
6982 "Address family\n"
6983 "Network in the BGP routing table to display\n")
6984
6985DEFUN (show_bgp_view_prefix,
6986 show_bgp_view_prefix_cmd,
6987 "show bgp view WORD X:X::X:X/M",
6988 SHOW_STR
6989 BGP_STR
6990 "BGP view\n"
6991 "View name\n"
6992 "IPv6 prefix <network>/<length>\n")
6993{
6994 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6995}
6996
6997ALIAS (show_bgp_view_prefix,
6998 show_bgp_view_ipv6_prefix_cmd,
6999 "show bgp view WORD ipv6 X:X::X:X/M",
7000 SHOW_STR
7001 BGP_STR
7002 "BGP view\n"
7003 "View name\n"
7004 "Address family\n"
7005 "IPv6 prefix <network>/<length>\n")
7006
paul718e3742002-12-13 20:15:29 +00007007/* old command */
7008DEFUN (show_ipv6_mbgp,
7009 show_ipv6_mbgp_cmd,
7010 "show ipv6 mbgp",
7011 SHOW_STR
7012 IP_STR
7013 MBGP_STR)
7014{
ajs5a646652004-11-05 01:25:55 +00007015 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7016 NULL);
paul718e3742002-12-13 20:15:29 +00007017}
7018
7019/* old command */
7020DEFUN (show_ipv6_mbgp_route,
7021 show_ipv6_mbgp_route_cmd,
7022 "show ipv6 mbgp X:X::X:X",
7023 SHOW_STR
7024 IP_STR
7025 MBGP_STR
7026 "Network in the MBGP routing table to display\n")
7027{
7028 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7029}
7030
7031/* old command */
7032DEFUN (show_ipv6_mbgp_prefix,
7033 show_ipv6_mbgp_prefix_cmd,
7034 "show ipv6 mbgp X:X::X:X/M",
7035 SHOW_STR
7036 IP_STR
7037 MBGP_STR
7038 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7039{
7040 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7041}
7042#endif
7043
paul718e3742002-12-13 20:15:29 +00007044
paul94f2b392005-06-28 12:44:16 +00007045static int
paulfd79ac92004-10-13 05:06:08 +00007046bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007047 safi_t safi, enum bgp_show_type type)
7048{
7049 int i;
7050 struct buffer *b;
7051 char *regstr;
7052 int first;
7053 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007054 int rc;
paul718e3742002-12-13 20:15:29 +00007055
7056 first = 0;
7057 b = buffer_new (1024);
7058 for (i = 0; i < argc; i++)
7059 {
7060 if (first)
7061 buffer_putc (b, ' ');
7062 else
7063 {
7064 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7065 continue;
7066 first = 1;
7067 }
7068
7069 buffer_putstr (b, argv[i]);
7070 }
7071 buffer_putc (b, '\0');
7072
7073 regstr = buffer_getstr (b);
7074 buffer_free (b);
7075
7076 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007077 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007078 if (! regex)
7079 {
7080 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7081 VTY_NEWLINE);
7082 return CMD_WARNING;
7083 }
7084
ajs5a646652004-11-05 01:25:55 +00007085 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7086 bgp_regex_free (regex);
7087 return rc;
paul718e3742002-12-13 20:15:29 +00007088}
7089
7090DEFUN (show_ip_bgp_regexp,
7091 show_ip_bgp_regexp_cmd,
7092 "show ip bgp regexp .LINE",
7093 SHOW_STR
7094 IP_STR
7095 BGP_STR
7096 "Display routes matching the AS path regular expression\n"
7097 "A regular-expression to match the BGP AS paths\n")
7098{
7099 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7100 bgp_show_type_regexp);
7101}
7102
7103DEFUN (show_ip_bgp_flap_regexp,
7104 show_ip_bgp_flap_regexp_cmd,
7105 "show ip bgp flap-statistics regexp .LINE",
7106 SHOW_STR
7107 IP_STR
7108 BGP_STR
7109 "Display flap statistics of routes\n"
7110 "Display routes matching the AS path regular expression\n"
7111 "A regular-expression to match the BGP AS paths\n")
7112{
7113 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7114 bgp_show_type_flap_regexp);
7115}
7116
7117DEFUN (show_ip_bgp_ipv4_regexp,
7118 show_ip_bgp_ipv4_regexp_cmd,
7119 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7120 SHOW_STR
7121 IP_STR
7122 BGP_STR
7123 "Address family\n"
7124 "Address Family modifier\n"
7125 "Address Family modifier\n"
7126 "Display routes matching the AS path regular expression\n"
7127 "A regular-expression to match the BGP AS paths\n")
7128{
7129 if (strncmp (argv[0], "m", 1) == 0)
7130 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7131 bgp_show_type_regexp);
7132
7133 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7134 bgp_show_type_regexp);
7135}
7136
7137#ifdef HAVE_IPV6
7138DEFUN (show_bgp_regexp,
7139 show_bgp_regexp_cmd,
7140 "show bgp regexp .LINE",
7141 SHOW_STR
7142 BGP_STR
7143 "Display routes matching the AS path regular expression\n"
7144 "A regular-expression to match the BGP AS paths\n")
7145{
7146 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7147 bgp_show_type_regexp);
7148}
7149
7150ALIAS (show_bgp_regexp,
7151 show_bgp_ipv6_regexp_cmd,
7152 "show bgp ipv6 regexp .LINE",
7153 SHOW_STR
7154 BGP_STR
7155 "Address family\n"
7156 "Display routes matching the AS path regular expression\n"
7157 "A regular-expression to match the BGP AS paths\n")
7158
7159/* old command */
7160DEFUN (show_ipv6_bgp_regexp,
7161 show_ipv6_bgp_regexp_cmd,
7162 "show ipv6 bgp regexp .LINE",
7163 SHOW_STR
7164 IP_STR
7165 BGP_STR
7166 "Display routes matching the AS path regular expression\n"
7167 "A regular-expression to match the BGP AS paths\n")
7168{
7169 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7170 bgp_show_type_regexp);
7171}
7172
7173/* old command */
7174DEFUN (show_ipv6_mbgp_regexp,
7175 show_ipv6_mbgp_regexp_cmd,
7176 "show ipv6 mbgp regexp .LINE",
7177 SHOW_STR
7178 IP_STR
7179 BGP_STR
7180 "Display routes matching the AS path regular expression\n"
7181 "A regular-expression to match the MBGP AS paths\n")
7182{
7183 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7184 bgp_show_type_regexp);
7185}
7186#endif /* HAVE_IPV6 */
7187
paul94f2b392005-06-28 12:44:16 +00007188static int
paulfd79ac92004-10-13 05:06:08 +00007189bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007190 safi_t safi, enum bgp_show_type type)
7191{
7192 struct prefix_list *plist;
7193
7194 plist = prefix_list_lookup (afi, prefix_list_str);
7195 if (plist == NULL)
7196 {
7197 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7198 prefix_list_str, VTY_NEWLINE);
7199 return CMD_WARNING;
7200 }
7201
ajs5a646652004-11-05 01:25:55 +00007202 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007203}
7204
7205DEFUN (show_ip_bgp_prefix_list,
7206 show_ip_bgp_prefix_list_cmd,
7207 "show ip bgp prefix-list WORD",
7208 SHOW_STR
7209 IP_STR
7210 BGP_STR
7211 "Display routes conforming to the prefix-list\n"
7212 "IP prefix-list name\n")
7213{
7214 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7215 bgp_show_type_prefix_list);
7216}
7217
7218DEFUN (show_ip_bgp_flap_prefix_list,
7219 show_ip_bgp_flap_prefix_list_cmd,
7220 "show ip bgp flap-statistics prefix-list WORD",
7221 SHOW_STR
7222 IP_STR
7223 BGP_STR
7224 "Display flap statistics of routes\n"
7225 "Display routes conforming to the prefix-list\n"
7226 "IP prefix-list name\n")
7227{
7228 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7229 bgp_show_type_flap_prefix_list);
7230}
7231
7232DEFUN (show_ip_bgp_ipv4_prefix_list,
7233 show_ip_bgp_ipv4_prefix_list_cmd,
7234 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7235 SHOW_STR
7236 IP_STR
7237 BGP_STR
7238 "Address family\n"
7239 "Address Family modifier\n"
7240 "Address Family modifier\n"
7241 "Display routes conforming to the prefix-list\n"
7242 "IP prefix-list name\n")
7243{
7244 if (strncmp (argv[0], "m", 1) == 0)
7245 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7246 bgp_show_type_prefix_list);
7247
7248 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7249 bgp_show_type_prefix_list);
7250}
7251
7252#ifdef HAVE_IPV6
7253DEFUN (show_bgp_prefix_list,
7254 show_bgp_prefix_list_cmd,
7255 "show bgp prefix-list WORD",
7256 SHOW_STR
7257 BGP_STR
7258 "Display routes conforming to the prefix-list\n"
7259 "IPv6 prefix-list name\n")
7260{
7261 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7262 bgp_show_type_prefix_list);
7263}
7264
7265ALIAS (show_bgp_prefix_list,
7266 show_bgp_ipv6_prefix_list_cmd,
7267 "show bgp ipv6 prefix-list WORD",
7268 SHOW_STR
7269 BGP_STR
7270 "Address family\n"
7271 "Display routes conforming to the prefix-list\n"
7272 "IPv6 prefix-list name\n")
7273
7274/* old command */
7275DEFUN (show_ipv6_bgp_prefix_list,
7276 show_ipv6_bgp_prefix_list_cmd,
7277 "show ipv6 bgp prefix-list WORD",
7278 SHOW_STR
7279 IPV6_STR
7280 BGP_STR
7281 "Display routes matching the prefix-list\n"
7282 "IPv6 prefix-list name\n")
7283{
7284 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7285 bgp_show_type_prefix_list);
7286}
7287
7288/* old command */
7289DEFUN (show_ipv6_mbgp_prefix_list,
7290 show_ipv6_mbgp_prefix_list_cmd,
7291 "show ipv6 mbgp prefix-list WORD",
7292 SHOW_STR
7293 IPV6_STR
7294 MBGP_STR
7295 "Display routes matching the prefix-list\n"
7296 "IPv6 prefix-list name\n")
7297{
7298 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7299 bgp_show_type_prefix_list);
7300}
7301#endif /* HAVE_IPV6 */
7302
paul94f2b392005-06-28 12:44:16 +00007303static int
paulfd79ac92004-10-13 05:06:08 +00007304bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007305 safi_t safi, enum bgp_show_type type)
7306{
7307 struct as_list *as_list;
7308
7309 as_list = as_list_lookup (filter);
7310 if (as_list == NULL)
7311 {
7312 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7313 return CMD_WARNING;
7314 }
7315
ajs5a646652004-11-05 01:25:55 +00007316 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007317}
7318
7319DEFUN (show_ip_bgp_filter_list,
7320 show_ip_bgp_filter_list_cmd,
7321 "show ip bgp filter-list WORD",
7322 SHOW_STR
7323 IP_STR
7324 BGP_STR
7325 "Display routes conforming to the filter-list\n"
7326 "Regular expression access list name\n")
7327{
7328 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7329 bgp_show_type_filter_list);
7330}
7331
7332DEFUN (show_ip_bgp_flap_filter_list,
7333 show_ip_bgp_flap_filter_list_cmd,
7334 "show ip bgp flap-statistics filter-list WORD",
7335 SHOW_STR
7336 IP_STR
7337 BGP_STR
7338 "Display flap statistics of routes\n"
7339 "Display routes conforming to the filter-list\n"
7340 "Regular expression access list name\n")
7341{
7342 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7343 bgp_show_type_flap_filter_list);
7344}
7345
7346DEFUN (show_ip_bgp_ipv4_filter_list,
7347 show_ip_bgp_ipv4_filter_list_cmd,
7348 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7349 SHOW_STR
7350 IP_STR
7351 BGP_STR
7352 "Address family\n"
7353 "Address Family modifier\n"
7354 "Address Family modifier\n"
7355 "Display routes conforming to the filter-list\n"
7356 "Regular expression access list name\n")
7357{
7358 if (strncmp (argv[0], "m", 1) == 0)
7359 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7360 bgp_show_type_filter_list);
7361
7362 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7363 bgp_show_type_filter_list);
7364}
7365
7366#ifdef HAVE_IPV6
7367DEFUN (show_bgp_filter_list,
7368 show_bgp_filter_list_cmd,
7369 "show bgp filter-list WORD",
7370 SHOW_STR
7371 BGP_STR
7372 "Display routes conforming to the filter-list\n"
7373 "Regular expression access list name\n")
7374{
7375 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7376 bgp_show_type_filter_list);
7377}
7378
7379ALIAS (show_bgp_filter_list,
7380 show_bgp_ipv6_filter_list_cmd,
7381 "show bgp ipv6 filter-list WORD",
7382 SHOW_STR
7383 BGP_STR
7384 "Address family\n"
7385 "Display routes conforming to the filter-list\n"
7386 "Regular expression access list name\n")
7387
7388/* old command */
7389DEFUN (show_ipv6_bgp_filter_list,
7390 show_ipv6_bgp_filter_list_cmd,
7391 "show ipv6 bgp filter-list WORD",
7392 SHOW_STR
7393 IPV6_STR
7394 BGP_STR
7395 "Display routes conforming to the filter-list\n"
7396 "Regular expression access list name\n")
7397{
7398 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7399 bgp_show_type_filter_list);
7400}
7401
7402/* old command */
7403DEFUN (show_ipv6_mbgp_filter_list,
7404 show_ipv6_mbgp_filter_list_cmd,
7405 "show ipv6 mbgp filter-list WORD",
7406 SHOW_STR
7407 IPV6_STR
7408 MBGP_STR
7409 "Display routes conforming to the filter-list\n"
7410 "Regular expression access list name\n")
7411{
7412 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7413 bgp_show_type_filter_list);
7414}
7415#endif /* HAVE_IPV6 */
7416
paul94f2b392005-06-28 12:44:16 +00007417static int
paulfd79ac92004-10-13 05:06:08 +00007418bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007419 safi_t safi, enum bgp_show_type type)
7420{
7421 struct route_map *rmap;
7422
7423 rmap = route_map_lookup_by_name (rmap_str);
7424 if (! rmap)
7425 {
7426 vty_out (vty, "%% %s is not a valid route-map name%s",
7427 rmap_str, VTY_NEWLINE);
7428 return CMD_WARNING;
7429 }
7430
ajs5a646652004-11-05 01:25:55 +00007431 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007432}
7433
7434DEFUN (show_ip_bgp_route_map,
7435 show_ip_bgp_route_map_cmd,
7436 "show ip bgp route-map WORD",
7437 SHOW_STR
7438 IP_STR
7439 BGP_STR
7440 "Display routes matching the route-map\n"
7441 "A route-map to match on\n")
7442{
7443 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7444 bgp_show_type_route_map);
7445}
7446
7447DEFUN (show_ip_bgp_flap_route_map,
7448 show_ip_bgp_flap_route_map_cmd,
7449 "show ip bgp flap-statistics route-map WORD",
7450 SHOW_STR
7451 IP_STR
7452 BGP_STR
7453 "Display flap statistics of routes\n"
7454 "Display routes matching the route-map\n"
7455 "A route-map to match on\n")
7456{
7457 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7458 bgp_show_type_flap_route_map);
7459}
7460
7461DEFUN (show_ip_bgp_ipv4_route_map,
7462 show_ip_bgp_ipv4_route_map_cmd,
7463 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
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 routes matching the route-map\n"
7471 "A route-map to match on\n")
7472{
7473 if (strncmp (argv[0], "m", 1) == 0)
7474 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7475 bgp_show_type_route_map);
7476
7477 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7478 bgp_show_type_route_map);
7479}
7480
7481DEFUN (show_bgp_route_map,
7482 show_bgp_route_map_cmd,
7483 "show bgp route-map WORD",
7484 SHOW_STR
7485 BGP_STR
7486 "Display routes matching the route-map\n"
7487 "A route-map to match on\n")
7488{
7489 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7490 bgp_show_type_route_map);
7491}
7492
7493ALIAS (show_bgp_route_map,
7494 show_bgp_ipv6_route_map_cmd,
7495 "show bgp ipv6 route-map WORD",
7496 SHOW_STR
7497 BGP_STR
7498 "Address family\n"
7499 "Display routes matching the route-map\n"
7500 "A route-map to match on\n")
7501
7502DEFUN (show_ip_bgp_cidr_only,
7503 show_ip_bgp_cidr_only_cmd,
7504 "show ip bgp cidr-only",
7505 SHOW_STR
7506 IP_STR
7507 BGP_STR
7508 "Display only routes with non-natural netmasks\n")
7509{
7510 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007511 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007512}
7513
7514DEFUN (show_ip_bgp_flap_cidr_only,
7515 show_ip_bgp_flap_cidr_only_cmd,
7516 "show ip bgp flap-statistics cidr-only",
7517 SHOW_STR
7518 IP_STR
7519 BGP_STR
7520 "Display flap statistics of routes\n"
7521 "Display only routes with non-natural netmasks\n")
7522{
7523 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007524 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007525}
7526
7527DEFUN (show_ip_bgp_ipv4_cidr_only,
7528 show_ip_bgp_ipv4_cidr_only_cmd,
7529 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7530 SHOW_STR
7531 IP_STR
7532 BGP_STR
7533 "Address family\n"
7534 "Address Family modifier\n"
7535 "Address Family modifier\n"
7536 "Display only routes with non-natural netmasks\n")
7537{
7538 if (strncmp (argv[0], "m", 1) == 0)
7539 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007540 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007541
7542 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007543 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007544}
7545
7546DEFUN (show_ip_bgp_community_all,
7547 show_ip_bgp_community_all_cmd,
7548 "show ip bgp community",
7549 SHOW_STR
7550 IP_STR
7551 BGP_STR
7552 "Display routes matching the communities\n")
7553{
7554 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007555 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007556}
7557
7558DEFUN (show_ip_bgp_ipv4_community_all,
7559 show_ip_bgp_ipv4_community_all_cmd,
7560 "show ip bgp ipv4 (unicast|multicast) community",
7561 SHOW_STR
7562 IP_STR
7563 BGP_STR
7564 "Address family\n"
7565 "Address Family modifier\n"
7566 "Address Family modifier\n"
7567 "Display routes matching the communities\n")
7568{
7569 if (strncmp (argv[0], "m", 1) == 0)
7570 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007571 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007572
7573 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007574 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007575}
7576
7577#ifdef HAVE_IPV6
7578DEFUN (show_bgp_community_all,
7579 show_bgp_community_all_cmd,
7580 "show bgp community",
7581 SHOW_STR
7582 BGP_STR
7583 "Display routes matching the communities\n")
7584{
7585 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007586 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007587}
7588
7589ALIAS (show_bgp_community_all,
7590 show_bgp_ipv6_community_all_cmd,
7591 "show bgp ipv6 community",
7592 SHOW_STR
7593 BGP_STR
7594 "Address family\n"
7595 "Display routes matching the communities\n")
7596
7597/* old command */
7598DEFUN (show_ipv6_bgp_community_all,
7599 show_ipv6_bgp_community_all_cmd,
7600 "show ipv6 bgp community",
7601 SHOW_STR
7602 IPV6_STR
7603 BGP_STR
7604 "Display routes matching the communities\n")
7605{
7606 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007607 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007608}
7609
7610/* old command */
7611DEFUN (show_ipv6_mbgp_community_all,
7612 show_ipv6_mbgp_community_all_cmd,
7613 "show ipv6 mbgp community",
7614 SHOW_STR
7615 IPV6_STR
7616 MBGP_STR
7617 "Display routes matching the communities\n")
7618{
7619 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007620 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007621}
7622#endif /* HAVE_IPV6 */
7623
paul94f2b392005-06-28 12:44:16 +00007624static int
paulfd79ac92004-10-13 05:06:08 +00007625bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04007626 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007627{
7628 struct community *com;
7629 struct buffer *b;
7630 int i;
7631 char *str;
7632 int first = 0;
7633
7634 b = buffer_new (1024);
7635 for (i = 0; i < argc; i++)
7636 {
7637 if (first)
7638 buffer_putc (b, ' ');
7639 else
7640 {
7641 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7642 continue;
7643 first = 1;
7644 }
7645
7646 buffer_putstr (b, argv[i]);
7647 }
7648 buffer_putc (b, '\0');
7649
7650 str = buffer_getstr (b);
7651 buffer_free (b);
7652
7653 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007654 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007655 if (! com)
7656 {
7657 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7658 return CMD_WARNING;
7659 }
7660
ajs5a646652004-11-05 01:25:55 +00007661 return bgp_show (vty, NULL, afi, safi,
7662 (exact ? bgp_show_type_community_exact :
7663 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007664}
7665
7666DEFUN (show_ip_bgp_community,
7667 show_ip_bgp_community_cmd,
7668 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7669 SHOW_STR
7670 IP_STR
7671 BGP_STR
7672 "Display routes matching the communities\n"
7673 "community number\n"
7674 "Do not send outside local AS (well-known community)\n"
7675 "Do not advertise to any peer (well-known community)\n"
7676 "Do not export to next AS (well-known community)\n")
7677{
7678 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7679}
7680
7681ALIAS (show_ip_bgp_community,
7682 show_ip_bgp_community2_cmd,
7683 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7684 SHOW_STR
7685 IP_STR
7686 BGP_STR
7687 "Display routes matching the communities\n"
7688 "community number\n"
7689 "Do not send outside local AS (well-known community)\n"
7690 "Do not advertise to any peer (well-known community)\n"
7691 "Do not export to next AS (well-known community)\n"
7692 "community number\n"
7693 "Do not send outside local AS (well-known community)\n"
7694 "Do not advertise to any peer (well-known community)\n"
7695 "Do not export to next AS (well-known community)\n")
7696
7697ALIAS (show_ip_bgp_community,
7698 show_ip_bgp_community3_cmd,
7699 "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)",
7700 SHOW_STR
7701 IP_STR
7702 BGP_STR
7703 "Display routes matching the communities\n"
7704 "community number\n"
7705 "Do not send outside local AS (well-known community)\n"
7706 "Do not advertise to any peer (well-known community)\n"
7707 "Do not export to next AS (well-known community)\n"
7708 "community number\n"
7709 "Do not send outside local AS (well-known community)\n"
7710 "Do not advertise to any peer (well-known community)\n"
7711 "Do not export to next AS (well-known community)\n"
7712 "community number\n"
7713 "Do not send outside local AS (well-known community)\n"
7714 "Do not advertise to any peer (well-known community)\n"
7715 "Do not export to next AS (well-known community)\n")
7716
7717ALIAS (show_ip_bgp_community,
7718 show_ip_bgp_community4_cmd,
7719 "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)",
7720 SHOW_STR
7721 IP_STR
7722 BGP_STR
7723 "Display routes matching the communities\n"
7724 "community number\n"
7725 "Do not send outside local AS (well-known community)\n"
7726 "Do not advertise to any peer (well-known community)\n"
7727 "Do not export to next AS (well-known community)\n"
7728 "community number\n"
7729 "Do not send outside local AS (well-known community)\n"
7730 "Do not advertise to any peer (well-known community)\n"
7731 "Do not export to next AS (well-known community)\n"
7732 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\n"
7736 "community number\n"
7737 "Do not send outside local AS (well-known community)\n"
7738 "Do not advertise to any peer (well-known community)\n"
7739 "Do not export to next AS (well-known community)\n")
7740
7741DEFUN (show_ip_bgp_ipv4_community,
7742 show_ip_bgp_ipv4_community_cmd,
7743 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7744 SHOW_STR
7745 IP_STR
7746 BGP_STR
7747 "Address family\n"
7748 "Address Family modifier\n"
7749 "Address Family modifier\n"
7750 "Display routes matching the communities\n"
7751 "community number\n"
7752 "Do not send outside local AS (well-known community)\n"
7753 "Do not advertise to any peer (well-known community)\n"
7754 "Do not export to next AS (well-known community)\n")
7755{
7756 if (strncmp (argv[0], "m", 1) == 0)
7757 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7758
7759 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7760}
7761
7762ALIAS (show_ip_bgp_ipv4_community,
7763 show_ip_bgp_ipv4_community2_cmd,
7764 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7765 SHOW_STR
7766 IP_STR
7767 BGP_STR
7768 "Address family\n"
7769 "Address Family modifier\n"
7770 "Address Family modifier\n"
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 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\n")
7780
7781ALIAS (show_ip_bgp_ipv4_community,
7782 show_ip_bgp_ipv4_community3_cmd,
7783 "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)",
7784 SHOW_STR
7785 IP_STR
7786 BGP_STR
7787 "Address family\n"
7788 "Address Family modifier\n"
7789 "Address Family modifier\n"
7790 "Display routes matching the communities\n"
7791 "community number\n"
7792 "Do not send outside local AS (well-known community)\n"
7793 "Do not advertise to any peer (well-known community)\n"
7794 "Do not export to next AS (well-known community)\n"
7795 "community number\n"
7796 "Do not send outside local AS (well-known community)\n"
7797 "Do not advertise to any peer (well-known community)\n"
7798 "Do not export to next AS (well-known community)\n"
7799 "community number\n"
7800 "Do not send outside local AS (well-known community)\n"
7801 "Do not advertise to any peer (well-known community)\n"
7802 "Do not export to next AS (well-known community)\n")
7803
7804ALIAS (show_ip_bgp_ipv4_community,
7805 show_ip_bgp_ipv4_community4_cmd,
7806 "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)",
7807 SHOW_STR
7808 IP_STR
7809 BGP_STR
7810 "Address family\n"
7811 "Address Family modifier\n"
7812 "Address Family modifier\n"
7813 "Display routes matching the communities\n"
7814 "community number\n"
7815 "Do not send outside local AS (well-known community)\n"
7816 "Do not advertise to any peer (well-known community)\n"
7817 "Do not export to next AS (well-known community)\n"
7818 "community number\n"
7819 "Do not send outside local AS (well-known community)\n"
7820 "Do not advertise to any peer (well-known community)\n"
7821 "Do not export to next AS (well-known community)\n"
7822 "community number\n"
7823 "Do not send outside local AS (well-known community)\n"
7824 "Do not advertise to any peer (well-known community)\n"
7825 "Do not export to next AS (well-known community)\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
7831DEFUN (show_ip_bgp_community_exact,
7832 show_ip_bgp_community_exact_cmd,
7833 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7834 SHOW_STR
7835 IP_STR
7836 BGP_STR
7837 "Display routes matching the communities\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{
7844 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7845}
7846
7847ALIAS (show_ip_bgp_community_exact,
7848 show_ip_bgp_community2_exact_cmd,
7849 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7850 SHOW_STR
7851 IP_STR
7852 BGP_STR
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 "community number\n"
7859 "Do not send outside local AS (well-known community)\n"
7860 "Do not advertise to any peer (well-known community)\n"
7861 "Do not export to next AS (well-known community)\n"
7862 "Exact match of the communities")
7863
7864ALIAS (show_ip_bgp_community_exact,
7865 show_ip_bgp_community3_exact_cmd,
7866 "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",
7867 SHOW_STR
7868 IP_STR
7869 BGP_STR
7870 "Display routes matching the communities\n"
7871 "community number\n"
7872 "Do not send outside local AS (well-known community)\n"
7873 "Do not advertise to any peer (well-known community)\n"
7874 "Do not export to next AS (well-known community)\n"
7875 "community number\n"
7876 "Do not send outside local AS (well-known community)\n"
7877 "Do not advertise to any peer (well-known community)\n"
7878 "Do not export to next AS (well-known community)\n"
7879 "community number\n"
7880 "Do not send outside local AS (well-known community)\n"
7881 "Do not advertise to any peer (well-known community)\n"
7882 "Do not export to next AS (well-known community)\n"
7883 "Exact match of the communities")
7884
7885ALIAS (show_ip_bgp_community_exact,
7886 show_ip_bgp_community4_exact_cmd,
7887 "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",
7888 SHOW_STR
7889 IP_STR
7890 BGP_STR
7891 "Display routes matching the communities\n"
7892 "community number\n"
7893 "Do not send outside local AS (well-known community)\n"
7894 "Do not advertise to any peer (well-known community)\n"
7895 "Do not export to next AS (well-known community)\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
7910DEFUN (show_ip_bgp_ipv4_community_exact,
7911 show_ip_bgp_ipv4_community_exact_cmd,
7912 "show ip bgp ipv4 (unicast|multicast) community (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 "Exact match of the communities")
7925{
7926 if (strncmp (argv[0], "m", 1) == 0)
7927 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7928
7929 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7930}
7931
7932ALIAS (show_ip_bgp_ipv4_community_exact,
7933 show_ip_bgp_ipv4_community2_exact_cmd,
7934 "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",
7935 SHOW_STR
7936 IP_STR
7937 BGP_STR
7938 "Address family\n"
7939 "Address Family modifier\n"
7940 "Address Family modifier\n"
7941 "Display routes matching the communities\n"
7942 "community number\n"
7943 "Do not send outside local AS (well-known community)\n"
7944 "Do not advertise to any peer (well-known community)\n"
7945 "Do not export to next AS (well-known community)\n"
7946 "community number\n"
7947 "Do not send outside local AS (well-known community)\n"
7948 "Do not advertise to any peer (well-known community)\n"
7949 "Do not export to next AS (well-known community)\n"
7950 "Exact match of the communities")
7951
7952ALIAS (show_ip_bgp_ipv4_community_exact,
7953 show_ip_bgp_ipv4_community3_exact_cmd,
7954 "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",
7955 SHOW_STR
7956 IP_STR
7957 BGP_STR
7958 "Address family\n"
7959 "Address Family modifier\n"
7960 "Address Family modifier\n"
7961 "Display routes matching the communities\n"
7962 "community number\n"
7963 "Do not send outside local AS (well-known community)\n"
7964 "Do not advertise to any peer (well-known community)\n"
7965 "Do not export to next AS (well-known community)\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n"
7970 "community number\n"
7971 "Do not send outside local AS (well-known community)\n"
7972 "Do not advertise to any peer (well-known community)\n"
7973 "Do not export to next AS (well-known community)\n"
7974 "Exact match of the communities")
7975
7976ALIAS (show_ip_bgp_ipv4_community_exact,
7977 show_ip_bgp_ipv4_community4_exact_cmd,
7978 "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",
7979 SHOW_STR
7980 IP_STR
7981 BGP_STR
7982 "Address family\n"
7983 "Address Family modifier\n"
7984 "Address Family modifier\n"
7985 "Display routes matching the communities\n"
7986 "community number\n"
7987 "Do not send outside local AS (well-known community)\n"
7988 "Do not advertise to any peer (well-known community)\n"
7989 "Do not export to next AS (well-known community)\n"
7990 "community number\n"
7991 "Do not send outside local AS (well-known community)\n"
7992 "Do not advertise to any peer (well-known community)\n"
7993 "Do not export to next AS (well-known community)\n"
7994 "community number\n"
7995 "Do not send outside local AS (well-known community)\n"
7996 "Do not advertise to any peer (well-known community)\n"
7997 "Do not export to next AS (well-known community)\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "Exact match of the communities")
8003
8004#ifdef HAVE_IPV6
8005DEFUN (show_bgp_community,
8006 show_bgp_community_cmd,
8007 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8008 SHOW_STR
8009 BGP_STR
8010 "Display routes matching the communities\n"
8011 "community number\n"
8012 "Do not send outside local AS (well-known community)\n"
8013 "Do not advertise to any peer (well-known community)\n"
8014 "Do not export to next AS (well-known community)\n")
8015{
8016 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8017}
8018
8019ALIAS (show_bgp_community,
8020 show_bgp_ipv6_community_cmd,
8021 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8022 SHOW_STR
8023 BGP_STR
8024 "Address family\n"
8025 "Display routes matching the communities\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
8031ALIAS (show_bgp_community,
8032 show_bgp_community2_cmd,
8033 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8034 SHOW_STR
8035 BGP_STR
8036 "Display routes matching the communities\n"
8037 "community number\n"
8038 "Do not send outside local AS (well-known community)\n"
8039 "Do not advertise to any peer (well-known community)\n"
8040 "Do not export to next AS (well-known community)\n"
8041 "community number\n"
8042 "Do not send outside local AS (well-known community)\n"
8043 "Do not advertise to any peer (well-known community)\n"
8044 "Do not export to next AS (well-known community)\n")
8045
8046ALIAS (show_bgp_community,
8047 show_bgp_ipv6_community2_cmd,
8048 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8049 SHOW_STR
8050 BGP_STR
8051 "Address family\n"
8052 "Display routes matching the communities\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 "community number\n"
8058 "Do not send outside local AS (well-known community)\n"
8059 "Do not advertise to any peer (well-known community)\n"
8060 "Do not export to next AS (well-known community)\n")
8061
8062ALIAS (show_bgp_community,
8063 show_bgp_community3_cmd,
8064 "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)",
8065 SHOW_STR
8066 BGP_STR
8067 "Display routes matching the communities\n"
8068 "community number\n"
8069 "Do not send outside local AS (well-known community)\n"
8070 "Do not advertise to any peer (well-known community)\n"
8071 "Do not export to next AS (well-known community)\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n")
8080
8081ALIAS (show_bgp_community,
8082 show_bgp_ipv6_community3_cmd,
8083 "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)",
8084 SHOW_STR
8085 BGP_STR
8086 "Address family\n"
8087 "Display routes matching the communities\n"
8088 "community number\n"
8089 "Do not send outside local AS (well-known community)\n"
8090 "Do not advertise to any peer (well-known community)\n"
8091 "Do not export to next AS (well-known community)\n"
8092 "community number\n"
8093 "Do not send outside local AS (well-known community)\n"
8094 "Do not advertise to any peer (well-known community)\n"
8095 "Do not export to next AS (well-known community)\n"
8096 "community number\n"
8097 "Do not send outside local AS (well-known community)\n"
8098 "Do not advertise to any peer (well-known community)\n"
8099 "Do not export to next AS (well-known community)\n")
8100
8101ALIAS (show_bgp_community,
8102 show_bgp_community4_cmd,
8103 "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)",
8104 SHOW_STR
8105 BGP_STR
8106 "Display routes matching the communities\n"
8107 "community number\n"
8108 "Do not send outside local AS (well-known community)\n"
8109 "Do not advertise to any peer (well-known community)\n"
8110 "Do not export to next AS (well-known community)\n"
8111 "community number\n"
8112 "Do not send outside local AS (well-known community)\n"
8113 "Do not advertise to any peer (well-known community)\n"
8114 "Do not export to next AS (well-known community)\n"
8115 "community number\n"
8116 "Do not send outside local AS (well-known community)\n"
8117 "Do not advertise to any peer (well-known community)\n"
8118 "Do not export to next AS (well-known community)\n"
8119 "community number\n"
8120 "Do not send outside local AS (well-known community)\n"
8121 "Do not advertise to any peer (well-known community)\n"
8122 "Do not export to next AS (well-known community)\n")
8123
8124ALIAS (show_bgp_community,
8125 show_bgp_ipv6_community4_cmd,
8126 "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)",
8127 SHOW_STR
8128 BGP_STR
8129 "Address family\n"
8130 "Display routes matching the communities\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 "community number\n"
8136 "Do not send outside local AS (well-known community)\n"
8137 "Do not advertise to any peer (well-known community)\n"
8138 "Do not export to next AS (well-known community)\n"
8139 "community number\n"
8140 "Do not send outside local AS (well-known community)\n"
8141 "Do not advertise to any peer (well-known community)\n"
8142 "Do not export to next AS (well-known community)\n"
8143 "community number\n"
8144 "Do not send outside local AS (well-known community)\n"
8145 "Do not advertise to any peer (well-known community)\n"
8146 "Do not export to next AS (well-known community)\n")
8147
8148/* old command */
8149DEFUN (show_ipv6_bgp_community,
8150 show_ipv6_bgp_community_cmd,
8151 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8152 SHOW_STR
8153 IPV6_STR
8154 BGP_STR
8155 "Display routes matching the communities\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{
8161 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8162}
8163
8164/* old command */
8165ALIAS (show_ipv6_bgp_community,
8166 show_ipv6_bgp_community2_cmd,
8167 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8168 SHOW_STR
8169 IPV6_STR
8170 BGP_STR
8171 "Display routes matching the communities\n"
8172 "community number\n"
8173 "Do not send outside local AS (well-known community)\n"
8174 "Do not advertise to any peer (well-known community)\n"
8175 "Do not export to next AS (well-known community)\n"
8176 "community number\n"
8177 "Do not send outside local AS (well-known community)\n"
8178 "Do not advertise to any peer (well-known community)\n"
8179 "Do not export to next AS (well-known community)\n")
8180
8181/* old command */
8182ALIAS (show_ipv6_bgp_community,
8183 show_ipv6_bgp_community3_cmd,
8184 "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)",
8185 SHOW_STR
8186 IPV6_STR
8187 BGP_STR
8188 "Display routes matching the communities\n"
8189 "community number\n"
8190 "Do not send outside local AS (well-known community)\n"
8191 "Do not advertise to any peer (well-known community)\n"
8192 "Do not export to next AS (well-known community)\n"
8193 "community number\n"
8194 "Do not send outside local AS (well-known community)\n"
8195 "Do not advertise to any peer (well-known community)\n"
8196 "Do not export to next AS (well-known community)\n"
8197 "community number\n"
8198 "Do not send outside local AS (well-known community)\n"
8199 "Do not advertise to any peer (well-known community)\n"
8200 "Do not export to next AS (well-known community)\n")
8201
8202/* old command */
8203ALIAS (show_ipv6_bgp_community,
8204 show_ipv6_bgp_community4_cmd,
8205 "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)",
8206 SHOW_STR
8207 IPV6_STR
8208 BGP_STR
8209 "Display routes matching the communities\n"
8210 "community number\n"
8211 "Do not send outside local AS (well-known community)\n"
8212 "Do not advertise to any peer (well-known community)\n"
8213 "Do not export to next AS (well-known community)\n"
8214 "community number\n"
8215 "Do not send outside local AS (well-known community)\n"
8216 "Do not advertise to any peer (well-known community)\n"
8217 "Do not export to next AS (well-known community)\n"
8218 "community number\n"
8219 "Do not send outside local AS (well-known community)\n"
8220 "Do not advertise to any peer (well-known community)\n"
8221 "Do not export to next AS (well-known community)\n"
8222 "community number\n"
8223 "Do not send outside local AS (well-known community)\n"
8224 "Do not advertise to any peer (well-known community)\n"
8225 "Do not export to next AS (well-known community)\n")
8226
8227DEFUN (show_bgp_community_exact,
8228 show_bgp_community_exact_cmd,
8229 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8230 SHOW_STR
8231 BGP_STR
8232 "Display routes matching the communities\n"
8233 "community number\n"
8234 "Do not send outside local AS (well-known community)\n"
8235 "Do not advertise to any peer (well-known community)\n"
8236 "Do not export to next AS (well-known community)\n"
8237 "Exact match of the communities")
8238{
8239 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8240}
8241
8242ALIAS (show_bgp_community_exact,
8243 show_bgp_ipv6_community_exact_cmd,
8244 "show bgp ipv6 community (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 "Exact match of the communities")
8254
8255ALIAS (show_bgp_community_exact,
8256 show_bgp_community2_exact_cmd,
8257 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8258 SHOW_STR
8259 BGP_STR
8260 "Display routes matching the communities\n"
8261 "community number\n"
8262 "Do not send outside local AS (well-known community)\n"
8263 "Do not advertise to any peer (well-known community)\n"
8264 "Do not export to next AS (well-known community)\n"
8265 "community number\n"
8266 "Do not send outside local AS (well-known community)\n"
8267 "Do not advertise to any peer (well-known community)\n"
8268 "Do not export to next AS (well-known community)\n"
8269 "Exact match of the communities")
8270
8271ALIAS (show_bgp_community_exact,
8272 show_bgp_ipv6_community2_exact_cmd,
8273 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8274 SHOW_STR
8275 BGP_STR
8276 "Address family\n"
8277 "Display routes matching the communities\n"
8278 "community number\n"
8279 "Do not send outside local AS (well-known community)\n"
8280 "Do not advertise to any peer (well-known community)\n"
8281 "Do not export to next AS (well-known community)\n"
8282 "community number\n"
8283 "Do not send outside local AS (well-known community)\n"
8284 "Do not advertise to any peer (well-known community)\n"
8285 "Do not export to next AS (well-known community)\n"
8286 "Exact match of the communities")
8287
8288ALIAS (show_bgp_community_exact,
8289 show_bgp_community3_exact_cmd,
8290 "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",
8291 SHOW_STR
8292 BGP_STR
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 "Exact match of the communities")
8307
8308ALIAS (show_bgp_community_exact,
8309 show_bgp_ipv6_community3_exact_cmd,
8310 "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",
8311 SHOW_STR
8312 BGP_STR
8313 "Address family\n"
8314 "Display routes matching the communities\n"
8315 "community number\n"
8316 "Do not send outside local AS (well-known community)\n"
8317 "Do not advertise to any peer (well-known community)\n"
8318 "Do not export to next AS (well-known community)\n"
8319 "community number\n"
8320 "Do not send outside local AS (well-known community)\n"
8321 "Do not advertise to any peer (well-known community)\n"
8322 "Do not export to next AS (well-known community)\n"
8323 "community number\n"
8324 "Do not send outside local AS (well-known community)\n"
8325 "Do not advertise to any peer (well-known community)\n"
8326 "Do not export to next AS (well-known community)\n"
8327 "Exact match of the communities")
8328
8329ALIAS (show_bgp_community_exact,
8330 show_bgp_community4_exact_cmd,
8331 "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",
8332 SHOW_STR
8333 BGP_STR
8334 "Display routes matching the communities\n"
8335 "community number\n"
8336 "Do not send outside local AS (well-known community)\n"
8337 "Do not advertise to any peer (well-known community)\n"
8338 "Do not export to next AS (well-known community)\n"
8339 "community number\n"
8340 "Do not send outside local AS (well-known community)\n"
8341 "Do not advertise to any peer (well-known community)\n"
8342 "Do not export to next AS (well-known community)\n"
8343 "community number\n"
8344 "Do not send outside local AS (well-known community)\n"
8345 "Do not advertise to any peer (well-known community)\n"
8346 "Do not export to next AS (well-known community)\n"
8347 "community number\n"
8348 "Do not send outside local AS (well-known community)\n"
8349 "Do not advertise to any peer (well-known community)\n"
8350 "Do not export to next AS (well-known community)\n"
8351 "Exact match of the communities")
8352
8353ALIAS (show_bgp_community_exact,
8354 show_bgp_ipv6_community4_exact_cmd,
8355 "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",
8356 SHOW_STR
8357 BGP_STR
8358 "Address family\n"
8359 "Display routes matching the communities\n"
8360 "community number\n"
8361 "Do not send outside local AS (well-known community)\n"
8362 "Do not advertise to any peer (well-known community)\n"
8363 "Do not export to next AS (well-known community)\n"
8364 "community number\n"
8365 "Do not send outside local AS (well-known community)\n"
8366 "Do not advertise to any peer (well-known community)\n"
8367 "Do not export to next AS (well-known community)\n"
8368 "community number\n"
8369 "Do not send outside local AS (well-known community)\n"
8370 "Do not advertise to any peer (well-known community)\n"
8371 "Do not export to next AS (well-known community)\n"
8372 "community number\n"
8373 "Do not send outside local AS (well-known community)\n"
8374 "Do not advertise to any peer (well-known community)\n"
8375 "Do not export to next AS (well-known community)\n"
8376 "Exact match of the communities")
8377
8378/* old command */
8379DEFUN (show_ipv6_bgp_community_exact,
8380 show_ipv6_bgp_community_exact_cmd,
8381 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8382 SHOW_STR
8383 IPV6_STR
8384 BGP_STR
8385 "Display routes matching the communities\n"
8386 "community number\n"
8387 "Do not send outside local AS (well-known community)\n"
8388 "Do not advertise to any peer (well-known community)\n"
8389 "Do not export to next AS (well-known community)\n"
8390 "Exact match of the communities")
8391{
8392 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8393}
8394
8395/* old command */
8396ALIAS (show_ipv6_bgp_community_exact,
8397 show_ipv6_bgp_community2_exact_cmd,
8398 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8399 SHOW_STR
8400 IPV6_STR
8401 BGP_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 "community number\n"
8408 "Do not send outside local AS (well-known community)\n"
8409 "Do not advertise to any peer (well-known community)\n"
8410 "Do not export to next AS (well-known community)\n"
8411 "Exact match of the communities")
8412
8413/* old command */
8414ALIAS (show_ipv6_bgp_community_exact,
8415 show_ipv6_bgp_community3_exact_cmd,
8416 "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",
8417 SHOW_STR
8418 IPV6_STR
8419 BGP_STR
8420 "Display routes matching the communities\n"
8421 "community number\n"
8422 "Do not send outside local AS (well-known community)\n"
8423 "Do not advertise to any peer (well-known community)\n"
8424 "Do not export to next AS (well-known community)\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n"
8433 "Exact match of the communities")
8434
8435/* old command */
8436ALIAS (show_ipv6_bgp_community_exact,
8437 show_ipv6_bgp_community4_exact_cmd,
8438 "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",
8439 SHOW_STR
8440 IPV6_STR
8441 BGP_STR
8442 "Display routes matching the communities\n"
8443 "community number\n"
8444 "Do not send outside local AS (well-known community)\n"
8445 "Do not advertise to any peer (well-known community)\n"
8446 "Do not export to next AS (well-known community)\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n"
8455 "community number\n"
8456 "Do not send outside local AS (well-known community)\n"
8457 "Do not advertise to any peer (well-known community)\n"
8458 "Do not export to next AS (well-known community)\n"
8459 "Exact match of the communities")
8460
8461/* old command */
8462DEFUN (show_ipv6_mbgp_community,
8463 show_ipv6_mbgp_community_cmd,
8464 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8465 SHOW_STR
8466 IPV6_STR
8467 MBGP_STR
8468 "Display routes matching the communities\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 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8475}
8476
8477/* old command */
8478ALIAS (show_ipv6_mbgp_community,
8479 show_ipv6_mbgp_community2_cmd,
8480 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8481 SHOW_STR
8482 IPV6_STR
8483 MBGP_STR
8484 "Display routes matching the communities\n"
8485 "community number\n"
8486 "Do not send outside local AS (well-known community)\n"
8487 "Do not advertise to any peer (well-known community)\n"
8488 "Do not export to next AS (well-known community)\n"
8489 "community number\n"
8490 "Do not send outside local AS (well-known community)\n"
8491 "Do not advertise to any peer (well-known community)\n"
8492 "Do not export to next AS (well-known community)\n")
8493
8494/* old command */
8495ALIAS (show_ipv6_mbgp_community,
8496 show_ipv6_mbgp_community3_cmd,
8497 "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)",
8498 SHOW_STR
8499 IPV6_STR
8500 MBGP_STR
8501 "Display routes matching the communities\n"
8502 "community number\n"
8503 "Do not send outside local AS (well-known community)\n"
8504 "Do not advertise to any peer (well-known community)\n"
8505 "Do not export to next AS (well-known community)\n"
8506 "community number\n"
8507 "Do not send outside local AS (well-known community)\n"
8508 "Do not advertise to any peer (well-known community)\n"
8509 "Do not export to next AS (well-known community)\n"
8510 "community number\n"
8511 "Do not send outside local AS (well-known community)\n"
8512 "Do not advertise to any peer (well-known community)\n"
8513 "Do not export to next AS (well-known community)\n")
8514
8515/* old command */
8516ALIAS (show_ipv6_mbgp_community,
8517 show_ipv6_mbgp_community4_cmd,
8518 "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)",
8519 SHOW_STR
8520 IPV6_STR
8521 MBGP_STR
8522 "Display routes matching the communities\n"
8523 "community number\n"
8524 "Do not send outside local AS (well-known community)\n"
8525 "Do not advertise to any peer (well-known community)\n"
8526 "Do not export to next AS (well-known community)\n"
8527 "community number\n"
8528 "Do not send outside local AS (well-known community)\n"
8529 "Do not advertise to any peer (well-known community)\n"
8530 "Do not export to next AS (well-known community)\n"
8531 "community number\n"
8532 "Do not send outside local AS (well-known community)\n"
8533 "Do not advertise to any peer (well-known community)\n"
8534 "Do not export to next AS (well-known community)\n"
8535 "community number\n"
8536 "Do not send outside local AS (well-known community)\n"
8537 "Do not advertise to any peer (well-known community)\n"
8538 "Do not export to next AS (well-known community)\n")
8539
8540/* old command */
8541DEFUN (show_ipv6_mbgp_community_exact,
8542 show_ipv6_mbgp_community_exact_cmd,
8543 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8544 SHOW_STR
8545 IPV6_STR
8546 MBGP_STR
8547 "Display routes matching the communities\n"
8548 "community number\n"
8549 "Do not send outside local AS (well-known community)\n"
8550 "Do not advertise to any peer (well-known community)\n"
8551 "Do not export to next AS (well-known community)\n"
8552 "Exact match of the communities")
8553{
8554 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8555}
8556
8557/* old command */
8558ALIAS (show_ipv6_mbgp_community_exact,
8559 show_ipv6_mbgp_community2_exact_cmd,
8560 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8561 SHOW_STR
8562 IPV6_STR
8563 MBGP_STR
8564 "Display routes matching the communities\n"
8565 "community number\n"
8566 "Do not send outside local AS (well-known community)\n"
8567 "Do not advertise to any peer (well-known community)\n"
8568 "Do not export to next AS (well-known community)\n"
8569 "community number\n"
8570 "Do not send outside local AS (well-known community)\n"
8571 "Do not advertise to any peer (well-known community)\n"
8572 "Do not export to next AS (well-known community)\n"
8573 "Exact match of the communities")
8574
8575/* old command */
8576ALIAS (show_ipv6_mbgp_community_exact,
8577 show_ipv6_mbgp_community3_exact_cmd,
8578 "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",
8579 SHOW_STR
8580 IPV6_STR
8581 MBGP_STR
8582 "Display routes matching the communities\n"
8583 "community number\n"
8584 "Do not send outside local AS (well-known community)\n"
8585 "Do not advertise to any peer (well-known community)\n"
8586 "Do not export to next AS (well-known community)\n"
8587 "community number\n"
8588 "Do not send outside local AS (well-known community)\n"
8589 "Do not advertise to any peer (well-known community)\n"
8590 "Do not export to next AS (well-known community)\n"
8591 "community number\n"
8592 "Do not send outside local AS (well-known community)\n"
8593 "Do not advertise to any peer (well-known community)\n"
8594 "Do not export to next AS (well-known community)\n"
8595 "Exact match of the communities")
8596
8597/* old command */
8598ALIAS (show_ipv6_mbgp_community_exact,
8599 show_ipv6_mbgp_community4_exact_cmd,
8600 "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",
8601 SHOW_STR
8602 IPV6_STR
8603 MBGP_STR
8604 "Display routes matching the communities\n"
8605 "community number\n"
8606 "Do not send outside local AS (well-known community)\n"
8607 "Do not advertise to any peer (well-known community)\n"
8608 "Do not export to next AS (well-known community)\n"
8609 "community number\n"
8610 "Do not send outside local AS (well-known community)\n"
8611 "Do not advertise to any peer (well-known community)\n"
8612 "Do not export to next AS (well-known community)\n"
8613 "community number\n"
8614 "Do not send outside local AS (well-known community)\n"
8615 "Do not advertise to any peer (well-known community)\n"
8616 "Do not export to next AS (well-known community)\n"
8617 "community number\n"
8618 "Do not send outside local AS (well-known community)\n"
8619 "Do not advertise to any peer (well-known community)\n"
8620 "Do not export to next AS (well-known community)\n"
8621 "Exact match of the communities")
8622#endif /* HAVE_IPV6 */
8623
paul94f2b392005-06-28 12:44:16 +00008624static int
paulfd79ac92004-10-13 05:06:08 +00008625bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008626 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008627{
8628 struct community_list *list;
8629
hassofee6e4e2005-02-02 16:29:31 +00008630 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008631 if (list == NULL)
8632 {
8633 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8634 VTY_NEWLINE);
8635 return CMD_WARNING;
8636 }
8637
ajs5a646652004-11-05 01:25:55 +00008638 return bgp_show (vty, NULL, afi, safi,
8639 (exact ? bgp_show_type_community_list_exact :
8640 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008641}
8642
8643DEFUN (show_ip_bgp_community_list,
8644 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008645 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008646 SHOW_STR
8647 IP_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_IP, SAFI_UNICAST);
8654}
8655
8656DEFUN (show_ip_bgp_ipv4_community_list,
8657 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008658 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008659 SHOW_STR
8660 IP_STR
8661 BGP_STR
8662 "Address family\n"
8663 "Address Family modifier\n"
8664 "Address Family modifier\n"
8665 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008666 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008667 "community-list name\n")
8668{
8669 if (strncmp (argv[0], "m", 1) == 0)
8670 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8671
8672 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8673}
8674
8675DEFUN (show_ip_bgp_community_list_exact,
8676 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008677 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008678 SHOW_STR
8679 IP_STR
8680 BGP_STR
8681 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008682 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008683 "community-list name\n"
8684 "Exact match of the communities\n")
8685{
8686 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8687}
8688
8689DEFUN (show_ip_bgp_ipv4_community_list_exact,
8690 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008691 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008692 SHOW_STR
8693 IP_STR
8694 BGP_STR
8695 "Address family\n"
8696 "Address Family modifier\n"
8697 "Address Family modifier\n"
8698 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008699 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008700 "community-list name\n"
8701 "Exact match of the communities\n")
8702{
8703 if (strncmp (argv[0], "m", 1) == 0)
8704 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8705
8706 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8707}
8708
8709#ifdef HAVE_IPV6
8710DEFUN (show_bgp_community_list,
8711 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008712 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008713 SHOW_STR
8714 BGP_STR
8715 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008716 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008717 "community-list name\n")
8718{
8719 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8720}
8721
8722ALIAS (show_bgp_community_list,
8723 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008724 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008725 SHOW_STR
8726 BGP_STR
8727 "Address family\n"
8728 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008729 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008730 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008731
8732/* old command */
8733DEFUN (show_ipv6_bgp_community_list,
8734 show_ipv6_bgp_community_list_cmd,
8735 "show ipv6 bgp community-list WORD",
8736 SHOW_STR
8737 IPV6_STR
8738 BGP_STR
8739 "Display routes matching the community-list\n"
8740 "community-list name\n")
8741{
8742 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8743}
8744
8745/* old command */
8746DEFUN (show_ipv6_mbgp_community_list,
8747 show_ipv6_mbgp_community_list_cmd,
8748 "show ipv6 mbgp community-list WORD",
8749 SHOW_STR
8750 IPV6_STR
8751 MBGP_STR
8752 "Display routes matching the community-list\n"
8753 "community-list name\n")
8754{
8755 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8756}
8757
8758DEFUN (show_bgp_community_list_exact,
8759 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008760 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008761 SHOW_STR
8762 BGP_STR
8763 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008764 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008765 "community-list name\n"
8766 "Exact match of the communities\n")
8767{
8768 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8769}
8770
8771ALIAS (show_bgp_community_list_exact,
8772 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008773 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008774 SHOW_STR
8775 BGP_STR
8776 "Address family\n"
8777 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008778 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008779 "community-list name\n"
8780 "Exact match of the communities\n")
8781
8782/* old command */
8783DEFUN (show_ipv6_bgp_community_list_exact,
8784 show_ipv6_bgp_community_list_exact_cmd,
8785 "show ipv6 bgp community-list WORD exact-match",
8786 SHOW_STR
8787 IPV6_STR
8788 BGP_STR
8789 "Display routes matching the community-list\n"
8790 "community-list name\n"
8791 "Exact match of the communities\n")
8792{
8793 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8794}
8795
8796/* old command */
8797DEFUN (show_ipv6_mbgp_community_list_exact,
8798 show_ipv6_mbgp_community_list_exact_cmd,
8799 "show ipv6 mbgp community-list WORD exact-match",
8800 SHOW_STR
8801 IPV6_STR
8802 MBGP_STR
8803 "Display routes matching the community-list\n"
8804 "community-list name\n"
8805 "Exact match of the communities\n")
8806{
8807 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8808}
8809#endif /* HAVE_IPV6 */
8810
paul94f2b392005-06-28 12:44:16 +00008811static int
paulfd79ac92004-10-13 05:06:08 +00008812bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008813 safi_t safi, enum bgp_show_type type)
8814{
8815 int ret;
8816 struct prefix *p;
8817
8818 p = prefix_new();
8819
8820 ret = str2prefix (prefix, p);
8821 if (! ret)
8822 {
8823 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8824 return CMD_WARNING;
8825 }
8826
ajs5a646652004-11-05 01:25:55 +00008827 ret = bgp_show (vty, NULL, afi, safi, type, p);
8828 prefix_free(p);
8829 return ret;
paul718e3742002-12-13 20:15:29 +00008830}
8831
8832DEFUN (show_ip_bgp_prefix_longer,
8833 show_ip_bgp_prefix_longer_cmd,
8834 "show ip bgp A.B.C.D/M longer-prefixes",
8835 SHOW_STR
8836 IP_STR
8837 BGP_STR
8838 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8839 "Display route and more specific routes\n")
8840{
8841 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8842 bgp_show_type_prefix_longer);
8843}
8844
8845DEFUN (show_ip_bgp_flap_prefix_longer,
8846 show_ip_bgp_flap_prefix_longer_cmd,
8847 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8848 SHOW_STR
8849 IP_STR
8850 BGP_STR
8851 "Display flap statistics of routes\n"
8852 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8853 "Display route and more specific routes\n")
8854{
8855 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8856 bgp_show_type_flap_prefix_longer);
8857}
8858
8859DEFUN (show_ip_bgp_ipv4_prefix_longer,
8860 show_ip_bgp_ipv4_prefix_longer_cmd,
8861 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8862 SHOW_STR
8863 IP_STR
8864 BGP_STR
8865 "Address family\n"
8866 "Address Family modifier\n"
8867 "Address Family modifier\n"
8868 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8869 "Display route and more specific routes\n")
8870{
8871 if (strncmp (argv[0], "m", 1) == 0)
8872 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8873 bgp_show_type_prefix_longer);
8874
8875 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8876 bgp_show_type_prefix_longer);
8877}
8878
8879DEFUN (show_ip_bgp_flap_address,
8880 show_ip_bgp_flap_address_cmd,
8881 "show ip bgp flap-statistics A.B.C.D",
8882 SHOW_STR
8883 IP_STR
8884 BGP_STR
8885 "Display flap statistics of routes\n"
8886 "Network in the BGP routing table to display\n")
8887{
8888 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8889 bgp_show_type_flap_address);
8890}
8891
8892DEFUN (show_ip_bgp_flap_prefix,
8893 show_ip_bgp_flap_prefix_cmd,
8894 "show ip bgp flap-statistics A.B.C.D/M",
8895 SHOW_STR
8896 IP_STR
8897 BGP_STR
8898 "Display flap statistics of routes\n"
8899 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8900{
8901 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8902 bgp_show_type_flap_prefix);
8903}
8904#ifdef HAVE_IPV6
8905DEFUN (show_bgp_prefix_longer,
8906 show_bgp_prefix_longer_cmd,
8907 "show bgp X:X::X:X/M longer-prefixes",
8908 SHOW_STR
8909 BGP_STR
8910 "IPv6 prefix <network>/<length>\n"
8911 "Display route and more specific routes\n")
8912{
8913 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8914 bgp_show_type_prefix_longer);
8915}
8916
8917ALIAS (show_bgp_prefix_longer,
8918 show_bgp_ipv6_prefix_longer_cmd,
8919 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8920 SHOW_STR
8921 BGP_STR
8922 "Address family\n"
8923 "IPv6 prefix <network>/<length>\n"
8924 "Display route and more specific routes\n")
8925
8926/* old command */
8927DEFUN (show_ipv6_bgp_prefix_longer,
8928 show_ipv6_bgp_prefix_longer_cmd,
8929 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8930 SHOW_STR
8931 IPV6_STR
8932 BGP_STR
8933 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8934 "Display route and more specific routes\n")
8935{
8936 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8937 bgp_show_type_prefix_longer);
8938}
8939
8940/* old command */
8941DEFUN (show_ipv6_mbgp_prefix_longer,
8942 show_ipv6_mbgp_prefix_longer_cmd,
8943 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8944 SHOW_STR
8945 IPV6_STR
8946 MBGP_STR
8947 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8948 "Display route and more specific routes\n")
8949{
8950 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8951 bgp_show_type_prefix_longer);
8952}
8953#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008954
paul94f2b392005-06-28 12:44:16 +00008955static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008956peer_lookup_in_view (struct vty *vty, const char *view_name,
8957 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008958{
8959 int ret;
8960 struct bgp *bgp;
8961 struct peer *peer;
8962 union sockunion su;
8963
8964 /* BGP structure lookup. */
8965 if (view_name)
8966 {
8967 bgp = bgp_lookup_by_name (view_name);
8968 if (! bgp)
8969 {
8970 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8971 return NULL;
8972 }
8973 }
paul5228ad22004-06-04 17:58:18 +00008974 else
paulbb46e942003-10-24 19:02:03 +00008975 {
8976 bgp = bgp_get_default ();
8977 if (! bgp)
8978 {
8979 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8980 return NULL;
8981 }
8982 }
8983
8984 /* Get peer sockunion. */
8985 ret = str2sockunion (ip_str, &su);
8986 if (ret < 0)
8987 {
8988 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8989 return NULL;
8990 }
8991
8992 /* Peer structure lookup. */
8993 peer = peer_lookup (bgp, &su);
8994 if (! peer)
8995 {
8996 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8997 return NULL;
8998 }
8999
9000 return peer;
9001}
Paul Jakma2815e612006-09-14 02:56:07 +00009002
9003enum bgp_stats
9004{
9005 BGP_STATS_MAXBITLEN = 0,
9006 BGP_STATS_RIB,
9007 BGP_STATS_PREFIXES,
9008 BGP_STATS_TOTPLEN,
9009 BGP_STATS_UNAGGREGATEABLE,
9010 BGP_STATS_MAX_AGGREGATEABLE,
9011 BGP_STATS_AGGREGATES,
9012 BGP_STATS_SPACE,
9013 BGP_STATS_ASPATH_COUNT,
9014 BGP_STATS_ASPATH_MAXHOPS,
9015 BGP_STATS_ASPATH_TOTHOPS,
9016 BGP_STATS_ASPATH_MAXSIZE,
9017 BGP_STATS_ASPATH_TOTSIZE,
9018 BGP_STATS_ASN_HIGHEST,
9019 BGP_STATS_MAX,
9020};
paulbb46e942003-10-24 19:02:03 +00009021
Paul Jakma2815e612006-09-14 02:56:07 +00009022static const char *table_stats_strs[] =
9023{
9024 [BGP_STATS_PREFIXES] = "Total Prefixes",
9025 [BGP_STATS_TOTPLEN] = "Average prefix length",
9026 [BGP_STATS_RIB] = "Total Advertisements",
9027 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9028 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9029 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9030 [BGP_STATS_SPACE] = "Address space advertised",
9031 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9032 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9033 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9034 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9035 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9036 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9037 [BGP_STATS_MAX] = NULL,
9038};
9039
9040struct bgp_table_stats
9041{
9042 struct bgp_table *table;
9043 unsigned long long counts[BGP_STATS_MAX];
9044};
9045
9046#if 0
9047#define TALLY_SIGFIG 100000
9048static unsigned long
9049ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9050{
9051 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9052 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9053 unsigned long ret = newtot / count;
9054
9055 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9056 return ret + 1;
9057 else
9058 return ret;
9059}
9060#endif
9061
9062static int
9063bgp_table_stats_walker (struct thread *t)
9064{
9065 struct bgp_node *rn;
9066 struct bgp_node *top;
9067 struct bgp_table_stats *ts = THREAD_ARG (t);
9068 unsigned int space = 0;
9069
Paul Jakma53d9f672006-10-15 23:41:16 +00009070 if (!(top = bgp_table_top (ts->table)))
9071 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009072
9073 switch (top->p.family)
9074 {
9075 case AF_INET:
9076 space = IPV4_MAX_BITLEN;
9077 break;
9078 case AF_INET6:
9079 space = IPV6_MAX_BITLEN;
9080 break;
9081 }
9082
9083 ts->counts[BGP_STATS_MAXBITLEN] = space;
9084
9085 for (rn = top; rn; rn = bgp_route_next (rn))
9086 {
9087 struct bgp_info *ri;
9088 struct bgp_node *prn = rn->parent;
9089 unsigned int rinum = 0;
9090
9091 if (rn == top)
9092 continue;
9093
9094 if (!rn->info)
9095 continue;
9096
9097 ts->counts[BGP_STATS_PREFIXES]++;
9098 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9099
9100#if 0
9101 ts->counts[BGP_STATS_AVGPLEN]
9102 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9103 ts->counts[BGP_STATS_AVGPLEN],
9104 rn->p.prefixlen);
9105#endif
9106
9107 /* check if the prefix is included by any other announcements */
9108 while (prn && !prn->info)
9109 prn = prn->parent;
9110
9111 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009112 {
9113 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9114 /* announced address space */
9115 if (space)
9116 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9117 }
Paul Jakma2815e612006-09-14 02:56:07 +00009118 else if (prn->info)
9119 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9120
Paul Jakma2815e612006-09-14 02:56:07 +00009121 for (ri = rn->info; ri; ri = ri->next)
9122 {
9123 rinum++;
9124 ts->counts[BGP_STATS_RIB]++;
9125
9126 if (ri->attr &&
9127 (CHECK_FLAG (ri->attr->flag,
9128 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9129 ts->counts[BGP_STATS_AGGREGATES]++;
9130
9131 /* as-path stats */
9132 if (ri->attr && ri->attr->aspath)
9133 {
9134 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9135 unsigned int size = aspath_size (ri->attr->aspath);
9136 as_t highest = aspath_highest (ri->attr->aspath);
9137
9138 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9139
9140 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9141 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9142
9143 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9144 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9145
9146 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9147 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9148#if 0
9149 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9150 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9151 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9152 hops);
9153 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9154 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9155 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9156 size);
9157#endif
9158 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9159 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9160 }
9161 }
9162 }
9163 return 0;
9164}
9165
9166static int
9167bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9168{
9169 struct bgp_table_stats ts;
9170 unsigned int i;
9171
9172 if (!bgp->rib[afi][safi])
9173 {
9174 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9175 return CMD_WARNING;
9176 }
9177
9178 memset (&ts, 0, sizeof (ts));
9179 ts.table = bgp->rib[afi][safi];
9180 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9181
9182 vty_out (vty, "BGP %s RIB statistics%s%s",
9183 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9184
9185 for (i = 0; i < BGP_STATS_MAX; i++)
9186 {
9187 if (!table_stats_strs[i])
9188 continue;
9189
9190 switch (i)
9191 {
9192#if 0
9193 case BGP_STATS_ASPATH_AVGHOPS:
9194 case BGP_STATS_ASPATH_AVGSIZE:
9195 case BGP_STATS_AVGPLEN:
9196 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9197 vty_out (vty, "%12.2f",
9198 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9199 break;
9200#endif
9201 case BGP_STATS_ASPATH_TOTHOPS:
9202 case BGP_STATS_ASPATH_TOTSIZE:
9203 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9204 vty_out (vty, "%12.2f",
9205 ts.counts[i] ?
9206 (float)ts.counts[i] /
9207 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9208 : 0);
9209 break;
9210 case BGP_STATS_TOTPLEN:
9211 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9212 vty_out (vty, "%12.2f",
9213 ts.counts[i] ?
9214 (float)ts.counts[i] /
9215 (float)ts.counts[BGP_STATS_PREFIXES]
9216 : 0);
9217 break;
9218 case BGP_STATS_SPACE:
9219 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9220 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9221 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9222 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009223 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009224 vty_out (vty, "%12.2f%s",
9225 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009226 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009227 VTY_NEWLINE);
9228 vty_out (vty, "%30s: ", "/8 equivalent ");
9229 vty_out (vty, "%12.2f%s",
9230 (float)ts.counts[BGP_STATS_SPACE] /
9231 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9232 VTY_NEWLINE);
9233 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9234 break;
9235 vty_out (vty, "%30s: ", "/24 equivalent ");
9236 vty_out (vty, "%12.2f",
9237 (float)ts.counts[BGP_STATS_SPACE] /
9238 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9239 break;
9240 default:
9241 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9242 vty_out (vty, "%12llu", ts.counts[i]);
9243 }
9244
9245 vty_out (vty, "%s", VTY_NEWLINE);
9246 }
9247 return CMD_SUCCESS;
9248}
9249
9250static int
9251bgp_table_stats_vty (struct vty *vty, const char *name,
9252 const char *afi_str, const char *safi_str)
9253{
9254 struct bgp *bgp;
9255 afi_t afi;
9256 safi_t safi;
9257
9258 if (name)
9259 bgp = bgp_lookup_by_name (name);
9260 else
9261 bgp = bgp_get_default ();
9262
9263 if (!bgp)
9264 {
9265 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9266 return CMD_WARNING;
9267 }
9268 if (strncmp (afi_str, "ipv", 3) == 0)
9269 {
9270 if (strncmp (afi_str, "ipv4", 4) == 0)
9271 afi = AFI_IP;
9272 else if (strncmp (afi_str, "ipv6", 4) == 0)
9273 afi = AFI_IP6;
9274 else
9275 {
9276 vty_out (vty, "%% Invalid address family %s%s",
9277 afi_str, VTY_NEWLINE);
9278 return CMD_WARNING;
9279 }
9280 if (strncmp (safi_str, "m", 1) == 0)
9281 safi = SAFI_MULTICAST;
9282 else if (strncmp (safi_str, "u", 1) == 0)
9283 safi = SAFI_UNICAST;
9284 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9285 safi = BGP_SAFI_VPNV4;
9286 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9287 safi = BGP_SAFI_VPNV6;
9288 else
9289 {
9290 vty_out (vty, "%% Invalid subsequent address family %s%s",
9291 safi_str, VTY_NEWLINE);
9292 return CMD_WARNING;
9293 }
9294 }
9295 else
9296 {
9297 vty_out (vty, "%% Invalid address family %s%s",
9298 afi_str, VTY_NEWLINE);
9299 return CMD_WARNING;
9300 }
9301
9302 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9303 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9304 {
9305 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9306 afi_str, safi_str, VTY_NEWLINE);
9307 return CMD_WARNING;
9308 }
9309 return bgp_table_stats (vty, bgp, afi, safi);
9310}
9311
9312DEFUN (show_bgp_statistics,
9313 show_bgp_statistics_cmd,
9314 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9315 SHOW_STR
9316 BGP_STR
9317 "Address family\n"
9318 "Address family\n"
9319 "Address Family modifier\n"
9320 "Address Family modifier\n"
9321 "BGP RIB advertisement statistics\n")
9322{
9323 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9324}
9325
9326ALIAS (show_bgp_statistics,
9327 show_bgp_statistics_vpnv4_cmd,
9328 "show bgp (ipv4) (vpnv4) statistics",
9329 SHOW_STR
9330 BGP_STR
9331 "Address family\n"
9332 "Address Family modifier\n"
9333 "BGP RIB advertisement statistics\n")
9334
9335DEFUN (show_bgp_statistics_view,
9336 show_bgp_statistics_view_cmd,
9337 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9338 SHOW_STR
9339 BGP_STR
9340 "BGP view\n"
9341 "Address family\n"
9342 "Address family\n"
9343 "Address Family modifier\n"
9344 "Address Family modifier\n"
9345 "BGP RIB advertisement statistics\n")
9346{
9347 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9348}
9349
9350ALIAS (show_bgp_statistics_view,
9351 show_bgp_statistics_view_vpnv4_cmd,
9352 "show bgp view WORD (ipv4) (vpnv4) statistics",
9353 SHOW_STR
9354 BGP_STR
9355 "BGP view\n"
9356 "Address family\n"
9357 "Address Family modifier\n"
9358 "BGP RIB advertisement statistics\n")
9359
Paul Jakmaff7924f2006-09-04 01:10:36 +00009360enum bgp_pcounts
9361{
9362 PCOUNT_ADJ_IN = 0,
9363 PCOUNT_DAMPED,
9364 PCOUNT_REMOVED,
9365 PCOUNT_HISTORY,
9366 PCOUNT_STALE,
9367 PCOUNT_VALID,
9368 PCOUNT_ALL,
9369 PCOUNT_COUNTED,
9370 PCOUNT_PFCNT, /* the figure we display to users */
9371 PCOUNT_MAX,
9372};
9373
9374static const char *pcount_strs[] =
9375{
9376 [PCOUNT_ADJ_IN] = "Adj-in",
9377 [PCOUNT_DAMPED] = "Damped",
9378 [PCOUNT_REMOVED] = "Removed",
9379 [PCOUNT_HISTORY] = "History",
9380 [PCOUNT_STALE] = "Stale",
9381 [PCOUNT_VALID] = "Valid",
9382 [PCOUNT_ALL] = "All RIB",
9383 [PCOUNT_COUNTED] = "PfxCt counted",
9384 [PCOUNT_PFCNT] = "Useable",
9385 [PCOUNT_MAX] = NULL,
9386};
9387
Paul Jakma2815e612006-09-14 02:56:07 +00009388struct peer_pcounts
9389{
9390 unsigned int count[PCOUNT_MAX];
9391 const struct peer *peer;
9392 const struct bgp_table *table;
9393};
9394
Paul Jakmaff7924f2006-09-04 01:10:36 +00009395static int
Paul Jakma2815e612006-09-14 02:56:07 +00009396bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009397{
9398 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009399 struct peer_pcounts *pc = THREAD_ARG (t);
9400 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009401
Paul Jakma2815e612006-09-14 02:56:07 +00009402 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009403 {
9404 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009405 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009406
9407 for (ain = rn->adj_in; ain; ain = ain->next)
9408 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009409 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009410
Paul Jakmaff7924f2006-09-04 01:10:36 +00009411 for (ri = rn->info; ri; ri = ri->next)
9412 {
9413 char buf[SU_ADDRSTRLEN];
9414
9415 if (ri->peer != peer)
9416 continue;
9417
Paul Jakma2815e612006-09-14 02:56:07 +00009418 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009419
9420 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009421 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009422 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009423 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009424 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009425 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009426 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009427 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009428 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009429 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009430 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009431 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009432
9433 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9434 {
Paul Jakma2815e612006-09-14 02:56:07 +00009435 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009436 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009437 plog_warn (peer->log,
9438 "%s [pcount] %s/%d is counted but flags 0x%x",
9439 peer->host,
9440 inet_ntop(rn->p.family, &rn->p.u.prefix,
9441 buf, SU_ADDRSTRLEN),
9442 rn->p.prefixlen,
9443 ri->flags);
9444 }
9445 else
9446 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009447 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009448 plog_warn (peer->log,
9449 "%s [pcount] %s/%d not counted but flags 0x%x",
9450 peer->host,
9451 inet_ntop(rn->p.family, &rn->p.u.prefix,
9452 buf, SU_ADDRSTRLEN),
9453 rn->p.prefixlen,
9454 ri->flags);
9455 }
9456 }
9457 }
Paul Jakma2815e612006-09-14 02:56:07 +00009458 return 0;
9459}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009460
Paul Jakma2815e612006-09-14 02:56:07 +00009461static int
9462bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9463{
9464 struct peer_pcounts pcounts = { .peer = peer };
9465 unsigned int i;
9466
9467 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9468 || !peer->bgp->rib[afi][safi])
9469 {
9470 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9471 return CMD_WARNING;
9472 }
9473
9474 memset (&pcounts, 0, sizeof(pcounts));
9475 pcounts.peer = peer;
9476 pcounts.table = peer->bgp->rib[afi][safi];
9477
9478 /* in-place call via thread subsystem so as to record execution time
9479 * stats for the thread-walk (i.e. ensure this can't be blamed on
9480 * on just vty_read()).
9481 */
9482 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9483
Paul Jakmaff7924f2006-09-04 01:10:36 +00009484 vty_out (vty, "Prefix counts for %s, %s%s",
9485 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9486 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9487 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9488 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9489
9490 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009491 vty_out (vty, "%20s: %-10d%s",
9492 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009493
Paul Jakma2815e612006-09-14 02:56:07 +00009494 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009495 {
9496 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9497 peer->host, VTY_NEWLINE);
9498 vty_out (vty, "Please report this bug, with the above command output%s",
9499 VTY_NEWLINE);
9500 }
9501
9502 return CMD_SUCCESS;
9503}
9504
9505DEFUN (show_ip_bgp_neighbor_prefix_counts,
9506 show_ip_bgp_neighbor_prefix_counts_cmd,
9507 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9508 SHOW_STR
9509 IP_STR
9510 BGP_STR
9511 "Detailed information on TCP and BGP neighbor connections\n"
9512 "Neighbor to display information about\n"
9513 "Neighbor to display information about\n"
9514 "Display detailed prefix count information\n")
9515{
9516 struct peer *peer;
9517
9518 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9519 if (! peer)
9520 return CMD_WARNING;
9521
9522 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9523}
9524
9525DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9526 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9527 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9528 SHOW_STR
9529 BGP_STR
9530 "Address family\n"
9531 "Detailed information on TCP and BGP neighbor connections\n"
9532 "Neighbor to display information about\n"
9533 "Neighbor to display information about\n"
9534 "Display detailed prefix count information\n")
9535{
9536 struct peer *peer;
9537
9538 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9539 if (! peer)
9540 return CMD_WARNING;
9541
9542 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9543}
9544
9545DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9546 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9547 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9548 SHOW_STR
9549 IP_STR
9550 BGP_STR
9551 "Address family\n"
9552 "Address Family modifier\n"
9553 "Address Family modifier\n"
9554 "Detailed information on TCP and BGP neighbor connections\n"
9555 "Neighbor to display information about\n"
9556 "Neighbor to display information about\n"
9557 "Display detailed prefix count information\n")
9558{
9559 struct peer *peer;
9560
9561 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9562 if (! peer)
9563 return CMD_WARNING;
9564
9565 if (strncmp (argv[0], "m", 1) == 0)
9566 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9567
9568 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9569}
9570
9571DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9572 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9573 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9574 SHOW_STR
9575 IP_STR
9576 BGP_STR
9577 "Address family\n"
9578 "Address Family modifier\n"
9579 "Address Family modifier\n"
9580 "Detailed information on TCP and BGP neighbor connections\n"
9581 "Neighbor to display information about\n"
9582 "Neighbor to display information about\n"
9583 "Display detailed prefix count information\n")
9584{
9585 struct peer *peer;
9586
9587 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9588 if (! peer)
9589 return CMD_WARNING;
9590
9591 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9592}
9593
9594
paul94f2b392005-06-28 12:44:16 +00009595static void
paul718e3742002-12-13 20:15:29 +00009596show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9597 int in)
9598{
9599 struct bgp_table *table;
9600 struct bgp_adj_in *ain;
9601 struct bgp_adj_out *adj;
9602 unsigned long output_count;
9603 struct bgp_node *rn;
9604 int header1 = 1;
9605 struct bgp *bgp;
9606 int header2 = 1;
9607
paulbb46e942003-10-24 19:02:03 +00009608 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009609
9610 if (! bgp)
9611 return;
9612
9613 table = bgp->rib[afi][safi];
9614
9615 output_count = 0;
9616
9617 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9618 PEER_STATUS_DEFAULT_ORIGINATE))
9619 {
9620 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 +00009621 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9622 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009623
9624 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9625 VTY_NEWLINE, VTY_NEWLINE);
9626 header1 = 0;
9627 }
9628
9629 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9630 if (in)
9631 {
9632 for (ain = rn->adj_in; ain; ain = ain->next)
9633 if (ain->peer == peer)
9634 {
9635 if (header1)
9636 {
9637 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 +00009638 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9639 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009640 header1 = 0;
9641 }
9642 if (header2)
9643 {
9644 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9645 header2 = 0;
9646 }
9647 if (ain->attr)
9648 {
9649 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9650 output_count++;
9651 }
9652 }
9653 }
9654 else
9655 {
9656 for (adj = rn->adj_out; adj; adj = adj->next)
9657 if (adj->peer == peer)
9658 {
9659 if (header1)
9660 {
9661 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 +00009662 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9663 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009664 header1 = 0;
9665 }
9666 if (header2)
9667 {
9668 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9669 header2 = 0;
9670 }
9671 if (adj->attr)
9672 {
9673 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9674 output_count++;
9675 }
9676 }
9677 }
9678
9679 if (output_count != 0)
9680 vty_out (vty, "%sTotal number of prefixes %ld%s",
9681 VTY_NEWLINE, output_count, VTY_NEWLINE);
9682}
9683
paul94f2b392005-06-28 12:44:16 +00009684static int
paulbb46e942003-10-24 19:02:03 +00009685peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9686{
paul718e3742002-12-13 20:15:29 +00009687 if (! peer || ! peer->afc[afi][safi])
9688 {
9689 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9690 return CMD_WARNING;
9691 }
9692
9693 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9694 {
9695 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9696 VTY_NEWLINE);
9697 return CMD_WARNING;
9698 }
9699
9700 show_adj_route (vty, peer, afi, safi, in);
9701
9702 return CMD_SUCCESS;
9703}
9704
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009705DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9706 show_ip_bgp_view_neighbor_advertised_route_cmd,
9707 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9708 SHOW_STR
9709 IP_STR
9710 BGP_STR
9711 "BGP view\n"
9712 "View name\n"
9713 "Detailed information on TCP and BGP neighbor connections\n"
9714 "Neighbor to display information about\n"
9715 "Neighbor to display information about\n"
9716 "Display the routes advertised to a BGP neighbor\n")
9717{
9718 struct peer *peer;
9719
9720 if (argc == 2)
9721 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9722 else
9723 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9724
9725 if (! peer)
9726 return CMD_WARNING;
9727
9728 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9729}
9730
9731ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009732 show_ip_bgp_neighbor_advertised_route_cmd,
9733 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9734 SHOW_STR
9735 IP_STR
9736 BGP_STR
9737 "Detailed information on TCP and BGP neighbor connections\n"
9738 "Neighbor to display information about\n"
9739 "Neighbor to display information about\n"
9740 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009741
9742DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9743 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9744 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9745 SHOW_STR
9746 IP_STR
9747 BGP_STR
9748 "Address family\n"
9749 "Address Family modifier\n"
9750 "Address Family modifier\n"
9751 "Detailed information on TCP and BGP neighbor connections\n"
9752 "Neighbor to display information about\n"
9753 "Neighbor to display information about\n"
9754 "Display the routes advertised to a BGP neighbor\n")
9755{
paulbb46e942003-10-24 19:02:03 +00009756 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009757
paulbb46e942003-10-24 19:02:03 +00009758 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9759 if (! peer)
9760 return CMD_WARNING;
9761
9762 if (strncmp (argv[0], "m", 1) == 0)
9763 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9764
9765 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009766}
9767
9768#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009769DEFUN (show_bgp_view_neighbor_advertised_route,
9770 show_bgp_view_neighbor_advertised_route_cmd,
9771 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9772 SHOW_STR
9773 BGP_STR
9774 "BGP view\n"
9775 "View name\n"
9776 "Detailed information on TCP and BGP neighbor connections\n"
9777 "Neighbor to display information about\n"
9778 "Neighbor to display information about\n"
9779 "Display the routes advertised to a BGP neighbor\n")
9780{
9781 struct peer *peer;
9782
9783 if (argc == 2)
9784 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9785 else
9786 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9787
9788 if (! peer)
9789 return CMD_WARNING;
9790
9791 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9792}
9793
9794ALIAS (show_bgp_view_neighbor_advertised_route,
9795 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9796 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9797 SHOW_STR
9798 BGP_STR
9799 "BGP view\n"
9800 "View name\n"
9801 "Address family\n"
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
9807DEFUN (show_bgp_view_neighbor_received_routes,
9808 show_bgp_view_neighbor_received_routes_cmd,
9809 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9810 SHOW_STR
9811 BGP_STR
9812 "BGP view\n"
9813 "View name\n"
9814 "Detailed information on TCP and BGP neighbor connections\n"
9815 "Neighbor to display information about\n"
9816 "Neighbor to display information about\n"
9817 "Display the received routes from neighbor\n")
9818{
9819 struct peer *peer;
9820
9821 if (argc == 2)
9822 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9823 else
9824 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9825
9826 if (! peer)
9827 return CMD_WARNING;
9828
9829 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9830}
9831
9832ALIAS (show_bgp_view_neighbor_received_routes,
9833 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9834 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9835 SHOW_STR
9836 BGP_STR
9837 "BGP view\n"
9838 "View name\n"
9839 "Address family\n"
9840 "Detailed information on TCP and BGP neighbor connections\n"
9841 "Neighbor to display information about\n"
9842 "Neighbor to display information about\n"
9843 "Display the received routes from neighbor\n")
9844
9845ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009846 show_bgp_neighbor_advertised_route_cmd,
9847 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9848 SHOW_STR
9849 BGP_STR
9850 "Detailed information on TCP and BGP neighbor connections\n"
9851 "Neighbor to display information about\n"
9852 "Neighbor to display information about\n"
9853 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009854
9855ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009856 show_bgp_ipv6_neighbor_advertised_route_cmd,
9857 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9858 SHOW_STR
9859 BGP_STR
9860 "Address family\n"
9861 "Detailed information on TCP and BGP neighbor connections\n"
9862 "Neighbor to display information about\n"
9863 "Neighbor to display information about\n"
9864 "Display the routes advertised to a BGP neighbor\n")
9865
9866/* old command */
paulbb46e942003-10-24 19:02:03 +00009867ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009868 ipv6_bgp_neighbor_advertised_route_cmd,
9869 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9870 SHOW_STR
9871 IPV6_STR
9872 BGP_STR
9873 "Detailed information on TCP and BGP neighbor connections\n"
9874 "Neighbor to display information about\n"
9875 "Neighbor to display information about\n"
9876 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009877
paul718e3742002-12-13 20:15:29 +00009878/* old command */
9879DEFUN (ipv6_mbgp_neighbor_advertised_route,
9880 ipv6_mbgp_neighbor_advertised_route_cmd,
9881 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9882 SHOW_STR
9883 IPV6_STR
9884 MBGP_STR
9885 "Detailed information on TCP and BGP neighbor connections\n"
9886 "Neighbor to display information about\n"
9887 "Neighbor to display information about\n"
9888 "Display the routes advertised to a BGP neighbor\n")
9889{
paulbb46e942003-10-24 19:02:03 +00009890 struct peer *peer;
9891
9892 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9893 if (! peer)
9894 return CMD_WARNING;
9895
9896 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009897}
9898#endif /* HAVE_IPV6 */
9899
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009900DEFUN (show_ip_bgp_view_neighbor_received_routes,
9901 show_ip_bgp_view_neighbor_received_routes_cmd,
9902 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9903 SHOW_STR
9904 IP_STR
9905 BGP_STR
9906 "BGP view\n"
9907 "View name\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 the received routes from neighbor\n")
9912{
9913 struct peer *peer;
9914
9915 if (argc == 2)
9916 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9917 else
9918 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9919
9920 if (! peer)
9921 return CMD_WARNING;
9922
9923 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9924}
9925
9926ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009927 show_ip_bgp_neighbor_received_routes_cmd,
9928 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9929 SHOW_STR
9930 IP_STR
9931 BGP_STR
9932 "Detailed information on TCP and BGP neighbor connections\n"
9933 "Neighbor to display information about\n"
9934 "Neighbor to display information about\n"
9935 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009936
9937DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9938 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9939 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9940 SHOW_STR
9941 IP_STR
9942 BGP_STR
9943 "Address family\n"
9944 "Address Family modifier\n"
9945 "Address Family modifier\n"
9946 "Detailed information on TCP and BGP neighbor connections\n"
9947 "Neighbor to display information about\n"
9948 "Neighbor to display information about\n"
9949 "Display the received routes from neighbor\n")
9950{
paulbb46e942003-10-24 19:02:03 +00009951 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009952
paulbb46e942003-10-24 19:02:03 +00009953 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9954 if (! peer)
9955 return CMD_WARNING;
9956
9957 if (strncmp (argv[0], "m", 1) == 0)
9958 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9959
9960 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009961}
9962
9963DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9964 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9965 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9966 SHOW_STR
9967 IP_STR
9968 BGP_STR
9969 "Detailed information on TCP and BGP neighbor connections\n"
9970 "Neighbor to display information about\n"
9971 "Neighbor to display information about\n"
9972 "Display information received from a BGP neighbor\n"
9973 "Display the prefixlist filter\n")
9974{
9975 char name[BUFSIZ];
9976 union sockunion *su;
9977 struct peer *peer;
9978 int count;
9979
9980 su = sockunion_str2su (argv[0]);
9981 if (su == NULL)
9982 return CMD_WARNING;
9983
9984 peer = peer_lookup (NULL, su);
9985 if (! peer)
9986 return CMD_WARNING;
9987
9988 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9989 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9990 if (count)
9991 {
9992 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9993 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9994 }
9995
9996 return CMD_SUCCESS;
9997}
9998
9999DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10000 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10001 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10002 SHOW_STR
10003 IP_STR
10004 BGP_STR
10005 "Address family\n"
10006 "Address Family modifier\n"
10007 "Address Family modifier\n"
10008 "Detailed information on TCP and BGP neighbor connections\n"
10009 "Neighbor to display information about\n"
10010 "Neighbor to display information about\n"
10011 "Display information received from a BGP neighbor\n"
10012 "Display the prefixlist filter\n")
10013{
10014 char name[BUFSIZ];
10015 union sockunion *su;
10016 struct peer *peer;
10017 int count;
10018
10019 su = sockunion_str2su (argv[1]);
10020 if (su == NULL)
10021 return CMD_WARNING;
10022
10023 peer = peer_lookup (NULL, su);
10024 if (! peer)
10025 return CMD_WARNING;
10026
10027 if (strncmp (argv[0], "m", 1) == 0)
10028 {
10029 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10030 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10031 if (count)
10032 {
10033 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10034 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10035 }
10036 }
10037 else
10038 {
10039 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10040 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10041 if (count)
10042 {
10043 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10044 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10045 }
10046 }
10047
10048 return CMD_SUCCESS;
10049}
10050
10051
10052#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010053ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010054 show_bgp_neighbor_received_routes_cmd,
10055 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10056 SHOW_STR
10057 BGP_STR
10058 "Detailed information on TCP and BGP neighbor connections\n"
10059 "Neighbor to display information about\n"
10060 "Neighbor to display information about\n"
10061 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010062
paulbb46e942003-10-24 19:02:03 +000010063ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010064 show_bgp_ipv6_neighbor_received_routes_cmd,
10065 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10066 SHOW_STR
10067 BGP_STR
10068 "Address family\n"
10069 "Detailed information on TCP and BGP neighbor connections\n"
10070 "Neighbor to display information about\n"
10071 "Neighbor to display information about\n"
10072 "Display the received routes from neighbor\n")
10073
10074DEFUN (show_bgp_neighbor_received_prefix_filter,
10075 show_bgp_neighbor_received_prefix_filter_cmd,
10076 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10077 SHOW_STR
10078 BGP_STR
10079 "Detailed information on TCP and BGP neighbor connections\n"
10080 "Neighbor to display information about\n"
10081 "Neighbor to display information about\n"
10082 "Display information received from a BGP neighbor\n"
10083 "Display the prefixlist filter\n")
10084{
10085 char name[BUFSIZ];
10086 union sockunion *su;
10087 struct peer *peer;
10088 int count;
10089
10090 su = sockunion_str2su (argv[0]);
10091 if (su == NULL)
10092 return CMD_WARNING;
10093
10094 peer = peer_lookup (NULL, su);
10095 if (! peer)
10096 return CMD_WARNING;
10097
10098 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10099 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10100 if (count)
10101 {
10102 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10103 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10104 }
10105
10106 return CMD_SUCCESS;
10107}
10108
10109ALIAS (show_bgp_neighbor_received_prefix_filter,
10110 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10111 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10112 SHOW_STR
10113 BGP_STR
10114 "Address family\n"
10115 "Detailed information on TCP and BGP neighbor connections\n"
10116 "Neighbor to display information about\n"
10117 "Neighbor to display information about\n"
10118 "Display information received from a BGP neighbor\n"
10119 "Display the prefixlist filter\n")
10120
10121/* old command */
paulbb46e942003-10-24 19:02:03 +000010122ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010123 ipv6_bgp_neighbor_received_routes_cmd,
10124 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10125 SHOW_STR
10126 IPV6_STR
10127 BGP_STR
10128 "Detailed information on TCP and BGP neighbor connections\n"
10129 "Neighbor to display information about\n"
10130 "Neighbor to display information about\n"
10131 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010132
10133/* old command */
10134DEFUN (ipv6_mbgp_neighbor_received_routes,
10135 ipv6_mbgp_neighbor_received_routes_cmd,
10136 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10137 SHOW_STR
10138 IPV6_STR
10139 MBGP_STR
10140 "Detailed information on TCP and BGP neighbor connections\n"
10141 "Neighbor to display information about\n"
10142 "Neighbor to display information about\n"
10143 "Display the received routes from neighbor\n")
10144{
paulbb46e942003-10-24 19:02:03 +000010145 struct peer *peer;
10146
10147 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10148 if (! peer)
10149 return CMD_WARNING;
10150
10151 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010152}
paulbb46e942003-10-24 19:02:03 +000010153
10154DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10155 show_bgp_view_neighbor_received_prefix_filter_cmd,
10156 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10157 SHOW_STR
10158 BGP_STR
10159 "BGP view\n"
10160 "View name\n"
10161 "Detailed information on TCP and BGP neighbor connections\n"
10162 "Neighbor to display information about\n"
10163 "Neighbor to display information about\n"
10164 "Display information received from a BGP neighbor\n"
10165 "Display the prefixlist filter\n")
10166{
10167 char name[BUFSIZ];
10168 union sockunion *su;
10169 struct peer *peer;
10170 struct bgp *bgp;
10171 int count;
10172
10173 /* BGP structure lookup. */
10174 bgp = bgp_lookup_by_name (argv[0]);
10175 if (bgp == NULL)
10176 {
10177 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10178 return CMD_WARNING;
10179 }
10180
10181 su = sockunion_str2su (argv[1]);
10182 if (su == NULL)
10183 return CMD_WARNING;
10184
10185 peer = peer_lookup (bgp, su);
10186 if (! peer)
10187 return CMD_WARNING;
10188
10189 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10190 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10191 if (count)
10192 {
10193 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10194 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10195 }
10196
10197 return CMD_SUCCESS;
10198}
10199
10200ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10201 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10202 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10203 SHOW_STR
10204 BGP_STR
10205 "BGP view\n"
10206 "View name\n"
10207 "Address family\n"
10208 "Detailed information on TCP and BGP neighbor connections\n"
10209 "Neighbor to display information about\n"
10210 "Neighbor to display information about\n"
10211 "Display information received from a BGP neighbor\n"
10212 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010213#endif /* HAVE_IPV6 */
10214
paul94f2b392005-06-28 12:44:16 +000010215static int
paulbb46e942003-10-24 19:02:03 +000010216bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010217 safi_t safi, enum bgp_show_type type)
10218{
paul718e3742002-12-13 20:15:29 +000010219 if (! peer || ! peer->afc[afi][safi])
10220 {
10221 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010222 return CMD_WARNING;
10223 }
10224
ajs5a646652004-11-05 01:25:55 +000010225 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010226}
10227
10228DEFUN (show_ip_bgp_neighbor_routes,
10229 show_ip_bgp_neighbor_routes_cmd,
10230 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10231 SHOW_STR
10232 IP_STR
10233 BGP_STR
10234 "Detailed information on TCP and BGP neighbor connections\n"
10235 "Neighbor to display information about\n"
10236 "Neighbor to display information about\n"
10237 "Display routes learned from neighbor\n")
10238{
paulbb46e942003-10-24 19:02:03 +000010239 struct peer *peer;
10240
10241 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10242 if (! peer)
10243 return CMD_WARNING;
10244
10245 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010246 bgp_show_type_neighbor);
10247}
10248
10249DEFUN (show_ip_bgp_neighbor_flap,
10250 show_ip_bgp_neighbor_flap_cmd,
10251 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10252 SHOW_STR
10253 IP_STR
10254 BGP_STR
10255 "Detailed information on TCP and BGP neighbor connections\n"
10256 "Neighbor to display information about\n"
10257 "Neighbor to display information about\n"
10258 "Display flap statistics of the routes learned from neighbor\n")
10259{
paulbb46e942003-10-24 19:02:03 +000010260 struct peer *peer;
10261
10262 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10263 if (! peer)
10264 return CMD_WARNING;
10265
10266 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010267 bgp_show_type_flap_neighbor);
10268}
10269
10270DEFUN (show_ip_bgp_neighbor_damp,
10271 show_ip_bgp_neighbor_damp_cmd,
10272 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10273 SHOW_STR
10274 IP_STR
10275 BGP_STR
10276 "Detailed information on TCP and BGP neighbor connections\n"
10277 "Neighbor to display information about\n"
10278 "Neighbor to display information about\n"
10279 "Display the dampened routes received from neighbor\n")
10280{
paulbb46e942003-10-24 19:02:03 +000010281 struct peer *peer;
10282
10283 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10284 if (! peer)
10285 return CMD_WARNING;
10286
10287 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010288 bgp_show_type_damp_neighbor);
10289}
10290
10291DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10292 show_ip_bgp_ipv4_neighbor_routes_cmd,
10293 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10294 SHOW_STR
10295 IP_STR
10296 BGP_STR
10297 "Address family\n"
10298 "Address Family modifier\n"
10299 "Address Family modifier\n"
10300 "Detailed information on TCP and BGP neighbor connections\n"
10301 "Neighbor to display information about\n"
10302 "Neighbor to display information about\n"
10303 "Display routes learned from neighbor\n")
10304{
paulbb46e942003-10-24 19:02:03 +000010305 struct peer *peer;
10306
10307 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10308 if (! peer)
10309 return CMD_WARNING;
10310
paul718e3742002-12-13 20:15:29 +000010311 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010312 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010313 bgp_show_type_neighbor);
10314
paulbb46e942003-10-24 19:02:03 +000010315 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010316 bgp_show_type_neighbor);
10317}
paulbb46e942003-10-24 19:02:03 +000010318
paulfee0f4c2004-09-13 05:12:46 +000010319DEFUN (show_ip_bgp_view_rsclient,
10320 show_ip_bgp_view_rsclient_cmd,
10321 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10322 SHOW_STR
10323 IP_STR
10324 BGP_STR
10325 "BGP view\n"
10326 "BGP view name\n"
10327 "Information about Route Server Client\n"
10328 NEIGHBOR_ADDR_STR)
10329{
10330 struct bgp_table *table;
10331 struct peer *peer;
10332
10333 if (argc == 2)
10334 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10335 else
10336 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10337
10338 if (! peer)
10339 return CMD_WARNING;
10340
10341 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10342 {
10343 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10344 VTY_NEWLINE);
10345 return CMD_WARNING;
10346 }
10347
10348 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10349 PEER_FLAG_RSERVER_CLIENT))
10350 {
10351 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10352 VTY_NEWLINE);
10353 return CMD_WARNING;
10354 }
10355
10356 table = peer->rib[AFI_IP][SAFI_UNICAST];
10357
ajs5a646652004-11-05 01:25:55 +000010358 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010359}
10360
10361ALIAS (show_ip_bgp_view_rsclient,
10362 show_ip_bgp_rsclient_cmd,
10363 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10364 SHOW_STR
10365 IP_STR
10366 BGP_STR
10367 "Information about Route Server Client\n"
10368 NEIGHBOR_ADDR_STR)
10369
10370DEFUN (show_ip_bgp_view_rsclient_route,
10371 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010372 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010373 SHOW_STR
10374 IP_STR
10375 BGP_STR
10376 "BGP view\n"
10377 "BGP view name\n"
10378 "Information about Route Server Client\n"
10379 NEIGHBOR_ADDR_STR
10380 "Network in the BGP routing table to display\n")
10381{
10382 struct bgp *bgp;
10383 struct peer *peer;
10384
10385 /* BGP structure lookup. */
10386 if (argc == 3)
10387 {
10388 bgp = bgp_lookup_by_name (argv[0]);
10389 if (bgp == NULL)
10390 {
10391 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10392 return CMD_WARNING;
10393 }
10394 }
10395 else
10396 {
10397 bgp = bgp_get_default ();
10398 if (bgp == NULL)
10399 {
10400 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10401 return CMD_WARNING;
10402 }
10403 }
10404
10405 if (argc == 3)
10406 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10407 else
10408 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10409
10410 if (! peer)
10411 return CMD_WARNING;
10412
10413 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10414 {
10415 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10416 VTY_NEWLINE);
10417 return CMD_WARNING;
10418}
10419
10420 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10421 PEER_FLAG_RSERVER_CLIENT))
10422 {
10423 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10424 VTY_NEWLINE);
10425 return CMD_WARNING;
10426 }
10427
10428 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10429 (argc == 3) ? argv[2] : argv[1],
10430 AFI_IP, SAFI_UNICAST, NULL, 0);
10431}
10432
10433ALIAS (show_ip_bgp_view_rsclient_route,
10434 show_ip_bgp_rsclient_route_cmd,
10435 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10436 SHOW_STR
10437 IP_STR
10438 BGP_STR
10439 "Information about Route Server Client\n"
10440 NEIGHBOR_ADDR_STR
10441 "Network in the BGP routing table to display\n")
10442
10443DEFUN (show_ip_bgp_view_rsclient_prefix,
10444 show_ip_bgp_view_rsclient_prefix_cmd,
10445 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10446 SHOW_STR
10447 IP_STR
10448 BGP_STR
10449 "BGP view\n"
10450 "BGP view name\n"
10451 "Information about Route Server Client\n"
10452 NEIGHBOR_ADDR_STR
10453 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10454{
10455 struct bgp *bgp;
10456 struct peer *peer;
10457
10458 /* BGP structure lookup. */
10459 if (argc == 3)
10460 {
10461 bgp = bgp_lookup_by_name (argv[0]);
10462 if (bgp == NULL)
10463 {
10464 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10465 return CMD_WARNING;
10466 }
10467 }
10468 else
10469 {
10470 bgp = bgp_get_default ();
10471 if (bgp == NULL)
10472 {
10473 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10474 return CMD_WARNING;
10475 }
10476 }
10477
10478 if (argc == 3)
10479 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10480 else
10481 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10482
10483 if (! peer)
10484 return CMD_WARNING;
10485
10486 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10487 {
10488 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10489 VTY_NEWLINE);
10490 return CMD_WARNING;
10491}
10492
10493 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10494 PEER_FLAG_RSERVER_CLIENT))
10495{
10496 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10497 VTY_NEWLINE);
10498 return CMD_WARNING;
10499 }
10500
10501 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10502 (argc == 3) ? argv[2] : argv[1],
10503 AFI_IP, SAFI_UNICAST, NULL, 1);
10504}
10505
10506ALIAS (show_ip_bgp_view_rsclient_prefix,
10507 show_ip_bgp_rsclient_prefix_cmd,
10508 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10509 SHOW_STR
10510 IP_STR
10511 BGP_STR
10512 "Information about Route Server Client\n"
10513 NEIGHBOR_ADDR_STR
10514 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10515
10516
paul718e3742002-12-13 20:15:29 +000010517#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010518DEFUN (show_bgp_view_neighbor_routes,
10519 show_bgp_view_neighbor_routes_cmd,
10520 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10521 SHOW_STR
10522 BGP_STR
10523 "BGP view\n"
10524 "BGP view name\n"
10525 "Detailed information on TCP and BGP neighbor connections\n"
10526 "Neighbor to display information about\n"
10527 "Neighbor to display information about\n"
10528 "Display routes learned from neighbor\n")
10529{
10530 struct peer *peer;
10531
10532 if (argc == 2)
10533 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10534 else
10535 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10536
10537 if (! peer)
10538 return CMD_WARNING;
10539
10540 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10541 bgp_show_type_neighbor);
10542}
10543
10544ALIAS (show_bgp_view_neighbor_routes,
10545 show_bgp_view_ipv6_neighbor_routes_cmd,
10546 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10547 SHOW_STR
10548 BGP_STR
10549 "BGP view\n"
10550 "BGP view name\n"
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
10557DEFUN (show_bgp_view_neighbor_damp,
10558 show_bgp_view_neighbor_damp_cmd,
10559 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10560 SHOW_STR
10561 BGP_STR
10562 "BGP view\n"
10563 "BGP view name\n"
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 the dampened routes received from neighbor\n")
10568{
10569 struct peer *peer;
10570
10571 if (argc == 2)
10572 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10573 else
10574 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10575
10576 if (! peer)
10577 return CMD_WARNING;
10578
10579 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10580 bgp_show_type_damp_neighbor);
10581}
10582
10583ALIAS (show_bgp_view_neighbor_damp,
10584 show_bgp_view_ipv6_neighbor_damp_cmd,
10585 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10586 SHOW_STR
10587 BGP_STR
10588 "BGP view\n"
10589 "BGP view name\n"
10590 "Address family\n"
10591 "Detailed information on TCP and BGP neighbor connections\n"
10592 "Neighbor to display information about\n"
10593 "Neighbor to display information about\n"
10594 "Display the dampened routes received from neighbor\n")
10595
10596DEFUN (show_bgp_view_neighbor_flap,
10597 show_bgp_view_neighbor_flap_cmd,
10598 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10599 SHOW_STR
10600 BGP_STR
10601 "BGP view\n"
10602 "BGP view name\n"
10603 "Detailed information on TCP and BGP neighbor connections\n"
10604 "Neighbor to display information about\n"
10605 "Neighbor to display information about\n"
10606 "Display flap statistics of the routes learned from neighbor\n")
10607{
10608 struct peer *peer;
10609
10610 if (argc == 2)
10611 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10612 else
10613 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10614
10615 if (! peer)
10616 return CMD_WARNING;
10617
10618 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10619 bgp_show_type_flap_neighbor);
10620}
10621
10622ALIAS (show_bgp_view_neighbor_flap,
10623 show_bgp_view_ipv6_neighbor_flap_cmd,
10624 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10625 SHOW_STR
10626 BGP_STR
10627 "BGP view\n"
10628 "BGP view name\n"
10629 "Address family\n"
10630 "Detailed information on TCP and BGP neighbor connections\n"
10631 "Neighbor to display information about\n"
10632 "Neighbor to display information about\n"
10633 "Display flap statistics of the routes learned from neighbor\n")
10634
10635ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010636 show_bgp_neighbor_routes_cmd,
10637 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10638 SHOW_STR
10639 BGP_STR
10640 "Detailed information on TCP and BGP neighbor connections\n"
10641 "Neighbor to display information about\n"
10642 "Neighbor to display information about\n"
10643 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010644
paulbb46e942003-10-24 19:02:03 +000010645
10646ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010647 show_bgp_ipv6_neighbor_routes_cmd,
10648 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10649 SHOW_STR
10650 BGP_STR
10651 "Address family\n"
10652 "Detailed information on TCP and BGP neighbor connections\n"
10653 "Neighbor to display information about\n"
10654 "Neighbor to display information about\n"
10655 "Display routes learned from neighbor\n")
10656
10657/* old command */
paulbb46e942003-10-24 19:02:03 +000010658ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010659 ipv6_bgp_neighbor_routes_cmd,
10660 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10661 SHOW_STR
10662 IPV6_STR
10663 BGP_STR
10664 "Detailed information on TCP and BGP neighbor connections\n"
10665 "Neighbor to display information about\n"
10666 "Neighbor to display information about\n"
10667 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010668
10669/* old command */
10670DEFUN (ipv6_mbgp_neighbor_routes,
10671 ipv6_mbgp_neighbor_routes_cmd,
10672 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10673 SHOW_STR
10674 IPV6_STR
10675 MBGP_STR
10676 "Detailed information on TCP and BGP neighbor connections\n"
10677 "Neighbor to display information about\n"
10678 "Neighbor to display information about\n"
10679 "Display routes learned from neighbor\n")
10680{
paulbb46e942003-10-24 19:02:03 +000010681 struct peer *peer;
10682
10683 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10684 if (! peer)
10685 return CMD_WARNING;
10686
10687 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010688 bgp_show_type_neighbor);
10689}
paulbb46e942003-10-24 19:02:03 +000010690
10691ALIAS (show_bgp_view_neighbor_flap,
10692 show_bgp_neighbor_flap_cmd,
10693 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10694 SHOW_STR
10695 BGP_STR
10696 "Detailed information on TCP and BGP neighbor connections\n"
10697 "Neighbor to display information about\n"
10698 "Neighbor to display information about\n"
10699 "Display flap statistics of the routes learned from neighbor\n")
10700
10701ALIAS (show_bgp_view_neighbor_flap,
10702 show_bgp_ipv6_neighbor_flap_cmd,
10703 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10704 SHOW_STR
10705 BGP_STR
10706 "Address family\n"
10707 "Detailed information on TCP and BGP neighbor connections\n"
10708 "Neighbor to display information about\n"
10709 "Neighbor to display information about\n"
10710 "Display flap statistics of the routes learned from neighbor\n")
10711
10712ALIAS (show_bgp_view_neighbor_damp,
10713 show_bgp_neighbor_damp_cmd,
10714 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10715 SHOW_STR
10716 BGP_STR
10717 "Detailed information on TCP and BGP neighbor connections\n"
10718 "Neighbor to display information about\n"
10719 "Neighbor to display information about\n"
10720 "Display the dampened routes received from neighbor\n")
10721
10722ALIAS (show_bgp_view_neighbor_damp,
10723 show_bgp_ipv6_neighbor_damp_cmd,
10724 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10725 SHOW_STR
10726 BGP_STR
10727 "Address family\n"
10728 "Detailed information on TCP and BGP neighbor connections\n"
10729 "Neighbor to display information about\n"
10730 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010731 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010732
10733DEFUN (show_bgp_view_rsclient,
10734 show_bgp_view_rsclient_cmd,
10735 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10736 SHOW_STR
10737 BGP_STR
10738 "BGP view\n"
10739 "BGP view name\n"
10740 "Information about Route Server Client\n"
10741 NEIGHBOR_ADDR_STR)
10742{
10743 struct bgp_table *table;
10744 struct peer *peer;
10745
10746 if (argc == 2)
10747 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10748 else
10749 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10750
10751 if (! peer)
10752 return CMD_WARNING;
10753
10754 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10755 {
10756 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10757 VTY_NEWLINE);
10758 return CMD_WARNING;
10759 }
10760
10761 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10762 PEER_FLAG_RSERVER_CLIENT))
10763 {
10764 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10765 VTY_NEWLINE);
10766 return CMD_WARNING;
10767 }
10768
10769 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10770
ajs5a646652004-11-05 01:25:55 +000010771 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010772}
10773
10774ALIAS (show_bgp_view_rsclient,
10775 show_bgp_rsclient_cmd,
10776 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10777 SHOW_STR
10778 BGP_STR
10779 "Information about Route Server Client\n"
10780 NEIGHBOR_ADDR_STR)
10781
10782DEFUN (show_bgp_view_rsclient_route,
10783 show_bgp_view_rsclient_route_cmd,
10784 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10785 SHOW_STR
10786 BGP_STR
10787 "BGP view\n"
10788 "BGP view name\n"
10789 "Information about Route Server Client\n"
10790 NEIGHBOR_ADDR_STR
10791 "Network in the BGP routing table to display\n")
10792{
10793 struct bgp *bgp;
10794 struct peer *peer;
10795
10796 /* BGP structure lookup. */
10797 if (argc == 3)
10798 {
10799 bgp = bgp_lookup_by_name (argv[0]);
10800 if (bgp == NULL)
10801 {
10802 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10803 return CMD_WARNING;
10804 }
10805 }
10806 else
10807 {
10808 bgp = bgp_get_default ();
10809 if (bgp == NULL)
10810 {
10811 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10812 return CMD_WARNING;
10813 }
10814 }
10815
10816 if (argc == 3)
10817 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10818 else
10819 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10820
10821 if (! peer)
10822 return CMD_WARNING;
10823
10824 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10825 {
10826 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10827 VTY_NEWLINE);
10828 return CMD_WARNING;
10829 }
10830
10831 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10832 PEER_FLAG_RSERVER_CLIENT))
10833 {
10834 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10835 VTY_NEWLINE);
10836 return CMD_WARNING;
10837 }
10838
10839 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10840 (argc == 3) ? argv[2] : argv[1],
10841 AFI_IP6, SAFI_UNICAST, NULL, 0);
10842}
10843
10844ALIAS (show_bgp_view_rsclient_route,
10845 show_bgp_rsclient_route_cmd,
10846 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10847 SHOW_STR
10848 BGP_STR
10849 "Information about Route Server Client\n"
10850 NEIGHBOR_ADDR_STR
10851 "Network in the BGP routing table to display\n")
10852
10853DEFUN (show_bgp_view_rsclient_prefix,
10854 show_bgp_view_rsclient_prefix_cmd,
10855 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10856 SHOW_STR
10857 BGP_STR
10858 "BGP view\n"
10859 "BGP view name\n"
10860 "Information about Route Server Client\n"
10861 NEIGHBOR_ADDR_STR
10862 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10863{
10864 struct bgp *bgp;
10865 struct peer *peer;
10866
10867 /* BGP structure lookup. */
10868 if (argc == 3)
10869 {
10870 bgp = bgp_lookup_by_name (argv[0]);
10871 if (bgp == NULL)
10872 {
10873 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10874 return CMD_WARNING;
10875 }
10876 }
10877 else
10878 {
10879 bgp = bgp_get_default ();
10880 if (bgp == NULL)
10881 {
10882 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10883 return CMD_WARNING;
10884 }
10885 }
10886
10887 if (argc == 3)
10888 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10889 else
10890 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10891
10892 if (! peer)
10893 return CMD_WARNING;
10894
10895 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10896 {
10897 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10898 VTY_NEWLINE);
10899 return CMD_WARNING;
10900 }
10901
10902 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10903 PEER_FLAG_RSERVER_CLIENT))
10904 {
10905 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10906 VTY_NEWLINE);
10907 return CMD_WARNING;
10908 }
10909
10910 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10911 (argc == 3) ? argv[2] : argv[1],
10912 AFI_IP6, SAFI_UNICAST, NULL, 1);
10913}
10914
10915ALIAS (show_bgp_view_rsclient_prefix,
10916 show_bgp_rsclient_prefix_cmd,
10917 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10918 SHOW_STR
10919 BGP_STR
10920 "Information about Route Server Client\n"
10921 NEIGHBOR_ADDR_STR
10922 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10923
paul718e3742002-12-13 20:15:29 +000010924#endif /* HAVE_IPV6 */
10925
10926struct bgp_table *bgp_distance_table;
10927
10928struct bgp_distance
10929{
10930 /* Distance value for the IP source prefix. */
10931 u_char distance;
10932
10933 /* Name of the access-list to be matched. */
10934 char *access_list;
10935};
10936
paul94f2b392005-06-28 12:44:16 +000010937static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010938bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010939{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010940 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010941}
10942
paul94f2b392005-06-28 12:44:16 +000010943static void
paul718e3742002-12-13 20:15:29 +000010944bgp_distance_free (struct bgp_distance *bdistance)
10945{
10946 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10947}
10948
paul94f2b392005-06-28 12:44:16 +000010949static int
paulfd79ac92004-10-13 05:06:08 +000010950bgp_distance_set (struct vty *vty, const char *distance_str,
10951 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010952{
10953 int ret;
10954 struct prefix_ipv4 p;
10955 u_char distance;
10956 struct bgp_node *rn;
10957 struct bgp_distance *bdistance;
10958
10959 ret = str2prefix_ipv4 (ip_str, &p);
10960 if (ret == 0)
10961 {
10962 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10963 return CMD_WARNING;
10964 }
10965
10966 distance = atoi (distance_str);
10967
10968 /* Get BGP distance node. */
10969 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10970 if (rn->info)
10971 {
10972 bdistance = rn->info;
10973 bgp_unlock_node (rn);
10974 }
10975 else
10976 {
10977 bdistance = bgp_distance_new ();
10978 rn->info = bdistance;
10979 }
10980
10981 /* Set distance value. */
10982 bdistance->distance = distance;
10983
10984 /* Reset access-list configuration. */
10985 if (bdistance->access_list)
10986 {
10987 free (bdistance->access_list);
10988 bdistance->access_list = NULL;
10989 }
10990 if (access_list_str)
10991 bdistance->access_list = strdup (access_list_str);
10992
10993 return CMD_SUCCESS;
10994}
10995
paul94f2b392005-06-28 12:44:16 +000010996static int
paulfd79ac92004-10-13 05:06:08 +000010997bgp_distance_unset (struct vty *vty, const char *distance_str,
10998 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010999{
11000 int ret;
11001 struct prefix_ipv4 p;
11002 u_char distance;
11003 struct bgp_node *rn;
11004 struct bgp_distance *bdistance;
11005
11006 ret = str2prefix_ipv4 (ip_str, &p);
11007 if (ret == 0)
11008 {
11009 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11010 return CMD_WARNING;
11011 }
11012
11013 distance = atoi (distance_str);
11014
11015 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11016 if (! rn)
11017 {
11018 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11019 return CMD_WARNING;
11020 }
11021
11022 bdistance = rn->info;
11023
11024 if (bdistance->access_list)
11025 free (bdistance->access_list);
11026 bgp_distance_free (bdistance);
11027
11028 rn->info = NULL;
11029 bgp_unlock_node (rn);
11030 bgp_unlock_node (rn);
11031
11032 return CMD_SUCCESS;
11033}
11034
paul718e3742002-12-13 20:15:29 +000011035/* Apply BGP information to distance method. */
11036u_char
11037bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11038{
11039 struct bgp_node *rn;
11040 struct prefix_ipv4 q;
11041 struct peer *peer;
11042 struct bgp_distance *bdistance;
11043 struct access_list *alist;
11044 struct bgp_static *bgp_static;
11045
11046 if (! bgp)
11047 return 0;
11048
11049 if (p->family != AF_INET)
11050 return 0;
11051
11052 peer = rinfo->peer;
11053
11054 if (peer->su.sa.sa_family != AF_INET)
11055 return 0;
11056
11057 memset (&q, 0, sizeof (struct prefix_ipv4));
11058 q.family = AF_INET;
11059 q.prefix = peer->su.sin.sin_addr;
11060 q.prefixlen = IPV4_MAX_BITLEN;
11061
11062 /* Check source address. */
11063 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11064 if (rn)
11065 {
11066 bdistance = rn->info;
11067 bgp_unlock_node (rn);
11068
11069 if (bdistance->access_list)
11070 {
11071 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11072 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11073 return bdistance->distance;
11074 }
11075 else
11076 return bdistance->distance;
11077 }
11078
11079 /* Backdoor check. */
11080 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11081 if (rn)
11082 {
11083 bgp_static = rn->info;
11084 bgp_unlock_node (rn);
11085
11086 if (bgp_static->backdoor)
11087 {
11088 if (bgp->distance_local)
11089 return bgp->distance_local;
11090 else
11091 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11092 }
11093 }
11094
11095 if (peer_sort (peer) == BGP_PEER_EBGP)
11096 {
11097 if (bgp->distance_ebgp)
11098 return bgp->distance_ebgp;
11099 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11100 }
11101 else
11102 {
11103 if (bgp->distance_ibgp)
11104 return bgp->distance_ibgp;
11105 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11106 }
11107}
11108
11109DEFUN (bgp_distance,
11110 bgp_distance_cmd,
11111 "distance bgp <1-255> <1-255> <1-255>",
11112 "Define an administrative distance\n"
11113 "BGP distance\n"
11114 "Distance for routes external to the AS\n"
11115 "Distance for routes internal to the AS\n"
11116 "Distance for local routes\n")
11117{
11118 struct bgp *bgp;
11119
11120 bgp = vty->index;
11121
11122 bgp->distance_ebgp = atoi (argv[0]);
11123 bgp->distance_ibgp = atoi (argv[1]);
11124 bgp->distance_local = atoi (argv[2]);
11125 return CMD_SUCCESS;
11126}
11127
11128DEFUN (no_bgp_distance,
11129 no_bgp_distance_cmd,
11130 "no distance bgp <1-255> <1-255> <1-255>",
11131 NO_STR
11132 "Define an administrative distance\n"
11133 "BGP distance\n"
11134 "Distance for routes external to the AS\n"
11135 "Distance for routes internal to the AS\n"
11136 "Distance for local routes\n")
11137{
11138 struct bgp *bgp;
11139
11140 bgp = vty->index;
11141
11142 bgp->distance_ebgp= 0;
11143 bgp->distance_ibgp = 0;
11144 bgp->distance_local = 0;
11145 return CMD_SUCCESS;
11146}
11147
11148ALIAS (no_bgp_distance,
11149 no_bgp_distance2_cmd,
11150 "no distance bgp",
11151 NO_STR
11152 "Define an administrative distance\n"
11153 "BGP distance\n")
11154
11155DEFUN (bgp_distance_source,
11156 bgp_distance_source_cmd,
11157 "distance <1-255> A.B.C.D/M",
11158 "Define an administrative distance\n"
11159 "Administrative distance\n"
11160 "IP source prefix\n")
11161{
11162 bgp_distance_set (vty, argv[0], argv[1], NULL);
11163 return CMD_SUCCESS;
11164}
11165
11166DEFUN (no_bgp_distance_source,
11167 no_bgp_distance_source_cmd,
11168 "no distance <1-255> A.B.C.D/M",
11169 NO_STR
11170 "Define an administrative distance\n"
11171 "Administrative distance\n"
11172 "IP source prefix\n")
11173{
11174 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11175 return CMD_SUCCESS;
11176}
11177
11178DEFUN (bgp_distance_source_access_list,
11179 bgp_distance_source_access_list_cmd,
11180 "distance <1-255> A.B.C.D/M WORD",
11181 "Define an administrative distance\n"
11182 "Administrative distance\n"
11183 "IP source prefix\n"
11184 "Access list name\n")
11185{
11186 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11187 return CMD_SUCCESS;
11188}
11189
11190DEFUN (no_bgp_distance_source_access_list,
11191 no_bgp_distance_source_access_list_cmd,
11192 "no distance <1-255> A.B.C.D/M WORD",
11193 NO_STR
11194 "Define an administrative distance\n"
11195 "Administrative distance\n"
11196 "IP source prefix\n"
11197 "Access list name\n")
11198{
11199 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11200 return CMD_SUCCESS;
11201}
11202
11203DEFUN (bgp_damp_set,
11204 bgp_damp_set_cmd,
11205 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11206 "BGP Specific commands\n"
11207 "Enable route-flap dampening\n"
11208 "Half-life time for the penalty\n"
11209 "Value to start reusing a route\n"
11210 "Value to start suppressing a route\n"
11211 "Maximum duration to suppress a stable route\n")
11212{
11213 struct bgp *bgp;
11214 int half = DEFAULT_HALF_LIFE * 60;
11215 int reuse = DEFAULT_REUSE;
11216 int suppress = DEFAULT_SUPPRESS;
11217 int max = 4 * half;
11218
11219 if (argc == 4)
11220 {
11221 half = atoi (argv[0]) * 60;
11222 reuse = atoi (argv[1]);
11223 suppress = atoi (argv[2]);
11224 max = atoi (argv[3]) * 60;
11225 }
11226 else if (argc == 1)
11227 {
11228 half = atoi (argv[0]) * 60;
11229 max = 4 * half;
11230 }
11231
11232 bgp = vty->index;
11233 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11234 half, reuse, suppress, max);
11235}
11236
11237ALIAS (bgp_damp_set,
11238 bgp_damp_set2_cmd,
11239 "bgp dampening <1-45>",
11240 "BGP Specific commands\n"
11241 "Enable route-flap dampening\n"
11242 "Half-life time for the penalty\n")
11243
11244ALIAS (bgp_damp_set,
11245 bgp_damp_set3_cmd,
11246 "bgp dampening",
11247 "BGP Specific commands\n"
11248 "Enable route-flap dampening\n")
11249
11250DEFUN (bgp_damp_unset,
11251 bgp_damp_unset_cmd,
11252 "no bgp dampening",
11253 NO_STR
11254 "BGP Specific commands\n"
11255 "Enable route-flap dampening\n")
11256{
11257 struct bgp *bgp;
11258
11259 bgp = vty->index;
11260 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11261}
11262
11263ALIAS (bgp_damp_unset,
11264 bgp_damp_unset2_cmd,
11265 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11266 NO_STR
11267 "BGP Specific commands\n"
11268 "Enable route-flap dampening\n"
11269 "Half-life time for the penalty\n"
11270 "Value to start reusing a route\n"
11271 "Value to start suppressing a route\n"
11272 "Maximum duration to suppress a stable route\n")
11273
11274DEFUN (show_ip_bgp_dampened_paths,
11275 show_ip_bgp_dampened_paths_cmd,
11276 "show ip bgp dampened-paths",
11277 SHOW_STR
11278 IP_STR
11279 BGP_STR
11280 "Display paths suppressed due to dampening\n")
11281{
ajs5a646652004-11-05 01:25:55 +000011282 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11283 NULL);
paul718e3742002-12-13 20:15:29 +000011284}
11285
11286DEFUN (show_ip_bgp_flap_statistics,
11287 show_ip_bgp_flap_statistics_cmd,
11288 "show ip bgp flap-statistics",
11289 SHOW_STR
11290 IP_STR
11291 BGP_STR
11292 "Display flap statistics of routes\n")
11293{
ajs5a646652004-11-05 01:25:55 +000011294 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11295 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011296}
11297
11298/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011299static int
paulfd79ac92004-10-13 05:06:08 +000011300bgp_clear_damp_route (struct vty *vty, const char *view_name,
11301 const char *ip_str, afi_t afi, safi_t safi,
11302 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011303{
11304 int ret;
11305 struct prefix match;
11306 struct bgp_node *rn;
11307 struct bgp_node *rm;
11308 struct bgp_info *ri;
11309 struct bgp_info *ri_temp;
11310 struct bgp *bgp;
11311 struct bgp_table *table;
11312
11313 /* BGP structure lookup. */
11314 if (view_name)
11315 {
11316 bgp = bgp_lookup_by_name (view_name);
11317 if (bgp == NULL)
11318 {
11319 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11320 return CMD_WARNING;
11321 }
11322 }
11323 else
11324 {
11325 bgp = bgp_get_default ();
11326 if (bgp == NULL)
11327 {
11328 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11329 return CMD_WARNING;
11330 }
11331 }
11332
11333 /* Check IP address argument. */
11334 ret = str2prefix (ip_str, &match);
11335 if (! ret)
11336 {
11337 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11338 return CMD_WARNING;
11339 }
11340
11341 match.family = afi2family (afi);
11342
11343 if (safi == SAFI_MPLS_VPN)
11344 {
11345 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11346 {
11347 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11348 continue;
11349
11350 if ((table = rn->info) != NULL)
11351 if ((rm = bgp_node_match (table, &match)) != NULL)
11352 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11353 {
11354 ri = rm->info;
11355 while (ri)
11356 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011357 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011358 {
11359 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011360 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011361 ri = ri_temp;
11362 }
11363 else
11364 ri = ri->next;
11365 }
11366 }
11367 }
11368 }
11369 else
11370 {
11371 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11372 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11373 {
11374 ri = rn->info;
11375 while (ri)
11376 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011377 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011378 {
11379 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011380 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011381 ri = ri_temp;
11382 }
11383 else
11384 ri = ri->next;
11385 }
11386 }
11387 }
11388
11389 return CMD_SUCCESS;
11390}
11391
11392DEFUN (clear_ip_bgp_dampening,
11393 clear_ip_bgp_dampening_cmd,
11394 "clear ip bgp dampening",
11395 CLEAR_STR
11396 IP_STR
11397 BGP_STR
11398 "Clear route flap dampening information\n")
11399{
11400 bgp_damp_info_clean ();
11401 return CMD_SUCCESS;
11402}
11403
11404DEFUN (clear_ip_bgp_dampening_prefix,
11405 clear_ip_bgp_dampening_prefix_cmd,
11406 "clear ip bgp dampening A.B.C.D/M",
11407 CLEAR_STR
11408 IP_STR
11409 BGP_STR
11410 "Clear route flap dampening information\n"
11411 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11412{
11413 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11414 SAFI_UNICAST, NULL, 1);
11415}
11416
11417DEFUN (clear_ip_bgp_dampening_address,
11418 clear_ip_bgp_dampening_address_cmd,
11419 "clear ip bgp dampening A.B.C.D",
11420 CLEAR_STR
11421 IP_STR
11422 BGP_STR
11423 "Clear route flap dampening information\n"
11424 "Network to clear damping information\n")
11425{
11426 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11427 SAFI_UNICAST, NULL, 0);
11428}
11429
11430DEFUN (clear_ip_bgp_dampening_address_mask,
11431 clear_ip_bgp_dampening_address_mask_cmd,
11432 "clear ip bgp dampening A.B.C.D A.B.C.D",
11433 CLEAR_STR
11434 IP_STR
11435 BGP_STR
11436 "Clear route flap dampening information\n"
11437 "Network to clear damping information\n"
11438 "Network mask\n")
11439{
11440 int ret;
11441 char prefix_str[BUFSIZ];
11442
11443 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11444 if (! ret)
11445 {
11446 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11447 return CMD_WARNING;
11448 }
11449
11450 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11451 SAFI_UNICAST, NULL, 0);
11452}
11453
paul94f2b392005-06-28 12:44:16 +000011454static int
paul718e3742002-12-13 20:15:29 +000011455bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11456 afi_t afi, safi_t safi, int *write)
11457{
11458 struct bgp_node *prn;
11459 struct bgp_node *rn;
11460 struct bgp_table *table;
11461 struct prefix *p;
11462 struct prefix_rd *prd;
11463 struct bgp_static *bgp_static;
11464 u_int32_t label;
11465 char buf[SU_ADDRSTRLEN];
11466 char rdbuf[RD_ADDRSTRLEN];
11467
11468 /* Network configuration. */
11469 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11470 if ((table = prn->info) != NULL)
11471 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11472 if ((bgp_static = rn->info) != NULL)
11473 {
11474 p = &rn->p;
11475 prd = (struct prefix_rd *) &prn->p;
11476
11477 /* "address-family" display. */
11478 bgp_config_write_family_header (vty, afi, safi, write);
11479
11480 /* "network" configuration display. */
11481 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11482 label = decode_label (bgp_static->tag);
11483
11484 vty_out (vty, " network %s/%d rd %s tag %d",
11485 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11486 p->prefixlen,
11487 rdbuf, label);
11488 vty_out (vty, "%s", VTY_NEWLINE);
11489 }
11490 return 0;
11491}
11492
11493/* Configuration of static route announcement and aggregate
11494 information. */
11495int
11496bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11497 afi_t afi, safi_t safi, int *write)
11498{
11499 struct bgp_node *rn;
11500 struct prefix *p;
11501 struct bgp_static *bgp_static;
11502 struct bgp_aggregate *bgp_aggregate;
11503 char buf[SU_ADDRSTRLEN];
11504
11505 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11506 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11507
11508 /* Network configuration. */
11509 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11510 if ((bgp_static = rn->info) != NULL)
11511 {
11512 p = &rn->p;
11513
11514 /* "address-family" display. */
11515 bgp_config_write_family_header (vty, afi, safi, write);
11516
11517 /* "network" configuration display. */
11518 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11519 {
11520 u_int32_t destination;
11521 struct in_addr netmask;
11522
11523 destination = ntohl (p->u.prefix4.s_addr);
11524 masklen2ip (p->prefixlen, &netmask);
11525 vty_out (vty, " network %s",
11526 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11527
11528 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11529 || (IN_CLASSB (destination) && p->prefixlen == 16)
11530 || (IN_CLASSA (destination) && p->prefixlen == 8)
11531 || p->u.prefix4.s_addr == 0)
11532 {
11533 /* Natural mask is not display. */
11534 }
11535 else
11536 vty_out (vty, " mask %s", inet_ntoa (netmask));
11537 }
11538 else
11539 {
11540 vty_out (vty, " network %s/%d",
11541 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11542 p->prefixlen);
11543 }
11544
11545 if (bgp_static->rmap.name)
11546 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011547 else
11548 {
11549 if (bgp_static->backdoor)
11550 vty_out (vty, " backdoor");
11551 if (bgp_static->ttl)
11552 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11553 }
paul718e3742002-12-13 20:15:29 +000011554
11555 vty_out (vty, "%s", VTY_NEWLINE);
11556 }
11557
11558 /* Aggregate-address configuration. */
11559 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11560 if ((bgp_aggregate = rn->info) != NULL)
11561 {
11562 p = &rn->p;
11563
11564 /* "address-family" display. */
11565 bgp_config_write_family_header (vty, afi, safi, write);
11566
11567 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11568 {
11569 struct in_addr netmask;
11570
11571 masklen2ip (p->prefixlen, &netmask);
11572 vty_out (vty, " aggregate-address %s %s",
11573 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11574 inet_ntoa (netmask));
11575 }
11576 else
11577 {
11578 vty_out (vty, " aggregate-address %s/%d",
11579 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11580 p->prefixlen);
11581 }
11582
11583 if (bgp_aggregate->as_set)
11584 vty_out (vty, " as-set");
11585
11586 if (bgp_aggregate->summary_only)
11587 vty_out (vty, " summary-only");
11588
11589 vty_out (vty, "%s", VTY_NEWLINE);
11590 }
11591
11592 return 0;
11593}
11594
11595int
11596bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11597{
11598 struct bgp_node *rn;
11599 struct bgp_distance *bdistance;
11600
11601 /* Distance configuration. */
11602 if (bgp->distance_ebgp
11603 && bgp->distance_ibgp
11604 && bgp->distance_local
11605 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11606 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11607 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11608 vty_out (vty, " distance bgp %d %d %d%s",
11609 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11610 VTY_NEWLINE);
11611
11612 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11613 if ((bdistance = rn->info) != NULL)
11614 {
11615 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11616 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11617 bdistance->access_list ? bdistance->access_list : "",
11618 VTY_NEWLINE);
11619 }
11620
11621 return 0;
11622}
11623
11624/* Allocate routing table structure and install commands. */
11625void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011626bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011627{
11628 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011629 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011630
11631 /* IPv4 BGP commands. */
11632 install_element (BGP_NODE, &bgp_network_cmd);
11633 install_element (BGP_NODE, &bgp_network_mask_cmd);
11634 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11635 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11636 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11637 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11638 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11639 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11640 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011641 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11642 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11643 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11644 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11645 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11646 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011647 install_element (BGP_NODE, &no_bgp_network_cmd);
11648 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11649 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11650 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11651 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11652 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11653 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11654 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11655 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011656 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11657 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11658 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11659 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11660 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11661 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011662
11663 install_element (BGP_NODE, &aggregate_address_cmd);
11664 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11665 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11666 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11667 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11668 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11669 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11670 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11671 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11672 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11673 install_element (BGP_NODE, &no_aggregate_address_cmd);
11674 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11675 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11676 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11677 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11678 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11679 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11680 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11681 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11682 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11683
11684 /* IPv4 unicast configuration. */
11685 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11686 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11687 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11688 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11689 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11690 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011691 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11692 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11693 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11694 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11695 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11696 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 +000011697 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11698 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11699 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11700 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11701 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011702 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11703 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11704 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11705 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11706 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11707 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 +000011708 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11709 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11710 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11711 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11712 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11713 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11714 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11715 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11716 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11717 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11718 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11719 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11720 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11721 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11722 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11723 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11724 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11725 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11726 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11727 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11728
11729 /* IPv4 multicast configuration. */
11730 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11731 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11732 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11733 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11734 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11735 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011736 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11737 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11738 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11739 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11740 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11741 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 +000011742 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11743 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11744 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11745 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11746 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11747 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011748 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11749 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11750 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11751 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11752 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11753 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 +000011754 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11755 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11756 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11757 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11758 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11759 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11760 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11761 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11762 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11763 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11764 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11765 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11766 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11767 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11768 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11769 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11770 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11771 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11772 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11773 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11774
11775 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11776 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11777 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11778 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11779 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11780 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11781 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11782 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11783 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11784 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11785 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11786 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11787 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11788 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11789 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11790 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11791 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11792 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11793 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11794 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11795 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11796 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11797 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11798 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11799 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11800 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11801 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11802 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11803 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11804 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11805 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11806 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11807 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11808 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11809 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11810 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11811 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11812 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11813 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11814 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11815 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11816 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11817 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11818 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11819 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11820 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11821 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11822 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11823 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11824 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11825 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11826 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11827 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11828 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11829 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11830 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11831 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11832 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11833 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11834 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11835 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11836 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11837 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11838 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11839 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11840 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11841 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011842 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11843 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11844 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011845 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11846 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011847 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11848 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11849 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011850
11851 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11852 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11853 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11854 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11855 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11856 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11857 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11858 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11859 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11860 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11861 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11862 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11863 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11864 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11865 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11866 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11867 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11868 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11869 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11870 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11871 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11872 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11873 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11874 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11875 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11876 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11877 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11878 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11879 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11880 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011881
11882 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11883 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11884 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11885 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11886 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11887 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11888 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11889 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11890 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11891 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11892 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11893 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11894 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11895 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11896 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11897 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11898 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11899 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11900 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11901 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11902 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11903 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11904 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11905 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11906 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11907 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11908 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11909 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11910 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11911 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11912 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11913 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11914 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11915 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11916 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11917 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11918 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11919 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11920 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11921 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11922 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11923 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11924 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11925 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11926 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11927 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11928 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11929 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11930 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11931 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11932 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11933 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11934 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11935 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11936 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11937 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11938 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11939 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11940 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11941 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11942 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11943 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11944 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11945 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11946 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11947 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11948 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011949 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11950 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11951 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011952 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11953 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011954 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11955 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11956 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011957
11958 /* BGP dampening clear commands */
11959 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11960 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11961 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11962 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11963
Paul Jakmaff7924f2006-09-04 01:10:36 +000011964 /* prefix count */
11965 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11966 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11967 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011968#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011969 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11970
paul718e3742002-12-13 20:15:29 +000011971 /* New config IPv6 BGP commands. */
11972 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11973 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011974 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011975 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11976 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011977 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011978
11979 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11980 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11981 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11982 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11983
11984 /* Old config IPv6 BGP commands. */
11985 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11986 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11987
11988 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11989 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11990 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11991 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11992
11993 install_element (VIEW_NODE, &show_bgp_cmd);
11994 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11995 install_element (VIEW_NODE, &show_bgp_route_cmd);
11996 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11997 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11998 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11999 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12000 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12001 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12002 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12003 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12004 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12005 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12006 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12007 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12008 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12009 install_element (VIEW_NODE, &show_bgp_community_cmd);
12010 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12011 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12012 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12013 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12014 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12015 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12016 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12017 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12018 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12019 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12020 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12021 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12022 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12023 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12024 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12025 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12026 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12027 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12028 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12029 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12030 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12031 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12032 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12033 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12034 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12035 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12036 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12037 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12038 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012039 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12040 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12041 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12042 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012043 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
12044 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
12045 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012046 install_element (VIEW_NODE, &show_bgp_view_cmd);
12047 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12048 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12049 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12050 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12051 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12052 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12053 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12054 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12055 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12056 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12057 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12058 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12059 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12060 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12061 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12062 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12063 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012064 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
12065 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
12066 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012067
12068 /* Restricted:
12069 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12070 */
12071 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12072 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
12073 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12074 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
12075 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12076 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12077 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12078 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12079 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12080 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12081 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12082 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12083 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12084 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12085 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12086 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12087 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12088 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12089 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12090 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12091 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
12092 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
12093 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12094 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12095 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12096 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12097 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12098 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12099 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
12100 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012101
12102 install_element (ENABLE_NODE, &show_bgp_cmd);
12103 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
12104 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12105 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
12106 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12107 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
12108 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12109 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12110 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12111 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12112 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12113 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12114 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12115 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12116 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12117 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12118 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12119 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12120 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12121 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12122 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12123 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12124 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12125 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12126 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12127 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12128 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12129 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12130 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12131 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12132 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12133 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12134 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12135 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12136 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12137 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12138 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12139 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12140 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12141 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12142 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12143 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12144 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12145 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12146 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12147 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012148 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12149 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12150 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12151 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012152 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12153 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12154 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012155 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12156 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12157 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12158 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12159 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12160 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12161 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12162 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12163 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12164 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12165 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12166 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12167 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12168 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12169 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12170 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12171 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12172 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012173 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12174 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12175 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012176
12177 /* Statistics */
12178 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12179 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12180 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12181 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12182
paul718e3742002-12-13 20:15:29 +000012183 /* old command */
12184 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12185 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12186 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12187 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12188 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12189 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12190 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12191 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12192 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12193 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12194 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12195 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12196 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12197 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12198 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12199 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12200 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12201 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12202 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12203 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12204 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12205 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12206 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12207 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12208 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12209 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12210 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12211 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12212 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12213 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12214 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12215 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12216 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12217 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12218 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12219 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012220
paul718e3742002-12-13 20:15:29 +000012221 /* old command */
12222 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12223 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12224 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12225 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12226 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12227 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12228 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12229 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12230 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12231 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12232 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12233 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12234 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12235 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12236 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12237 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12238 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12239 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12240 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12241 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12242 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12243 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12244 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12245 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12246 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12247 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12248 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12249 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12250 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12251 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12252 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12253 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12254 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12255 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12256 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12257 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12258
12259 /* old command */
12260 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12261 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12262 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12263 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12264
12265 /* old command */
12266 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12267 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12268 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12269 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12270
12271 /* old command */
12272 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12273 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12274 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12275 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12276#endif /* HAVE_IPV6 */
12277
12278 install_element (BGP_NODE, &bgp_distance_cmd);
12279 install_element (BGP_NODE, &no_bgp_distance_cmd);
12280 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12281 install_element (BGP_NODE, &bgp_distance_source_cmd);
12282 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12283 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12284 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12285
12286 install_element (BGP_NODE, &bgp_damp_set_cmd);
12287 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12288 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12289 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12290 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12291 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12292 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12293 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12294 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12295 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12296}
Chris Caputo228da422009-07-18 05:44:03 +000012297
12298void
12299bgp_route_finish (void)
12300{
12301 bgp_table_unlock (bgp_distance_table);
12302 bgp_distance_table = NULL;
12303}