blob: 8b0a3bf9c16d5a88bbc94a5c814702449c07c3a4 [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;
paul200df112005-06-01 11:17:05 +00001617 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001618 bm->process_main_queue->spec.max_retries = 0;
1619 bm->process_main_queue->spec.hold = 50;
1620
1621 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1622 sizeof (struct work_queue *));
1623 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001624}
1625
1626void
paulfee0f4c2004-09-13 05:12:46 +00001627bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1628{
paul200df112005-06-01 11:17:05 +00001629 struct bgp_process_queue *pqnode;
1630
1631 /* already scheduled for processing? */
1632 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1633 return;
1634
1635 if ( (bm->process_main_queue == NULL) ||
1636 (bm->process_rsclient_queue == NULL) )
1637 bgp_process_queue_init ();
1638
1639 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1640 sizeof (struct bgp_process_queue));
1641 if (!pqnode)
1642 return;
Chris Caputo228da422009-07-18 05:44:03 +00001643
1644 /* all unlocked in bgp_processq_del */
1645 bgp_table_lock (rn->table);
1646 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001647 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001648 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001649 pqnode->afi = afi;
1650 pqnode->safi = safi;
1651
paulfee0f4c2004-09-13 05:12:46 +00001652 switch (rn->table->type)
1653 {
paul200df112005-06-01 11:17:05 +00001654 case BGP_TABLE_MAIN:
1655 work_queue_add (bm->process_main_queue, pqnode);
1656 break;
1657 case BGP_TABLE_RSCLIENT:
1658 work_queue_add (bm->process_rsclient_queue, pqnode);
1659 break;
paulfee0f4c2004-09-13 05:12:46 +00001660 }
paul200df112005-06-01 11:17:05 +00001661
1662 return;
paulfee0f4c2004-09-13 05:12:46 +00001663}
hasso0a486e52005-02-01 20:57:17 +00001664
paul94f2b392005-06-28 12:44:16 +00001665static int
hasso0a486e52005-02-01 20:57:17 +00001666bgp_maximum_prefix_restart_timer (struct thread *thread)
1667{
1668 struct peer *peer;
1669
1670 peer = THREAD_ARG (thread);
1671 peer->t_pmax_restart = NULL;
1672
1673 if (BGP_DEBUG (events, EVENTS))
1674 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1675 peer->host);
1676
1677 peer_clear (peer);
1678
1679 return 0;
1680}
1681
paulfee0f4c2004-09-13 05:12:46 +00001682int
paul5228ad22004-06-04 17:58:18 +00001683bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1684 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001685{
hassoe0701b72004-05-20 09:19:34 +00001686 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1687 return 0;
1688
1689 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001690 {
hassoe0701b72004-05-20 09:19:34 +00001691 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1692 && ! always)
1693 return 0;
paul718e3742002-12-13 20:15:29 +00001694
hassoe0701b72004-05-20 09:19:34 +00001695 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001696 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1697 "limit %ld", afi_safi_print (afi, safi), peer->host,
1698 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001699 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001700
hassoe0701b72004-05-20 09:19:34 +00001701 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1702 return 0;
paul718e3742002-12-13 20:15:29 +00001703
hassoe0701b72004-05-20 09:19:34 +00001704 {
paul5228ad22004-06-04 17:58:18 +00001705 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001706
1707 if (safi == SAFI_MPLS_VPN)
1708 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001709
1710 ndata[0] = (afi >> 8);
1711 ndata[1] = afi;
1712 ndata[2] = safi;
1713 ndata[3] = (peer->pmax[afi][safi] >> 24);
1714 ndata[4] = (peer->pmax[afi][safi] >> 16);
1715 ndata[5] = (peer->pmax[afi][safi] >> 8);
1716 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001717
1718 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1719 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1720 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1721 }
hasso0a486e52005-02-01 20:57:17 +00001722
1723 /* restart timer start */
1724 if (peer->pmax_restart[afi][safi])
1725 {
1726 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1727
1728 if (BGP_DEBUG (events, EVENTS))
1729 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1730 peer->host, peer->v_pmax_restart);
1731
1732 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1733 peer->v_pmax_restart);
1734 }
1735
hassoe0701b72004-05-20 09:19:34 +00001736 return 1;
paul718e3742002-12-13 20:15:29 +00001737 }
hassoe0701b72004-05-20 09:19:34 +00001738 else
1739 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1740
1741 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1742 {
1743 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1744 && ! always)
1745 return 0;
1746
1747 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001748 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1749 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1750 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001751 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1752 }
1753 else
1754 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001755 return 0;
1756}
1757
paulb40d9392005-08-22 22:34:41 +00001758/* Unconditionally remove the route from the RIB, without taking
1759 * damping into consideration (eg, because the session went down)
1760 */
paul94f2b392005-06-28 12:44:16 +00001761static void
paul718e3742002-12-13 20:15:29 +00001762bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1763 afi_t afi, safi_t safi)
1764{
paul902212c2006-02-05 17:51:19 +00001765 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1766
1767 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1768 bgp_info_delete (rn, ri); /* keep historical info */
1769
paulb40d9392005-08-22 22:34:41 +00001770 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001771}
1772
paul94f2b392005-06-28 12:44:16 +00001773static void
paul718e3742002-12-13 20:15:29 +00001774bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001775 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001776{
paul718e3742002-12-13 20:15:29 +00001777 int status = BGP_DAMP_NONE;
1778
paulb40d9392005-08-22 22:34:41 +00001779 /* apply dampening, if result is suppressed, we'll be retaining
1780 * the bgp_info in the RIB for historical reference.
1781 */
1782 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1783 && peer_sort (peer) == BGP_PEER_EBGP)
1784 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1785 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001786 {
paul902212c2006-02-05 17:51:19 +00001787 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1788 return;
1789 }
1790
1791 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001792}
1793
paul94f2b392005-06-28 12:44:16 +00001794static void
paulfee0f4c2004-09-13 05:12:46 +00001795bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1796 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1797 int sub_type, struct prefix_rd *prd, u_char *tag)
1798{
1799 struct bgp_node *rn;
1800 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001801 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001802 struct attr *attr_new;
1803 struct attr *attr_new2;
1804 struct bgp_info *ri;
1805 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001806 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001807 char buf[SU_ADDRSTRLEN];
1808
1809 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1810 if (peer == rsclient)
1811 return;
1812
1813 bgp = peer->bgp;
1814 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1815
1816 /* Check previously received route. */
1817 for (ri = rn->info; ri; ri = ri->next)
1818 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1819 break;
1820
1821 /* AS path loop check. */
1822 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1823 {
1824 reason = "as-path contains our own AS;";
1825 goto filtered;
1826 }
1827
1828 /* Route reflector originator ID check. */
1829 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001830 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001831 {
1832 reason = "originator is us;";
1833 goto filtered;
1834 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001835
1836 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001837
1838 /* Apply export policy. */
1839 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1840 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1841 {
1842 reason = "export-policy;";
1843 goto filtered;
1844 }
1845
1846 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001847
paulfee0f4c2004-09-13 05:12:46 +00001848 /* Apply import policy. */
1849 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1850 {
1851 bgp_attr_unintern (attr_new2);
1852
1853 reason = "import-policy;";
1854 goto filtered;
1855 }
1856
1857 attr_new = bgp_attr_intern (&new_attr);
1858 bgp_attr_unintern (attr_new2);
1859
1860 /* IPv4 unicast next hop check. */
1861 if (afi == AFI_IP && safi == SAFI_UNICAST)
1862 {
1863 /* Next hop must not be 0.0.0.0 nor Class E address. */
1864 if (new_attr.nexthop.s_addr == 0
1865 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1866 {
1867 bgp_attr_unintern (attr_new);
1868
1869 reason = "martian next-hop;";
1870 goto filtered;
1871 }
1872 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001873
1874 /* new_attr isn't passed to any functions after here */
1875 bgp_attr_extra_free (&new_attr);
1876
paulfee0f4c2004-09-13 05:12:46 +00001877 /* If the update is implicit withdraw. */
1878 if (ri)
1879 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001880 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001881
1882 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001883 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1884 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001885 {
1886
Paul Jakma1a392d42006-09-07 00:24:49 +00001887 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001888
1889 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001890 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001891 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1892 peer->host,
1893 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1894 p->prefixlen, rsclient->host);
1895
Chris Caputo228da422009-07-18 05:44:03 +00001896 bgp_unlock_node (rn);
1897 bgp_attr_unintern (attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001898
Chris Caputo228da422009-07-18 05:44:03 +00001899 return;
paulfee0f4c2004-09-13 05:12:46 +00001900 }
1901
Paul Jakma16d2e242007-04-10 19:32:10 +00001902 /* Withdraw/Announce before we fully processed the withdraw */
1903 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1904 bgp_info_restore (rn, ri);
1905
paulfee0f4c2004-09-13 05:12:46 +00001906 /* Received Logging. */
1907 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001908 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001909 peer->host,
1910 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1911 p->prefixlen, rsclient->host);
1912
1913 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001914 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001915
1916 /* Update to new attribute. */
1917 bgp_attr_unintern (ri->attr);
1918 ri->attr = attr_new;
1919
1920 /* Update MPLS tag. */
1921 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001922 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001923
Paul Jakma1a392d42006-09-07 00:24:49 +00001924 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001925
1926 /* Process change. */
1927 bgp_process (bgp, rn, afi, safi);
1928 bgp_unlock_node (rn);
1929
1930 return;
1931 }
1932
1933 /* Received Logging. */
1934 if (BGP_DEBUG (update, UPDATE_IN))
1935 {
ajsd2c1f162004-12-08 21:10:20 +00001936 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001937 peer->host,
1938 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1939 p->prefixlen, rsclient->host);
1940 }
1941
1942 /* Make new BGP info. */
1943 new = bgp_info_new ();
1944 new->type = type;
1945 new->sub_type = sub_type;
1946 new->peer = peer;
1947 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001948 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001949
1950 /* Update MPLS tag. */
1951 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001952 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001953
Paul Jakma1a392d42006-09-07 00:24:49 +00001954 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001955
1956 /* Register new BGP information. */
1957 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001958
1959 /* route_node_get lock */
1960 bgp_unlock_node (rn);
1961
paulfee0f4c2004-09-13 05:12:46 +00001962 /* Process change. */
1963 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001964
1965 bgp_attr_extra_free (&new_attr);
1966
paulfee0f4c2004-09-13 05:12:46 +00001967 return;
1968
1969 filtered:
1970
1971 /* This BGP update is filtered. Log the reason then update BGP entry. */
1972 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001973 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001974 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1975 peer->host,
1976 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1977 p->prefixlen, rsclient->host, reason);
1978
1979 if (ri)
paulb40d9392005-08-22 22:34:41 +00001980 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001981
1982 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001983
1984 if (new_attr.extra)
1985 bgp_attr_extra_free (&new_attr);
1986
paulfee0f4c2004-09-13 05:12:46 +00001987 return;
1988}
1989
paul94f2b392005-06-28 12:44:16 +00001990static void
paulfee0f4c2004-09-13 05:12:46 +00001991bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1992 struct peer *peer, struct prefix *p, int type, int sub_type,
1993 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00001994{
paulfee0f4c2004-09-13 05:12:46 +00001995 struct bgp_node *rn;
1996 struct bgp_info *ri;
1997 char buf[SU_ADDRSTRLEN];
1998
1999 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002000 return;
paulfee0f4c2004-09-13 05:12:46 +00002001
2002 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2003
2004 /* Lookup withdrawn route. */
2005 for (ri = rn->info; ri; ri = ri->next)
2006 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2007 break;
2008
2009 /* Withdraw specified route from routing table. */
2010 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002011 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002012 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002013 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002014 "%s Can't find the route %s/%d", peer->host,
2015 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2016 p->prefixlen);
2017
2018 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002019 bgp_unlock_node (rn);
2020}
paulfee0f4c2004-09-13 05:12:46 +00002021
paul94f2b392005-06-28 12:44:16 +00002022static int
paulfee0f4c2004-09-13 05:12:46 +00002023bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002024 afi_t afi, safi_t safi, int type, int sub_type,
2025 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2026{
2027 int ret;
2028 int aspath_loop_count = 0;
2029 struct bgp_node *rn;
2030 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002031 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002032 struct attr *attr_new;
2033 struct bgp_info *ri;
2034 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002035 const char *reason;
paul718e3742002-12-13 20:15:29 +00002036 char buf[SU_ADDRSTRLEN];
2037
2038 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002039 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002040
paul718e3742002-12-13 20:15:29 +00002041 /* When peer's soft reconfiguration enabled. Record input packet in
2042 Adj-RIBs-In. */
2043 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2044 && peer != bgp->peer_self && ! soft_reconfig)
2045 bgp_adj_in_set (rn, peer, attr);
2046
2047 /* Check previously received route. */
2048 for (ri = rn->info; ri; ri = ri->next)
2049 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2050 break;
2051
2052 /* AS path local-as loop check. */
2053 if (peer->change_local_as)
2054 {
2055 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2056 aspath_loop_count = 1;
2057
2058 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2059 {
2060 reason = "as-path contains our own AS;";
2061 goto filtered;
2062 }
2063 }
2064
2065 /* AS path loop check. */
2066 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2067 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2068 && aspath_loop_check(attr->aspath, bgp->confed_id)
2069 > peer->allowas_in[afi][safi]))
2070 {
2071 reason = "as-path contains our own AS;";
2072 goto filtered;
2073 }
2074
2075 /* Route reflector originator ID check. */
2076 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002077 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002078 {
2079 reason = "originator is us;";
2080 goto filtered;
2081 }
2082
2083 /* Route reflector cluster ID check. */
2084 if (bgp_cluster_filter (peer, attr))
2085 {
2086 reason = "reflected from the same cluster;";
2087 goto filtered;
2088 }
2089
2090 /* Apply incoming filter. */
2091 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2092 {
2093 reason = "filter;";
2094 goto filtered;
2095 }
2096
2097 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002098 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002099
2100 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2101 {
2102 reason = "route-map;";
2103 goto filtered;
2104 }
2105
2106 /* IPv4 unicast next hop check. */
2107 if (afi == AFI_IP && safi == SAFI_UNICAST)
2108 {
2109 /* If the peer is EBGP and nexthop is not on connected route,
2110 discard it. */
2111 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2112 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002113 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002114 {
2115 reason = "non-connected next-hop;";
2116 goto filtered;
2117 }
2118
2119 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2120 must not be my own address. */
2121 if (bgp_nexthop_self (afi, &new_attr)
2122 || new_attr.nexthop.s_addr == 0
2123 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2124 {
2125 reason = "martian next-hop;";
2126 goto filtered;
2127 }
2128 }
2129
2130 attr_new = bgp_attr_intern (&new_attr);
2131
2132 /* If the update is implicit withdraw. */
2133 if (ri)
2134 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002135 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002136
2137 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002138 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2139 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002140 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002141 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002142
2143 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2144 && peer_sort (peer) == BGP_PEER_EBGP
2145 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2146 {
2147 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002148 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002149 peer->host,
2150 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2151 p->prefixlen);
2152
paul902212c2006-02-05 17:51:19 +00002153 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2154 {
2155 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2156 bgp_process (bgp, rn, afi, safi);
2157 }
paul718e3742002-12-13 20:15:29 +00002158 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002159 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002160 {
2161 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002162 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002163 "%s rcvd %s/%d...duplicate ignored",
2164 peer->host,
2165 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2166 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002167
2168 /* graceful restart STALE flag unset. */
2169 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2170 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002171 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002172 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002173 }
paul718e3742002-12-13 20:15:29 +00002174 }
2175
2176 bgp_unlock_node (rn);
2177 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002178 bgp_attr_extra_free (&new_attr);
2179
paul718e3742002-12-13 20:15:29 +00002180 return 0;
2181 }
2182
Paul Jakma16d2e242007-04-10 19:32:10 +00002183 /* Withdraw/Announce before we fully processed the withdraw */
2184 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2185 {
2186 if (BGP_DEBUG (update, UPDATE_IN))
2187 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2188 peer->host,
2189 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2190 p->prefixlen);
2191 bgp_info_restore (rn, ri);
2192 }
2193
paul718e3742002-12-13 20:15:29 +00002194 /* Received Logging. */
2195 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002196 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002197 peer->host,
2198 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2199 p->prefixlen);
2200
hasso93406d82005-02-02 14:40:33 +00002201 /* graceful restart STALE flag unset. */
2202 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002203 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002204
paul718e3742002-12-13 20:15:29 +00002205 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002206 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002207
2208 /* implicit withdraw, decrement aggregate and pcount here.
2209 * only if update is accepted, they'll increment below.
2210 */
paul902212c2006-02-05 17:51:19 +00002211 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2212
paul718e3742002-12-13 20:15:29 +00002213 /* Update bgp route dampening information. */
2214 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2215 && peer_sort (peer) == BGP_PEER_EBGP)
2216 {
2217 /* This is implicit withdraw so we should update dampening
2218 information. */
2219 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2220 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002221 }
2222
paul718e3742002-12-13 20:15:29 +00002223 /* Update to new attribute. */
2224 bgp_attr_unintern (ri->attr);
2225 ri->attr = attr_new;
2226
2227 /* Update MPLS tag. */
2228 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002229 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002230
2231 /* Update bgp route dampening information. */
2232 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2233 && peer_sort (peer) == BGP_PEER_EBGP)
2234 {
2235 /* Now we do normal update dampening. */
2236 ret = bgp_damp_update (ri, rn, afi, safi);
2237 if (ret == BGP_DAMP_SUPPRESSED)
2238 {
2239 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002240 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002241 return 0;
2242 }
2243 }
2244
2245 /* Nexthop reachability check. */
2246 if ((afi == AFI_IP || afi == AFI_IP6)
2247 && safi == SAFI_UNICAST
2248 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002249 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002250 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002251 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002252 {
2253 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002254 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002255 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002256 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002257 }
2258 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002259 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002260
2261 /* Process change. */
2262 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2263
2264 bgp_process (bgp, rn, afi, safi);
2265 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002266 bgp_attr_extra_free (&new_attr);
2267
paul718e3742002-12-13 20:15:29 +00002268 return 0;
2269 }
2270
2271 /* Received Logging. */
2272 if (BGP_DEBUG (update, UPDATE_IN))
2273 {
ajsd2c1f162004-12-08 21:10:20 +00002274 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002275 peer->host,
2276 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2277 p->prefixlen);
2278 }
2279
paul718e3742002-12-13 20:15:29 +00002280 /* Make new BGP info. */
2281 new = bgp_info_new ();
2282 new->type = type;
2283 new->sub_type = sub_type;
2284 new->peer = peer;
2285 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002286 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002287
2288 /* Update MPLS tag. */
2289 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002290 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002291
2292 /* Nexthop reachability check. */
2293 if ((afi == AFI_IP || afi == AFI_IP6)
2294 && safi == SAFI_UNICAST
2295 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002296 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002297 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002298 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002299 {
2300 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002301 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002302 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002303 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002304 }
2305 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002306 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002307
paul902212c2006-02-05 17:51:19 +00002308 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002309 bgp_aggregate_increment (bgp, p, new, afi, safi);
2310
2311 /* Register new BGP information. */
2312 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002313
2314 /* route_node_get lock */
2315 bgp_unlock_node (rn);
2316
Paul Jakmafb982c22007-05-04 20:15:47 +00002317 bgp_attr_extra_free (&new_attr);
2318
paul718e3742002-12-13 20:15:29 +00002319 /* If maximum prefix count is configured and current prefix
2320 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002321 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2322 return -1;
paul718e3742002-12-13 20:15:29 +00002323
2324 /* Process change. */
2325 bgp_process (bgp, rn, afi, safi);
2326
2327 return 0;
2328
2329 /* This BGP update is filtered. Log the reason then update BGP
2330 entry. */
2331 filtered:
2332 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002333 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002334 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2335 peer->host,
2336 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2337 p->prefixlen, reason);
2338
2339 if (ri)
paulb40d9392005-08-22 22:34:41 +00002340 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002341
2342 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002343
2344 bgp_attr_extra_free (&new_attr);
2345
paul718e3742002-12-13 20:15:29 +00002346 return 0;
2347}
2348
2349int
paulfee0f4c2004-09-13 05:12:46 +00002350bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2351 afi_t afi, safi_t safi, int type, int sub_type,
2352 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2353{
2354 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002355 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002356 struct bgp *bgp;
2357 int ret;
2358
2359 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2360 soft_reconfig);
2361
2362 bgp = peer->bgp;
2363
2364 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002365 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002366 {
2367 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2368 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2369 sub_type, prd, tag);
2370 }
2371
2372 return ret;
2373}
2374
2375int
paul718e3742002-12-13 20:15:29 +00002376bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002377 afi_t afi, safi_t safi, int type, int sub_type,
2378 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002379{
2380 struct bgp *bgp;
2381 char buf[SU_ADDRSTRLEN];
2382 struct bgp_node *rn;
2383 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002384 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002385 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002386
2387 bgp = peer->bgp;
2388
paulfee0f4c2004-09-13 05:12:46 +00002389 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002390 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002391 {
2392 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2393 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2394 }
2395
paul718e3742002-12-13 20:15:29 +00002396 /* Logging. */
2397 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002398 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002399 peer->host,
2400 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2401 p->prefixlen);
2402
2403 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002404 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002405
2406 /* If peer is soft reconfiguration enabled. Record input packet for
2407 further calculation. */
2408 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2409 && peer != bgp->peer_self)
2410 bgp_adj_in_unset (rn, peer);
2411
2412 /* Lookup withdrawn route. */
2413 for (ri = rn->info; ri; ri = ri->next)
2414 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2415 break;
2416
2417 /* Withdraw specified route from routing table. */
2418 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002419 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002420 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002421 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002422 "%s Can't find the route %s/%d", peer->host,
2423 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2424 p->prefixlen);
2425
2426 /* Unlock bgp_node_get() lock. */
2427 bgp_unlock_node (rn);
2428
2429 return 0;
2430}
2431
2432void
2433bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2434{
2435 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002436 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002437 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002438 struct prefix p;
2439 struct bgp_info binfo;
2440 struct peer *from;
2441 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002442
Paul Jakmab2497022007-06-14 11:17:58 +00002443 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002444 return;
2445
paul718e3742002-12-13 20:15:29 +00002446 bgp = peer->bgp;
2447 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002448
paul718e3742002-12-13 20:15:29 +00002449 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2450 aspath = attr.aspath;
2451 attr.local_pref = bgp->default_local_pref;
2452 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2453
2454 if (afi == AFI_IP)
2455 str2prefix ("0.0.0.0/0", &p);
2456#ifdef HAVE_IPV6
2457 else if (afi == AFI_IP6)
2458 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002459 struct attr_extra *ae;
2460 attr.extra = NULL;
2461
2462 ae = bgp_attr_extra_get (&attr);
2463 attr.extra = ae;
2464
paul718e3742002-12-13 20:15:29 +00002465 str2prefix ("::/0", &p);
2466
2467 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002468 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002469 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002470 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002471
2472 /* If the peer is on shared nextwork and we have link-local
2473 nexthop set it. */
2474 if (peer->shared_network
2475 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2476 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002477 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002478 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002479 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002480 }
2481 }
2482#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002483
2484 if (peer->default_rmap[afi][safi].name)
2485 {
2486 binfo.peer = bgp->peer_self;
2487 binfo.attr = &attr;
2488
paulfee0f4c2004-09-13 05:12:46 +00002489 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2490
paul718e3742002-12-13 20:15:29 +00002491 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2492 RMAP_BGP, &binfo);
2493
paulfee0f4c2004-09-13 05:12:46 +00002494 bgp->peer_self->rmap_type = 0;
2495
paul718e3742002-12-13 20:15:29 +00002496 if (ret == RMAP_DENYMATCH)
2497 {
2498 bgp_attr_flush (&attr);
2499 withdraw = 1;
2500 }
2501 }
2502
2503 if (withdraw)
2504 {
2505 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2506 bgp_default_withdraw_send (peer, afi, safi);
2507 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2508 }
2509 else
2510 {
2511 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2512 bgp_default_update_send (peer, &attr, afi, safi, from);
2513 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002514
2515 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002516 aspath_unintern (aspath);
2517}
2518
2519static void
2520bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002521 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002522{
2523 struct bgp_node *rn;
2524 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002525 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002526
paul718e3742002-12-13 20:15:29 +00002527 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002528 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002529
2530 if (safi != SAFI_MPLS_VPN
2531 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2532 bgp_default_originate (peer, afi, safi, 0);
2533
2534 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2535 for (ri = rn->info; ri; ri = ri->next)
2536 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2537 {
paulfee0f4c2004-09-13 05:12:46 +00002538 if ( (rsclient) ?
2539 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2540 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002541 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2542 else
2543 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002544
2545 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002546 }
2547}
2548
2549void
2550bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2551{
2552 struct bgp_node *rn;
2553 struct bgp_table *table;
2554
2555 if (peer->status != Established)
2556 return;
2557
2558 if (! peer->afc_nego[afi][safi])
2559 return;
2560
2561 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2562 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2563 return;
2564
2565 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002566 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002567 else
2568 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2569 rn = bgp_route_next(rn))
2570 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002571 bgp_announce_table (peer, afi, safi, table, 0);
2572
2573 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2574 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002575}
2576
2577void
2578bgp_announce_route_all (struct peer *peer)
2579{
2580 afi_t afi;
2581 safi_t safi;
2582
2583 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2584 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2585 bgp_announce_route (peer, afi, safi);
2586}
2587
2588static void
paulfee0f4c2004-09-13 05:12:46 +00002589bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2590 safi_t safi, struct bgp_table *table)
2591{
2592 struct bgp_node *rn;
2593 struct bgp_adj_in *ain;
2594
2595 if (! table)
2596 table = rsclient->bgp->rib[afi][safi];
2597
2598 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2599 for (ain = rn->adj_in; ain; ain = ain->next)
2600 {
2601 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2602 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2603 }
2604}
2605
2606void
2607bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2608{
2609 struct bgp_table *table;
2610 struct bgp_node *rn;
2611
2612 if (safi != SAFI_MPLS_VPN)
2613 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2614
2615 else
2616 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2617 rn = bgp_route_next (rn))
2618 if ((table = rn->info) != NULL)
2619 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2620}
2621
2622static void
paul718e3742002-12-13 20:15:29 +00002623bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2624 struct bgp_table *table)
2625{
2626 int ret;
2627 struct bgp_node *rn;
2628 struct bgp_adj_in *ain;
2629
2630 if (! table)
2631 table = peer->bgp->rib[afi][safi];
2632
2633 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2634 for (ain = rn->adj_in; ain; ain = ain->next)
2635 {
2636 if (ain->peer == peer)
2637 {
2638 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2639 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2640 NULL, NULL, 1);
2641 if (ret < 0)
2642 {
2643 bgp_unlock_node (rn);
2644 return;
2645 }
2646 continue;
2647 }
2648 }
2649}
2650
2651void
2652bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2653{
2654 struct bgp_node *rn;
2655 struct bgp_table *table;
2656
2657 if (peer->status != Established)
2658 return;
2659
2660 if (safi != SAFI_MPLS_VPN)
2661 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2662 else
2663 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2664 rn = bgp_route_next (rn))
2665 if ((table = rn->info) != NULL)
2666 bgp_soft_reconfig_table (peer, afi, safi, table);
2667}
2668
Chris Caputo228da422009-07-18 05:44:03 +00002669
2670struct bgp_clear_node_queue
2671{
2672 struct bgp_node *rn;
2673 enum bgp_clear_route_type purpose;
2674};
2675
paul200df112005-06-01 11:17:05 +00002676static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002677bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002678{
Chris Caputo228da422009-07-18 05:44:03 +00002679 struct bgp_clear_node_queue *cnq = data;
2680 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002681 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002682 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002683 afi_t afi = rn->table->afi;
2684 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002685
Paul Jakma64e580a2006-02-21 01:09:01 +00002686 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002687
Paul Jakma64e580a2006-02-21 01:09:01 +00002688 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002689 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002690 {
2691 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002692 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2693 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002694 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002695 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2696 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002697 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002698 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002699 break;
2700 }
paul200df112005-06-01 11:17:05 +00002701 return WQ_SUCCESS;
2702}
2703
2704static void
paul0fb58d52005-11-14 14:31:49 +00002705bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002706{
Chris Caputo228da422009-07-18 05:44:03 +00002707 struct bgp_clear_node_queue *cnq = data;
2708 struct bgp_node *rn = cnq->rn;
2709 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002710
2711 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002712 bgp_table_unlock (table);
2713 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002714}
2715
2716static void
paul94f2b392005-06-28 12:44:16 +00002717bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002718{
Paul Jakma64e580a2006-02-21 01:09:01 +00002719 struct peer *peer = wq->spec.data;
2720
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002721 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002722 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002723
2724 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002725}
2726
2727static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002728bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002729{
Paul Jakmaa2943652009-07-21 14:02:04 +01002730 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002731
Paul Jakmaa2943652009-07-21 14:02:04 +01002732 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002733#undef CLEAR_QUEUE_NAME_LEN
2734
2735 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002736 {
2737 zlog_err ("%s: Failed to allocate work queue", __func__);
2738 exit (1);
2739 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002740 peer->clear_node_queue->spec.hold = 10;
2741 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2742 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2743 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2744 peer->clear_node_queue->spec.max_retries = 0;
2745
2746 /* we only 'lock' this peer reference when the queue is actually active */
2747 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002748}
2749
paul718e3742002-12-13 20:15:29 +00002750static void
2751bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002752 struct bgp_table *table, struct peer *rsclient,
2753 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002754{
2755 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002756
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002757
paul718e3742002-12-13 20:15:29 +00002758 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002759 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002760
hasso6cf159b2005-03-21 10:28:14 +00002761 /* If still no table => afi/safi isn't configured at all or smth. */
2762 if (! table)
2763 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002764
2765 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2766 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002767 struct bgp_info *ri;
2768 struct bgp_adj_in *ain;
2769 struct bgp_adj_out *aout;
2770
Paul Jakma65ca75e2006-05-04 08:08:15 +00002771 if (rn->info == NULL)
2772 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002773
2774 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2775 * queued for every clearing peer, regardless of whether it is
2776 * relevant to the peer at hand.
2777 *
2778 * Overview: There are 3 different indices which need to be
2779 * scrubbed, potentially, when a peer is removed:
2780 *
2781 * 1 peer's routes visible via the RIB (ie accepted routes)
2782 * 2 peer's routes visible by the (optional) peer's adj-in index
2783 * 3 other routes visible by the peer's adj-out index
2784 *
2785 * 3 there is no hurry in scrubbing, once the struct peer is
2786 * removed from bgp->peer, we could just GC such deleted peer's
2787 * adj-outs at our leisure.
2788 *
2789 * 1 and 2 must be 'scrubbed' in some way, at least made
2790 * invisible via RIB index before peer session is allowed to be
2791 * brought back up. So one needs to know when such a 'search' is
2792 * complete.
2793 *
2794 * Ideally:
2795 *
2796 * - there'd be a single global queue or a single RIB walker
2797 * - rather than tracking which route_nodes still need to be
2798 * examined on a peer basis, we'd track which peers still
2799 * aren't cleared
2800 *
2801 * Given that our per-peer prefix-counts now should be reliable,
2802 * this may actually be achievable. It doesn't seem to be a huge
2803 * problem at this time,
2804 */
2805 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002806 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002807 {
Chris Caputo228da422009-07-18 05:44:03 +00002808 struct bgp_clear_node_queue *cnq;
2809
2810 /* both unlocked in bgp_clear_node_queue_del */
2811 bgp_table_lock (rn->table);
2812 bgp_lock_node (rn);
2813 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2814 sizeof (struct bgp_clear_node_queue));
2815 cnq->rn = rn;
2816 cnq->purpose = purpose;
2817 work_queue_add (peer->clear_node_queue, cnq);
2818 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002819 }
2820
2821 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002822 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002823 {
2824 bgp_adj_in_remove (rn, ain);
2825 bgp_unlock_node (rn);
2826 break;
2827 }
2828 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002829 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002830 {
2831 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2832 bgp_unlock_node (rn);
2833 break;
2834 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002835 }
2836 return;
2837}
2838
2839void
Chris Caputo228da422009-07-18 05:44:03 +00002840bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2841 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002842{
2843 struct bgp_node *rn;
2844 struct bgp_table *table;
2845 struct peer *rsclient;
2846 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002847
Paul Jakma64e580a2006-02-21 01:09:01 +00002848 if (peer->clear_node_queue == NULL)
2849 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002850
Paul Jakmaca058a32006-09-14 02:58:49 +00002851 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2852 * Idle until it receives a Clearing_Completed event. This protects
2853 * against peers which flap faster than we can we clear, which could
2854 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002855 *
2856 * a) race with routes from the new session being installed before
2857 * clear_route_node visits the node (to delete the route of that
2858 * peer)
2859 * b) resource exhaustion, clear_route_node likely leads to an entry
2860 * on the process_main queue. Fast-flapping could cause that queue
2861 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002862 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002863 if (!peer->clear_node_queue->thread)
2864 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002865
Chris Caputo228da422009-07-18 05:44:03 +00002866 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002867 {
Chris Caputo228da422009-07-18 05:44:03 +00002868 case BGP_CLEAR_ROUTE_NORMAL:
2869 if (safi != SAFI_MPLS_VPN)
2870 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2871 else
2872 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2873 rn = bgp_route_next (rn))
2874 if ((table = rn->info) != NULL)
2875 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2876
2877 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2878 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2879 PEER_FLAG_RSERVER_CLIENT))
2880 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2881 break;
2882
2883 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2884 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2885 break;
2886
2887 default:
2888 assert (0);
2889 break;
paulfee0f4c2004-09-13 05:12:46 +00002890 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002891
Paul Jakmaca058a32006-09-14 02:58:49 +00002892 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002893 * completion function won't be run by workqueue code - call it here.
2894 * XXX: Actually, this assumption doesn't hold, see
2895 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002896 *
2897 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002898 * really needed if peer state is Established - peers in
2899 * pre-Established states shouldn't have any route-update state
2900 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002901 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002902 * We still can get here in pre-Established though, through
2903 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2904 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002905 *
2906 * At some future point, this check could be move to the top of the
2907 * function, and do a quick early-return when state is
2908 * pre-Established, avoiding above list and table scans. Once we're
2909 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002910 */
2911 if (!peer->clear_node_queue->thread)
2912 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002913}
2914
2915void
2916bgp_clear_route_all (struct peer *peer)
2917{
2918 afi_t afi;
2919 safi_t safi;
2920
2921 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2922 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002923 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002924}
2925
2926void
2927bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2928{
2929 struct bgp_table *table;
2930 struct bgp_node *rn;
2931 struct bgp_adj_in *ain;
2932
2933 table = peer->bgp->rib[afi][safi];
2934
2935 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2936 for (ain = rn->adj_in; ain ; ain = ain->next)
2937 if (ain->peer == peer)
2938 {
2939 bgp_adj_in_remove (rn, ain);
2940 bgp_unlock_node (rn);
2941 break;
2942 }
2943}
hasso93406d82005-02-02 14:40:33 +00002944
2945void
2946bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2947{
2948 struct bgp_node *rn;
2949 struct bgp_info *ri;
2950 struct bgp_table *table;
2951
2952 table = peer->bgp->rib[afi][safi];
2953
2954 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2955 {
2956 for (ri = rn->info; ri; ri = ri->next)
2957 if (ri->peer == peer)
2958 {
2959 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2960 bgp_rib_remove (rn, ri, peer, afi, safi);
2961 break;
2962 }
2963 }
2964}
paul718e3742002-12-13 20:15:29 +00002965
2966/* Delete all kernel routes. */
2967void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002968bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002969{
2970 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002971 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002972 struct bgp_node *rn;
2973 struct bgp_table *table;
2974 struct bgp_info *ri;
2975
paul1eb8ef22005-04-07 07:30:20 +00002976 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002977 {
2978 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2979
2980 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2981 for (ri = rn->info; ri; ri = ri->next)
2982 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2983 && ri->type == ZEBRA_ROUTE_BGP
2984 && ri->sub_type == BGP_ROUTE_NORMAL)
2985 bgp_zebra_withdraw (&rn->p, ri);
2986
2987 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2988
2989 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2990 for (ri = rn->info; ri; ri = ri->next)
2991 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2992 && ri->type == ZEBRA_ROUTE_BGP
2993 && ri->sub_type == BGP_ROUTE_NORMAL)
2994 bgp_zebra_withdraw (&rn->p, ri);
2995 }
2996}
2997
2998void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002999bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003000{
3001 vty_reset ();
3002 bgp_zclient_reset ();
3003 access_list_reset ();
3004 prefix_list_reset ();
3005}
3006
3007/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3008 value. */
3009int
3010bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3011{
3012 u_char *pnt;
3013 u_char *lim;
3014 struct prefix p;
3015 int psize;
3016 int ret;
3017
3018 /* Check peer status. */
3019 if (peer->status != Established)
3020 return 0;
3021
3022 pnt = packet->nlri;
3023 lim = pnt + packet->length;
3024
3025 for (; pnt < lim; pnt += psize)
3026 {
3027 /* Clear prefix structure. */
3028 memset (&p, 0, sizeof (struct prefix));
3029
3030 /* Fetch prefix length. */
3031 p.prefixlen = *pnt++;
3032 p.family = afi2family (packet->afi);
3033
3034 /* Already checked in nlri_sanity_check(). We do double check
3035 here. */
3036 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3037 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3038 return -1;
3039
3040 /* Packet size overflow check. */
3041 psize = PSIZE (p.prefixlen);
3042
3043 /* When packet overflow occur return immediately. */
3044 if (pnt + psize > lim)
3045 return -1;
3046
3047 /* Fetch prefix from NLRI packet. */
3048 memcpy (&p.u.prefix, pnt, psize);
3049
3050 /* Check address. */
3051 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3052 {
3053 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3054 {
paulf5ba3872004-07-09 12:11:31 +00003055 /*
3056 * From draft-ietf-idr-bgp4-22, Section 6.3:
3057 * If a BGP router receives an UPDATE message with a
3058 * semantically incorrect NLRI field, in which a prefix is
3059 * semantically incorrect (eg. an unexpected multicast IP
3060 * address), it should ignore the prefix.
3061 */
paul718e3742002-12-13 20:15:29 +00003062 zlog (peer->log, LOG_ERR,
3063 "IPv4 unicast NLRI is multicast address %s",
3064 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003065
paul718e3742002-12-13 20:15:29 +00003066 return -1;
3067 }
3068 }
3069
3070#ifdef HAVE_IPV6
3071 /* Check address. */
3072 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3073 {
3074 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3075 {
3076 char buf[BUFSIZ];
3077
3078 zlog (peer->log, LOG_WARNING,
3079 "IPv6 link-local NLRI received %s ignore this NLRI",
3080 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3081
3082 continue;
3083 }
3084 }
3085#endif /* HAVE_IPV6 */
3086
3087 /* Normal process. */
3088 if (attr)
3089 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3090 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3091 else
3092 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3093 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3094
3095 /* Address family configuration mismatch or maximum-prefix count
3096 overflow. */
3097 if (ret < 0)
3098 return -1;
3099 }
3100
3101 /* Packet length consistency check. */
3102 if (pnt != lim)
3103 return -1;
3104
3105 return 0;
3106}
3107
3108/* NLRI encode syntax check routine. */
3109int
3110bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3111 bgp_size_t length)
3112{
3113 u_char *end;
3114 u_char prefixlen;
3115 int psize;
3116
3117 end = pnt + length;
3118
3119 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3120 syntactic validity. If the field is syntactically incorrect,
3121 then the Error Subcode is set to Invalid Network Field. */
3122
3123 while (pnt < end)
3124 {
3125 prefixlen = *pnt++;
3126
3127 /* Prefix length check. */
3128 if ((afi == AFI_IP && prefixlen > 32)
3129 || (afi == AFI_IP6 && prefixlen > 128))
3130 {
3131 plog_err (peer->log,
3132 "%s [Error] Update packet error (wrong prefix length %d)",
3133 peer->host, prefixlen);
3134 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3135 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3136 return -1;
3137 }
3138
3139 /* Packet size overflow check. */
3140 psize = PSIZE (prefixlen);
3141
3142 if (pnt + psize > end)
3143 {
3144 plog_err (peer->log,
3145 "%s [Error] Update packet error"
3146 " (prefix data overflow prefix size is %d)",
3147 peer->host, psize);
3148 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3149 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3150 return -1;
3151 }
3152
3153 pnt += psize;
3154 }
3155
3156 /* Packet length consistency check. */
3157 if (pnt != end)
3158 {
3159 plog_err (peer->log,
3160 "%s [Error] Update packet error"
3161 " (prefix length mismatch with total length)",
3162 peer->host);
3163 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3164 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3165 return -1;
3166 }
3167 return 0;
3168}
3169
paul94f2b392005-06-28 12:44:16 +00003170static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003171bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003172{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003173 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003174}
3175
paul94f2b392005-06-28 12:44:16 +00003176static void
paul718e3742002-12-13 20:15:29 +00003177bgp_static_free (struct bgp_static *bgp_static)
3178{
3179 if (bgp_static->rmap.name)
3180 free (bgp_static->rmap.name);
3181 XFREE (MTYPE_BGP_STATIC, bgp_static);
3182}
3183
paul94f2b392005-06-28 12:44:16 +00003184static void
paulfee0f4c2004-09-13 05:12:46 +00003185bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3186 struct prefix *p, afi_t afi, safi_t safi)
3187{
3188 struct bgp_node *rn;
3189 struct bgp_info *ri;
3190
3191 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3192
3193 /* Check selected route and self inserted route. */
3194 for (ri = rn->info; ri; ri = ri->next)
3195 if (ri->peer == bgp->peer_self
3196 && ri->type == ZEBRA_ROUTE_BGP
3197 && ri->sub_type == BGP_ROUTE_STATIC)
3198 break;
3199
3200 /* Withdraw static BGP route from routing table. */
3201 if (ri)
3202 {
paulfee0f4c2004-09-13 05:12:46 +00003203 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003204 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003205 }
3206
3207 /* Unlock bgp_node_lookup. */
3208 bgp_unlock_node (rn);
3209}
3210
paul94f2b392005-06-28 12:44:16 +00003211static void
paulfee0f4c2004-09-13 05:12:46 +00003212bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003213 struct bgp_static *bgp_static,
3214 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003215{
3216 struct bgp_node *rn;
3217 struct bgp_info *ri;
3218 struct bgp_info *new;
3219 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003220 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003221 struct attr attr = {0 };
3222 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003223 struct bgp *bgp;
3224 int ret;
3225 char buf[SU_ADDRSTRLEN];
3226
3227 bgp = rsclient->bgp;
3228
Paul Jakma06e110f2006-05-12 23:29:22 +00003229 assert (bgp_static);
3230 if (!bgp_static)
3231 return;
3232
paulfee0f4c2004-09-13 05:12:46 +00003233 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3234
3235 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003236
3237 attr.nexthop = bgp_static->igpnexthop;
3238 attr.med = bgp_static->igpmetric;
3239 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003240
3241 if (bgp_static->ttl)
3242 {
3243 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3244 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3245 attr.pathlimit.as = 0;
3246 attr.pathlimit.ttl = bgp_static->ttl;
3247 }
3248
3249 if (bgp_static->atomic)
3250 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3251
paulfee0f4c2004-09-13 05:12:46 +00003252 /* Apply network route-map for export to this rsclient. */
3253 if (bgp_static->rmap.name)
3254 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003255 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003256 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003257 info.attr = &attr_tmp;
3258
paulfee0f4c2004-09-13 05:12:46 +00003259 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3260 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3261
3262 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3263
3264 rsclient->rmap_type = 0;
3265
3266 if (ret == RMAP_DENYMATCH)
3267 {
3268 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003269 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003270
3271 /* Unintern original. */
3272 aspath_unintern (attr.aspath);
3273 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003274 bgp_attr_extra_free (&attr);
3275
paulfee0f4c2004-09-13 05:12:46 +00003276 return;
3277 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003278 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003279 }
3280 else
3281 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003282
paulfee0f4c2004-09-13 05:12:46 +00003283 new_attr = *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003284
paulfee0f4c2004-09-13 05:12:46 +00003285 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3286
Paul Jakmafb982c22007-05-04 20:15:47 +00003287 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3288 == RMAP_DENY)
3289 {
paulfee0f4c2004-09-13 05:12:46 +00003290 /* This BGP update is filtered. Log the reason then update BGP entry. */
3291 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003292 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003293 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3294 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3295 p->prefixlen, rsclient->host);
3296
3297 bgp->peer_self->rmap_type = 0;
3298
3299 bgp_attr_unintern (attr_new);
3300 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003301 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003302
3303 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3304
3305 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003306 }
paulfee0f4c2004-09-13 05:12:46 +00003307
3308 bgp->peer_self->rmap_type = 0;
3309
3310 bgp_attr_unintern (attr_new);
3311 attr_new = bgp_attr_intern (&new_attr);
3312
3313 for (ri = rn->info; ri; ri = ri->next)
3314 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3315 && ri->sub_type == BGP_ROUTE_STATIC)
3316 break;
3317
3318 if (ri)
3319 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003320 if (attrhash_cmp (ri->attr, attr_new) &&
3321 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003322 {
3323 bgp_unlock_node (rn);
3324 bgp_attr_unintern (attr_new);
3325 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003326 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003327 return;
3328 }
3329 else
3330 {
3331 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003332 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003333
3334 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003335 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3336 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003337 bgp_attr_unintern (ri->attr);
3338 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003339 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003340
3341 /* Process change. */
3342 bgp_process (bgp, rn, afi, safi);
3343 bgp_unlock_node (rn);
3344 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003345 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003346 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003347 }
paulfee0f4c2004-09-13 05:12:46 +00003348 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003349
paulfee0f4c2004-09-13 05:12:46 +00003350 /* Make new BGP info. */
3351 new = bgp_info_new ();
3352 new->type = ZEBRA_ROUTE_BGP;
3353 new->sub_type = BGP_ROUTE_STATIC;
3354 new->peer = bgp->peer_self;
3355 SET_FLAG (new->flags, BGP_INFO_VALID);
3356 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003357 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003358
3359 /* Register new BGP information. */
3360 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003361
3362 /* route_node_get lock */
3363 bgp_unlock_node (rn);
3364
paulfee0f4c2004-09-13 05:12:46 +00003365 /* Process change. */
3366 bgp_process (bgp, rn, afi, safi);
3367
3368 /* Unintern original. */
3369 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003370 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003371}
3372
paul94f2b392005-06-28 12:44:16 +00003373static void
paulfee0f4c2004-09-13 05:12:46 +00003374bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003375 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3376{
3377 struct bgp_node *rn;
3378 struct bgp_info *ri;
3379 struct bgp_info *new;
3380 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003381 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003382 struct attr *attr_new;
3383 int ret;
3384
Paul Jakmadd8103a2006-05-12 23:27:30 +00003385 assert (bgp_static);
3386 if (!bgp_static)
3387 return;
3388
paulfee0f4c2004-09-13 05:12:46 +00003389 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003390
3391 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003392
3393 attr.nexthop = bgp_static->igpnexthop;
3394 attr.med = bgp_static->igpmetric;
3395 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003396
Paul Jakma41367172007-08-06 15:24:51 +00003397 if (bgp_static->ttl)
3398 {
3399 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3400 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3401 attr.pathlimit.as = 0;
3402 attr.pathlimit.ttl = bgp_static->ttl;
3403 }
3404
3405 if (bgp_static->atomic)
3406 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3407
paul718e3742002-12-13 20:15:29 +00003408 /* Apply route-map. */
3409 if (bgp_static->rmap.name)
3410 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003411 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003412 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003413 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003414
paulfee0f4c2004-09-13 05:12:46 +00003415 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3416
paul718e3742002-12-13 20:15:29 +00003417 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003418
paulfee0f4c2004-09-13 05:12:46 +00003419 bgp->peer_self->rmap_type = 0;
3420
paul718e3742002-12-13 20:15:29 +00003421 if (ret == RMAP_DENYMATCH)
3422 {
3423 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003424 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003425
3426 /* Unintern original. */
3427 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003428 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003429 bgp_static_withdraw (bgp, p, afi, safi);
3430 return;
3431 }
paul286e1e72003-08-08 00:24:31 +00003432 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003433 }
paul286e1e72003-08-08 00:24:31 +00003434 else
3435 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003436
3437 for (ri = rn->info; ri; ri = ri->next)
3438 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3439 && ri->sub_type == BGP_ROUTE_STATIC)
3440 break;
3441
3442 if (ri)
3443 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003444 if (attrhash_cmp (ri->attr, attr_new) &&
3445 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003446 {
3447 bgp_unlock_node (rn);
3448 bgp_attr_unintern (attr_new);
3449 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003450 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003451 return;
3452 }
3453 else
3454 {
3455 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003456 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003457
3458 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003459 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3460 bgp_info_restore(rn, ri);
3461 else
3462 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003463 bgp_attr_unintern (ri->attr);
3464 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003465 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003466
3467 /* Process change. */
3468 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3469 bgp_process (bgp, rn, afi, safi);
3470 bgp_unlock_node (rn);
3471 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003472 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003473 return;
3474 }
3475 }
3476
3477 /* Make new BGP info. */
3478 new = bgp_info_new ();
3479 new->type = ZEBRA_ROUTE_BGP;
3480 new->sub_type = BGP_ROUTE_STATIC;
3481 new->peer = bgp->peer_self;
3482 SET_FLAG (new->flags, BGP_INFO_VALID);
3483 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003484 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003485
3486 /* Aggregate address increment. */
3487 bgp_aggregate_increment (bgp, p, new, afi, safi);
3488
3489 /* Register new BGP information. */
3490 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003491
3492 /* route_node_get lock */
3493 bgp_unlock_node (rn);
3494
paul718e3742002-12-13 20:15:29 +00003495 /* Process change. */
3496 bgp_process (bgp, rn, afi, safi);
3497
3498 /* Unintern original. */
3499 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003500 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003501}
3502
3503void
paulfee0f4c2004-09-13 05:12:46 +00003504bgp_static_update (struct bgp *bgp, struct prefix *p,
3505 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3506{
3507 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003508 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003509
3510 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3511
paul1eb8ef22005-04-07 07:30:20 +00003512 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003513 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003514 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3515 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003516 }
3517}
3518
paul94f2b392005-06-28 12:44:16 +00003519static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003520bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3521 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003522{
3523 struct bgp_node *rn;
3524 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003525
paulfee0f4c2004-09-13 05:12:46 +00003526 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003527
3528 /* Make new BGP info. */
3529 new = bgp_info_new ();
3530 new->type = ZEBRA_ROUTE_BGP;
3531 new->sub_type = BGP_ROUTE_STATIC;
3532 new->peer = bgp->peer_self;
3533 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3534 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003535 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003536 new->extra = bgp_info_extra_new();
3537 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003538
3539 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003540 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003541
3542 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003543 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003544
paul200df112005-06-01 11:17:05 +00003545 /* route_node_get lock */
3546 bgp_unlock_node (rn);
3547
paul718e3742002-12-13 20:15:29 +00003548 /* Process change. */
3549 bgp_process (bgp, rn, afi, safi);
3550}
3551
3552void
3553bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3554 safi_t safi)
3555{
3556 struct bgp_node *rn;
3557 struct bgp_info *ri;
3558
paulfee0f4c2004-09-13 05:12:46 +00003559 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003560
3561 /* Check selected route and self inserted route. */
3562 for (ri = rn->info; ri; ri = ri->next)
3563 if (ri->peer == bgp->peer_self
3564 && ri->type == ZEBRA_ROUTE_BGP
3565 && ri->sub_type == BGP_ROUTE_STATIC)
3566 break;
3567
3568 /* Withdraw static BGP route from routing table. */
3569 if (ri)
3570 {
3571 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003572 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003573 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003574 }
3575
3576 /* Unlock bgp_node_lookup. */
3577 bgp_unlock_node (rn);
3578}
3579
3580void
paulfee0f4c2004-09-13 05:12:46 +00003581bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3582{
3583 struct bgp_static *bgp_static;
3584 struct bgp *bgp;
3585 struct bgp_node *rn;
3586 struct prefix *p;
3587
3588 bgp = rsclient->bgp;
3589
3590 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3591 if ((bgp_static = rn->info) != NULL)
3592 {
3593 p = &rn->p;
3594
3595 bgp_static_update_rsclient (rsclient, p, bgp_static,
3596 afi, safi);
3597 }
3598}
3599
paul94f2b392005-06-28 12:44:16 +00003600static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003601bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3602 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003603{
3604 struct bgp_node *rn;
3605 struct bgp_info *ri;
3606
paulfee0f4c2004-09-13 05:12:46 +00003607 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003608
3609 /* Check selected route and self inserted route. */
3610 for (ri = rn->info; ri; ri = ri->next)
3611 if (ri->peer == bgp->peer_self
3612 && ri->type == ZEBRA_ROUTE_BGP
3613 && ri->sub_type == BGP_ROUTE_STATIC)
3614 break;
3615
3616 /* Withdraw static BGP route from routing table. */
3617 if (ri)
3618 {
3619 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003620 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003621 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003622 }
3623
3624 /* Unlock bgp_node_lookup. */
3625 bgp_unlock_node (rn);
3626}
3627
Paul Jakma41367172007-08-06 15:24:51 +00003628static void
3629bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3630 int ttl_edge)
3631{
3632 struct bgp_node *parent = rn;
3633 struct bgp_static *sp;
3634
3635 /* Existing static changed TTL, search parents and adjust their atomic */
3636 while ((parent = parent->parent))
3637 if ((sp = parent->info))
3638 {
3639 int sp_level = (sp->atomic ? 1 : 0);
3640 ttl_edge ? sp->atomic++ : sp->atomic--;
3641
3642 /* did we change state of parent whether atomic is set or not? */
3643 if (sp_level != (sp->atomic ? 1 : 0))
3644 {
3645 bgp_static_update (bgp, &parent->p, sp,
3646 rn->table->afi, rn->table->safi);
3647 }
3648 }
3649}
3650
paul718e3742002-12-13 20:15:29 +00003651/* Configure static BGP network. When user don't run zebra, static
3652 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003653static int
paulfd79ac92004-10-13 05:06:08 +00003654bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003655 afi_t afi, safi_t safi, const char *rmap, int backdoor,
Paul Jakma41367172007-08-06 15:24:51 +00003656 u_char ttl)
paul718e3742002-12-13 20:15:29 +00003657{
3658 int ret;
3659 struct prefix p;
3660 struct bgp_static *bgp_static;
3661 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003662 u_char need_update = 0;
3663 u_char ttl_change = 0;
3664 u_char ttl_edge = (ttl ? 1 : 0);
3665 u_char new = 0;
paul718e3742002-12-13 20:15:29 +00003666
3667 /* Convert IP prefix string to struct prefix. */
3668 ret = str2prefix (ip_str, &p);
3669 if (! ret)
3670 {
3671 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3672 return CMD_WARNING;
3673 }
3674#ifdef HAVE_IPV6
3675 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3676 {
3677 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3678 VTY_NEWLINE);
3679 return CMD_WARNING;
3680 }
3681#endif /* HAVE_IPV6 */
3682
3683 apply_mask (&p);
3684
3685 /* Set BGP static route configuration. */
3686 rn = bgp_node_get (bgp->route[afi][safi], &p);
3687
3688 if (rn->info)
3689 {
3690 /* Configuration change. */
3691 bgp_static = rn->info;
3692
3693 /* Check previous routes are installed into BGP. */
Paul Jakma41367172007-08-06 15:24:51 +00003694 if (bgp_static->valid)
3695 {
3696 if (bgp_static->backdoor != backdoor
3697 || bgp_static->ttl != ttl)
3698 need_update = 1;
3699 }
3700
3701 /* need to catch TTL set/unset transitions for handling of
3702 * ATOMIC_AGGREGATE
3703 */
3704 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3705 ttl_change = 1;
3706
paul718e3742002-12-13 20:15:29 +00003707 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003708 bgp_static->ttl = ttl;
3709
paul718e3742002-12-13 20:15:29 +00003710 if (rmap)
3711 {
3712 if (bgp_static->rmap.name)
3713 free (bgp_static->rmap.name);
3714 bgp_static->rmap.name = strdup (rmap);
3715 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3716 }
3717 else
3718 {
3719 if (bgp_static->rmap.name)
3720 free (bgp_static->rmap.name);
3721 bgp_static->rmap.name = NULL;
3722 bgp_static->rmap.map = NULL;
3723 bgp_static->valid = 0;
3724 }
3725 bgp_unlock_node (rn);
3726 }
3727 else
3728 {
3729 /* New configuration. */
3730 bgp_static = bgp_static_new ();
3731 bgp_static->backdoor = backdoor;
3732 bgp_static->valid = 0;
3733 bgp_static->igpmetric = 0;
3734 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003735 bgp_static->ttl = ttl;
3736 ttl_change = ttl_edge;
3737 new = 1;
3738
paul718e3742002-12-13 20:15:29 +00003739 if (rmap)
3740 {
3741 if (bgp_static->rmap.name)
3742 free (bgp_static->rmap.name);
3743 bgp_static->rmap.name = strdup (rmap);
3744 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3745 }
3746 rn->info = bgp_static;
3747 }
3748
Paul Jakma41367172007-08-06 15:24:51 +00003749 /* ".. sites that choose to advertise the
3750 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3751 * all less specific covering prefixes as well as the more specific
3752 * prefixes."
3753 *
3754 * So:
3755 * Prefix that has just had pathlimit set/unset:
3756 * - Must bump ATOMIC refcount on all parents.
3757 *
3758 * To catch less specific prefixes:
3759 * - Must search children for ones with TTL, bump atomic refcount
3760 * (we dont care if we're deleting a less specific prefix..)
3761 */
3762 if (ttl_change)
3763 {
3764 /* Existing static changed TTL, search parents and adjust their atomic */
3765 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3766 }
3767
3768 if (new)
3769 {
3770 struct bgp_node *child;
3771 struct bgp_static *sc;
3772
3773 /* New static, search children and bump this statics atomic.. */
3774 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3775 while ((child = bgp_route_next_until (child, rn)))
3776 {
3777 if ((sc = child->info) && sc->ttl)
3778 bgp_static->atomic++;
3779 }
3780 }
3781
paul718e3742002-12-13 20:15:29 +00003782 /* If BGP scan is not enabled, we should install this route here. */
3783 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3784 {
3785 bgp_static->valid = 1;
3786
3787 if (need_update)
3788 bgp_static_withdraw (bgp, &p, afi, safi);
3789
3790 if (! bgp_static->backdoor)
3791 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3792 }
3793
3794 return CMD_SUCCESS;
3795}
3796
3797/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003798static int
paulfd79ac92004-10-13 05:06:08 +00003799bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003800 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003801{
3802 int ret;
3803 struct prefix p;
3804 struct bgp_static *bgp_static;
3805 struct bgp_node *rn;
3806
3807 /* Convert IP prefix string to struct prefix. */
3808 ret = str2prefix (ip_str, &p);
3809 if (! ret)
3810 {
3811 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3812 return CMD_WARNING;
3813 }
3814#ifdef HAVE_IPV6
3815 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3816 {
3817 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3818 VTY_NEWLINE);
3819 return CMD_WARNING;
3820 }
3821#endif /* HAVE_IPV6 */
3822
3823 apply_mask (&p);
3824
3825 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3826 if (! rn)
3827 {
3828 vty_out (vty, "%% Can't find specified static route configuration.%s",
3829 VTY_NEWLINE);
3830 return CMD_WARNING;
3831 }
3832
3833 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003834
3835 /* decrement atomic in parents, see bgp_static_set */
3836 bgp_pathlimit_update_parents (bgp, rn, 0);
3837
paul718e3742002-12-13 20:15:29 +00003838 /* Update BGP RIB. */
3839 if (! bgp_static->backdoor)
3840 bgp_static_withdraw (bgp, &p, afi, safi);
3841
3842 /* Clear configuration. */
3843 bgp_static_free (bgp_static);
3844 rn->info = NULL;
3845 bgp_unlock_node (rn);
3846 bgp_unlock_node (rn);
3847
3848 return CMD_SUCCESS;
3849}
3850
3851/* Called from bgp_delete(). Delete all static routes from the BGP
3852 instance. */
3853void
3854bgp_static_delete (struct bgp *bgp)
3855{
3856 afi_t afi;
3857 safi_t safi;
3858 struct bgp_node *rn;
3859 struct bgp_node *rm;
3860 struct bgp_table *table;
3861 struct bgp_static *bgp_static;
3862
3863 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3864 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3865 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3866 if (rn->info != NULL)
3867 {
3868 if (safi == SAFI_MPLS_VPN)
3869 {
3870 table = rn->info;
3871
3872 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3873 {
3874 bgp_static = rn->info;
3875 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3876 AFI_IP, SAFI_MPLS_VPN,
3877 (struct prefix_rd *)&rn->p,
3878 bgp_static->tag);
3879 bgp_static_free (bgp_static);
3880 rn->info = NULL;
3881 bgp_unlock_node (rn);
3882 }
3883 }
3884 else
3885 {
3886 bgp_static = rn->info;
3887 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3888 bgp_static_free (bgp_static);
3889 rn->info = NULL;
3890 bgp_unlock_node (rn);
3891 }
3892 }
3893}
3894
3895int
paulfd79ac92004-10-13 05:06:08 +00003896bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3897 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003898{
3899 int ret;
3900 struct prefix p;
3901 struct prefix_rd prd;
3902 struct bgp *bgp;
3903 struct bgp_node *prn;
3904 struct bgp_node *rn;
3905 struct bgp_table *table;
3906 struct bgp_static *bgp_static;
3907 u_char tag[3];
3908
3909 bgp = vty->index;
3910
3911 ret = str2prefix (ip_str, &p);
3912 if (! ret)
3913 {
3914 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3915 return CMD_WARNING;
3916 }
3917 apply_mask (&p);
3918
3919 ret = str2prefix_rd (rd_str, &prd);
3920 if (! ret)
3921 {
3922 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3923 return CMD_WARNING;
3924 }
3925
3926 ret = str2tag (tag_str, tag);
3927 if (! ret)
3928 {
3929 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3930 return CMD_WARNING;
3931 }
3932
3933 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3934 (struct prefix *)&prd);
3935 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003936 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003937 else
3938 bgp_unlock_node (prn);
3939 table = prn->info;
3940
3941 rn = bgp_node_get (table, &p);
3942
3943 if (rn->info)
3944 {
3945 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3946 bgp_unlock_node (rn);
3947 }
3948 else
3949 {
3950 /* New configuration. */
3951 bgp_static = bgp_static_new ();
3952 bgp_static->valid = 1;
3953 memcpy (bgp_static->tag, tag, 3);
3954 rn->info = bgp_static;
3955
3956 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3957 }
3958
3959 return CMD_SUCCESS;
3960}
3961
3962/* Configure static BGP network. */
3963int
paulfd79ac92004-10-13 05:06:08 +00003964bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3965 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003966{
3967 int ret;
3968 struct bgp *bgp;
3969 struct prefix p;
3970 struct prefix_rd prd;
3971 struct bgp_node *prn;
3972 struct bgp_node *rn;
3973 struct bgp_table *table;
3974 struct bgp_static *bgp_static;
3975 u_char tag[3];
3976
3977 bgp = vty->index;
3978
3979 /* Convert IP prefix string to struct prefix. */
3980 ret = str2prefix (ip_str, &p);
3981 if (! ret)
3982 {
3983 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3984 return CMD_WARNING;
3985 }
3986 apply_mask (&p);
3987
3988 ret = str2prefix_rd (rd_str, &prd);
3989 if (! ret)
3990 {
3991 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3992 return CMD_WARNING;
3993 }
3994
3995 ret = str2tag (tag_str, tag);
3996 if (! ret)
3997 {
3998 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3999 return CMD_WARNING;
4000 }
4001
4002 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4003 (struct prefix *)&prd);
4004 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004005 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004006 else
4007 bgp_unlock_node (prn);
4008 table = prn->info;
4009
4010 rn = bgp_node_lookup (table, &p);
4011
4012 if (rn)
4013 {
4014 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4015
4016 bgp_static = rn->info;
4017 bgp_static_free (bgp_static);
4018 rn->info = NULL;
4019 bgp_unlock_node (rn);
4020 bgp_unlock_node (rn);
4021 }
4022 else
4023 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4024
4025 return CMD_SUCCESS;
4026}
4027
4028DEFUN (bgp_network,
4029 bgp_network_cmd,
4030 "network A.B.C.D/M",
4031 "Specify a network to announce via BGP\n"
4032 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4033{
Paul Jakma41367172007-08-06 15:24:51 +00004034 u_char ttl = 0;
4035
4036 if (argc == 2)
4037 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4038
paul718e3742002-12-13 20:15:29 +00004039 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004040 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004041}
4042
Paul Jakma41367172007-08-06 15:24:51 +00004043ALIAS (bgp_network,
4044 bgp_network_ttl_cmd,
4045 "network A.B.C.D/M pathlimit <0-255>",
4046 "Specify a network to announce via BGP\n"
4047 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4048 "AS-Path hopcount limit attribute\n"
4049 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4050
paul718e3742002-12-13 20:15:29 +00004051DEFUN (bgp_network_route_map,
4052 bgp_network_route_map_cmd,
4053 "network A.B.C.D/M route-map WORD",
4054 "Specify a network to announce via BGP\n"
4055 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4056 "Route-map to modify the attributes\n"
4057 "Name of the route map\n")
4058{
4059 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004060 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004061}
4062
4063DEFUN (bgp_network_backdoor,
4064 bgp_network_backdoor_cmd,
4065 "network A.B.C.D/M backdoor",
4066 "Specify a network to announce via BGP\n"
4067 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4068 "Specify a BGP backdoor route\n")
4069{
Paul Jakma41367172007-08-06 15:24:51 +00004070 u_char ttl = 0;
4071
4072 if (argc == 2)
4073 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4074
4075 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4076 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004077}
4078
Paul Jakma41367172007-08-06 15:24:51 +00004079ALIAS (bgp_network_backdoor,
4080 bgp_network_backdoor_ttl_cmd,
4081 "network A.B.C.D/M backdoor pathlimit <0-255>",
4082 "Specify a network to announce via BGP\n"
4083 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4084 "Specify a BGP backdoor route\n"
4085 "AS-Path hopcount limit attribute\n"
4086 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4087
paul718e3742002-12-13 20:15:29 +00004088DEFUN (bgp_network_mask,
4089 bgp_network_mask_cmd,
4090 "network A.B.C.D mask A.B.C.D",
4091 "Specify a network to announce via BGP\n"
4092 "Network number\n"
4093 "Network mask\n"
4094 "Network mask\n")
4095{
4096 int ret;
4097 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004098 u_char ttl = 0;
4099
4100 if (argc == 3)
4101 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4102
paul718e3742002-12-13 20:15:29 +00004103 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4104 if (! ret)
4105 {
4106 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4107 return CMD_WARNING;
4108 }
4109
4110 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004111 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004112}
4113
Paul Jakma41367172007-08-06 15:24:51 +00004114ALIAS (bgp_network_mask,
4115 bgp_network_mask_ttl_cmd,
4116 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4117 "Specify a network to announce via BGP\n"
4118 "Network number\n"
4119 "Network mask\n"
4120 "Network mask\n"
4121 "AS-Path hopcount limit attribute\n"
4122 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4123
paul718e3742002-12-13 20:15:29 +00004124DEFUN (bgp_network_mask_route_map,
4125 bgp_network_mask_route_map_cmd,
4126 "network A.B.C.D mask A.B.C.D route-map WORD",
4127 "Specify a network to announce via BGP\n"
4128 "Network number\n"
4129 "Network mask\n"
4130 "Network mask\n"
4131 "Route-map to modify the attributes\n"
4132 "Name of the route map\n")
4133{
4134 int ret;
4135 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004136
paul718e3742002-12-13 20:15:29 +00004137 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4138 if (! ret)
4139 {
4140 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4141 return CMD_WARNING;
4142 }
4143
4144 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004145 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
paul718e3742002-12-13 20:15:29 +00004146}
4147
4148DEFUN (bgp_network_mask_backdoor,
4149 bgp_network_mask_backdoor_cmd,
4150 "network A.B.C.D mask A.B.C.D backdoor",
4151 "Specify a network to announce via BGP\n"
4152 "Network number\n"
4153 "Network mask\n"
4154 "Network mask\n"
4155 "Specify a BGP backdoor route\n")
4156{
4157 int ret;
4158 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004159 u_char ttl = 0;
4160
4161 if (argc == 3)
4162 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
paul718e3742002-12-13 20:15:29 +00004163
4164 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4165 if (! ret)
4166 {
4167 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4168 return CMD_WARNING;
4169 }
4170
Paul Jakma41367172007-08-06 15:24:51 +00004171 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4172 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004173}
4174
Paul Jakma41367172007-08-06 15:24:51 +00004175ALIAS (bgp_network_mask_backdoor,
4176 bgp_network_mask_backdoor_ttl_cmd,
4177 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4178 "Specify a network to announce via BGP\n"
4179 "Network number\n"
4180 "Network mask\n"
4181 "Network mask\n"
4182 "Specify a BGP backdoor route\n"
4183 "AS-Path hopcount limit attribute\n"
4184 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4185
paul718e3742002-12-13 20:15:29 +00004186DEFUN (bgp_network_mask_natural,
4187 bgp_network_mask_natural_cmd,
4188 "network A.B.C.D",
4189 "Specify a network to announce via BGP\n"
4190 "Network number\n")
4191{
4192 int ret;
4193 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004194 u_char ttl = 0;
4195
4196 if (argc == 2)
4197 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004198
4199 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4200 if (! ret)
4201 {
4202 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4203 return CMD_WARNING;
4204 }
4205
4206 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004207 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004208}
4209
Paul Jakma41367172007-08-06 15:24:51 +00004210ALIAS (bgp_network_mask_natural,
4211 bgp_network_mask_natural_ttl_cmd,
4212 "network A.B.C.D pathlimit <0-255>",
4213 "Specify a network to announce via BGP\n"
4214 "Network number\n"
4215 "AS-Path hopcount limit attribute\n"
4216 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4217
paul718e3742002-12-13 20:15:29 +00004218DEFUN (bgp_network_mask_natural_route_map,
4219 bgp_network_mask_natural_route_map_cmd,
4220 "network A.B.C.D route-map WORD",
4221 "Specify a network to announce via BGP\n"
4222 "Network number\n"
4223 "Route-map to modify the attributes\n"
4224 "Name of the route map\n")
4225{
4226 int ret;
4227 char prefix_str[BUFSIZ];
4228
4229 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4230 if (! ret)
4231 {
4232 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4233 return CMD_WARNING;
4234 }
4235
4236 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004237 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004238}
4239
4240DEFUN (bgp_network_mask_natural_backdoor,
4241 bgp_network_mask_natural_backdoor_cmd,
4242 "network A.B.C.D backdoor",
4243 "Specify a network to announce via BGP\n"
4244 "Network number\n"
4245 "Specify a BGP backdoor route\n")
4246{
4247 int ret;
4248 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004249 u_char ttl = 0;
4250
4251 if (argc == 2)
4252 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004253
4254 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4255 if (! ret)
4256 {
4257 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4258 return CMD_WARNING;
4259 }
4260
Paul Jakma41367172007-08-06 15:24:51 +00004261 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4262 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004263}
4264
Paul Jakma41367172007-08-06 15:24:51 +00004265ALIAS (bgp_network_mask_natural_backdoor,
4266 bgp_network_mask_natural_backdoor_ttl_cmd,
4267 "network A.B.C.D backdoor pathlimit (1-255>",
4268 "Specify a network to announce via BGP\n"
4269 "Network number\n"
4270 "Specify a BGP backdoor route\n"
4271 "AS-Path hopcount limit attribute\n"
4272 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4273
paul718e3742002-12-13 20:15:29 +00004274DEFUN (no_bgp_network,
4275 no_bgp_network_cmd,
4276 "no network A.B.C.D/M",
4277 NO_STR
4278 "Specify a network to announce via BGP\n"
4279 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4280{
4281 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4282 bgp_node_safi (vty));
4283}
4284
4285ALIAS (no_bgp_network,
Paul Jakma41367172007-08-06 15:24:51 +00004286 no_bgp_network_ttl_cmd,
4287 "no network A.B.C.D/M pathlimit <0-255>",
4288 NO_STR
4289 "Specify a network to announce via BGP\n"
4290 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4291 "AS-Path hopcount limit attribute\n"
4292 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4293
4294ALIAS (no_bgp_network,
paul718e3742002-12-13 20:15:29 +00004295 no_bgp_network_route_map_cmd,
4296 "no network A.B.C.D/M route-map WORD",
4297 NO_STR
4298 "Specify a network to announce via BGP\n"
4299 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4300 "Route-map to modify the attributes\n"
4301 "Name of the route map\n")
4302
4303ALIAS (no_bgp_network,
4304 no_bgp_network_backdoor_cmd,
4305 "no network A.B.C.D/M backdoor",
4306 NO_STR
4307 "Specify a network to announce via BGP\n"
4308 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4309 "Specify a BGP backdoor route\n")
4310
Paul Jakma41367172007-08-06 15:24:51 +00004311ALIAS (no_bgp_network,
4312 no_bgp_network_backdoor_ttl_cmd,
4313 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4314 NO_STR
4315 "Specify a network to announce via BGP\n"
4316 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4317 "Specify a BGP backdoor route\n"
4318 "AS-Path hopcount limit attribute\n"
4319 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4320
paul718e3742002-12-13 20:15:29 +00004321DEFUN (no_bgp_network_mask,
4322 no_bgp_network_mask_cmd,
4323 "no network A.B.C.D mask A.B.C.D",
4324 NO_STR
4325 "Specify a network to announce via BGP\n"
4326 "Network number\n"
4327 "Network mask\n"
4328 "Network mask\n")
4329{
4330 int ret;
4331 char prefix_str[BUFSIZ];
4332
4333 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4334 if (! ret)
4335 {
4336 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4337 return CMD_WARNING;
4338 }
4339
4340 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4341 bgp_node_safi (vty));
4342}
4343
Paul Jakma41367172007-08-06 15:24:51 +00004344ALIAS (no_bgp_network,
4345 no_bgp_network_mask_ttl_cmd,
4346 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4347 NO_STR
4348 "Specify a network to announce via BGP\n"
4349 "Network number\n"
4350 "Network mask\n"
4351 "Network mask\n"
4352 "AS-Path hopcount limit attribute\n"
4353 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4354
paul718e3742002-12-13 20:15:29 +00004355ALIAS (no_bgp_network_mask,
4356 no_bgp_network_mask_route_map_cmd,
4357 "no network A.B.C.D mask A.B.C.D route-map WORD",
4358 NO_STR
4359 "Specify a network to announce via BGP\n"
4360 "Network number\n"
4361 "Network mask\n"
4362 "Network mask\n"
4363 "Route-map to modify the attributes\n"
4364 "Name of the route map\n")
4365
4366ALIAS (no_bgp_network_mask,
4367 no_bgp_network_mask_backdoor_cmd,
4368 "no network A.B.C.D mask A.B.C.D backdoor",
4369 NO_STR
4370 "Specify a network to announce via BGP\n"
4371 "Network number\n"
4372 "Network mask\n"
4373 "Network mask\n"
4374 "Specify a BGP backdoor route\n")
4375
Paul Jakma41367172007-08-06 15:24:51 +00004376ALIAS (no_bgp_network_mask,
4377 no_bgp_network_mask_backdoor_ttl_cmd,
4378 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4379 NO_STR
4380 "Specify a network to announce via BGP\n"
4381 "Network number\n"
4382 "Network mask\n"
4383 "Network mask\n"
4384 "Specify a BGP backdoor route\n"
4385 "AS-Path hopcount limit attribute\n"
4386 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4387
paul718e3742002-12-13 20:15:29 +00004388DEFUN (no_bgp_network_mask_natural,
4389 no_bgp_network_mask_natural_cmd,
4390 "no network A.B.C.D",
4391 NO_STR
4392 "Specify a network to announce via BGP\n"
4393 "Network number\n")
4394{
4395 int ret;
4396 char prefix_str[BUFSIZ];
4397
4398 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4399 if (! ret)
4400 {
4401 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4402 return CMD_WARNING;
4403 }
4404
4405 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4406 bgp_node_safi (vty));
4407}
4408
4409ALIAS (no_bgp_network_mask_natural,
4410 no_bgp_network_mask_natural_route_map_cmd,
4411 "no network A.B.C.D route-map WORD",
4412 NO_STR
4413 "Specify a network to announce via BGP\n"
4414 "Network number\n"
4415 "Route-map to modify the attributes\n"
4416 "Name of the route map\n")
4417
4418ALIAS (no_bgp_network_mask_natural,
4419 no_bgp_network_mask_natural_backdoor_cmd,
4420 "no network A.B.C.D backdoor",
4421 NO_STR
4422 "Specify a network to announce via BGP\n"
4423 "Network number\n"
4424 "Specify a BGP backdoor route\n")
4425
Paul Jakma41367172007-08-06 15:24:51 +00004426ALIAS (no_bgp_network_mask_natural,
4427 no_bgp_network_mask_natural_ttl_cmd,
4428 "no network A.B.C.D pathlimit <0-255>",
4429 NO_STR
4430 "Specify a network to announce via BGP\n"
4431 "Network number\n"
4432 "AS-Path hopcount limit attribute\n"
4433 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4434
4435ALIAS (no_bgp_network_mask_natural,
4436 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4437 "no network A.B.C.D backdoor pathlimit <0-255>",
4438 NO_STR
4439 "Specify a network to announce via BGP\n"
4440 "Network number\n"
4441 "Specify a BGP backdoor route\n"
4442 "AS-Path hopcount limit attribute\n"
4443 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4444
paul718e3742002-12-13 20:15:29 +00004445#ifdef HAVE_IPV6
4446DEFUN (ipv6_bgp_network,
4447 ipv6_bgp_network_cmd,
4448 "network X:X::X:X/M",
4449 "Specify a network to announce via BGP\n"
4450 "IPv6 prefix <network>/<length>\n")
4451{
Paul Jakma41367172007-08-06 15:24:51 +00004452 u_char ttl = 0;
4453
4454 if (argc == 2)
4455 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4456
4457 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4458 NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004459}
4460
Paul Jakma41367172007-08-06 15:24:51 +00004461ALIAS (ipv6_bgp_network,
4462 ipv6_bgp_network_ttl_cmd,
4463 "network X:X::X:X/M pathlimit <0-255>",
4464 "Specify a network to announce via BGP\n"
4465 "IPv6 prefix <network>/<length>\n"
4466 "AS-Path hopcount limit attribute\n"
4467 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4468
paul718e3742002-12-13 20:15:29 +00004469DEFUN (ipv6_bgp_network_route_map,
4470 ipv6_bgp_network_route_map_cmd,
4471 "network X:X::X:X/M route-map WORD",
4472 "Specify a network to announce via BGP\n"
4473 "IPv6 prefix <network>/<length>\n"
4474 "Route-map to modify the attributes\n"
4475 "Name of the route map\n")
4476{
4477 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakma41367172007-08-06 15:24:51 +00004478 bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004479}
4480
4481DEFUN (no_ipv6_bgp_network,
4482 no_ipv6_bgp_network_cmd,
4483 "no network X:X::X:X/M",
4484 NO_STR
4485 "Specify a network to announce via BGP\n"
4486 "IPv6 prefix <network>/<length>\n")
4487{
4488 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4489}
4490
4491ALIAS (no_ipv6_bgp_network,
4492 no_ipv6_bgp_network_route_map_cmd,
4493 "no network X:X::X:X/M route-map WORD",
4494 NO_STR
4495 "Specify a network to announce via BGP\n"
4496 "IPv6 prefix <network>/<length>\n"
4497 "Route-map to modify the attributes\n"
4498 "Name of the route map\n")
4499
Paul Jakma41367172007-08-06 15:24:51 +00004500ALIAS (no_ipv6_bgp_network,
4501 no_ipv6_bgp_network_ttl_cmd,
4502 "no network X:X::X:X/M pathlimit <0-255>",
4503 NO_STR
4504 "Specify a network to announce via BGP\n"
4505 "IPv6 prefix <network>/<length>\n"
4506 "AS-Path hopcount limit attribute\n"
4507 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4508
paul718e3742002-12-13 20:15:29 +00004509ALIAS (ipv6_bgp_network,
4510 old_ipv6_bgp_network_cmd,
4511 "ipv6 bgp network X:X::X:X/M",
4512 IPV6_STR
4513 BGP_STR
4514 "Specify a network to announce via BGP\n"
4515 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4516
4517ALIAS (no_ipv6_bgp_network,
4518 old_no_ipv6_bgp_network_cmd,
4519 "no ipv6 bgp network X:X::X:X/M",
4520 NO_STR
4521 IPV6_STR
4522 BGP_STR
4523 "Specify a network to announce via BGP\n"
4524 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4525#endif /* HAVE_IPV6 */
4526
4527/* Aggreagete address:
4528
4529 advertise-map Set condition to advertise attribute
4530 as-set Generate AS set path information
4531 attribute-map Set attributes of aggregate
4532 route-map Set parameters of aggregate
4533 summary-only Filter more specific routes from updates
4534 suppress-map Conditionally filter more specific routes from updates
4535 <cr>
4536 */
4537struct bgp_aggregate
4538{
4539 /* Summary-only flag. */
4540 u_char summary_only;
4541
4542 /* AS set generation. */
4543 u_char as_set;
4544
4545 /* Route-map for aggregated route. */
4546 struct route_map *map;
4547
4548 /* Suppress-count. */
4549 unsigned long count;
4550
4551 /* SAFI configuration. */
4552 safi_t safi;
4553};
4554
paul94f2b392005-06-28 12:44:16 +00004555static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004556bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004557{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004558 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004559}
4560
paul94f2b392005-06-28 12:44:16 +00004561static void
paul718e3742002-12-13 20:15:29 +00004562bgp_aggregate_free (struct bgp_aggregate *aggregate)
4563{
4564 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4565}
4566
paul94f2b392005-06-28 12:44:16 +00004567static void
paul718e3742002-12-13 20:15:29 +00004568bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4569 afi_t afi, safi_t safi, struct bgp_info *del,
4570 struct bgp_aggregate *aggregate)
4571{
4572 struct bgp_table *table;
4573 struct bgp_node *top;
4574 struct bgp_node *rn;
4575 u_char origin;
4576 struct aspath *aspath = NULL;
4577 struct aspath *asmerge = NULL;
4578 struct community *community = NULL;
4579 struct community *commerge = NULL;
4580 struct in_addr nexthop;
4581 u_int32_t med = 0;
4582 struct bgp_info *ri;
4583 struct bgp_info *new;
4584 int first = 1;
4585 unsigned long match = 0;
4586
4587 /* Record adding route's nexthop and med. */
4588 if (rinew)
4589 {
4590 nexthop = rinew->attr->nexthop;
4591 med = rinew->attr->med;
4592 }
4593
4594 /* ORIGIN attribute: If at least one route among routes that are
4595 aggregated has ORIGIN with the value INCOMPLETE, then the
4596 aggregated route must have the ORIGIN attribute with the value
4597 INCOMPLETE. Otherwise, if at least one route among routes that
4598 are aggregated has ORIGIN with the value EGP, then the aggregated
4599 route must have the origin attribute with the value EGP. In all
4600 other case the value of the ORIGIN attribute of the aggregated
4601 route is INTERNAL. */
4602 origin = BGP_ORIGIN_IGP;
4603
4604 table = bgp->rib[afi][safi];
4605
4606 top = bgp_node_get (table, p);
4607 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4608 if (rn->p.prefixlen > p->prefixlen)
4609 {
4610 match = 0;
4611
4612 for (ri = rn->info; ri; ri = ri->next)
4613 {
4614 if (BGP_INFO_HOLDDOWN (ri))
4615 continue;
4616
4617 if (del && ri == del)
4618 continue;
4619
4620 if (! rinew && first)
4621 {
4622 nexthop = ri->attr->nexthop;
4623 med = ri->attr->med;
4624 first = 0;
4625 }
4626
4627#ifdef AGGREGATE_NEXTHOP_CHECK
4628 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4629 || ri->attr->med != med)
4630 {
4631 if (aspath)
4632 aspath_free (aspath);
4633 if (community)
4634 community_free (community);
4635 bgp_unlock_node (rn);
4636 bgp_unlock_node (top);
4637 return;
4638 }
4639#endif /* AGGREGATE_NEXTHOP_CHECK */
4640
4641 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4642 {
4643 if (aggregate->summary_only)
4644 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004645 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004646 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004647 match++;
4648 }
4649
4650 aggregate->count++;
4651
4652 if (aggregate->as_set)
4653 {
4654 if (origin < ri->attr->origin)
4655 origin = ri->attr->origin;
4656
4657 if (aspath)
4658 {
4659 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4660 aspath_free (aspath);
4661 aspath = asmerge;
4662 }
4663 else
4664 aspath = aspath_dup (ri->attr->aspath);
4665
4666 if (ri->attr->community)
4667 {
4668 if (community)
4669 {
4670 commerge = community_merge (community,
4671 ri->attr->community);
4672 community = community_uniq_sort (commerge);
4673 community_free (commerge);
4674 }
4675 else
4676 community = community_dup (ri->attr->community);
4677 }
4678 }
4679 }
4680 }
4681 if (match)
4682 bgp_process (bgp, rn, afi, safi);
4683 }
4684 bgp_unlock_node (top);
4685
4686 if (rinew)
4687 {
4688 aggregate->count++;
4689
4690 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004691 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004692
4693 if (aggregate->as_set)
4694 {
4695 if (origin < rinew->attr->origin)
4696 origin = rinew->attr->origin;
4697
4698 if (aspath)
4699 {
4700 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4701 aspath_free (aspath);
4702 aspath = asmerge;
4703 }
4704 else
4705 aspath = aspath_dup (rinew->attr->aspath);
4706
4707 if (rinew->attr->community)
4708 {
4709 if (community)
4710 {
4711 commerge = community_merge (community,
4712 rinew->attr->community);
4713 community = community_uniq_sort (commerge);
4714 community_free (commerge);
4715 }
4716 else
4717 community = community_dup (rinew->attr->community);
4718 }
4719 }
4720 }
4721
4722 if (aggregate->count > 0)
4723 {
4724 rn = bgp_node_get (table, p);
4725 new = bgp_info_new ();
4726 new->type = ZEBRA_ROUTE_BGP;
4727 new->sub_type = BGP_ROUTE_AGGREGATE;
4728 new->peer = bgp->peer_self;
4729 SET_FLAG (new->flags, BGP_INFO_VALID);
4730 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004731 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004732
4733 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004734 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004735 bgp_process (bgp, rn, afi, safi);
4736 }
4737 else
4738 {
4739 if (aspath)
4740 aspath_free (aspath);
4741 if (community)
4742 community_free (community);
4743 }
4744}
4745
4746void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4747 struct bgp_aggregate *);
4748
4749void
4750bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4751 struct bgp_info *ri, afi_t afi, safi_t safi)
4752{
4753 struct bgp_node *child;
4754 struct bgp_node *rn;
4755 struct bgp_aggregate *aggregate;
4756
4757 /* MPLS-VPN aggregation is not yet supported. */
4758 if (safi == SAFI_MPLS_VPN)
4759 return;
4760
4761 if (p->prefixlen == 0)
4762 return;
4763
4764 if (BGP_INFO_HOLDDOWN (ri))
4765 return;
4766
4767 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4768
4769 /* Aggregate address configuration check. */
4770 for (rn = child; rn; rn = rn->parent)
4771 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4772 {
4773 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004774 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004775 }
4776 bgp_unlock_node (child);
4777}
4778
4779void
4780bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4781 struct bgp_info *del, afi_t afi, safi_t safi)
4782{
4783 struct bgp_node *child;
4784 struct bgp_node *rn;
4785 struct bgp_aggregate *aggregate;
4786
4787 /* MPLS-VPN aggregation is not yet supported. */
4788 if (safi == SAFI_MPLS_VPN)
4789 return;
4790
4791 if (p->prefixlen == 0)
4792 return;
4793
4794 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4795
4796 /* Aggregate address configuration check. */
4797 for (rn = child; rn; rn = rn->parent)
4798 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4799 {
4800 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004801 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004802 }
4803 bgp_unlock_node (child);
4804}
4805
paul94f2b392005-06-28 12:44:16 +00004806static void
paul718e3742002-12-13 20:15:29 +00004807bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4808 struct bgp_aggregate *aggregate)
4809{
4810 struct bgp_table *table;
4811 struct bgp_node *top;
4812 struct bgp_node *rn;
4813 struct bgp_info *new;
4814 struct bgp_info *ri;
4815 unsigned long match;
4816 u_char origin = BGP_ORIGIN_IGP;
4817 struct aspath *aspath = NULL;
4818 struct aspath *asmerge = NULL;
4819 struct community *community = NULL;
4820 struct community *commerge = NULL;
4821
4822 table = bgp->rib[afi][safi];
4823
4824 /* Sanity check. */
4825 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4826 return;
4827 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4828 return;
4829
4830 /* If routes exists below this node, generate aggregate routes. */
4831 top = bgp_node_get (table, p);
4832 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4833 if (rn->p.prefixlen > p->prefixlen)
4834 {
4835 match = 0;
4836
4837 for (ri = rn->info; ri; ri = ri->next)
4838 {
4839 if (BGP_INFO_HOLDDOWN (ri))
4840 continue;
4841
4842 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4843 {
4844 /* summary-only aggregate route suppress aggregated
4845 route announcement. */
4846 if (aggregate->summary_only)
4847 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004848 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004849 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004850 match++;
4851 }
4852 /* as-set aggregate route generate origin, as path,
4853 community aggregation. */
4854 if (aggregate->as_set)
4855 {
4856 if (origin < ri->attr->origin)
4857 origin = ri->attr->origin;
4858
4859 if (aspath)
4860 {
4861 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4862 aspath_free (aspath);
4863 aspath = asmerge;
4864 }
4865 else
4866 aspath = aspath_dup (ri->attr->aspath);
4867
4868 if (ri->attr->community)
4869 {
4870 if (community)
4871 {
4872 commerge = community_merge (community,
4873 ri->attr->community);
4874 community = community_uniq_sort (commerge);
4875 community_free (commerge);
4876 }
4877 else
4878 community = community_dup (ri->attr->community);
4879 }
4880 }
4881 aggregate->count++;
4882 }
4883 }
4884
4885 /* If this node is suppressed, process the change. */
4886 if (match)
4887 bgp_process (bgp, rn, afi, safi);
4888 }
4889 bgp_unlock_node (top);
4890
4891 /* Add aggregate route to BGP table. */
4892 if (aggregate->count)
4893 {
4894 rn = bgp_node_get (table, p);
4895
4896 new = bgp_info_new ();
4897 new->type = ZEBRA_ROUTE_BGP;
4898 new->sub_type = BGP_ROUTE_AGGREGATE;
4899 new->peer = bgp->peer_self;
4900 SET_FLAG (new->flags, BGP_INFO_VALID);
4901 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004902 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004903
4904 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004905 bgp_unlock_node (rn);
4906
paul718e3742002-12-13 20:15:29 +00004907 /* Process change. */
4908 bgp_process (bgp, rn, afi, safi);
4909 }
4910}
4911
4912void
4913bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4914 safi_t safi, struct bgp_aggregate *aggregate)
4915{
4916 struct bgp_table *table;
4917 struct bgp_node *top;
4918 struct bgp_node *rn;
4919 struct bgp_info *ri;
4920 unsigned long match;
4921
4922 table = bgp->rib[afi][safi];
4923
4924 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4925 return;
4926 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4927 return;
4928
4929 /* If routes exists below this node, generate aggregate routes. */
4930 top = bgp_node_get (table, p);
4931 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4932 if (rn->p.prefixlen > p->prefixlen)
4933 {
4934 match = 0;
4935
4936 for (ri = rn->info; ri; ri = ri->next)
4937 {
4938 if (BGP_INFO_HOLDDOWN (ri))
4939 continue;
4940
4941 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4942 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004943 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004944 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004945 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004946
Paul Jakmafb982c22007-05-04 20:15:47 +00004947 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004948 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004949 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004950 match++;
4951 }
4952 }
4953 aggregate->count--;
4954 }
4955 }
4956
Paul Jakmafb982c22007-05-04 20:15:47 +00004957 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004958 if (match)
4959 bgp_process (bgp, rn, afi, safi);
4960 }
4961 bgp_unlock_node (top);
4962
4963 /* Delete aggregate route from BGP table. */
4964 rn = bgp_node_get (table, p);
4965
4966 for (ri = rn->info; ri; ri = ri->next)
4967 if (ri->peer == bgp->peer_self
4968 && ri->type == ZEBRA_ROUTE_BGP
4969 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4970 break;
4971
4972 /* Withdraw static BGP route from routing table. */
4973 if (ri)
4974 {
paul718e3742002-12-13 20:15:29 +00004975 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004976 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004977 }
4978
4979 /* Unlock bgp_node_lookup. */
4980 bgp_unlock_node (rn);
4981}
4982
4983/* Aggregate route attribute. */
4984#define AGGREGATE_SUMMARY_ONLY 1
4985#define AGGREGATE_AS_SET 1
4986
paul94f2b392005-06-28 12:44:16 +00004987static int
Robert Baysf6269b42010-08-05 10:26:28 -07004988bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4989 afi_t afi, safi_t safi)
4990{
4991 int ret;
4992 struct prefix p;
4993 struct bgp_node *rn;
4994 struct bgp *bgp;
4995 struct bgp_aggregate *aggregate;
4996
4997 /* Convert string to prefix structure. */
4998 ret = str2prefix (prefix_str, &p);
4999 if (!ret)
5000 {
5001 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5002 return CMD_WARNING;
5003 }
5004 apply_mask (&p);
5005
5006 /* Get BGP structure. */
5007 bgp = vty->index;
5008
5009 /* Old configuration check. */
5010 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5011 if (! rn)
5012 {
5013 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5014 VTY_NEWLINE);
5015 return CMD_WARNING;
5016 }
5017
5018 aggregate = rn->info;
5019 if (aggregate->safi & SAFI_UNICAST)
5020 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5021 if (aggregate->safi & SAFI_MULTICAST)
5022 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5023
5024 /* Unlock aggregate address configuration. */
5025 rn->info = NULL;
5026 bgp_aggregate_free (aggregate);
5027 bgp_unlock_node (rn);
5028 bgp_unlock_node (rn);
5029
5030 return CMD_SUCCESS;
5031}
5032
5033static int
5034bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005035 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005036 u_char summary_only, u_char as_set)
5037{
5038 int ret;
5039 struct prefix p;
5040 struct bgp_node *rn;
5041 struct bgp *bgp;
5042 struct bgp_aggregate *aggregate;
5043
5044 /* Convert string to prefix structure. */
5045 ret = str2prefix (prefix_str, &p);
5046 if (!ret)
5047 {
5048 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5049 return CMD_WARNING;
5050 }
5051 apply_mask (&p);
5052
5053 /* Get BGP structure. */
5054 bgp = vty->index;
5055
5056 /* Old configuration check. */
5057 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5058
5059 if (rn->info)
5060 {
5061 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005062 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005063 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5064 if (ret)
5065 {
Robert Bays368473f2010-08-05 10:26:29 -07005066 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5067 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005068 return CMD_WARNING;
5069 }
paul718e3742002-12-13 20:15:29 +00005070 }
5071
5072 /* Make aggregate address structure. */
5073 aggregate = bgp_aggregate_new ();
5074 aggregate->summary_only = summary_only;
5075 aggregate->as_set = as_set;
5076 aggregate->safi = safi;
5077 rn->info = aggregate;
5078
5079 /* Aggregate address insert into BGP routing table. */
5080 if (safi & SAFI_UNICAST)
5081 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5082 if (safi & SAFI_MULTICAST)
5083 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5084
5085 return CMD_SUCCESS;
5086}
5087
paul718e3742002-12-13 20:15:29 +00005088DEFUN (aggregate_address,
5089 aggregate_address_cmd,
5090 "aggregate-address A.B.C.D/M",
5091 "Configure BGP aggregate entries\n"
5092 "Aggregate prefix\n")
5093{
5094 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5095}
5096
5097DEFUN (aggregate_address_mask,
5098 aggregate_address_mask_cmd,
5099 "aggregate-address A.B.C.D A.B.C.D",
5100 "Configure BGP aggregate entries\n"
5101 "Aggregate address\n"
5102 "Aggregate mask\n")
5103{
5104 int ret;
5105 char prefix_str[BUFSIZ];
5106
5107 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5108
5109 if (! ret)
5110 {
5111 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5112 return CMD_WARNING;
5113 }
5114
5115 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5116 0, 0);
5117}
5118
5119DEFUN (aggregate_address_summary_only,
5120 aggregate_address_summary_only_cmd,
5121 "aggregate-address A.B.C.D/M summary-only",
5122 "Configure BGP aggregate entries\n"
5123 "Aggregate prefix\n"
5124 "Filter more specific routes from updates\n")
5125{
5126 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5127 AGGREGATE_SUMMARY_ONLY, 0);
5128}
5129
5130DEFUN (aggregate_address_mask_summary_only,
5131 aggregate_address_mask_summary_only_cmd,
5132 "aggregate-address A.B.C.D A.B.C.D summary-only",
5133 "Configure BGP aggregate entries\n"
5134 "Aggregate address\n"
5135 "Aggregate mask\n"
5136 "Filter more specific routes from updates\n")
5137{
5138 int ret;
5139 char prefix_str[BUFSIZ];
5140
5141 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5142
5143 if (! ret)
5144 {
5145 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5146 return CMD_WARNING;
5147 }
5148
5149 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5150 AGGREGATE_SUMMARY_ONLY, 0);
5151}
5152
5153DEFUN (aggregate_address_as_set,
5154 aggregate_address_as_set_cmd,
5155 "aggregate-address A.B.C.D/M as-set",
5156 "Configure BGP aggregate entries\n"
5157 "Aggregate prefix\n"
5158 "Generate AS set path information\n")
5159{
5160 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5161 0, AGGREGATE_AS_SET);
5162}
5163
5164DEFUN (aggregate_address_mask_as_set,
5165 aggregate_address_mask_as_set_cmd,
5166 "aggregate-address A.B.C.D A.B.C.D as-set",
5167 "Configure BGP aggregate entries\n"
5168 "Aggregate address\n"
5169 "Aggregate mask\n"
5170 "Generate AS set path information\n")
5171{
5172 int ret;
5173 char prefix_str[BUFSIZ];
5174
5175 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5176
5177 if (! ret)
5178 {
5179 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5180 return CMD_WARNING;
5181 }
5182
5183 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5184 0, AGGREGATE_AS_SET);
5185}
5186
5187
5188DEFUN (aggregate_address_as_set_summary,
5189 aggregate_address_as_set_summary_cmd,
5190 "aggregate-address A.B.C.D/M as-set summary-only",
5191 "Configure BGP aggregate entries\n"
5192 "Aggregate prefix\n"
5193 "Generate AS set path information\n"
5194 "Filter more specific routes from updates\n")
5195{
5196 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5197 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5198}
5199
5200ALIAS (aggregate_address_as_set_summary,
5201 aggregate_address_summary_as_set_cmd,
5202 "aggregate-address A.B.C.D/M summary-only as-set",
5203 "Configure BGP aggregate entries\n"
5204 "Aggregate prefix\n"
5205 "Filter more specific routes from updates\n"
5206 "Generate AS set path information\n")
5207
5208DEFUN (aggregate_address_mask_as_set_summary,
5209 aggregate_address_mask_as_set_summary_cmd,
5210 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5211 "Configure BGP aggregate entries\n"
5212 "Aggregate address\n"
5213 "Aggregate mask\n"
5214 "Generate AS set path information\n"
5215 "Filter more specific routes from updates\n")
5216{
5217 int ret;
5218 char prefix_str[BUFSIZ];
5219
5220 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5221
5222 if (! ret)
5223 {
5224 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5225 return CMD_WARNING;
5226 }
5227
5228 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5229 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5230}
5231
5232ALIAS (aggregate_address_mask_as_set_summary,
5233 aggregate_address_mask_summary_as_set_cmd,
5234 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5235 "Configure BGP aggregate entries\n"
5236 "Aggregate address\n"
5237 "Aggregate mask\n"
5238 "Filter more specific routes from updates\n"
5239 "Generate AS set path information\n")
5240
5241DEFUN (no_aggregate_address,
5242 no_aggregate_address_cmd,
5243 "no aggregate-address A.B.C.D/M",
5244 NO_STR
5245 "Configure BGP aggregate entries\n"
5246 "Aggregate prefix\n")
5247{
5248 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5249}
5250
5251ALIAS (no_aggregate_address,
5252 no_aggregate_address_summary_only_cmd,
5253 "no aggregate-address A.B.C.D/M summary-only",
5254 NO_STR
5255 "Configure BGP aggregate entries\n"
5256 "Aggregate prefix\n"
5257 "Filter more specific routes from updates\n")
5258
5259ALIAS (no_aggregate_address,
5260 no_aggregate_address_as_set_cmd,
5261 "no aggregate-address A.B.C.D/M as-set",
5262 NO_STR
5263 "Configure BGP aggregate entries\n"
5264 "Aggregate prefix\n"
5265 "Generate AS set path information\n")
5266
5267ALIAS (no_aggregate_address,
5268 no_aggregate_address_as_set_summary_cmd,
5269 "no aggregate-address A.B.C.D/M as-set summary-only",
5270 NO_STR
5271 "Configure BGP aggregate entries\n"
5272 "Aggregate prefix\n"
5273 "Generate AS set path information\n"
5274 "Filter more specific routes from updates\n")
5275
5276ALIAS (no_aggregate_address,
5277 no_aggregate_address_summary_as_set_cmd,
5278 "no aggregate-address A.B.C.D/M summary-only as-set",
5279 NO_STR
5280 "Configure BGP aggregate entries\n"
5281 "Aggregate prefix\n"
5282 "Filter more specific routes from updates\n"
5283 "Generate AS set path information\n")
5284
5285DEFUN (no_aggregate_address_mask,
5286 no_aggregate_address_mask_cmd,
5287 "no aggregate-address A.B.C.D A.B.C.D",
5288 NO_STR
5289 "Configure BGP aggregate entries\n"
5290 "Aggregate address\n"
5291 "Aggregate mask\n")
5292{
5293 int ret;
5294 char prefix_str[BUFSIZ];
5295
5296 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5297
5298 if (! ret)
5299 {
5300 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5301 return CMD_WARNING;
5302 }
5303
5304 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5305}
5306
5307ALIAS (no_aggregate_address_mask,
5308 no_aggregate_address_mask_summary_only_cmd,
5309 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5310 NO_STR
5311 "Configure BGP aggregate entries\n"
5312 "Aggregate address\n"
5313 "Aggregate mask\n"
5314 "Filter more specific routes from updates\n")
5315
5316ALIAS (no_aggregate_address_mask,
5317 no_aggregate_address_mask_as_set_cmd,
5318 "no aggregate-address A.B.C.D A.B.C.D as-set",
5319 NO_STR
5320 "Configure BGP aggregate entries\n"
5321 "Aggregate address\n"
5322 "Aggregate mask\n"
5323 "Generate AS set path information\n")
5324
5325ALIAS (no_aggregate_address_mask,
5326 no_aggregate_address_mask_as_set_summary_cmd,
5327 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5328 NO_STR
5329 "Configure BGP aggregate entries\n"
5330 "Aggregate address\n"
5331 "Aggregate mask\n"
5332 "Generate AS set path information\n"
5333 "Filter more specific routes from updates\n")
5334
5335ALIAS (no_aggregate_address_mask,
5336 no_aggregate_address_mask_summary_as_set_cmd,
5337 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5338 NO_STR
5339 "Configure BGP aggregate entries\n"
5340 "Aggregate address\n"
5341 "Aggregate mask\n"
5342 "Filter more specific routes from updates\n"
5343 "Generate AS set path information\n")
5344
5345#ifdef HAVE_IPV6
5346DEFUN (ipv6_aggregate_address,
5347 ipv6_aggregate_address_cmd,
5348 "aggregate-address X:X::X:X/M",
5349 "Configure BGP aggregate entries\n"
5350 "Aggregate prefix\n")
5351{
5352 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5353}
5354
5355DEFUN (ipv6_aggregate_address_summary_only,
5356 ipv6_aggregate_address_summary_only_cmd,
5357 "aggregate-address X:X::X:X/M summary-only",
5358 "Configure BGP aggregate entries\n"
5359 "Aggregate prefix\n"
5360 "Filter more specific routes from updates\n")
5361{
5362 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5363 AGGREGATE_SUMMARY_ONLY, 0);
5364}
5365
5366DEFUN (no_ipv6_aggregate_address,
5367 no_ipv6_aggregate_address_cmd,
5368 "no aggregate-address X:X::X:X/M",
5369 NO_STR
5370 "Configure BGP aggregate entries\n"
5371 "Aggregate prefix\n")
5372{
5373 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5374}
5375
5376DEFUN (no_ipv6_aggregate_address_summary_only,
5377 no_ipv6_aggregate_address_summary_only_cmd,
5378 "no aggregate-address X:X::X:X/M summary-only",
5379 NO_STR
5380 "Configure BGP aggregate entries\n"
5381 "Aggregate prefix\n"
5382 "Filter more specific routes from updates\n")
5383{
5384 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5385}
5386
5387ALIAS (ipv6_aggregate_address,
5388 old_ipv6_aggregate_address_cmd,
5389 "ipv6 bgp aggregate-address X:X::X:X/M",
5390 IPV6_STR
5391 BGP_STR
5392 "Configure BGP aggregate entries\n"
5393 "Aggregate prefix\n")
5394
5395ALIAS (ipv6_aggregate_address_summary_only,
5396 old_ipv6_aggregate_address_summary_only_cmd,
5397 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5398 IPV6_STR
5399 BGP_STR
5400 "Configure BGP aggregate entries\n"
5401 "Aggregate prefix\n"
5402 "Filter more specific routes from updates\n")
5403
5404ALIAS (no_ipv6_aggregate_address,
5405 old_no_ipv6_aggregate_address_cmd,
5406 "no ipv6 bgp aggregate-address X:X::X:X/M",
5407 NO_STR
5408 IPV6_STR
5409 BGP_STR
5410 "Configure BGP aggregate entries\n"
5411 "Aggregate prefix\n")
5412
5413ALIAS (no_ipv6_aggregate_address_summary_only,
5414 old_no_ipv6_aggregate_address_summary_only_cmd,
5415 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5416 NO_STR
5417 IPV6_STR
5418 BGP_STR
5419 "Configure BGP aggregate entries\n"
5420 "Aggregate prefix\n"
5421 "Filter more specific routes from updates\n")
5422#endif /* HAVE_IPV6 */
5423
5424/* Redistribute route treatment. */
5425void
5426bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5427 u_int32_t metric, u_char type)
5428{
5429 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005430 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005431 struct bgp_info *new;
5432 struct bgp_info *bi;
5433 struct bgp_info info;
5434 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005435 struct attr attr = { 0 };
5436 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005437 struct attr *new_attr;
5438 afi_t afi;
5439 int ret;
5440
5441 /* Make default attribute. */
5442 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5443 if (nexthop)
5444 attr.nexthop = *nexthop;
5445
5446 attr.med = metric;
5447 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5448
paul1eb8ef22005-04-07 07:30:20 +00005449 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005450 {
5451 afi = family2afi (p->family);
5452
5453 if (bgp->redist[afi][type])
5454 {
5455 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005456 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005457
5458 if (bgp->redist_metric_flag[afi][type])
5459 attr_new.med = bgp->redist_metric[afi][type];
5460
5461 /* Apply route-map. */
5462 if (bgp->rmap[afi][type].map)
5463 {
5464 info.peer = bgp->peer_self;
5465 info.attr = &attr_new;
5466
paulfee0f4c2004-09-13 05:12:46 +00005467 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5468
paul718e3742002-12-13 20:15:29 +00005469 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5470 &info);
paulfee0f4c2004-09-13 05:12:46 +00005471
5472 bgp->peer_self->rmap_type = 0;
5473
paul718e3742002-12-13 20:15:29 +00005474 if (ret == RMAP_DENYMATCH)
5475 {
5476 /* Free uninterned attribute. */
5477 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005478 bgp_attr_extra_free (&attr_new);
5479
paul718e3742002-12-13 20:15:29 +00005480 /* Unintern original. */
5481 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005482 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005483 bgp_redistribute_delete (p, type);
5484 return;
5485 }
5486 }
5487
Paul Jakmafb982c22007-05-04 20:15:47 +00005488 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5489 afi, SAFI_UNICAST, p, NULL);
5490
paul718e3742002-12-13 20:15:29 +00005491 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005492 bgp_attr_extra_free (&attr_new);
5493
paul718e3742002-12-13 20:15:29 +00005494 for (bi = bn->info; bi; bi = bi->next)
5495 if (bi->peer == bgp->peer_self
5496 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5497 break;
5498
5499 if (bi)
5500 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005501 if (attrhash_cmp (bi->attr, new_attr) &&
5502 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005503 {
5504 bgp_attr_unintern (new_attr);
5505 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005506 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005507 bgp_unlock_node (bn);
5508 return;
5509 }
5510 else
5511 {
5512 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005513 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005514
5515 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005516 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5517 bgp_info_restore(bn, bi);
5518 else
5519 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005520 bgp_attr_unintern (bi->attr);
5521 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005522 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005523
5524 /* Process change. */
5525 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5526 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5527 bgp_unlock_node (bn);
5528 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005529 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005530 return;
5531 }
5532 }
5533
5534 new = bgp_info_new ();
5535 new->type = type;
5536 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5537 new->peer = bgp->peer_self;
5538 SET_FLAG (new->flags, BGP_INFO_VALID);
5539 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005540 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005541
5542 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5543 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005544 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005545 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5546 }
5547 }
5548
5549 /* Unintern original. */
5550 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005551 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005552}
5553
5554void
5555bgp_redistribute_delete (struct prefix *p, u_char type)
5556{
5557 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005558 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005559 afi_t afi;
5560 struct bgp_node *rn;
5561 struct bgp_info *ri;
5562
paul1eb8ef22005-04-07 07:30:20 +00005563 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005564 {
5565 afi = family2afi (p->family);
5566
5567 if (bgp->redist[afi][type])
5568 {
paulfee0f4c2004-09-13 05:12:46 +00005569 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005570
5571 for (ri = rn->info; ri; ri = ri->next)
5572 if (ri->peer == bgp->peer_self
5573 && ri->type == type)
5574 break;
5575
5576 if (ri)
5577 {
5578 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005579 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005580 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005581 }
5582 bgp_unlock_node (rn);
5583 }
5584 }
5585}
5586
5587/* Withdraw specified route type's route. */
5588void
5589bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5590{
5591 struct bgp_node *rn;
5592 struct bgp_info *ri;
5593 struct bgp_table *table;
5594
5595 table = bgp->rib[afi][SAFI_UNICAST];
5596
5597 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5598 {
5599 for (ri = rn->info; ri; ri = ri->next)
5600 if (ri->peer == bgp->peer_self
5601 && ri->type == type)
5602 break;
5603
5604 if (ri)
5605 {
5606 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005607 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005608 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005609 }
5610 }
5611}
5612
5613/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005614static void
paul718e3742002-12-13 20:15:29 +00005615route_vty_out_route (struct prefix *p, struct vty *vty)
5616{
5617 int len;
5618 u_int32_t destination;
5619 char buf[BUFSIZ];
5620
5621 if (p->family == AF_INET)
5622 {
5623 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5624 destination = ntohl (p->u.prefix4.s_addr);
5625
5626 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5627 || (IN_CLASSB (destination) && p->prefixlen == 16)
5628 || (IN_CLASSA (destination) && p->prefixlen == 8)
5629 || p->u.prefix4.s_addr == 0)
5630 {
5631 /* When mask is natural, mask is not displayed. */
5632 }
5633 else
5634 len += vty_out (vty, "/%d", p->prefixlen);
5635 }
5636 else
5637 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5638 p->prefixlen);
5639
5640 len = 17 - len;
5641 if (len < 1)
5642 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5643 else
5644 vty_out (vty, "%*s", len, " ");
5645}
5646
paul718e3742002-12-13 20:15:29 +00005647enum bgp_display_type
5648{
5649 normal_list,
5650};
5651
paulb40d9392005-08-22 22:34:41 +00005652/* Print the short form route status for a bgp_info */
5653static void
5654route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005655{
paulb40d9392005-08-22 22:34:41 +00005656 /* Route status display. */
5657 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5658 vty_out (vty, "R");
5659 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005660 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005661 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005662 vty_out (vty, "s");
5663 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5664 vty_out (vty, "*");
5665 else
5666 vty_out (vty, " ");
5667
5668 /* Selected */
5669 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5670 vty_out (vty, "h");
5671 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5672 vty_out (vty, "d");
5673 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5674 vty_out (vty, ">");
5675 else
5676 vty_out (vty, " ");
5677
5678 /* Internal route. */
5679 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5680 vty_out (vty, "i");
5681 else
paulb40d9392005-08-22 22:34:41 +00005682 vty_out (vty, " ");
5683}
5684
5685/* called from terminal list command */
5686void
5687route_vty_out (struct vty *vty, struct prefix *p,
5688 struct bgp_info *binfo, int display, safi_t safi)
5689{
5690 struct attr *attr;
5691
5692 /* short status lead text */
5693 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005694
5695 /* print prefix and mask */
5696 if (! display)
5697 route_vty_out_route (p, vty);
5698 else
5699 vty_out (vty, "%*s", 17, " ");
5700
5701 /* Print attribute */
5702 attr = binfo->attr;
5703 if (attr)
5704 {
5705 if (p->family == AF_INET)
5706 {
5707 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005708 vty_out (vty, "%-16s",
5709 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005710 else
5711 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5712 }
5713#ifdef HAVE_IPV6
5714 else if (p->family == AF_INET6)
5715 {
5716 int len;
5717 char buf[BUFSIZ];
5718
5719 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005720 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5721 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005722 len = 16 - len;
5723 if (len < 1)
5724 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5725 else
5726 vty_out (vty, "%*s", len, " ");
5727 }
5728#endif /* HAVE_IPV6 */
5729
5730 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5731 vty_out (vty, "%10d", attr->med);
5732 else
5733 vty_out (vty, " ");
5734
5735 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5736 vty_out (vty, "%7d", attr->local_pref);
5737 else
5738 vty_out (vty, " ");
5739
Paul Jakmafb982c22007-05-04 20:15:47 +00005740 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005741
Paul Jakmab2518c12006-05-12 23:48:40 +00005742 /* Print aspath */
5743 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005744 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005745
Paul Jakmab2518c12006-05-12 23:48:40 +00005746 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005747 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005748 }
paul718e3742002-12-13 20:15:29 +00005749 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005750}
5751
5752/* called from terminal list command */
5753void
5754route_vty_out_tmp (struct vty *vty, struct prefix *p,
5755 struct attr *attr, safi_t safi)
5756{
5757 /* Route status display. */
5758 vty_out (vty, "*");
5759 vty_out (vty, ">");
5760 vty_out (vty, " ");
5761
5762 /* print prefix and mask */
5763 route_vty_out_route (p, vty);
5764
5765 /* Print attribute */
5766 if (attr)
5767 {
5768 if (p->family == AF_INET)
5769 {
5770 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005771 vty_out (vty, "%-16s",
5772 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005773 else
5774 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5775 }
5776#ifdef HAVE_IPV6
5777 else if (p->family == AF_INET6)
5778 {
5779 int len;
5780 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005781
5782 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005783
5784 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005785 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5786 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005787 len = 16 - len;
5788 if (len < 1)
5789 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5790 else
5791 vty_out (vty, "%*s", len, " ");
5792 }
5793#endif /* HAVE_IPV6 */
5794
5795 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5796 vty_out (vty, "%10d", attr->med);
5797 else
5798 vty_out (vty, " ");
5799
5800 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5801 vty_out (vty, "%7d", attr->local_pref);
5802 else
5803 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005804
5805 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5806
Paul Jakmab2518c12006-05-12 23:48:40 +00005807 /* Print aspath */
5808 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005809 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005810
Paul Jakmab2518c12006-05-12 23:48:40 +00005811 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005812 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005813 }
paul718e3742002-12-13 20:15:29 +00005814
5815 vty_out (vty, "%s", VTY_NEWLINE);
5816}
5817
ajs5a646652004-11-05 01:25:55 +00005818void
paul718e3742002-12-13 20:15:29 +00005819route_vty_out_tag (struct vty *vty, struct prefix *p,
5820 struct bgp_info *binfo, int display, safi_t safi)
5821{
5822 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005823 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005824
5825 if (!binfo->extra)
5826 return;
5827
paulb40d9392005-08-22 22:34:41 +00005828 /* short status lead text */
5829 route_vty_short_status_out (vty, binfo);
5830
paul718e3742002-12-13 20:15:29 +00005831 /* print prefix and mask */
5832 if (! display)
5833 route_vty_out_route (p, vty);
5834 else
5835 vty_out (vty, "%*s", 17, " ");
5836
5837 /* Print attribute */
5838 attr = binfo->attr;
5839 if (attr)
5840 {
5841 if (p->family == AF_INET)
5842 {
5843 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005844 vty_out (vty, "%-16s",
5845 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005846 else
5847 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5848 }
5849#ifdef HAVE_IPV6
5850 else if (p->family == AF_INET6)
5851 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005852 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005853 char buf[BUFSIZ];
5854 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005855 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005856 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005857 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5858 buf, BUFSIZ));
5859 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005860 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005861 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5862 buf, BUFSIZ),
5863 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5864 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005865
5866 }
5867#endif /* HAVE_IPV6 */
5868 }
5869
Paul Jakmafb982c22007-05-04 20:15:47 +00005870 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005871
5872 vty_out (vty, "notag/%d", label);
5873
5874 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005875}
5876
5877/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005878static void
paul718e3742002-12-13 20:15:29 +00005879damp_route_vty_out (struct vty *vty, struct prefix *p,
5880 struct bgp_info *binfo, int display, safi_t safi)
5881{
5882 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005883 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005884 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005885
paulb40d9392005-08-22 22:34:41 +00005886 /* short status lead text */
5887 route_vty_short_status_out (vty, binfo);
5888
paul718e3742002-12-13 20:15:29 +00005889 /* print prefix and mask */
5890 if (! display)
5891 route_vty_out_route (p, vty);
5892 else
5893 vty_out (vty, "%*s", 17, " ");
5894
5895 len = vty_out (vty, "%s", binfo->peer->host);
5896 len = 17 - len;
5897 if (len < 1)
5898 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5899 else
5900 vty_out (vty, "%*s", len, " ");
5901
Chris Caputo50aef6f2009-06-23 06:06:49 +00005902 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005903
5904 /* Print attribute */
5905 attr = binfo->attr;
5906 if (attr)
5907 {
5908 /* Print aspath */
5909 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005910 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005911
5912 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005913 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005914 }
5915 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005916}
5917
paul718e3742002-12-13 20:15:29 +00005918/* flap route */
ajs5a646652004-11-05 01:25:55 +00005919static void
paul718e3742002-12-13 20:15:29 +00005920flap_route_vty_out (struct vty *vty, struct prefix *p,
5921 struct bgp_info *binfo, int display, safi_t safi)
5922{
5923 struct attr *attr;
5924 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005925 char timebuf[BGP_UPTIME_LEN];
5926 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005927
5928 if (!binfo->extra)
5929 return;
5930
5931 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005932
paulb40d9392005-08-22 22:34:41 +00005933 /* short status lead text */
5934 route_vty_short_status_out (vty, binfo);
5935
paul718e3742002-12-13 20:15:29 +00005936 /* print prefix and mask */
5937 if (! display)
5938 route_vty_out_route (p, vty);
5939 else
5940 vty_out (vty, "%*s", 17, " ");
5941
5942 len = vty_out (vty, "%s", binfo->peer->host);
5943 len = 16 - len;
5944 if (len < 1)
5945 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5946 else
5947 vty_out (vty, "%*s", len, " ");
5948
5949 len = vty_out (vty, "%d", bdi->flap);
5950 len = 5 - len;
5951 if (len < 1)
5952 vty_out (vty, " ");
5953 else
5954 vty_out (vty, "%*s ", len, " ");
5955
5956 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5957 timebuf, BGP_UPTIME_LEN));
5958
5959 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5960 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005961 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005962 else
5963 vty_out (vty, "%*s ", 8, " ");
5964
5965 /* Print attribute */
5966 attr = binfo->attr;
5967 if (attr)
5968 {
5969 /* Print aspath */
5970 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005971 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005972
5973 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005974 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005975 }
5976 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005977}
5978
paul94f2b392005-06-28 12:44:16 +00005979static void
paul718e3742002-12-13 20:15:29 +00005980route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5981 struct bgp_info *binfo, afi_t afi, safi_t safi)
5982{
5983 char buf[INET6_ADDRSTRLEN];
5984 char buf1[BUFSIZ];
5985 struct attr *attr;
5986 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005987#ifdef HAVE_CLOCK_MONOTONIC
5988 time_t tbuf;
5989#endif
paul718e3742002-12-13 20:15:29 +00005990
5991 attr = binfo->attr;
5992
5993 if (attr)
5994 {
5995 /* Line1 display AS-path, Aggregator */
5996 if (attr->aspath)
5997 {
5998 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005999 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006000 vty_out (vty, "Local");
6001 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006002 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006003 }
6004
paulb40d9392005-08-22 22:34:41 +00006005 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6006 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006007 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6008 vty_out (vty, ", (stale)");
6009 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006010 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006011 attr->extra->aggregator_as,
6012 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006013 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6014 vty_out (vty, ", (Received from a RR-client)");
6015 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6016 vty_out (vty, ", (Received from a RS-client)");
6017 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6018 vty_out (vty, ", (history entry)");
6019 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6020 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006021 vty_out (vty, "%s", VTY_NEWLINE);
6022
6023 /* Line2 display Next-hop, Neighbor, Router-id */
6024 if (p->family == AF_INET)
6025 {
6026 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006027 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006028 inet_ntoa (attr->nexthop));
6029 }
6030#ifdef HAVE_IPV6
6031 else
6032 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006033 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006034 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006035 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006036 buf, INET6_ADDRSTRLEN));
6037 }
6038#endif /* HAVE_IPV6 */
6039
6040 if (binfo->peer == bgp->peer_self)
6041 {
6042 vty_out (vty, " from %s ",
6043 p->family == AF_INET ? "0.0.0.0" : "::");
6044 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6045 }
6046 else
6047 {
6048 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6049 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006050 else if (binfo->extra && binfo->extra->igpmetric)
6051 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006052 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006053 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006054 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006055 else
6056 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6057 }
6058 vty_out (vty, "%s", VTY_NEWLINE);
6059
6060#ifdef HAVE_IPV6
6061 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006062 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006063 {
6064 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006065 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006066 buf, INET6_ADDRSTRLEN),
6067 VTY_NEWLINE);
6068 }
6069#endif /* HAVE_IPV6 */
6070
6071 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6072 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6073
6074 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6075 vty_out (vty, ", metric %d", attr->med);
6076
6077 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6078 vty_out (vty, ", localpref %d", attr->local_pref);
6079 else
6080 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6081
Paul Jakmafb982c22007-05-04 20:15:47 +00006082 if (attr->extra && attr->extra->weight != 0)
6083 vty_out (vty, ", weight %d", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006084
6085 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6086 vty_out (vty, ", valid");
6087
6088 if (binfo->peer != bgp->peer_self)
6089 {
6090 if (binfo->peer->as == binfo->peer->local_as)
6091 vty_out (vty, ", internal");
6092 else
6093 vty_out (vty, ", %s",
6094 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6095 }
6096 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6097 vty_out (vty, ", aggregated, local");
6098 else if (binfo->type != ZEBRA_ROUTE_BGP)
6099 vty_out (vty, ", sourced");
6100 else
6101 vty_out (vty, ", sourced, local");
6102
6103 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6104 vty_out (vty, ", atomic-aggregate");
6105
6106 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6107 vty_out (vty, ", best");
6108
6109 vty_out (vty, "%s", VTY_NEWLINE);
6110
6111 /* Line 4 display Community */
6112 if (attr->community)
6113 vty_out (vty, " Community: %s%s", attr->community->str,
6114 VTY_NEWLINE);
6115
6116 /* Line 5 display Extended-community */
6117 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006118 vty_out (vty, " Extended Community: %s%s",
6119 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006120
6121 /* Line 6 display Originator, Cluster-id */
6122 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6123 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6124 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006125 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006126 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006127 vty_out (vty, " Originator: %s",
6128 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006129
6130 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6131 {
6132 int i;
6133 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006134 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6135 vty_out (vty, "%s ",
6136 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006137 }
6138 vty_out (vty, "%s", VTY_NEWLINE);
6139 }
Paul Jakma41367172007-08-06 15:24:51 +00006140
6141 /* 7: AS Pathlimit */
6142 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6143 {
6144
6145 vty_out (vty, " AS-Pathlimit: %u",
6146 attr->pathlimit.ttl);
6147 if (attr->pathlimit.as)
6148 vty_out (vty, " (%u)", attr->pathlimit.as);
6149 vty_out (vty, "%s", VTY_NEWLINE);
6150 }
6151
Paul Jakmafb982c22007-05-04 20:15:47 +00006152 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006153 bgp_damp_info_vty (vty, binfo);
6154
6155 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006156#ifdef HAVE_CLOCK_MONOTONIC
6157 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006158 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006159#else
6160 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6161#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006162 }
6163 vty_out (vty, "%s", VTY_NEWLINE);
6164}
6165
paulb40d9392005-08-22 22:34:41 +00006166#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 +00006167#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006168#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6169#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6170#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6171
6172enum bgp_show_type
6173{
6174 bgp_show_type_normal,
6175 bgp_show_type_regexp,
6176 bgp_show_type_prefix_list,
6177 bgp_show_type_filter_list,
6178 bgp_show_type_route_map,
6179 bgp_show_type_neighbor,
6180 bgp_show_type_cidr_only,
6181 bgp_show_type_prefix_longer,
6182 bgp_show_type_community_all,
6183 bgp_show_type_community,
6184 bgp_show_type_community_exact,
6185 bgp_show_type_community_list,
6186 bgp_show_type_community_list_exact,
6187 bgp_show_type_flap_statistics,
6188 bgp_show_type_flap_address,
6189 bgp_show_type_flap_prefix,
6190 bgp_show_type_flap_cidr_only,
6191 bgp_show_type_flap_regexp,
6192 bgp_show_type_flap_filter_list,
6193 bgp_show_type_flap_prefix_list,
6194 bgp_show_type_flap_prefix_longer,
6195 bgp_show_type_flap_route_map,
6196 bgp_show_type_flap_neighbor,
6197 bgp_show_type_dampend_paths,
6198 bgp_show_type_damp_neighbor
6199};
6200
ajs5a646652004-11-05 01:25:55 +00006201static int
paulfee0f4c2004-09-13 05:12:46 +00006202bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006203 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006204{
paul718e3742002-12-13 20:15:29 +00006205 struct bgp_info *ri;
6206 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006207 int header = 1;
paul718e3742002-12-13 20:15:29 +00006208 int display;
ajs5a646652004-11-05 01:25:55 +00006209 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006210
6211 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006212 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006213
paul718e3742002-12-13 20:15:29 +00006214 /* Start processing of routes. */
6215 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6216 if (rn->info != NULL)
6217 {
6218 display = 0;
6219
6220 for (ri = rn->info; ri; ri = ri->next)
6221 {
ajs5a646652004-11-05 01:25:55 +00006222 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006223 || type == bgp_show_type_flap_address
6224 || type == bgp_show_type_flap_prefix
6225 || type == bgp_show_type_flap_cidr_only
6226 || type == bgp_show_type_flap_regexp
6227 || type == bgp_show_type_flap_filter_list
6228 || type == bgp_show_type_flap_prefix_list
6229 || type == bgp_show_type_flap_prefix_longer
6230 || type == bgp_show_type_flap_route_map
6231 || type == bgp_show_type_flap_neighbor
6232 || type == bgp_show_type_dampend_paths
6233 || type == bgp_show_type_damp_neighbor)
6234 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006235 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006236 continue;
6237 }
6238 if (type == bgp_show_type_regexp
6239 || type == bgp_show_type_flap_regexp)
6240 {
ajs5a646652004-11-05 01:25:55 +00006241 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006242
6243 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6244 continue;
6245 }
6246 if (type == bgp_show_type_prefix_list
6247 || type == bgp_show_type_flap_prefix_list)
6248 {
ajs5a646652004-11-05 01:25:55 +00006249 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006250
6251 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6252 continue;
6253 }
6254 if (type == bgp_show_type_filter_list
6255 || type == bgp_show_type_flap_filter_list)
6256 {
ajs5a646652004-11-05 01:25:55 +00006257 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006258
6259 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6260 continue;
6261 }
6262 if (type == bgp_show_type_route_map
6263 || type == bgp_show_type_flap_route_map)
6264 {
ajs5a646652004-11-05 01:25:55 +00006265 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006266 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006267 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006268 int ret;
6269
Paul Jakmafb982c22007-05-04 20:15:47 +00006270 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006271 binfo.peer = ri->peer;
6272 binfo.attr = &dummy_attr;
6273
6274 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006275
6276 bgp_attr_extra_free (&dummy_attr);
6277
paul718e3742002-12-13 20:15:29 +00006278 if (ret == RMAP_DENYMATCH)
6279 continue;
6280 }
6281 if (type == bgp_show_type_neighbor
6282 || type == bgp_show_type_flap_neighbor
6283 || type == bgp_show_type_damp_neighbor)
6284 {
ajs5a646652004-11-05 01:25:55 +00006285 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006286
6287 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6288 continue;
6289 }
6290 if (type == bgp_show_type_cidr_only
6291 || type == bgp_show_type_flap_cidr_only)
6292 {
6293 u_int32_t destination;
6294
6295 destination = ntohl (rn->p.u.prefix4.s_addr);
6296 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6297 continue;
6298 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6299 continue;
6300 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6301 continue;
6302 }
6303 if (type == bgp_show_type_prefix_longer
6304 || type == bgp_show_type_flap_prefix_longer)
6305 {
ajs5a646652004-11-05 01:25:55 +00006306 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006307
6308 if (! prefix_match (p, &rn->p))
6309 continue;
6310 }
6311 if (type == bgp_show_type_community_all)
6312 {
6313 if (! ri->attr->community)
6314 continue;
6315 }
6316 if (type == bgp_show_type_community)
6317 {
ajs5a646652004-11-05 01:25:55 +00006318 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006319
6320 if (! ri->attr->community ||
6321 ! community_match (ri->attr->community, com))
6322 continue;
6323 }
6324 if (type == bgp_show_type_community_exact)
6325 {
ajs5a646652004-11-05 01:25:55 +00006326 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006327
6328 if (! ri->attr->community ||
6329 ! community_cmp (ri->attr->community, com))
6330 continue;
6331 }
6332 if (type == bgp_show_type_community_list)
6333 {
ajs5a646652004-11-05 01:25:55 +00006334 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006335
6336 if (! community_list_match (ri->attr->community, list))
6337 continue;
6338 }
6339 if (type == bgp_show_type_community_list_exact)
6340 {
ajs5a646652004-11-05 01:25:55 +00006341 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006342
6343 if (! community_list_exact_match (ri->attr->community, list))
6344 continue;
6345 }
6346 if (type == bgp_show_type_flap_address
6347 || type == bgp_show_type_flap_prefix)
6348 {
ajs5a646652004-11-05 01:25:55 +00006349 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006350
6351 if (! prefix_match (&rn->p, p))
6352 continue;
6353
6354 if (type == bgp_show_type_flap_prefix)
6355 if (p->prefixlen != rn->p.prefixlen)
6356 continue;
6357 }
6358 if (type == bgp_show_type_dampend_paths
6359 || type == bgp_show_type_damp_neighbor)
6360 {
6361 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6362 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6363 continue;
6364 }
6365
6366 if (header)
6367 {
hasso93406d82005-02-02 14:40:33 +00006368 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6369 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6370 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006371 if (type == bgp_show_type_dampend_paths
6372 || type == bgp_show_type_damp_neighbor)
6373 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6374 else if (type == bgp_show_type_flap_statistics
6375 || type == bgp_show_type_flap_address
6376 || type == bgp_show_type_flap_prefix
6377 || type == bgp_show_type_flap_cidr_only
6378 || type == bgp_show_type_flap_regexp
6379 || type == bgp_show_type_flap_filter_list
6380 || type == bgp_show_type_flap_prefix_list
6381 || type == bgp_show_type_flap_prefix_longer
6382 || type == bgp_show_type_flap_route_map
6383 || type == bgp_show_type_flap_neighbor)
6384 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6385 else
6386 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006387 header = 0;
6388 }
6389
6390 if (type == bgp_show_type_dampend_paths
6391 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006392 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006393 else if (type == bgp_show_type_flap_statistics
6394 || type == bgp_show_type_flap_address
6395 || type == bgp_show_type_flap_prefix
6396 || type == bgp_show_type_flap_cidr_only
6397 || type == bgp_show_type_flap_regexp
6398 || type == bgp_show_type_flap_filter_list
6399 || type == bgp_show_type_flap_prefix_list
6400 || type == bgp_show_type_flap_prefix_longer
6401 || type == bgp_show_type_flap_route_map
6402 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006403 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006404 else
ajs5a646652004-11-05 01:25:55 +00006405 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006406 display++;
6407 }
6408 if (display)
ajs5a646652004-11-05 01:25:55 +00006409 output_count++;
paul718e3742002-12-13 20:15:29 +00006410 }
6411
6412 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006413 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006414 {
6415 if (type == bgp_show_type_normal)
6416 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6417 }
6418 else
6419 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006420 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006421
6422 return CMD_SUCCESS;
6423}
6424
ajs5a646652004-11-05 01:25:55 +00006425static int
paulfee0f4c2004-09-13 05:12:46 +00006426bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006427 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006428{
6429 struct bgp_table *table;
6430
6431 if (bgp == NULL) {
6432 bgp = bgp_get_default ();
6433 }
6434
6435 if (bgp == NULL)
6436 {
6437 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6438 return CMD_WARNING;
6439 }
6440
6441
6442 table = bgp->rib[afi][safi];
6443
ajs5a646652004-11-05 01:25:55 +00006444 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006445}
6446
paul718e3742002-12-13 20:15:29 +00006447/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006448static void
paul718e3742002-12-13 20:15:29 +00006449route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6450 struct bgp_node *rn,
6451 struct prefix_rd *prd, afi_t afi, safi_t safi)
6452{
6453 struct bgp_info *ri;
6454 struct prefix *p;
6455 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006456 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006457 char buf1[INET6_ADDRSTRLEN];
6458 char buf2[INET6_ADDRSTRLEN];
6459 int count = 0;
6460 int best = 0;
6461 int suppress = 0;
6462 int no_export = 0;
6463 int no_advertise = 0;
6464 int local_as = 0;
6465 int first = 0;
6466
6467 p = &rn->p;
6468 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6469 (safi == SAFI_MPLS_VPN ?
6470 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6471 safi == SAFI_MPLS_VPN ? ":" : "",
6472 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6473 p->prefixlen, VTY_NEWLINE);
6474
6475 for (ri = rn->info; ri; ri = ri->next)
6476 {
6477 count++;
6478 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6479 {
6480 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006481 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006482 suppress = 1;
6483 if (ri->attr->community != NULL)
6484 {
6485 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6486 no_advertise = 1;
6487 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6488 no_export = 1;
6489 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6490 local_as = 1;
6491 }
6492 }
6493 }
6494
6495 vty_out (vty, "Paths: (%d available", count);
6496 if (best)
6497 {
6498 vty_out (vty, ", best #%d", best);
6499 if (safi == SAFI_UNICAST)
6500 vty_out (vty, ", table Default-IP-Routing-Table");
6501 }
6502 else
6503 vty_out (vty, ", no best path");
6504 if (no_advertise)
6505 vty_out (vty, ", not advertised to any peer");
6506 else if (no_export)
6507 vty_out (vty, ", not advertised to EBGP peer");
6508 else if (local_as)
6509 vty_out (vty, ", not advertised outside local AS");
6510 if (suppress)
6511 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6512 vty_out (vty, ")%s", VTY_NEWLINE);
6513
6514 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006515 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006516 {
6517 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6518 {
6519 if (! first)
6520 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6521 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6522 first = 1;
6523 }
6524 }
6525 if (! first)
6526 vty_out (vty, " Not advertised to any peer");
6527 vty_out (vty, "%s", VTY_NEWLINE);
6528}
6529
6530/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006531static int
paulfee0f4c2004-09-13 05:12:46 +00006532bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006533 struct bgp_table *rib, const char *ip_str,
6534 afi_t afi, safi_t safi, struct prefix_rd *prd,
6535 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006536{
6537 int ret;
6538 int header;
6539 int display = 0;
6540 struct prefix match;
6541 struct bgp_node *rn;
6542 struct bgp_node *rm;
6543 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006544 struct bgp_table *table;
6545
paul718e3742002-12-13 20:15:29 +00006546 /* Check IP address argument. */
6547 ret = str2prefix (ip_str, &match);
6548 if (! ret)
6549 {
6550 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6551 return CMD_WARNING;
6552 }
6553
6554 match.family = afi2family (afi);
6555
6556 if (safi == SAFI_MPLS_VPN)
6557 {
paulfee0f4c2004-09-13 05:12:46 +00006558 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006559 {
6560 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6561 continue;
6562
6563 if ((table = rn->info) != NULL)
6564 {
6565 header = 1;
6566
6567 if ((rm = bgp_node_match (table, &match)) != NULL)
6568 {
6569 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006570 {
6571 bgp_unlock_node (rm);
6572 continue;
6573 }
paul718e3742002-12-13 20:15:29 +00006574
6575 for (ri = rm->info; ri; ri = ri->next)
6576 {
6577 if (header)
6578 {
6579 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6580 AFI_IP, SAFI_MPLS_VPN);
6581
6582 header = 0;
6583 }
6584 display++;
6585 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6586 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006587
6588 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006589 }
6590 }
6591 }
6592 }
6593 else
6594 {
6595 header = 1;
6596
paulfee0f4c2004-09-13 05:12:46 +00006597 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006598 {
6599 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6600 {
6601 for (ri = rn->info; ri; ri = ri->next)
6602 {
6603 if (header)
6604 {
6605 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6606 header = 0;
6607 }
6608 display++;
6609 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6610 }
6611 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006612
6613 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006614 }
6615 }
6616
6617 if (! display)
6618 {
6619 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6620 return CMD_WARNING;
6621 }
6622
6623 return CMD_SUCCESS;
6624}
6625
paulfee0f4c2004-09-13 05:12:46 +00006626/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006627static int
paulfd79ac92004-10-13 05:06:08 +00006628bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006629 afi_t afi, safi_t safi, struct prefix_rd *prd,
6630 int prefix_check)
6631{
6632 struct bgp *bgp;
6633
6634 /* BGP structure lookup. */
6635 if (view_name)
6636 {
6637 bgp = bgp_lookup_by_name (view_name);
6638 if (bgp == NULL)
6639 {
6640 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6641 return CMD_WARNING;
6642 }
6643 }
6644 else
6645 {
6646 bgp = bgp_get_default ();
6647 if (bgp == NULL)
6648 {
6649 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6650 return CMD_WARNING;
6651 }
6652 }
6653
6654 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6655 afi, safi, prd, prefix_check);
6656}
6657
paul718e3742002-12-13 20:15:29 +00006658/* BGP route print out function. */
6659DEFUN (show_ip_bgp,
6660 show_ip_bgp_cmd,
6661 "show ip bgp",
6662 SHOW_STR
6663 IP_STR
6664 BGP_STR)
6665{
ajs5a646652004-11-05 01:25:55 +00006666 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006667}
6668
6669DEFUN (show_ip_bgp_ipv4,
6670 show_ip_bgp_ipv4_cmd,
6671 "show ip bgp ipv4 (unicast|multicast)",
6672 SHOW_STR
6673 IP_STR
6674 BGP_STR
6675 "Address family\n"
6676 "Address Family modifier\n"
6677 "Address Family modifier\n")
6678{
6679 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006680 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6681 NULL);
paul718e3742002-12-13 20:15:29 +00006682
ajs5a646652004-11-05 01:25:55 +00006683 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006684}
6685
6686DEFUN (show_ip_bgp_route,
6687 show_ip_bgp_route_cmd,
6688 "show ip bgp A.B.C.D",
6689 SHOW_STR
6690 IP_STR
6691 BGP_STR
6692 "Network in the BGP routing table to display\n")
6693{
6694 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6695}
6696
6697DEFUN (show_ip_bgp_ipv4_route,
6698 show_ip_bgp_ipv4_route_cmd,
6699 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6700 SHOW_STR
6701 IP_STR
6702 BGP_STR
6703 "Address family\n"
6704 "Address Family modifier\n"
6705 "Address Family modifier\n"
6706 "Network in the BGP routing table to display\n")
6707{
6708 if (strncmp (argv[0], "m", 1) == 0)
6709 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6710
6711 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6712}
6713
6714DEFUN (show_ip_bgp_vpnv4_all_route,
6715 show_ip_bgp_vpnv4_all_route_cmd,
6716 "show ip bgp vpnv4 all A.B.C.D",
6717 SHOW_STR
6718 IP_STR
6719 BGP_STR
6720 "Display VPNv4 NLRI specific information\n"
6721 "Display information about all VPNv4 NLRIs\n"
6722 "Network in the BGP routing table to display\n")
6723{
6724 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6725}
6726
6727DEFUN (show_ip_bgp_vpnv4_rd_route,
6728 show_ip_bgp_vpnv4_rd_route_cmd,
6729 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6730 SHOW_STR
6731 IP_STR
6732 BGP_STR
6733 "Display VPNv4 NLRI specific information\n"
6734 "Display information for a route distinguisher\n"
6735 "VPN Route Distinguisher\n"
6736 "Network in the BGP routing table to display\n")
6737{
6738 int ret;
6739 struct prefix_rd prd;
6740
6741 ret = str2prefix_rd (argv[0], &prd);
6742 if (! ret)
6743 {
6744 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6745 return CMD_WARNING;
6746 }
6747 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6748}
6749
6750DEFUN (show_ip_bgp_prefix,
6751 show_ip_bgp_prefix_cmd,
6752 "show ip bgp A.B.C.D/M",
6753 SHOW_STR
6754 IP_STR
6755 BGP_STR
6756 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6757{
6758 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6759}
6760
6761DEFUN (show_ip_bgp_ipv4_prefix,
6762 show_ip_bgp_ipv4_prefix_cmd,
6763 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6764 SHOW_STR
6765 IP_STR
6766 BGP_STR
6767 "Address family\n"
6768 "Address Family modifier\n"
6769 "Address Family modifier\n"
6770 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6771{
6772 if (strncmp (argv[0], "m", 1) == 0)
6773 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6774
6775 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6776}
6777
6778DEFUN (show_ip_bgp_vpnv4_all_prefix,
6779 show_ip_bgp_vpnv4_all_prefix_cmd,
6780 "show ip bgp vpnv4 all A.B.C.D/M",
6781 SHOW_STR
6782 IP_STR
6783 BGP_STR
6784 "Display VPNv4 NLRI specific information\n"
6785 "Display information about all VPNv4 NLRIs\n"
6786 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6787{
6788 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6789}
6790
6791DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6792 show_ip_bgp_vpnv4_rd_prefix_cmd,
6793 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6794 SHOW_STR
6795 IP_STR
6796 BGP_STR
6797 "Display VPNv4 NLRI specific information\n"
6798 "Display information for a route distinguisher\n"
6799 "VPN Route Distinguisher\n"
6800 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6801{
6802 int ret;
6803 struct prefix_rd prd;
6804
6805 ret = str2prefix_rd (argv[0], &prd);
6806 if (! ret)
6807 {
6808 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6809 return CMD_WARNING;
6810 }
6811 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6812}
6813
6814DEFUN (show_ip_bgp_view,
6815 show_ip_bgp_view_cmd,
6816 "show ip bgp view WORD",
6817 SHOW_STR
6818 IP_STR
6819 BGP_STR
6820 "BGP view\n"
6821 "BGP view name\n")
6822{
paulbb46e942003-10-24 19:02:03 +00006823 struct bgp *bgp;
6824
6825 /* BGP structure lookup. */
6826 bgp = bgp_lookup_by_name (argv[0]);
6827 if (bgp == NULL)
6828 {
6829 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6830 return CMD_WARNING;
6831 }
6832
ajs5a646652004-11-05 01:25:55 +00006833 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006834}
6835
6836DEFUN (show_ip_bgp_view_route,
6837 show_ip_bgp_view_route_cmd,
6838 "show ip bgp view WORD A.B.C.D",
6839 SHOW_STR
6840 IP_STR
6841 BGP_STR
6842 "BGP view\n"
6843 "BGP view name\n"
6844 "Network in the BGP routing table to display\n")
6845{
6846 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6847}
6848
6849DEFUN (show_ip_bgp_view_prefix,
6850 show_ip_bgp_view_prefix_cmd,
6851 "show ip bgp view WORD A.B.C.D/M",
6852 SHOW_STR
6853 IP_STR
6854 BGP_STR
6855 "BGP view\n"
6856 "BGP view name\n"
6857 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6858{
6859 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6860}
6861
6862#ifdef HAVE_IPV6
6863DEFUN (show_bgp,
6864 show_bgp_cmd,
6865 "show bgp",
6866 SHOW_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
6873ALIAS (show_bgp,
6874 show_bgp_ipv6_cmd,
6875 "show bgp ipv6",
6876 SHOW_STR
6877 BGP_STR
6878 "Address family\n")
6879
6880/* old command */
6881DEFUN (show_ipv6_bgp,
6882 show_ipv6_bgp_cmd,
6883 "show ipv6 bgp",
6884 SHOW_STR
6885 IP_STR
6886 BGP_STR)
6887{
ajs5a646652004-11-05 01:25:55 +00006888 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6889 NULL);
paul718e3742002-12-13 20:15:29 +00006890}
6891
6892DEFUN (show_bgp_route,
6893 show_bgp_route_cmd,
6894 "show bgp X:X::X:X",
6895 SHOW_STR
6896 BGP_STR
6897 "Network in the BGP routing table to display\n")
6898{
6899 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6900}
6901
6902ALIAS (show_bgp_route,
6903 show_bgp_ipv6_route_cmd,
6904 "show bgp ipv6 X:X::X:X",
6905 SHOW_STR
6906 BGP_STR
6907 "Address family\n"
6908 "Network in the BGP routing table to display\n")
6909
6910/* old command */
6911DEFUN (show_ipv6_bgp_route,
6912 show_ipv6_bgp_route_cmd,
6913 "show ipv6 bgp X:X::X:X",
6914 SHOW_STR
6915 IP_STR
6916 BGP_STR
6917 "Network in the BGP routing table to display\n")
6918{
6919 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6920}
6921
6922DEFUN (show_bgp_prefix,
6923 show_bgp_prefix_cmd,
6924 "show bgp X:X::X:X/M",
6925 SHOW_STR
6926 BGP_STR
6927 "IPv6 prefix <network>/<length>\n")
6928{
6929 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6930}
6931
6932ALIAS (show_bgp_prefix,
6933 show_bgp_ipv6_prefix_cmd,
6934 "show bgp ipv6 X:X::X:X/M",
6935 SHOW_STR
6936 BGP_STR
6937 "Address family\n"
6938 "IPv6 prefix <network>/<length>\n")
6939
6940/* old command */
6941DEFUN (show_ipv6_bgp_prefix,
6942 show_ipv6_bgp_prefix_cmd,
6943 "show ipv6 bgp X:X::X:X/M",
6944 SHOW_STR
6945 IP_STR
6946 BGP_STR
6947 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6948{
6949 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6950}
6951
paulbb46e942003-10-24 19:02:03 +00006952DEFUN (show_bgp_view,
6953 show_bgp_view_cmd,
6954 "show bgp view WORD",
6955 SHOW_STR
6956 BGP_STR
6957 "BGP view\n"
6958 "View name\n")
6959{
6960 struct bgp *bgp;
6961
6962 /* BGP structure lookup. */
6963 bgp = bgp_lookup_by_name (argv[0]);
6964 if (bgp == NULL)
6965 {
6966 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6967 return CMD_WARNING;
6968 }
6969
ajs5a646652004-11-05 01:25:55 +00006970 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006971}
6972
6973ALIAS (show_bgp_view,
6974 show_bgp_view_ipv6_cmd,
6975 "show bgp view WORD ipv6",
6976 SHOW_STR
6977 BGP_STR
6978 "BGP view\n"
6979 "View name\n"
6980 "Address family\n")
6981
6982DEFUN (show_bgp_view_route,
6983 show_bgp_view_route_cmd,
6984 "show bgp view WORD X:X::X:X",
6985 SHOW_STR
6986 BGP_STR
6987 "BGP view\n"
6988 "View name\n"
6989 "Network in the BGP routing table to display\n")
6990{
6991 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6992}
6993
6994ALIAS (show_bgp_view_route,
6995 show_bgp_view_ipv6_route_cmd,
6996 "show bgp view WORD ipv6 X:X::X:X",
6997 SHOW_STR
6998 BGP_STR
6999 "BGP view\n"
7000 "View name\n"
7001 "Address family\n"
7002 "Network in the BGP routing table to display\n")
7003
7004DEFUN (show_bgp_view_prefix,
7005 show_bgp_view_prefix_cmd,
7006 "show bgp view WORD X:X::X:X/M",
7007 SHOW_STR
7008 BGP_STR
7009 "BGP view\n"
7010 "View name\n"
7011 "IPv6 prefix <network>/<length>\n")
7012{
7013 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7014}
7015
7016ALIAS (show_bgp_view_prefix,
7017 show_bgp_view_ipv6_prefix_cmd,
7018 "show bgp view WORD ipv6 X:X::X:X/M",
7019 SHOW_STR
7020 BGP_STR
7021 "BGP view\n"
7022 "View name\n"
7023 "Address family\n"
7024 "IPv6 prefix <network>/<length>\n")
7025
paul718e3742002-12-13 20:15:29 +00007026/* old command */
7027DEFUN (show_ipv6_mbgp,
7028 show_ipv6_mbgp_cmd,
7029 "show ipv6 mbgp",
7030 SHOW_STR
7031 IP_STR
7032 MBGP_STR)
7033{
ajs5a646652004-11-05 01:25:55 +00007034 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7035 NULL);
paul718e3742002-12-13 20:15:29 +00007036}
7037
7038/* old command */
7039DEFUN (show_ipv6_mbgp_route,
7040 show_ipv6_mbgp_route_cmd,
7041 "show ipv6 mbgp X:X::X:X",
7042 SHOW_STR
7043 IP_STR
7044 MBGP_STR
7045 "Network in the MBGP routing table to display\n")
7046{
7047 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7048}
7049
7050/* old command */
7051DEFUN (show_ipv6_mbgp_prefix,
7052 show_ipv6_mbgp_prefix_cmd,
7053 "show ipv6 mbgp X:X::X:X/M",
7054 SHOW_STR
7055 IP_STR
7056 MBGP_STR
7057 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7058{
7059 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7060}
7061#endif
7062
paul718e3742002-12-13 20:15:29 +00007063
paul94f2b392005-06-28 12:44:16 +00007064static int
paulfd79ac92004-10-13 05:06:08 +00007065bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007066 safi_t safi, enum bgp_show_type type)
7067{
7068 int i;
7069 struct buffer *b;
7070 char *regstr;
7071 int first;
7072 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007073 int rc;
paul718e3742002-12-13 20:15:29 +00007074
7075 first = 0;
7076 b = buffer_new (1024);
7077 for (i = 0; i < argc; i++)
7078 {
7079 if (first)
7080 buffer_putc (b, ' ');
7081 else
7082 {
7083 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7084 continue;
7085 first = 1;
7086 }
7087
7088 buffer_putstr (b, argv[i]);
7089 }
7090 buffer_putc (b, '\0');
7091
7092 regstr = buffer_getstr (b);
7093 buffer_free (b);
7094
7095 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007096 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007097 if (! regex)
7098 {
7099 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7100 VTY_NEWLINE);
7101 return CMD_WARNING;
7102 }
7103
ajs5a646652004-11-05 01:25:55 +00007104 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7105 bgp_regex_free (regex);
7106 return rc;
paul718e3742002-12-13 20:15:29 +00007107}
7108
7109DEFUN (show_ip_bgp_regexp,
7110 show_ip_bgp_regexp_cmd,
7111 "show ip bgp regexp .LINE",
7112 SHOW_STR
7113 IP_STR
7114 BGP_STR
7115 "Display routes matching the AS path regular expression\n"
7116 "A regular-expression to match the BGP AS paths\n")
7117{
7118 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7119 bgp_show_type_regexp);
7120}
7121
7122DEFUN (show_ip_bgp_flap_regexp,
7123 show_ip_bgp_flap_regexp_cmd,
7124 "show ip bgp flap-statistics regexp .LINE",
7125 SHOW_STR
7126 IP_STR
7127 BGP_STR
7128 "Display flap statistics of routes\n"
7129 "Display routes matching the AS path regular expression\n"
7130 "A regular-expression to match the BGP AS paths\n")
7131{
7132 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7133 bgp_show_type_flap_regexp);
7134}
7135
7136DEFUN (show_ip_bgp_ipv4_regexp,
7137 show_ip_bgp_ipv4_regexp_cmd,
7138 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7139 SHOW_STR
7140 IP_STR
7141 BGP_STR
7142 "Address family\n"
7143 "Address Family modifier\n"
7144 "Address Family modifier\n"
7145 "Display routes matching the AS path regular expression\n"
7146 "A regular-expression to match the BGP AS paths\n")
7147{
7148 if (strncmp (argv[0], "m", 1) == 0)
7149 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7150 bgp_show_type_regexp);
7151
7152 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7153 bgp_show_type_regexp);
7154}
7155
7156#ifdef HAVE_IPV6
7157DEFUN (show_bgp_regexp,
7158 show_bgp_regexp_cmd,
7159 "show bgp regexp .LINE",
7160 SHOW_STR
7161 BGP_STR
7162 "Display routes matching the AS path regular expression\n"
7163 "A regular-expression to match the BGP AS paths\n")
7164{
7165 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7166 bgp_show_type_regexp);
7167}
7168
7169ALIAS (show_bgp_regexp,
7170 show_bgp_ipv6_regexp_cmd,
7171 "show bgp ipv6 regexp .LINE",
7172 SHOW_STR
7173 BGP_STR
7174 "Address family\n"
7175 "Display routes matching the AS path regular expression\n"
7176 "A regular-expression to match the BGP AS paths\n")
7177
7178/* old command */
7179DEFUN (show_ipv6_bgp_regexp,
7180 show_ipv6_bgp_regexp_cmd,
7181 "show ipv6 bgp regexp .LINE",
7182 SHOW_STR
7183 IP_STR
7184 BGP_STR
7185 "Display routes matching the AS path regular expression\n"
7186 "A regular-expression to match the BGP AS paths\n")
7187{
7188 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7189 bgp_show_type_regexp);
7190}
7191
7192/* old command */
7193DEFUN (show_ipv6_mbgp_regexp,
7194 show_ipv6_mbgp_regexp_cmd,
7195 "show ipv6 mbgp regexp .LINE",
7196 SHOW_STR
7197 IP_STR
7198 BGP_STR
7199 "Display routes matching the AS path regular expression\n"
7200 "A regular-expression to match the MBGP AS paths\n")
7201{
7202 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7203 bgp_show_type_regexp);
7204}
7205#endif /* HAVE_IPV6 */
7206
paul94f2b392005-06-28 12:44:16 +00007207static int
paulfd79ac92004-10-13 05:06:08 +00007208bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007209 safi_t safi, enum bgp_show_type type)
7210{
7211 struct prefix_list *plist;
7212
7213 plist = prefix_list_lookup (afi, prefix_list_str);
7214 if (plist == NULL)
7215 {
7216 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7217 prefix_list_str, VTY_NEWLINE);
7218 return CMD_WARNING;
7219 }
7220
ajs5a646652004-11-05 01:25:55 +00007221 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007222}
7223
7224DEFUN (show_ip_bgp_prefix_list,
7225 show_ip_bgp_prefix_list_cmd,
7226 "show ip bgp prefix-list WORD",
7227 SHOW_STR
7228 IP_STR
7229 BGP_STR
7230 "Display routes conforming to the prefix-list\n"
7231 "IP prefix-list name\n")
7232{
7233 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7234 bgp_show_type_prefix_list);
7235}
7236
7237DEFUN (show_ip_bgp_flap_prefix_list,
7238 show_ip_bgp_flap_prefix_list_cmd,
7239 "show ip bgp flap-statistics prefix-list WORD",
7240 SHOW_STR
7241 IP_STR
7242 BGP_STR
7243 "Display flap statistics of routes\n"
7244 "Display routes conforming to the prefix-list\n"
7245 "IP prefix-list name\n")
7246{
7247 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7248 bgp_show_type_flap_prefix_list);
7249}
7250
7251DEFUN (show_ip_bgp_ipv4_prefix_list,
7252 show_ip_bgp_ipv4_prefix_list_cmd,
7253 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7254 SHOW_STR
7255 IP_STR
7256 BGP_STR
7257 "Address family\n"
7258 "Address Family modifier\n"
7259 "Address Family modifier\n"
7260 "Display routes conforming to the prefix-list\n"
7261 "IP prefix-list name\n")
7262{
7263 if (strncmp (argv[0], "m", 1) == 0)
7264 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7265 bgp_show_type_prefix_list);
7266
7267 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7268 bgp_show_type_prefix_list);
7269}
7270
7271#ifdef HAVE_IPV6
7272DEFUN (show_bgp_prefix_list,
7273 show_bgp_prefix_list_cmd,
7274 "show bgp prefix-list WORD",
7275 SHOW_STR
7276 BGP_STR
7277 "Display routes conforming to the prefix-list\n"
7278 "IPv6 prefix-list name\n")
7279{
7280 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7281 bgp_show_type_prefix_list);
7282}
7283
7284ALIAS (show_bgp_prefix_list,
7285 show_bgp_ipv6_prefix_list_cmd,
7286 "show bgp ipv6 prefix-list WORD",
7287 SHOW_STR
7288 BGP_STR
7289 "Address family\n"
7290 "Display routes conforming to the prefix-list\n"
7291 "IPv6 prefix-list name\n")
7292
7293/* old command */
7294DEFUN (show_ipv6_bgp_prefix_list,
7295 show_ipv6_bgp_prefix_list_cmd,
7296 "show ipv6 bgp prefix-list WORD",
7297 SHOW_STR
7298 IPV6_STR
7299 BGP_STR
7300 "Display routes matching the prefix-list\n"
7301 "IPv6 prefix-list name\n")
7302{
7303 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7304 bgp_show_type_prefix_list);
7305}
7306
7307/* old command */
7308DEFUN (show_ipv6_mbgp_prefix_list,
7309 show_ipv6_mbgp_prefix_list_cmd,
7310 "show ipv6 mbgp prefix-list WORD",
7311 SHOW_STR
7312 IPV6_STR
7313 MBGP_STR
7314 "Display routes matching the prefix-list\n"
7315 "IPv6 prefix-list name\n")
7316{
7317 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7318 bgp_show_type_prefix_list);
7319}
7320#endif /* HAVE_IPV6 */
7321
paul94f2b392005-06-28 12:44:16 +00007322static int
paulfd79ac92004-10-13 05:06:08 +00007323bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007324 safi_t safi, enum bgp_show_type type)
7325{
7326 struct as_list *as_list;
7327
7328 as_list = as_list_lookup (filter);
7329 if (as_list == NULL)
7330 {
7331 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7332 return CMD_WARNING;
7333 }
7334
ajs5a646652004-11-05 01:25:55 +00007335 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007336}
7337
7338DEFUN (show_ip_bgp_filter_list,
7339 show_ip_bgp_filter_list_cmd,
7340 "show ip bgp filter-list WORD",
7341 SHOW_STR
7342 IP_STR
7343 BGP_STR
7344 "Display routes conforming to the filter-list\n"
7345 "Regular expression access list name\n")
7346{
7347 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7348 bgp_show_type_filter_list);
7349}
7350
7351DEFUN (show_ip_bgp_flap_filter_list,
7352 show_ip_bgp_flap_filter_list_cmd,
7353 "show ip bgp flap-statistics filter-list WORD",
7354 SHOW_STR
7355 IP_STR
7356 BGP_STR
7357 "Display flap statistics of routes\n"
7358 "Display routes conforming to the filter-list\n"
7359 "Regular expression access list name\n")
7360{
7361 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7362 bgp_show_type_flap_filter_list);
7363}
7364
7365DEFUN (show_ip_bgp_ipv4_filter_list,
7366 show_ip_bgp_ipv4_filter_list_cmd,
7367 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7368 SHOW_STR
7369 IP_STR
7370 BGP_STR
7371 "Address family\n"
7372 "Address Family modifier\n"
7373 "Address Family modifier\n"
7374 "Display routes conforming to the filter-list\n"
7375 "Regular expression access list name\n")
7376{
7377 if (strncmp (argv[0], "m", 1) == 0)
7378 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7379 bgp_show_type_filter_list);
7380
7381 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7382 bgp_show_type_filter_list);
7383}
7384
7385#ifdef HAVE_IPV6
7386DEFUN (show_bgp_filter_list,
7387 show_bgp_filter_list_cmd,
7388 "show bgp filter-list WORD",
7389 SHOW_STR
7390 BGP_STR
7391 "Display routes conforming to the filter-list\n"
7392 "Regular expression access list name\n")
7393{
7394 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7395 bgp_show_type_filter_list);
7396}
7397
7398ALIAS (show_bgp_filter_list,
7399 show_bgp_ipv6_filter_list_cmd,
7400 "show bgp ipv6 filter-list WORD",
7401 SHOW_STR
7402 BGP_STR
7403 "Address family\n"
7404 "Display routes conforming to the filter-list\n"
7405 "Regular expression access list name\n")
7406
7407/* old command */
7408DEFUN (show_ipv6_bgp_filter_list,
7409 show_ipv6_bgp_filter_list_cmd,
7410 "show ipv6 bgp filter-list WORD",
7411 SHOW_STR
7412 IPV6_STR
7413 BGP_STR
7414 "Display routes conforming to the filter-list\n"
7415 "Regular expression access list name\n")
7416{
7417 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7418 bgp_show_type_filter_list);
7419}
7420
7421/* old command */
7422DEFUN (show_ipv6_mbgp_filter_list,
7423 show_ipv6_mbgp_filter_list_cmd,
7424 "show ipv6 mbgp filter-list WORD",
7425 SHOW_STR
7426 IPV6_STR
7427 MBGP_STR
7428 "Display routes conforming to the filter-list\n"
7429 "Regular expression access list name\n")
7430{
7431 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7432 bgp_show_type_filter_list);
7433}
7434#endif /* HAVE_IPV6 */
7435
paul94f2b392005-06-28 12:44:16 +00007436static int
paulfd79ac92004-10-13 05:06:08 +00007437bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007438 safi_t safi, enum bgp_show_type type)
7439{
7440 struct route_map *rmap;
7441
7442 rmap = route_map_lookup_by_name (rmap_str);
7443 if (! rmap)
7444 {
7445 vty_out (vty, "%% %s is not a valid route-map name%s",
7446 rmap_str, VTY_NEWLINE);
7447 return CMD_WARNING;
7448 }
7449
ajs5a646652004-11-05 01:25:55 +00007450 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007451}
7452
7453DEFUN (show_ip_bgp_route_map,
7454 show_ip_bgp_route_map_cmd,
7455 "show ip bgp route-map WORD",
7456 SHOW_STR
7457 IP_STR
7458 BGP_STR
7459 "Display routes matching the route-map\n"
7460 "A route-map to match on\n")
7461{
7462 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7463 bgp_show_type_route_map);
7464}
7465
7466DEFUN (show_ip_bgp_flap_route_map,
7467 show_ip_bgp_flap_route_map_cmd,
7468 "show ip bgp flap-statistics route-map WORD",
7469 SHOW_STR
7470 IP_STR
7471 BGP_STR
7472 "Display flap statistics of routes\n"
7473 "Display routes matching the route-map\n"
7474 "A route-map to match on\n")
7475{
7476 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7477 bgp_show_type_flap_route_map);
7478}
7479
7480DEFUN (show_ip_bgp_ipv4_route_map,
7481 show_ip_bgp_ipv4_route_map_cmd,
7482 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7483 SHOW_STR
7484 IP_STR
7485 BGP_STR
7486 "Address family\n"
7487 "Address Family modifier\n"
7488 "Address Family modifier\n"
7489 "Display routes matching the route-map\n"
7490 "A route-map to match on\n")
7491{
7492 if (strncmp (argv[0], "m", 1) == 0)
7493 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7494 bgp_show_type_route_map);
7495
7496 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7497 bgp_show_type_route_map);
7498}
7499
7500DEFUN (show_bgp_route_map,
7501 show_bgp_route_map_cmd,
7502 "show bgp route-map WORD",
7503 SHOW_STR
7504 BGP_STR
7505 "Display routes matching the route-map\n"
7506 "A route-map to match on\n")
7507{
7508 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7509 bgp_show_type_route_map);
7510}
7511
7512ALIAS (show_bgp_route_map,
7513 show_bgp_ipv6_route_map_cmd,
7514 "show bgp ipv6 route-map WORD",
7515 SHOW_STR
7516 BGP_STR
7517 "Address family\n"
7518 "Display routes matching the route-map\n"
7519 "A route-map to match on\n")
7520
7521DEFUN (show_ip_bgp_cidr_only,
7522 show_ip_bgp_cidr_only_cmd,
7523 "show ip bgp cidr-only",
7524 SHOW_STR
7525 IP_STR
7526 BGP_STR
7527 "Display only routes with non-natural netmasks\n")
7528{
7529 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007530 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007531}
7532
7533DEFUN (show_ip_bgp_flap_cidr_only,
7534 show_ip_bgp_flap_cidr_only_cmd,
7535 "show ip bgp flap-statistics cidr-only",
7536 SHOW_STR
7537 IP_STR
7538 BGP_STR
7539 "Display flap statistics of routes\n"
7540 "Display only routes with non-natural netmasks\n")
7541{
7542 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007543 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007544}
7545
7546DEFUN (show_ip_bgp_ipv4_cidr_only,
7547 show_ip_bgp_ipv4_cidr_only_cmd,
7548 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7549 SHOW_STR
7550 IP_STR
7551 BGP_STR
7552 "Address family\n"
7553 "Address Family modifier\n"
7554 "Address Family modifier\n"
7555 "Display only routes with non-natural netmasks\n")
7556{
7557 if (strncmp (argv[0], "m", 1) == 0)
7558 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007559 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007560
7561 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007562 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007563}
7564
7565DEFUN (show_ip_bgp_community_all,
7566 show_ip_bgp_community_all_cmd,
7567 "show ip bgp community",
7568 SHOW_STR
7569 IP_STR
7570 BGP_STR
7571 "Display routes matching the communities\n")
7572{
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
7577DEFUN (show_ip_bgp_ipv4_community_all,
7578 show_ip_bgp_ipv4_community_all_cmd,
7579 "show ip bgp ipv4 (unicast|multicast) community",
7580 SHOW_STR
7581 IP_STR
7582 BGP_STR
7583 "Address family\n"
7584 "Address Family modifier\n"
7585 "Address Family modifier\n"
7586 "Display routes matching the communities\n")
7587{
7588 if (strncmp (argv[0], "m", 1) == 0)
7589 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007590 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007591
7592 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007593 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007594}
7595
7596#ifdef HAVE_IPV6
7597DEFUN (show_bgp_community_all,
7598 show_bgp_community_all_cmd,
7599 "show bgp community",
7600 SHOW_STR
7601 BGP_STR
7602 "Display routes matching the communities\n")
7603{
7604 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007605 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007606}
7607
7608ALIAS (show_bgp_community_all,
7609 show_bgp_ipv6_community_all_cmd,
7610 "show bgp ipv6 community",
7611 SHOW_STR
7612 BGP_STR
7613 "Address family\n"
7614 "Display routes matching the communities\n")
7615
7616/* old command */
7617DEFUN (show_ipv6_bgp_community_all,
7618 show_ipv6_bgp_community_all_cmd,
7619 "show ipv6 bgp community",
7620 SHOW_STR
7621 IPV6_STR
7622 BGP_STR
7623 "Display routes matching the communities\n")
7624{
7625 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007626 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007627}
7628
7629/* old command */
7630DEFUN (show_ipv6_mbgp_community_all,
7631 show_ipv6_mbgp_community_all_cmd,
7632 "show ipv6 mbgp community",
7633 SHOW_STR
7634 IPV6_STR
7635 MBGP_STR
7636 "Display routes matching the communities\n")
7637{
7638 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007639 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007640}
7641#endif /* HAVE_IPV6 */
7642
paul94f2b392005-06-28 12:44:16 +00007643static int
paulfd79ac92004-10-13 05:06:08 +00007644bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04007645 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007646{
7647 struct community *com;
7648 struct buffer *b;
7649 int i;
7650 char *str;
7651 int first = 0;
7652
7653 b = buffer_new (1024);
7654 for (i = 0; i < argc; i++)
7655 {
7656 if (first)
7657 buffer_putc (b, ' ');
7658 else
7659 {
7660 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7661 continue;
7662 first = 1;
7663 }
7664
7665 buffer_putstr (b, argv[i]);
7666 }
7667 buffer_putc (b, '\0');
7668
7669 str = buffer_getstr (b);
7670 buffer_free (b);
7671
7672 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007673 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007674 if (! com)
7675 {
7676 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7677 return CMD_WARNING;
7678 }
7679
ajs5a646652004-11-05 01:25:55 +00007680 return bgp_show (vty, NULL, afi, safi,
7681 (exact ? bgp_show_type_community_exact :
7682 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007683}
7684
7685DEFUN (show_ip_bgp_community,
7686 show_ip_bgp_community_cmd,
7687 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7688 SHOW_STR
7689 IP_STR
7690 BGP_STR
7691 "Display routes matching the communities\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{
7697 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7698}
7699
7700ALIAS (show_ip_bgp_community,
7701 show_ip_bgp_community2_cmd,
7702 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7703 SHOW_STR
7704 IP_STR
7705 BGP_STR
7706 "Display routes matching the communities\n"
7707 "community number\n"
7708 "Do not send outside local AS (well-known community)\n"
7709 "Do not advertise to any peer (well-known community)\n"
7710 "Do not export to next AS (well-known community)\n"
7711 "community number\n"
7712 "Do not send outside local AS (well-known community)\n"
7713 "Do not advertise to any peer (well-known community)\n"
7714 "Do not export to next AS (well-known community)\n")
7715
7716ALIAS (show_ip_bgp_community,
7717 show_ip_bgp_community3_cmd,
7718 "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)",
7719 SHOW_STR
7720 IP_STR
7721 BGP_STR
7722 "Display routes matching the communities\n"
7723 "community number\n"
7724 "Do not send outside local AS (well-known community)\n"
7725 "Do not advertise to any peer (well-known community)\n"
7726 "Do not export to next AS (well-known community)\n"
7727 "community number\n"
7728 "Do not send outside local AS (well-known community)\n"
7729 "Do not advertise to any peer (well-known community)\n"
7730 "Do not export to next AS (well-known community)\n"
7731 "community number\n"
7732 "Do not send outside local AS (well-known community)\n"
7733 "Do not advertise to any peer (well-known community)\n"
7734 "Do not export to next AS (well-known community)\n")
7735
7736ALIAS (show_ip_bgp_community,
7737 show_ip_bgp_community4_cmd,
7738 "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)",
7739 SHOW_STR
7740 IP_STR
7741 BGP_STR
7742 "Display routes matching the communities\n"
7743 "community number\n"
7744 "Do not send outside local AS (well-known community)\n"
7745 "Do not advertise to any peer (well-known community)\n"
7746 "Do not export to next AS (well-known community)\n"
7747 "community number\n"
7748 "Do not send outside local AS (well-known community)\n"
7749 "Do not advertise to any peer (well-known community)\n"
7750 "Do not export to next AS (well-known community)\n"
7751 "community number\n"
7752 "Do not send outside local AS (well-known community)\n"
7753 "Do not advertise to any peer (well-known community)\n"
7754 "Do not export to next AS (well-known community)\n"
7755 "community number\n"
7756 "Do not send outside local AS (well-known community)\n"
7757 "Do not advertise to any peer (well-known community)\n"
7758 "Do not export to next AS (well-known community)\n")
7759
7760DEFUN (show_ip_bgp_ipv4_community,
7761 show_ip_bgp_ipv4_community_cmd,
7762 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7763 SHOW_STR
7764 IP_STR
7765 BGP_STR
7766 "Address family\n"
7767 "Address Family modifier\n"
7768 "Address Family modifier\n"
7769 "Display routes matching the communities\n"
7770 "community number\n"
7771 "Do not send outside local AS (well-known community)\n"
7772 "Do not advertise to any peer (well-known community)\n"
7773 "Do not export to next AS (well-known community)\n")
7774{
7775 if (strncmp (argv[0], "m", 1) == 0)
7776 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7777
7778 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7779}
7780
7781ALIAS (show_ip_bgp_ipv4_community,
7782 show_ip_bgp_ipv4_community2_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)",
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
7800ALIAS (show_ip_bgp_ipv4_community,
7801 show_ip_bgp_ipv4_community3_cmd,
7802 "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)",
7803 SHOW_STR
7804 IP_STR
7805 BGP_STR
7806 "Address family\n"
7807 "Address Family modifier\n"
7808 "Address Family modifier\n"
7809 "Display routes matching the communities\n"
7810 "community number\n"
7811 "Do not send outside local AS (well-known community)\n"
7812 "Do not advertise to any peer (well-known community)\n"
7813 "Do not export to next AS (well-known community)\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
7823ALIAS (show_ip_bgp_ipv4_community,
7824 show_ip_bgp_ipv4_community4_cmd,
7825 "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)",
7826 SHOW_STR
7827 IP_STR
7828 BGP_STR
7829 "Address family\n"
7830 "Address Family modifier\n"
7831 "Address Family modifier\n"
7832 "Display routes matching the communities\n"
7833 "community number\n"
7834 "Do not send outside local AS (well-known community)\n"
7835 "Do not advertise to any peer (well-known community)\n"
7836 "Do not export to next AS (well-known community)\n"
7837 "community number\n"
7838 "Do not send outside local AS (well-known community)\n"
7839 "Do not advertise to any peer (well-known community)\n"
7840 "Do not export to next AS (well-known community)\n"
7841 "community number\n"
7842 "Do not send outside local AS (well-known community)\n"
7843 "Do not advertise to any peer (well-known community)\n"
7844 "Do not export to next AS (well-known community)\n"
7845 "community number\n"
7846 "Do not send outside local AS (well-known community)\n"
7847 "Do not advertise to any peer (well-known community)\n"
7848 "Do not export to next AS (well-known community)\n")
7849
7850DEFUN (show_ip_bgp_community_exact,
7851 show_ip_bgp_community_exact_cmd,
7852 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7853 SHOW_STR
7854 IP_STR
7855 BGP_STR
7856 "Display routes matching the communities\n"
7857 "community number\n"
7858 "Do not send outside local AS (well-known community)\n"
7859 "Do not advertise to any peer (well-known community)\n"
7860 "Do not export to next AS (well-known community)\n"
7861 "Exact match of the communities")
7862{
7863 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7864}
7865
7866ALIAS (show_ip_bgp_community_exact,
7867 show_ip_bgp_community2_exact_cmd,
7868 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7869 SHOW_STR
7870 IP_STR
7871 BGP_STR
7872 "Display routes matching the communities\n"
7873 "community number\n"
7874 "Do not send outside local AS (well-known community)\n"
7875 "Do not advertise to any peer (well-known community)\n"
7876 "Do not export to next AS (well-known community)\n"
7877 "community number\n"
7878 "Do not send outside local AS (well-known community)\n"
7879 "Do not advertise to any peer (well-known community)\n"
7880 "Do not export to next AS (well-known community)\n"
7881 "Exact match of the communities")
7882
7883ALIAS (show_ip_bgp_community_exact,
7884 show_ip_bgp_community3_exact_cmd,
7885 "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",
7886 SHOW_STR
7887 IP_STR
7888 BGP_STR
7889 "Display routes matching the communities\n"
7890 "community number\n"
7891 "Do not send outside local AS (well-known community)\n"
7892 "Do not advertise to any peer (well-known community)\n"
7893 "Do not export to next AS (well-known community)\n"
7894 "community number\n"
7895 "Do not send outside local AS (well-known community)\n"
7896 "Do not advertise to any peer (well-known community)\n"
7897 "Do not export to next AS (well-known community)\n"
7898 "community number\n"
7899 "Do not send outside local AS (well-known community)\n"
7900 "Do not advertise to any peer (well-known community)\n"
7901 "Do not export to next AS (well-known community)\n"
7902 "Exact match of the communities")
7903
7904ALIAS (show_ip_bgp_community_exact,
7905 show_ip_bgp_community4_exact_cmd,
7906 "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",
7907 SHOW_STR
7908 IP_STR
7909 BGP_STR
7910 "Display routes matching the communities\n"
7911 "community number\n"
7912 "Do not send outside local AS (well-known community)\n"
7913 "Do not advertise to any peer (well-known community)\n"
7914 "Do not export to next AS (well-known community)\n"
7915 "community number\n"
7916 "Do not send outside local AS (well-known community)\n"
7917 "Do not advertise to any peer (well-known community)\n"
7918 "Do not export to next AS (well-known community)\n"
7919 "community number\n"
7920 "Do not send outside local AS (well-known community)\n"
7921 "Do not advertise to any peer (well-known community)\n"
7922 "Do not export to next AS (well-known community)\n"
7923 "community number\n"
7924 "Do not send outside local AS (well-known community)\n"
7925 "Do not advertise to any peer (well-known community)\n"
7926 "Do not export to next AS (well-known community)\n"
7927 "Exact match of the communities")
7928
7929DEFUN (show_ip_bgp_ipv4_community_exact,
7930 show_ip_bgp_ipv4_community_exact_cmd,
7931 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7932 SHOW_STR
7933 IP_STR
7934 BGP_STR
7935 "Address family\n"
7936 "Address Family modifier\n"
7937 "Address Family modifier\n"
7938 "Display routes matching the communities\n"
7939 "community number\n"
7940 "Do not send outside local AS (well-known community)\n"
7941 "Do not advertise to any peer (well-known community)\n"
7942 "Do not export to next AS (well-known community)\n"
7943 "Exact match of the communities")
7944{
7945 if (strncmp (argv[0], "m", 1) == 0)
7946 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7947
7948 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7949}
7950
7951ALIAS (show_ip_bgp_ipv4_community_exact,
7952 show_ip_bgp_ipv4_community2_exact_cmd,
7953 "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",
7954 SHOW_STR
7955 IP_STR
7956 BGP_STR
7957 "Address family\n"
7958 "Address Family modifier\n"
7959 "Address Family modifier\n"
7960 "Display routes matching the communities\n"
7961 "community number\n"
7962 "Do not send outside local AS (well-known community)\n"
7963 "Do not advertise to any peer (well-known community)\n"
7964 "Do not export to next AS (well-known community)\n"
7965 "community number\n"
7966 "Do not send outside local AS (well-known community)\n"
7967 "Do not advertise to any peer (well-known community)\n"
7968 "Do not export to next AS (well-known community)\n"
7969 "Exact match of the communities")
7970
7971ALIAS (show_ip_bgp_ipv4_community_exact,
7972 show_ip_bgp_ipv4_community3_exact_cmd,
7973 "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",
7974 SHOW_STR
7975 IP_STR
7976 BGP_STR
7977 "Address family\n"
7978 "Address Family modifier\n"
7979 "Address Family modifier\n"
7980 "Display routes matching the communities\n"
7981 "community number\n"
7982 "Do not send outside local AS (well-known community)\n"
7983 "Do not advertise to any peer (well-known community)\n"
7984 "Do not export to next AS (well-known community)\n"
7985 "community number\n"
7986 "Do not send outside local AS (well-known community)\n"
7987 "Do not advertise to any peer (well-known community)\n"
7988 "Do not export to next AS (well-known community)\n"
7989 "community number\n"
7990 "Do not send outside local AS (well-known community)\n"
7991 "Do not advertise to any peer (well-known community)\n"
7992 "Do not export to next AS (well-known community)\n"
7993 "Exact match of the communities")
7994
7995ALIAS (show_ip_bgp_ipv4_community_exact,
7996 show_ip_bgp_ipv4_community4_exact_cmd,
7997 "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",
7998 SHOW_STR
7999 IP_STR
8000 BGP_STR
8001 "Address family\n"
8002 "Address Family modifier\n"
8003 "Address Family modifier\n"
8004 "Display routes matching the communities\n"
8005 "community number\n"
8006 "Do not send outside local AS (well-known community)\n"
8007 "Do not advertise to any peer (well-known community)\n"
8008 "Do not export to next AS (well-known community)\n"
8009 "community number\n"
8010 "Do not send outside local AS (well-known community)\n"
8011 "Do not advertise to any peer (well-known community)\n"
8012 "Do not export to next AS (well-known community)\n"
8013 "community number\n"
8014 "Do not send outside local AS (well-known community)\n"
8015 "Do not advertise to any peer (well-known community)\n"
8016 "Do not export to next AS (well-known community)\n"
8017 "community number\n"
8018 "Do not send outside local AS (well-known community)\n"
8019 "Do not advertise to any peer (well-known community)\n"
8020 "Do not export to next AS (well-known community)\n"
8021 "Exact match of the communities")
8022
8023#ifdef HAVE_IPV6
8024DEFUN (show_bgp_community,
8025 show_bgp_community_cmd,
8026 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8027 SHOW_STR
8028 BGP_STR
8029 "Display routes matching the communities\n"
8030 "community number\n"
8031 "Do not send outside local AS (well-known community)\n"
8032 "Do not advertise to any peer (well-known community)\n"
8033 "Do not export to next AS (well-known community)\n")
8034{
8035 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8036}
8037
8038ALIAS (show_bgp_community,
8039 show_bgp_ipv6_community_cmd,
8040 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8041 SHOW_STR
8042 BGP_STR
8043 "Address family\n"
8044 "Display routes matching the communities\n"
8045 "community number\n"
8046 "Do not send outside local AS (well-known community)\n"
8047 "Do not advertise to any peer (well-known community)\n"
8048 "Do not export to next AS (well-known community)\n")
8049
8050ALIAS (show_bgp_community,
8051 show_bgp_community2_cmd,
8052 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8053 SHOW_STR
8054 BGP_STR
8055 "Display routes matching the communities\n"
8056 "community number\n"
8057 "Do not send outside local AS (well-known community)\n"
8058 "Do not advertise to any peer (well-known community)\n"
8059 "Do not export to next AS (well-known community)\n"
8060 "community number\n"
8061 "Do not send outside local AS (well-known community)\n"
8062 "Do not advertise to any peer (well-known community)\n"
8063 "Do not export to next AS (well-known community)\n")
8064
8065ALIAS (show_bgp_community,
8066 show_bgp_ipv6_community2_cmd,
8067 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8068 SHOW_STR
8069 BGP_STR
8070 "Address family\n"
8071 "Display routes matching the communities\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_community3_cmd,
8083 "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)",
8084 SHOW_STR
8085 BGP_STR
8086 "Display routes matching the communities\n"
8087 "community number\n"
8088 "Do not send outside local AS (well-known community)\n"
8089 "Do not advertise to any peer (well-known community)\n"
8090 "Do not export to next AS (well-known community)\n"
8091 "community number\n"
8092 "Do not send outside local AS (well-known community)\n"
8093 "Do not advertise to any peer (well-known community)\n"
8094 "Do not export to next AS (well-known community)\n"
8095 "community number\n"
8096 "Do not send outside local AS (well-known community)\n"
8097 "Do not advertise to any peer (well-known community)\n"
8098 "Do not export to next AS (well-known community)\n")
8099
8100ALIAS (show_bgp_community,
8101 show_bgp_ipv6_community3_cmd,
8102 "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)",
8103 SHOW_STR
8104 BGP_STR
8105 "Address family\n"
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
8120ALIAS (show_bgp_community,
8121 show_bgp_community4_cmd,
8122 "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)",
8123 SHOW_STR
8124 BGP_STR
8125 "Display routes matching the communities\n"
8126 "community number\n"
8127 "Do not send outside local AS (well-known community)\n"
8128 "Do not advertise to any peer (well-known community)\n"
8129 "Do not export to next AS (well-known community)\n"
8130 "community number\n"
8131 "Do not send outside local AS (well-known community)\n"
8132 "Do not advertise to any peer (well-known community)\n"
8133 "Do not export to next AS (well-known community)\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\n"
8138 "community number\n"
8139 "Do not send outside local AS (well-known community)\n"
8140 "Do not advertise to any peer (well-known community)\n"
8141 "Do not export to next AS (well-known community)\n")
8142
8143ALIAS (show_bgp_community,
8144 show_bgp_ipv6_community4_cmd,
8145 "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)",
8146 SHOW_STR
8147 BGP_STR
8148 "Address family\n"
8149 "Display routes matching the communities\n"
8150 "community number\n"
8151 "Do not send outside local AS (well-known community)\n"
8152 "Do not advertise to any peer (well-known community)\n"
8153 "Do not export to next AS (well-known community)\n"
8154 "community number\n"
8155 "Do not send outside local AS (well-known community)\n"
8156 "Do not advertise to any peer (well-known community)\n"
8157 "Do not export to next AS (well-known community)\n"
8158 "community number\n"
8159 "Do not send outside local AS (well-known community)\n"
8160 "Do not advertise to any peer (well-known community)\n"
8161 "Do not export to next AS (well-known community)\n"
8162 "community number\n"
8163 "Do not send outside local AS (well-known community)\n"
8164 "Do not advertise to any peer (well-known community)\n"
8165 "Do not export to next AS (well-known community)\n")
8166
8167/* old command */
8168DEFUN (show_ipv6_bgp_community,
8169 show_ipv6_bgp_community_cmd,
8170 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8171 SHOW_STR
8172 IPV6_STR
8173 BGP_STR
8174 "Display routes matching the communities\n"
8175 "community number\n"
8176 "Do not send outside local AS (well-known community)\n"
8177 "Do not advertise to any peer (well-known community)\n"
8178 "Do not export to next AS (well-known community)\n")
8179{
8180 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8181}
8182
8183/* old command */
8184ALIAS (show_ipv6_bgp_community,
8185 show_ipv6_bgp_community2_cmd,
8186 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8187 SHOW_STR
8188 IPV6_STR
8189 BGP_STR
8190 "Display routes matching the communities\n"
8191 "community number\n"
8192 "Do not send outside local AS (well-known community)\n"
8193 "Do not advertise to any peer (well-known community)\n"
8194 "Do not export to next AS (well-known community)\n"
8195 "community number\n"
8196 "Do not send outside local AS (well-known community)\n"
8197 "Do not advertise to any peer (well-known community)\n"
8198 "Do not export to next AS (well-known community)\n")
8199
8200/* old command */
8201ALIAS (show_ipv6_bgp_community,
8202 show_ipv6_bgp_community3_cmd,
8203 "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)",
8204 SHOW_STR
8205 IPV6_STR
8206 BGP_STR
8207 "Display routes matching the communities\n"
8208 "community number\n"
8209 "Do not send outside local AS (well-known community)\n"
8210 "Do not advertise to any peer (well-known community)\n"
8211 "Do not export to next AS (well-known community)\n"
8212 "community number\n"
8213 "Do not send outside local AS (well-known community)\n"
8214 "Do not advertise to any peer (well-known community)\n"
8215 "Do not export to next AS (well-known community)\n"
8216 "community number\n"
8217 "Do not send outside local AS (well-known community)\n"
8218 "Do not advertise to any peer (well-known community)\n"
8219 "Do not export to next AS (well-known community)\n")
8220
8221/* old command */
8222ALIAS (show_ipv6_bgp_community,
8223 show_ipv6_bgp_community4_cmd,
8224 "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)",
8225 SHOW_STR
8226 IPV6_STR
8227 BGP_STR
8228 "Display routes matching the communities\n"
8229 "community number\n"
8230 "Do not send outside local AS (well-known community)\n"
8231 "Do not advertise to any peer (well-known community)\n"
8232 "Do not export to next AS (well-known community)\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 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n")
8245
8246DEFUN (show_bgp_community_exact,
8247 show_bgp_community_exact_cmd,
8248 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8249 SHOW_STR
8250 BGP_STR
8251 "Display routes matching the communities\n"
8252 "community number\n"
8253 "Do not send outside local AS (well-known community)\n"
8254 "Do not advertise to any peer (well-known community)\n"
8255 "Do not export to next AS (well-known community)\n"
8256 "Exact match of the communities")
8257{
8258 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8259}
8260
8261ALIAS (show_bgp_community_exact,
8262 show_bgp_ipv6_community_exact_cmd,
8263 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8264 SHOW_STR
8265 BGP_STR
8266 "Address family\n"
8267 "Display routes matching the communities\n"
8268 "community number\n"
8269 "Do not send outside local AS (well-known community)\n"
8270 "Do not advertise to any peer (well-known community)\n"
8271 "Do not export to next AS (well-known community)\n"
8272 "Exact match of the communities")
8273
8274ALIAS (show_bgp_community_exact,
8275 show_bgp_community2_exact_cmd,
8276 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8277 SHOW_STR
8278 BGP_STR
8279 "Display routes matching the communities\n"
8280 "community number\n"
8281 "Do not send outside local AS (well-known community)\n"
8282 "Do not advertise to any peer (well-known community)\n"
8283 "Do not export to next AS (well-known community)\n"
8284 "community number\n"
8285 "Do not send outside local AS (well-known community)\n"
8286 "Do not advertise to any peer (well-known community)\n"
8287 "Do not export to next AS (well-known community)\n"
8288 "Exact match of the communities")
8289
8290ALIAS (show_bgp_community_exact,
8291 show_bgp_ipv6_community2_exact_cmd,
8292 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8293 SHOW_STR
8294 BGP_STR
8295 "Address family\n"
8296 "Display routes matching the communities\n"
8297 "community number\n"
8298 "Do not send outside local AS (well-known community)\n"
8299 "Do not advertise to any peer (well-known community)\n"
8300 "Do not export to next AS (well-known community)\n"
8301 "community number\n"
8302 "Do not send outside local AS (well-known community)\n"
8303 "Do not advertise to any peer (well-known community)\n"
8304 "Do not export to next AS (well-known community)\n"
8305 "Exact match of the communities")
8306
8307ALIAS (show_bgp_community_exact,
8308 show_bgp_community3_exact_cmd,
8309 "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",
8310 SHOW_STR
8311 BGP_STR
8312 "Display routes matching the communities\n"
8313 "community number\n"
8314 "Do not send outside local AS (well-known community)\n"
8315 "Do not advertise to any peer (well-known community)\n"
8316 "Do not export to next AS (well-known community)\n"
8317 "community number\n"
8318 "Do not send outside local AS (well-known community)\n"
8319 "Do not advertise to any peer (well-known community)\n"
8320 "Do not export to next AS (well-known community)\n"
8321 "community number\n"
8322 "Do not send outside local AS (well-known community)\n"
8323 "Do not advertise to any peer (well-known community)\n"
8324 "Do not export to next AS (well-known community)\n"
8325 "Exact match of the communities")
8326
8327ALIAS (show_bgp_community_exact,
8328 show_bgp_ipv6_community3_exact_cmd,
8329 "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",
8330 SHOW_STR
8331 BGP_STR
8332 "Address family\n"
8333 "Display routes matching the communities\n"
8334 "community number\n"
8335 "Do not send outside local AS (well-known community)\n"
8336 "Do not advertise to any peer (well-known community)\n"
8337 "Do not export to next AS (well-known community)\n"
8338 "community number\n"
8339 "Do not send outside local AS (well-known community)\n"
8340 "Do not advertise to any peer (well-known community)\n"
8341 "Do not export to next AS (well-known community)\n"
8342 "community number\n"
8343 "Do not send outside local AS (well-known community)\n"
8344 "Do not advertise to any peer (well-known community)\n"
8345 "Do not export to next AS (well-known community)\n"
8346 "Exact match of the communities")
8347
8348ALIAS (show_bgp_community_exact,
8349 show_bgp_community4_exact_cmd,
8350 "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",
8351 SHOW_STR
8352 BGP_STR
8353 "Display routes matching the communities\n"
8354 "community number\n"
8355 "Do not send outside local AS (well-known community)\n"
8356 "Do not advertise to any peer (well-known community)\n"
8357 "Do not export to next AS (well-known community)\n"
8358 "community number\n"
8359 "Do not send outside local AS (well-known community)\n"
8360 "Do not advertise to any peer (well-known community)\n"
8361 "Do not export to next AS (well-known community)\n"
8362 "community number\n"
8363 "Do not send outside local AS (well-known community)\n"
8364 "Do not advertise to any peer (well-known community)\n"
8365 "Do not export to next AS (well-known community)\n"
8366 "community number\n"
8367 "Do not send outside local AS (well-known community)\n"
8368 "Do not advertise to any peer (well-known community)\n"
8369 "Do not export to next AS (well-known community)\n"
8370 "Exact match of the communities")
8371
8372ALIAS (show_bgp_community_exact,
8373 show_bgp_ipv6_community4_exact_cmd,
8374 "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",
8375 SHOW_STR
8376 BGP_STR
8377 "Address family\n"
8378 "Display routes matching the communities\n"
8379 "community number\n"
8380 "Do not send outside local AS (well-known community)\n"
8381 "Do not advertise to any peer (well-known community)\n"
8382 "Do not export to next AS (well-known community)\n"
8383 "community number\n"
8384 "Do not send outside local AS (well-known community)\n"
8385 "Do not advertise to any peer (well-known community)\n"
8386 "Do not export to next AS (well-known community)\n"
8387 "community number\n"
8388 "Do not send outside local AS (well-known community)\n"
8389 "Do not advertise to any peer (well-known community)\n"
8390 "Do not export to next AS (well-known community)\n"
8391 "community number\n"
8392 "Do not send outside local AS (well-known community)\n"
8393 "Do not advertise to any peer (well-known community)\n"
8394 "Do not export to next AS (well-known community)\n"
8395 "Exact match of the communities")
8396
8397/* old command */
8398DEFUN (show_ipv6_bgp_community_exact,
8399 show_ipv6_bgp_community_exact_cmd,
8400 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8401 SHOW_STR
8402 IPV6_STR
8403 BGP_STR
8404 "Display routes matching the communities\n"
8405 "community number\n"
8406 "Do not send outside local AS (well-known community)\n"
8407 "Do not advertise to any peer (well-known community)\n"
8408 "Do not export to next AS (well-known community)\n"
8409 "Exact match of the communities")
8410{
8411 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8412}
8413
8414/* old command */
8415ALIAS (show_ipv6_bgp_community_exact,
8416 show_ipv6_bgp_community2_exact_cmd,
8417 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8418 SHOW_STR
8419 IPV6_STR
8420 BGP_STR
8421 "Display routes matching the communities\n"
8422 "community number\n"
8423 "Do not send outside local AS (well-known community)\n"
8424 "Do not advertise to any peer (well-known community)\n"
8425 "Do not export to next AS (well-known community)\n"
8426 "community number\n"
8427 "Do not send outside local AS (well-known community)\n"
8428 "Do not advertise to any peer (well-known community)\n"
8429 "Do not export to next AS (well-known community)\n"
8430 "Exact match of the communities")
8431
8432/* old command */
8433ALIAS (show_ipv6_bgp_community_exact,
8434 show_ipv6_bgp_community3_exact_cmd,
8435 "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",
8436 SHOW_STR
8437 IPV6_STR
8438 BGP_STR
8439 "Display routes matching the communities\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n"
8448 "community number\n"
8449 "Do not send outside local AS (well-known community)\n"
8450 "Do not advertise to any peer (well-known community)\n"
8451 "Do not export to next AS (well-known community)\n"
8452 "Exact match of the communities")
8453
8454/* old command */
8455ALIAS (show_ipv6_bgp_community_exact,
8456 show_ipv6_bgp_community4_exact_cmd,
8457 "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",
8458 SHOW_STR
8459 IPV6_STR
8460 BGP_STR
8461 "Display routes matching the communities\n"
8462 "community number\n"
8463 "Do not send outside local AS (well-known community)\n"
8464 "Do not advertise to any peer (well-known community)\n"
8465 "Do not export to next AS (well-known community)\n"
8466 "community number\n"
8467 "Do not send outside local AS (well-known community)\n"
8468 "Do not advertise to any peer (well-known community)\n"
8469 "Do not export to next AS (well-known community)\n"
8470 "community number\n"
8471 "Do not send outside local AS (well-known community)\n"
8472 "Do not advertise to any peer (well-known community)\n"
8473 "Do not export to next AS (well-known community)\n"
8474 "community number\n"
8475 "Do not send outside local AS (well-known community)\n"
8476 "Do not advertise to any peer (well-known community)\n"
8477 "Do not export to next AS (well-known community)\n"
8478 "Exact match of the communities")
8479
8480/* old command */
8481DEFUN (show_ipv6_mbgp_community,
8482 show_ipv6_mbgp_community_cmd,
8483 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8484 SHOW_STR
8485 IPV6_STR
8486 MBGP_STR
8487 "Display routes matching the communities\n"
8488 "community number\n"
8489 "Do not send outside local AS (well-known community)\n"
8490 "Do not advertise to any peer (well-known community)\n"
8491 "Do not export to next AS (well-known community)\n")
8492{
8493 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8494}
8495
8496/* old command */
8497ALIAS (show_ipv6_mbgp_community,
8498 show_ipv6_mbgp_community2_cmd,
8499 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8500 SHOW_STR
8501 IPV6_STR
8502 MBGP_STR
8503 "Display routes matching the communities\n"
8504 "community number\n"
8505 "Do not send outside local AS (well-known community)\n"
8506 "Do not advertise to any peer (well-known community)\n"
8507 "Do not export to next AS (well-known community)\n"
8508 "community number\n"
8509 "Do not send outside local AS (well-known community)\n"
8510 "Do not advertise to any peer (well-known community)\n"
8511 "Do not export to next AS (well-known community)\n")
8512
8513/* old command */
8514ALIAS (show_ipv6_mbgp_community,
8515 show_ipv6_mbgp_community3_cmd,
8516 "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)",
8517 SHOW_STR
8518 IPV6_STR
8519 MBGP_STR
8520 "Display routes matching the communities\n"
8521 "community number\n"
8522 "Do not send outside local AS (well-known community)\n"
8523 "Do not advertise to any peer (well-known community)\n"
8524 "Do not export to next AS (well-known community)\n"
8525 "community number\n"
8526 "Do not send outside local AS (well-known community)\n"
8527 "Do not advertise to any peer (well-known community)\n"
8528 "Do not export to next AS (well-known community)\n"
8529 "community number\n"
8530 "Do not send outside local AS (well-known community)\n"
8531 "Do not advertise to any peer (well-known community)\n"
8532 "Do not export to next AS (well-known community)\n")
8533
8534/* old command */
8535ALIAS (show_ipv6_mbgp_community,
8536 show_ipv6_mbgp_community4_cmd,
8537 "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)",
8538 SHOW_STR
8539 IPV6_STR
8540 MBGP_STR
8541 "Display routes matching the communities\n"
8542 "community number\n"
8543 "Do not send outside local AS (well-known community)\n"
8544 "Do not advertise to any peer (well-known community)\n"
8545 "Do not export to next AS (well-known community)\n"
8546 "community number\n"
8547 "Do not send outside local AS (well-known community)\n"
8548 "Do not advertise to any peer (well-known community)\n"
8549 "Do not export to next AS (well-known community)\n"
8550 "community number\n"
8551 "Do not send outside local AS (well-known community)\n"
8552 "Do not advertise to any peer (well-known community)\n"
8553 "Do not export to next AS (well-known community)\n"
8554 "community number\n"
8555 "Do not send outside local AS (well-known community)\n"
8556 "Do not advertise to any peer (well-known community)\n"
8557 "Do not export to next AS (well-known community)\n")
8558
8559/* old command */
8560DEFUN (show_ipv6_mbgp_community_exact,
8561 show_ipv6_mbgp_community_exact_cmd,
8562 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8563 SHOW_STR
8564 IPV6_STR
8565 MBGP_STR
8566 "Display routes matching the communities\n"
8567 "community number\n"
8568 "Do not send outside local AS (well-known community)\n"
8569 "Do not advertise to any peer (well-known community)\n"
8570 "Do not export to next AS (well-known community)\n"
8571 "Exact match of the communities")
8572{
8573 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8574}
8575
8576/* old command */
8577ALIAS (show_ipv6_mbgp_community_exact,
8578 show_ipv6_mbgp_community2_exact_cmd,
8579 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8580 SHOW_STR
8581 IPV6_STR
8582 MBGP_STR
8583 "Display routes matching the communities\n"
8584 "community number\n"
8585 "Do not send outside local AS (well-known community)\n"
8586 "Do not advertise to any peer (well-known community)\n"
8587 "Do not export to next AS (well-known community)\n"
8588 "community number\n"
8589 "Do not send outside local AS (well-known community)\n"
8590 "Do not advertise to any peer (well-known community)\n"
8591 "Do not export to next AS (well-known community)\n"
8592 "Exact match of the communities")
8593
8594/* old command */
8595ALIAS (show_ipv6_mbgp_community_exact,
8596 show_ipv6_mbgp_community3_exact_cmd,
8597 "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",
8598 SHOW_STR
8599 IPV6_STR
8600 MBGP_STR
8601 "Display routes matching the communities\n"
8602 "community number\n"
8603 "Do not send outside local AS (well-known community)\n"
8604 "Do not advertise to any peer (well-known community)\n"
8605 "Do not export to next AS (well-known community)\n"
8606 "community number\n"
8607 "Do not send outside local AS (well-known community)\n"
8608 "Do not advertise to any peer (well-known community)\n"
8609 "Do not export to next AS (well-known community)\n"
8610 "community number\n"
8611 "Do not send outside local AS (well-known community)\n"
8612 "Do not advertise to any peer (well-known community)\n"
8613 "Do not export to next AS (well-known community)\n"
8614 "Exact match of the communities")
8615
8616/* old command */
8617ALIAS (show_ipv6_mbgp_community_exact,
8618 show_ipv6_mbgp_community4_exact_cmd,
8619 "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",
8620 SHOW_STR
8621 IPV6_STR
8622 MBGP_STR
8623 "Display routes matching the communities\n"
8624 "community number\n"
8625 "Do not send outside local AS (well-known community)\n"
8626 "Do not advertise to any peer (well-known community)\n"
8627 "Do not export to next AS (well-known community)\n"
8628 "community number\n"
8629 "Do not send outside local AS (well-known community)\n"
8630 "Do not advertise to any peer (well-known community)\n"
8631 "Do not export to next AS (well-known community)\n"
8632 "community number\n"
8633 "Do not send outside local AS (well-known community)\n"
8634 "Do not advertise to any peer (well-known community)\n"
8635 "Do not export to next AS (well-known community)\n"
8636 "community number\n"
8637 "Do not send outside local AS (well-known community)\n"
8638 "Do not advertise to any peer (well-known community)\n"
8639 "Do not export to next AS (well-known community)\n"
8640 "Exact match of the communities")
8641#endif /* HAVE_IPV6 */
8642
paul94f2b392005-06-28 12:44:16 +00008643static int
paulfd79ac92004-10-13 05:06:08 +00008644bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008645 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008646{
8647 struct community_list *list;
8648
hassofee6e4e2005-02-02 16:29:31 +00008649 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008650 if (list == NULL)
8651 {
8652 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8653 VTY_NEWLINE);
8654 return CMD_WARNING;
8655 }
8656
ajs5a646652004-11-05 01:25:55 +00008657 return bgp_show (vty, NULL, afi, safi,
8658 (exact ? bgp_show_type_community_list_exact :
8659 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008660}
8661
8662DEFUN (show_ip_bgp_community_list,
8663 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008664 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008665 SHOW_STR
8666 IP_STR
8667 BGP_STR
8668 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008669 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008670 "community-list name\n")
8671{
8672 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8673}
8674
8675DEFUN (show_ip_bgp_ipv4_community_list,
8676 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008677 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008678 SHOW_STR
8679 IP_STR
8680 BGP_STR
8681 "Address family\n"
8682 "Address Family modifier\n"
8683 "Address Family modifier\n"
8684 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008685 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008686 "community-list name\n")
8687{
8688 if (strncmp (argv[0], "m", 1) == 0)
8689 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8690
8691 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8692}
8693
8694DEFUN (show_ip_bgp_community_list_exact,
8695 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008696 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008697 SHOW_STR
8698 IP_STR
8699 BGP_STR
8700 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008701 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008702 "community-list name\n"
8703 "Exact match of the communities\n")
8704{
8705 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8706}
8707
8708DEFUN (show_ip_bgp_ipv4_community_list_exact,
8709 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008710 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008711 SHOW_STR
8712 IP_STR
8713 BGP_STR
8714 "Address family\n"
8715 "Address Family modifier\n"
8716 "Address Family modifier\n"
8717 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008718 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008719 "community-list name\n"
8720 "Exact match of the communities\n")
8721{
8722 if (strncmp (argv[0], "m", 1) == 0)
8723 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8724
8725 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8726}
8727
8728#ifdef HAVE_IPV6
8729DEFUN (show_bgp_community_list,
8730 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008731 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008732 SHOW_STR
8733 BGP_STR
8734 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008735 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008736 "community-list name\n")
8737{
8738 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8739}
8740
8741ALIAS (show_bgp_community_list,
8742 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008743 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008744 SHOW_STR
8745 BGP_STR
8746 "Address family\n"
8747 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008748 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008749 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008750
8751/* old command */
8752DEFUN (show_ipv6_bgp_community_list,
8753 show_ipv6_bgp_community_list_cmd,
8754 "show ipv6 bgp community-list WORD",
8755 SHOW_STR
8756 IPV6_STR
8757 BGP_STR
8758 "Display routes matching the community-list\n"
8759 "community-list name\n")
8760{
8761 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8762}
8763
8764/* old command */
8765DEFUN (show_ipv6_mbgp_community_list,
8766 show_ipv6_mbgp_community_list_cmd,
8767 "show ipv6 mbgp community-list WORD",
8768 SHOW_STR
8769 IPV6_STR
8770 MBGP_STR
8771 "Display routes matching the community-list\n"
8772 "community-list name\n")
8773{
8774 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8775}
8776
8777DEFUN (show_bgp_community_list_exact,
8778 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008779 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008780 SHOW_STR
8781 BGP_STR
8782 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008783 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008784 "community-list name\n"
8785 "Exact match of the communities\n")
8786{
8787 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8788}
8789
8790ALIAS (show_bgp_community_list_exact,
8791 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008792 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008793 SHOW_STR
8794 BGP_STR
8795 "Address family\n"
8796 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008797 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008798 "community-list name\n"
8799 "Exact match of the communities\n")
8800
8801/* old command */
8802DEFUN (show_ipv6_bgp_community_list_exact,
8803 show_ipv6_bgp_community_list_exact_cmd,
8804 "show ipv6 bgp community-list WORD exact-match",
8805 SHOW_STR
8806 IPV6_STR
8807 BGP_STR
8808 "Display routes matching the community-list\n"
8809 "community-list name\n"
8810 "Exact match of the communities\n")
8811{
8812 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8813}
8814
8815/* old command */
8816DEFUN (show_ipv6_mbgp_community_list_exact,
8817 show_ipv6_mbgp_community_list_exact_cmd,
8818 "show ipv6 mbgp community-list WORD exact-match",
8819 SHOW_STR
8820 IPV6_STR
8821 MBGP_STR
8822 "Display routes matching the community-list\n"
8823 "community-list name\n"
8824 "Exact match of the communities\n")
8825{
8826 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8827}
8828#endif /* HAVE_IPV6 */
8829
paul94f2b392005-06-28 12:44:16 +00008830static int
paulfd79ac92004-10-13 05:06:08 +00008831bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008832 safi_t safi, enum bgp_show_type type)
8833{
8834 int ret;
8835 struct prefix *p;
8836
8837 p = prefix_new();
8838
8839 ret = str2prefix (prefix, p);
8840 if (! ret)
8841 {
8842 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8843 return CMD_WARNING;
8844 }
8845
ajs5a646652004-11-05 01:25:55 +00008846 ret = bgp_show (vty, NULL, afi, safi, type, p);
8847 prefix_free(p);
8848 return ret;
paul718e3742002-12-13 20:15:29 +00008849}
8850
8851DEFUN (show_ip_bgp_prefix_longer,
8852 show_ip_bgp_prefix_longer_cmd,
8853 "show ip bgp A.B.C.D/M longer-prefixes",
8854 SHOW_STR
8855 IP_STR
8856 BGP_STR
8857 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8858 "Display route and more specific routes\n")
8859{
8860 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8861 bgp_show_type_prefix_longer);
8862}
8863
8864DEFUN (show_ip_bgp_flap_prefix_longer,
8865 show_ip_bgp_flap_prefix_longer_cmd,
8866 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8867 SHOW_STR
8868 IP_STR
8869 BGP_STR
8870 "Display flap statistics of routes\n"
8871 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8872 "Display route and more specific routes\n")
8873{
8874 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8875 bgp_show_type_flap_prefix_longer);
8876}
8877
8878DEFUN (show_ip_bgp_ipv4_prefix_longer,
8879 show_ip_bgp_ipv4_prefix_longer_cmd,
8880 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8881 SHOW_STR
8882 IP_STR
8883 BGP_STR
8884 "Address family\n"
8885 "Address Family modifier\n"
8886 "Address Family modifier\n"
8887 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8888 "Display route and more specific routes\n")
8889{
8890 if (strncmp (argv[0], "m", 1) == 0)
8891 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8892 bgp_show_type_prefix_longer);
8893
8894 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8895 bgp_show_type_prefix_longer);
8896}
8897
8898DEFUN (show_ip_bgp_flap_address,
8899 show_ip_bgp_flap_address_cmd,
8900 "show ip bgp flap-statistics A.B.C.D",
8901 SHOW_STR
8902 IP_STR
8903 BGP_STR
8904 "Display flap statistics of routes\n"
8905 "Network in the BGP routing table to display\n")
8906{
8907 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8908 bgp_show_type_flap_address);
8909}
8910
8911DEFUN (show_ip_bgp_flap_prefix,
8912 show_ip_bgp_flap_prefix_cmd,
8913 "show ip bgp flap-statistics A.B.C.D/M",
8914 SHOW_STR
8915 IP_STR
8916 BGP_STR
8917 "Display flap statistics of routes\n"
8918 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8919{
8920 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8921 bgp_show_type_flap_prefix);
8922}
8923#ifdef HAVE_IPV6
8924DEFUN (show_bgp_prefix_longer,
8925 show_bgp_prefix_longer_cmd,
8926 "show bgp X:X::X:X/M longer-prefixes",
8927 SHOW_STR
8928 BGP_STR
8929 "IPv6 prefix <network>/<length>\n"
8930 "Display route and more specific routes\n")
8931{
8932 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8933 bgp_show_type_prefix_longer);
8934}
8935
8936ALIAS (show_bgp_prefix_longer,
8937 show_bgp_ipv6_prefix_longer_cmd,
8938 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8939 SHOW_STR
8940 BGP_STR
8941 "Address family\n"
8942 "IPv6 prefix <network>/<length>\n"
8943 "Display route and more specific routes\n")
8944
8945/* old command */
8946DEFUN (show_ipv6_bgp_prefix_longer,
8947 show_ipv6_bgp_prefix_longer_cmd,
8948 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8949 SHOW_STR
8950 IPV6_STR
8951 BGP_STR
8952 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8953 "Display route and more specific routes\n")
8954{
8955 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8956 bgp_show_type_prefix_longer);
8957}
8958
8959/* old command */
8960DEFUN (show_ipv6_mbgp_prefix_longer,
8961 show_ipv6_mbgp_prefix_longer_cmd,
8962 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8963 SHOW_STR
8964 IPV6_STR
8965 MBGP_STR
8966 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8967 "Display route and more specific routes\n")
8968{
8969 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8970 bgp_show_type_prefix_longer);
8971}
8972#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008973
paul94f2b392005-06-28 12:44:16 +00008974static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008975peer_lookup_in_view (struct vty *vty, const char *view_name,
8976 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008977{
8978 int ret;
8979 struct bgp *bgp;
8980 struct peer *peer;
8981 union sockunion su;
8982
8983 /* BGP structure lookup. */
8984 if (view_name)
8985 {
8986 bgp = bgp_lookup_by_name (view_name);
8987 if (! bgp)
8988 {
8989 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8990 return NULL;
8991 }
8992 }
paul5228ad22004-06-04 17:58:18 +00008993 else
paulbb46e942003-10-24 19:02:03 +00008994 {
8995 bgp = bgp_get_default ();
8996 if (! bgp)
8997 {
8998 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8999 return NULL;
9000 }
9001 }
9002
9003 /* Get peer sockunion. */
9004 ret = str2sockunion (ip_str, &su);
9005 if (ret < 0)
9006 {
9007 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9008 return NULL;
9009 }
9010
9011 /* Peer structure lookup. */
9012 peer = peer_lookup (bgp, &su);
9013 if (! peer)
9014 {
9015 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9016 return NULL;
9017 }
9018
9019 return peer;
9020}
Paul Jakma2815e612006-09-14 02:56:07 +00009021
9022enum bgp_stats
9023{
9024 BGP_STATS_MAXBITLEN = 0,
9025 BGP_STATS_RIB,
9026 BGP_STATS_PREFIXES,
9027 BGP_STATS_TOTPLEN,
9028 BGP_STATS_UNAGGREGATEABLE,
9029 BGP_STATS_MAX_AGGREGATEABLE,
9030 BGP_STATS_AGGREGATES,
9031 BGP_STATS_SPACE,
9032 BGP_STATS_ASPATH_COUNT,
9033 BGP_STATS_ASPATH_MAXHOPS,
9034 BGP_STATS_ASPATH_TOTHOPS,
9035 BGP_STATS_ASPATH_MAXSIZE,
9036 BGP_STATS_ASPATH_TOTSIZE,
9037 BGP_STATS_ASN_HIGHEST,
9038 BGP_STATS_MAX,
9039};
paulbb46e942003-10-24 19:02:03 +00009040
Paul Jakma2815e612006-09-14 02:56:07 +00009041static const char *table_stats_strs[] =
9042{
9043 [BGP_STATS_PREFIXES] = "Total Prefixes",
9044 [BGP_STATS_TOTPLEN] = "Average prefix length",
9045 [BGP_STATS_RIB] = "Total Advertisements",
9046 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9047 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9048 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9049 [BGP_STATS_SPACE] = "Address space advertised",
9050 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9051 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9052 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9053 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9054 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9055 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9056 [BGP_STATS_MAX] = NULL,
9057};
9058
9059struct bgp_table_stats
9060{
9061 struct bgp_table *table;
9062 unsigned long long counts[BGP_STATS_MAX];
9063};
9064
9065#if 0
9066#define TALLY_SIGFIG 100000
9067static unsigned long
9068ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9069{
9070 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9071 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9072 unsigned long ret = newtot / count;
9073
9074 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9075 return ret + 1;
9076 else
9077 return ret;
9078}
9079#endif
9080
9081static int
9082bgp_table_stats_walker (struct thread *t)
9083{
9084 struct bgp_node *rn;
9085 struct bgp_node *top;
9086 struct bgp_table_stats *ts = THREAD_ARG (t);
9087 unsigned int space = 0;
9088
Paul Jakma53d9f672006-10-15 23:41:16 +00009089 if (!(top = bgp_table_top (ts->table)))
9090 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009091
9092 switch (top->p.family)
9093 {
9094 case AF_INET:
9095 space = IPV4_MAX_BITLEN;
9096 break;
9097 case AF_INET6:
9098 space = IPV6_MAX_BITLEN;
9099 break;
9100 }
9101
9102 ts->counts[BGP_STATS_MAXBITLEN] = space;
9103
9104 for (rn = top; rn; rn = bgp_route_next (rn))
9105 {
9106 struct bgp_info *ri;
9107 struct bgp_node *prn = rn->parent;
9108 unsigned int rinum = 0;
9109
9110 if (rn == top)
9111 continue;
9112
9113 if (!rn->info)
9114 continue;
9115
9116 ts->counts[BGP_STATS_PREFIXES]++;
9117 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9118
9119#if 0
9120 ts->counts[BGP_STATS_AVGPLEN]
9121 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9122 ts->counts[BGP_STATS_AVGPLEN],
9123 rn->p.prefixlen);
9124#endif
9125
9126 /* check if the prefix is included by any other announcements */
9127 while (prn && !prn->info)
9128 prn = prn->parent;
9129
9130 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009131 {
9132 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9133 /* announced address space */
9134 if (space)
9135 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9136 }
Paul Jakma2815e612006-09-14 02:56:07 +00009137 else if (prn->info)
9138 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9139
Paul Jakma2815e612006-09-14 02:56:07 +00009140 for (ri = rn->info; ri; ri = ri->next)
9141 {
9142 rinum++;
9143 ts->counts[BGP_STATS_RIB]++;
9144
9145 if (ri->attr &&
9146 (CHECK_FLAG (ri->attr->flag,
9147 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9148 ts->counts[BGP_STATS_AGGREGATES]++;
9149
9150 /* as-path stats */
9151 if (ri->attr && ri->attr->aspath)
9152 {
9153 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9154 unsigned int size = aspath_size (ri->attr->aspath);
9155 as_t highest = aspath_highest (ri->attr->aspath);
9156
9157 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9158
9159 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9160 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9161
9162 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9163 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9164
9165 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9166 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9167#if 0
9168 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9169 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9170 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9171 hops);
9172 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9173 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9174 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9175 size);
9176#endif
9177 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9178 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9179 }
9180 }
9181 }
9182 return 0;
9183}
9184
9185static int
9186bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9187{
9188 struct bgp_table_stats ts;
9189 unsigned int i;
9190
9191 if (!bgp->rib[afi][safi])
9192 {
9193 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9194 return CMD_WARNING;
9195 }
9196
9197 memset (&ts, 0, sizeof (ts));
9198 ts.table = bgp->rib[afi][safi];
9199 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9200
9201 vty_out (vty, "BGP %s RIB statistics%s%s",
9202 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9203
9204 for (i = 0; i < BGP_STATS_MAX; i++)
9205 {
9206 if (!table_stats_strs[i])
9207 continue;
9208
9209 switch (i)
9210 {
9211#if 0
9212 case BGP_STATS_ASPATH_AVGHOPS:
9213 case BGP_STATS_ASPATH_AVGSIZE:
9214 case BGP_STATS_AVGPLEN:
9215 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9216 vty_out (vty, "%12.2f",
9217 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9218 break;
9219#endif
9220 case BGP_STATS_ASPATH_TOTHOPS:
9221 case BGP_STATS_ASPATH_TOTSIZE:
9222 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9223 vty_out (vty, "%12.2f",
9224 ts.counts[i] ?
9225 (float)ts.counts[i] /
9226 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9227 : 0);
9228 break;
9229 case BGP_STATS_TOTPLEN:
9230 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9231 vty_out (vty, "%12.2f",
9232 ts.counts[i] ?
9233 (float)ts.counts[i] /
9234 (float)ts.counts[BGP_STATS_PREFIXES]
9235 : 0);
9236 break;
9237 case BGP_STATS_SPACE:
9238 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9239 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9240 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9241 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009242 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009243 vty_out (vty, "%12.2f%s",
9244 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009245 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009246 VTY_NEWLINE);
9247 vty_out (vty, "%30s: ", "/8 equivalent ");
9248 vty_out (vty, "%12.2f%s",
9249 (float)ts.counts[BGP_STATS_SPACE] /
9250 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9251 VTY_NEWLINE);
9252 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9253 break;
9254 vty_out (vty, "%30s: ", "/24 equivalent ");
9255 vty_out (vty, "%12.2f",
9256 (float)ts.counts[BGP_STATS_SPACE] /
9257 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9258 break;
9259 default:
9260 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9261 vty_out (vty, "%12llu", ts.counts[i]);
9262 }
9263
9264 vty_out (vty, "%s", VTY_NEWLINE);
9265 }
9266 return CMD_SUCCESS;
9267}
9268
9269static int
9270bgp_table_stats_vty (struct vty *vty, const char *name,
9271 const char *afi_str, const char *safi_str)
9272{
9273 struct bgp *bgp;
9274 afi_t afi;
9275 safi_t safi;
9276
9277 if (name)
9278 bgp = bgp_lookup_by_name (name);
9279 else
9280 bgp = bgp_get_default ();
9281
9282 if (!bgp)
9283 {
9284 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9285 return CMD_WARNING;
9286 }
9287 if (strncmp (afi_str, "ipv", 3) == 0)
9288 {
9289 if (strncmp (afi_str, "ipv4", 4) == 0)
9290 afi = AFI_IP;
9291 else if (strncmp (afi_str, "ipv6", 4) == 0)
9292 afi = AFI_IP6;
9293 else
9294 {
9295 vty_out (vty, "%% Invalid address family %s%s",
9296 afi_str, VTY_NEWLINE);
9297 return CMD_WARNING;
9298 }
9299 if (strncmp (safi_str, "m", 1) == 0)
9300 safi = SAFI_MULTICAST;
9301 else if (strncmp (safi_str, "u", 1) == 0)
9302 safi = SAFI_UNICAST;
9303 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9304 safi = BGP_SAFI_VPNV4;
9305 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9306 safi = BGP_SAFI_VPNV6;
9307 else
9308 {
9309 vty_out (vty, "%% Invalid subsequent address family %s%s",
9310 safi_str, VTY_NEWLINE);
9311 return CMD_WARNING;
9312 }
9313 }
9314 else
9315 {
9316 vty_out (vty, "%% Invalid address family %s%s",
9317 afi_str, VTY_NEWLINE);
9318 return CMD_WARNING;
9319 }
9320
9321 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9322 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9323 {
9324 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9325 afi_str, safi_str, VTY_NEWLINE);
9326 return CMD_WARNING;
9327 }
9328 return bgp_table_stats (vty, bgp, afi, safi);
9329}
9330
9331DEFUN (show_bgp_statistics,
9332 show_bgp_statistics_cmd,
9333 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9334 SHOW_STR
9335 BGP_STR
9336 "Address family\n"
9337 "Address family\n"
9338 "Address Family modifier\n"
9339 "Address Family modifier\n"
9340 "BGP RIB advertisement statistics\n")
9341{
9342 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9343}
9344
9345ALIAS (show_bgp_statistics,
9346 show_bgp_statistics_vpnv4_cmd,
9347 "show bgp (ipv4) (vpnv4) statistics",
9348 SHOW_STR
9349 BGP_STR
9350 "Address family\n"
9351 "Address Family modifier\n"
9352 "BGP RIB advertisement statistics\n")
9353
9354DEFUN (show_bgp_statistics_view,
9355 show_bgp_statistics_view_cmd,
9356 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9357 SHOW_STR
9358 BGP_STR
9359 "BGP view\n"
9360 "Address family\n"
9361 "Address family\n"
9362 "Address Family modifier\n"
9363 "Address Family modifier\n"
9364 "BGP RIB advertisement statistics\n")
9365{
9366 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9367}
9368
9369ALIAS (show_bgp_statistics_view,
9370 show_bgp_statistics_view_vpnv4_cmd,
9371 "show bgp view WORD (ipv4) (vpnv4) statistics",
9372 SHOW_STR
9373 BGP_STR
9374 "BGP view\n"
9375 "Address family\n"
9376 "Address Family modifier\n"
9377 "BGP RIB advertisement statistics\n")
9378
Paul Jakmaff7924f2006-09-04 01:10:36 +00009379enum bgp_pcounts
9380{
9381 PCOUNT_ADJ_IN = 0,
9382 PCOUNT_DAMPED,
9383 PCOUNT_REMOVED,
9384 PCOUNT_HISTORY,
9385 PCOUNT_STALE,
9386 PCOUNT_VALID,
9387 PCOUNT_ALL,
9388 PCOUNT_COUNTED,
9389 PCOUNT_PFCNT, /* the figure we display to users */
9390 PCOUNT_MAX,
9391};
9392
9393static const char *pcount_strs[] =
9394{
9395 [PCOUNT_ADJ_IN] = "Adj-in",
9396 [PCOUNT_DAMPED] = "Damped",
9397 [PCOUNT_REMOVED] = "Removed",
9398 [PCOUNT_HISTORY] = "History",
9399 [PCOUNT_STALE] = "Stale",
9400 [PCOUNT_VALID] = "Valid",
9401 [PCOUNT_ALL] = "All RIB",
9402 [PCOUNT_COUNTED] = "PfxCt counted",
9403 [PCOUNT_PFCNT] = "Useable",
9404 [PCOUNT_MAX] = NULL,
9405};
9406
Paul Jakma2815e612006-09-14 02:56:07 +00009407struct peer_pcounts
9408{
9409 unsigned int count[PCOUNT_MAX];
9410 const struct peer *peer;
9411 const struct bgp_table *table;
9412};
9413
Paul Jakmaff7924f2006-09-04 01:10:36 +00009414static int
Paul Jakma2815e612006-09-14 02:56:07 +00009415bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009416{
9417 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009418 struct peer_pcounts *pc = THREAD_ARG (t);
9419 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009420
Paul Jakma2815e612006-09-14 02:56:07 +00009421 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009422 {
9423 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009424 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009425
9426 for (ain = rn->adj_in; ain; ain = ain->next)
9427 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009428 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009429
Paul Jakmaff7924f2006-09-04 01:10:36 +00009430 for (ri = rn->info; ri; ri = ri->next)
9431 {
9432 char buf[SU_ADDRSTRLEN];
9433
9434 if (ri->peer != peer)
9435 continue;
9436
Paul Jakma2815e612006-09-14 02:56:07 +00009437 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009438
9439 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009440 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009441 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009442 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009443 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009444 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009445 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009446 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009447 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009448 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009449 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009450 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009451
9452 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9453 {
Paul Jakma2815e612006-09-14 02:56:07 +00009454 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009455 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009456 plog_warn (peer->log,
9457 "%s [pcount] %s/%d is counted but flags 0x%x",
9458 peer->host,
9459 inet_ntop(rn->p.family, &rn->p.u.prefix,
9460 buf, SU_ADDRSTRLEN),
9461 rn->p.prefixlen,
9462 ri->flags);
9463 }
9464 else
9465 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009466 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009467 plog_warn (peer->log,
9468 "%s [pcount] %s/%d not counted but flags 0x%x",
9469 peer->host,
9470 inet_ntop(rn->p.family, &rn->p.u.prefix,
9471 buf, SU_ADDRSTRLEN),
9472 rn->p.prefixlen,
9473 ri->flags);
9474 }
9475 }
9476 }
Paul Jakma2815e612006-09-14 02:56:07 +00009477 return 0;
9478}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009479
Paul Jakma2815e612006-09-14 02:56:07 +00009480static int
9481bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9482{
9483 struct peer_pcounts pcounts = { .peer = peer };
9484 unsigned int i;
9485
9486 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9487 || !peer->bgp->rib[afi][safi])
9488 {
9489 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9490 return CMD_WARNING;
9491 }
9492
9493 memset (&pcounts, 0, sizeof(pcounts));
9494 pcounts.peer = peer;
9495 pcounts.table = peer->bgp->rib[afi][safi];
9496
9497 /* in-place call via thread subsystem so as to record execution time
9498 * stats for the thread-walk (i.e. ensure this can't be blamed on
9499 * on just vty_read()).
9500 */
9501 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9502
Paul Jakmaff7924f2006-09-04 01:10:36 +00009503 vty_out (vty, "Prefix counts for %s, %s%s",
9504 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9505 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9506 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9507 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9508
9509 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009510 vty_out (vty, "%20s: %-10d%s",
9511 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009512
Paul Jakma2815e612006-09-14 02:56:07 +00009513 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009514 {
9515 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9516 peer->host, VTY_NEWLINE);
9517 vty_out (vty, "Please report this bug, with the above command output%s",
9518 VTY_NEWLINE);
9519 }
9520
9521 return CMD_SUCCESS;
9522}
9523
9524DEFUN (show_ip_bgp_neighbor_prefix_counts,
9525 show_ip_bgp_neighbor_prefix_counts_cmd,
9526 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9527 SHOW_STR
9528 IP_STR
9529 BGP_STR
9530 "Detailed information on TCP and BGP neighbor connections\n"
9531 "Neighbor to display information about\n"
9532 "Neighbor to display information about\n"
9533 "Display detailed prefix count information\n")
9534{
9535 struct peer *peer;
9536
9537 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9538 if (! peer)
9539 return CMD_WARNING;
9540
9541 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9542}
9543
9544DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9545 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9546 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9547 SHOW_STR
9548 BGP_STR
9549 "Address family\n"
9550 "Detailed information on TCP and BGP neighbor connections\n"
9551 "Neighbor to display information about\n"
9552 "Neighbor to display information about\n"
9553 "Display detailed prefix count information\n")
9554{
9555 struct peer *peer;
9556
9557 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9558 if (! peer)
9559 return CMD_WARNING;
9560
9561 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9562}
9563
9564DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9565 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9566 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9567 SHOW_STR
9568 IP_STR
9569 BGP_STR
9570 "Address family\n"
9571 "Address Family modifier\n"
9572 "Address Family modifier\n"
9573 "Detailed information on TCP and BGP neighbor connections\n"
9574 "Neighbor to display information about\n"
9575 "Neighbor to display information about\n"
9576 "Display detailed prefix count information\n")
9577{
9578 struct peer *peer;
9579
9580 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9581 if (! peer)
9582 return CMD_WARNING;
9583
9584 if (strncmp (argv[0], "m", 1) == 0)
9585 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9586
9587 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9588}
9589
9590DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9591 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9592 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9593 SHOW_STR
9594 IP_STR
9595 BGP_STR
9596 "Address family\n"
9597 "Address Family modifier\n"
9598 "Address Family modifier\n"
9599 "Detailed information on TCP and BGP neighbor connections\n"
9600 "Neighbor to display information about\n"
9601 "Neighbor to display information about\n"
9602 "Display detailed prefix count information\n")
9603{
9604 struct peer *peer;
9605
9606 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9607 if (! peer)
9608 return CMD_WARNING;
9609
9610 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9611}
9612
9613
paul94f2b392005-06-28 12:44:16 +00009614static void
paul718e3742002-12-13 20:15:29 +00009615show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9616 int in)
9617{
9618 struct bgp_table *table;
9619 struct bgp_adj_in *ain;
9620 struct bgp_adj_out *adj;
9621 unsigned long output_count;
9622 struct bgp_node *rn;
9623 int header1 = 1;
9624 struct bgp *bgp;
9625 int header2 = 1;
9626
paulbb46e942003-10-24 19:02:03 +00009627 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009628
9629 if (! bgp)
9630 return;
9631
9632 table = bgp->rib[afi][safi];
9633
9634 output_count = 0;
9635
9636 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9637 PEER_STATUS_DEFAULT_ORIGINATE))
9638 {
9639 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 +00009640 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9641 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009642
9643 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9644 VTY_NEWLINE, VTY_NEWLINE);
9645 header1 = 0;
9646 }
9647
9648 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9649 if (in)
9650 {
9651 for (ain = rn->adj_in; ain; ain = ain->next)
9652 if (ain->peer == peer)
9653 {
9654 if (header1)
9655 {
9656 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 +00009657 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9658 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009659 header1 = 0;
9660 }
9661 if (header2)
9662 {
9663 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9664 header2 = 0;
9665 }
9666 if (ain->attr)
9667 {
9668 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9669 output_count++;
9670 }
9671 }
9672 }
9673 else
9674 {
9675 for (adj = rn->adj_out; adj; adj = adj->next)
9676 if (adj->peer == peer)
9677 {
9678 if (header1)
9679 {
9680 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 +00009681 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9682 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009683 header1 = 0;
9684 }
9685 if (header2)
9686 {
9687 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9688 header2 = 0;
9689 }
9690 if (adj->attr)
9691 {
9692 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9693 output_count++;
9694 }
9695 }
9696 }
9697
9698 if (output_count != 0)
9699 vty_out (vty, "%sTotal number of prefixes %ld%s",
9700 VTY_NEWLINE, output_count, VTY_NEWLINE);
9701}
9702
paul94f2b392005-06-28 12:44:16 +00009703static int
paulbb46e942003-10-24 19:02:03 +00009704peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9705{
paul718e3742002-12-13 20:15:29 +00009706 if (! peer || ! peer->afc[afi][safi])
9707 {
9708 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9709 return CMD_WARNING;
9710 }
9711
9712 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9713 {
9714 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9715 VTY_NEWLINE);
9716 return CMD_WARNING;
9717 }
9718
9719 show_adj_route (vty, peer, afi, safi, in);
9720
9721 return CMD_SUCCESS;
9722}
9723
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009724DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9725 show_ip_bgp_view_neighbor_advertised_route_cmd,
9726 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9727 SHOW_STR
9728 IP_STR
9729 BGP_STR
9730 "BGP view\n"
9731 "View name\n"
9732 "Detailed information on TCP and BGP neighbor connections\n"
9733 "Neighbor to display information about\n"
9734 "Neighbor to display information about\n"
9735 "Display the routes advertised to a BGP neighbor\n")
9736{
9737 struct peer *peer;
9738
9739 if (argc == 2)
9740 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9741 else
9742 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9743
9744 if (! peer)
9745 return CMD_WARNING;
9746
9747 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9748}
9749
9750ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009751 show_ip_bgp_neighbor_advertised_route_cmd,
9752 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9753 SHOW_STR
9754 IP_STR
9755 BGP_STR
9756 "Detailed information on TCP and BGP neighbor connections\n"
9757 "Neighbor to display information about\n"
9758 "Neighbor to display information about\n"
9759 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009760
9761DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9762 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9763 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9764 SHOW_STR
9765 IP_STR
9766 BGP_STR
9767 "Address family\n"
9768 "Address Family modifier\n"
9769 "Address Family modifier\n"
9770 "Detailed information on TCP and BGP neighbor connections\n"
9771 "Neighbor to display information about\n"
9772 "Neighbor to display information about\n"
9773 "Display the routes advertised to a BGP neighbor\n")
9774{
paulbb46e942003-10-24 19:02:03 +00009775 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009776
paulbb46e942003-10-24 19:02:03 +00009777 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9778 if (! peer)
9779 return CMD_WARNING;
9780
9781 if (strncmp (argv[0], "m", 1) == 0)
9782 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9783
9784 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009785}
9786
9787#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009788DEFUN (show_bgp_view_neighbor_advertised_route,
9789 show_bgp_view_neighbor_advertised_route_cmd,
9790 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9791 SHOW_STR
9792 BGP_STR
9793 "BGP view\n"
9794 "View name\n"
9795 "Detailed information on TCP and BGP neighbor connections\n"
9796 "Neighbor to display information about\n"
9797 "Neighbor to display information about\n"
9798 "Display the routes advertised to a BGP neighbor\n")
9799{
9800 struct peer *peer;
9801
9802 if (argc == 2)
9803 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9804 else
9805 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9806
9807 if (! peer)
9808 return CMD_WARNING;
9809
9810 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9811}
9812
9813ALIAS (show_bgp_view_neighbor_advertised_route,
9814 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9815 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9816 SHOW_STR
9817 BGP_STR
9818 "BGP view\n"
9819 "View name\n"
9820 "Address family\n"
9821 "Detailed information on TCP and BGP neighbor connections\n"
9822 "Neighbor to display information about\n"
9823 "Neighbor to display information about\n"
9824 "Display the routes advertised to a BGP neighbor\n")
9825
9826DEFUN (show_bgp_view_neighbor_received_routes,
9827 show_bgp_view_neighbor_received_routes_cmd,
9828 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9829 SHOW_STR
9830 BGP_STR
9831 "BGP view\n"
9832 "View name\n"
9833 "Detailed information on TCP and BGP neighbor connections\n"
9834 "Neighbor to display information about\n"
9835 "Neighbor to display information about\n"
9836 "Display the received routes from neighbor\n")
9837{
9838 struct peer *peer;
9839
9840 if (argc == 2)
9841 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9842 else
9843 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9844
9845 if (! peer)
9846 return CMD_WARNING;
9847
9848 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9849}
9850
9851ALIAS (show_bgp_view_neighbor_received_routes,
9852 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9853 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9854 SHOW_STR
9855 BGP_STR
9856 "BGP view\n"
9857 "View name\n"
9858 "Address family\n"
9859 "Detailed information on TCP and BGP neighbor connections\n"
9860 "Neighbor to display information about\n"
9861 "Neighbor to display information about\n"
9862 "Display the received routes from neighbor\n")
9863
9864ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009865 show_bgp_neighbor_advertised_route_cmd,
9866 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9867 SHOW_STR
9868 BGP_STR
9869 "Detailed information on TCP and BGP neighbor connections\n"
9870 "Neighbor to display information about\n"
9871 "Neighbor to display information about\n"
9872 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009873
9874ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009875 show_bgp_ipv6_neighbor_advertised_route_cmd,
9876 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9877 SHOW_STR
9878 BGP_STR
9879 "Address family\n"
9880 "Detailed information on TCP and BGP neighbor connections\n"
9881 "Neighbor to display information about\n"
9882 "Neighbor to display information about\n"
9883 "Display the routes advertised to a BGP neighbor\n")
9884
9885/* old command */
paulbb46e942003-10-24 19:02:03 +00009886ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009887 ipv6_bgp_neighbor_advertised_route_cmd,
9888 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9889 SHOW_STR
9890 IPV6_STR
9891 BGP_STR
9892 "Detailed information on TCP and BGP neighbor connections\n"
9893 "Neighbor to display information about\n"
9894 "Neighbor to display information about\n"
9895 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009896
paul718e3742002-12-13 20:15:29 +00009897/* old command */
9898DEFUN (ipv6_mbgp_neighbor_advertised_route,
9899 ipv6_mbgp_neighbor_advertised_route_cmd,
9900 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9901 SHOW_STR
9902 IPV6_STR
9903 MBGP_STR
9904 "Detailed information on TCP and BGP neighbor connections\n"
9905 "Neighbor to display information about\n"
9906 "Neighbor to display information about\n"
9907 "Display the routes advertised to a BGP neighbor\n")
9908{
paulbb46e942003-10-24 19:02:03 +00009909 struct peer *peer;
9910
9911 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9912 if (! peer)
9913 return CMD_WARNING;
9914
9915 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009916}
9917#endif /* HAVE_IPV6 */
9918
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009919DEFUN (show_ip_bgp_view_neighbor_received_routes,
9920 show_ip_bgp_view_neighbor_received_routes_cmd,
9921 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9922 SHOW_STR
9923 IP_STR
9924 BGP_STR
9925 "BGP view\n"
9926 "View name\n"
9927 "Detailed information on TCP and BGP neighbor connections\n"
9928 "Neighbor to display information about\n"
9929 "Neighbor to display information about\n"
9930 "Display the received routes from neighbor\n")
9931{
9932 struct peer *peer;
9933
9934 if (argc == 2)
9935 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9936 else
9937 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9938
9939 if (! peer)
9940 return CMD_WARNING;
9941
9942 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9943}
9944
9945ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009946 show_ip_bgp_neighbor_received_routes_cmd,
9947 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9948 SHOW_STR
9949 IP_STR
9950 BGP_STR
9951 "Detailed information on TCP and BGP neighbor connections\n"
9952 "Neighbor to display information about\n"
9953 "Neighbor to display information about\n"
9954 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009955
9956DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9957 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9958 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9959 SHOW_STR
9960 IP_STR
9961 BGP_STR
9962 "Address family\n"
9963 "Address Family modifier\n"
9964 "Address Family modifier\n"
9965 "Detailed information on TCP and BGP neighbor connections\n"
9966 "Neighbor to display information about\n"
9967 "Neighbor to display information about\n"
9968 "Display the received routes from neighbor\n")
9969{
paulbb46e942003-10-24 19:02:03 +00009970 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009971
paulbb46e942003-10-24 19:02:03 +00009972 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9973 if (! peer)
9974 return CMD_WARNING;
9975
9976 if (strncmp (argv[0], "m", 1) == 0)
9977 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9978
9979 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009980}
9981
9982DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9983 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9984 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9985 SHOW_STR
9986 IP_STR
9987 BGP_STR
9988 "Detailed information on TCP and BGP neighbor connections\n"
9989 "Neighbor to display information about\n"
9990 "Neighbor to display information about\n"
9991 "Display information received from a BGP neighbor\n"
9992 "Display the prefixlist filter\n")
9993{
9994 char name[BUFSIZ];
9995 union sockunion *su;
9996 struct peer *peer;
9997 int count;
9998
9999 su = sockunion_str2su (argv[0]);
10000 if (su == NULL)
10001 return CMD_WARNING;
10002
10003 peer = peer_lookup (NULL, su);
10004 if (! peer)
10005 return CMD_WARNING;
10006
10007 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10008 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10009 if (count)
10010 {
10011 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10012 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10013 }
10014
10015 return CMD_SUCCESS;
10016}
10017
10018DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10019 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10020 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10021 SHOW_STR
10022 IP_STR
10023 BGP_STR
10024 "Address family\n"
10025 "Address Family modifier\n"
10026 "Address Family modifier\n"
10027 "Detailed information on TCP and BGP neighbor connections\n"
10028 "Neighbor to display information about\n"
10029 "Neighbor to display information about\n"
10030 "Display information received from a BGP neighbor\n"
10031 "Display the prefixlist filter\n")
10032{
10033 char name[BUFSIZ];
10034 union sockunion *su;
10035 struct peer *peer;
10036 int count;
10037
10038 su = sockunion_str2su (argv[1]);
10039 if (su == NULL)
10040 return CMD_WARNING;
10041
10042 peer = peer_lookup (NULL, su);
10043 if (! peer)
10044 return CMD_WARNING;
10045
10046 if (strncmp (argv[0], "m", 1) == 0)
10047 {
10048 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10049 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10050 if (count)
10051 {
10052 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10053 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10054 }
10055 }
10056 else
10057 {
10058 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10059 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10060 if (count)
10061 {
10062 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10063 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10064 }
10065 }
10066
10067 return CMD_SUCCESS;
10068}
10069
10070
10071#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010072ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010073 show_bgp_neighbor_received_routes_cmd,
10074 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10075 SHOW_STR
10076 BGP_STR
10077 "Detailed information on TCP and BGP neighbor connections\n"
10078 "Neighbor to display information about\n"
10079 "Neighbor to display information about\n"
10080 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010081
paulbb46e942003-10-24 19:02:03 +000010082ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010083 show_bgp_ipv6_neighbor_received_routes_cmd,
10084 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10085 SHOW_STR
10086 BGP_STR
10087 "Address family\n"
10088 "Detailed information on TCP and BGP neighbor connections\n"
10089 "Neighbor to display information about\n"
10090 "Neighbor to display information about\n"
10091 "Display the received routes from neighbor\n")
10092
10093DEFUN (show_bgp_neighbor_received_prefix_filter,
10094 show_bgp_neighbor_received_prefix_filter_cmd,
10095 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10096 SHOW_STR
10097 BGP_STR
10098 "Detailed information on TCP and BGP neighbor connections\n"
10099 "Neighbor to display information about\n"
10100 "Neighbor to display information about\n"
10101 "Display information received from a BGP neighbor\n"
10102 "Display the prefixlist filter\n")
10103{
10104 char name[BUFSIZ];
10105 union sockunion *su;
10106 struct peer *peer;
10107 int count;
10108
10109 su = sockunion_str2su (argv[0]);
10110 if (su == NULL)
10111 return CMD_WARNING;
10112
10113 peer = peer_lookup (NULL, su);
10114 if (! peer)
10115 return CMD_WARNING;
10116
10117 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10118 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10119 if (count)
10120 {
10121 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10122 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10123 }
10124
10125 return CMD_SUCCESS;
10126}
10127
10128ALIAS (show_bgp_neighbor_received_prefix_filter,
10129 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10130 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10131 SHOW_STR
10132 BGP_STR
10133 "Address family\n"
10134 "Detailed information on TCP and BGP neighbor connections\n"
10135 "Neighbor to display information about\n"
10136 "Neighbor to display information about\n"
10137 "Display information received from a BGP neighbor\n"
10138 "Display the prefixlist filter\n")
10139
10140/* old command */
paulbb46e942003-10-24 19:02:03 +000010141ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010142 ipv6_bgp_neighbor_received_routes_cmd,
10143 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10144 SHOW_STR
10145 IPV6_STR
10146 BGP_STR
10147 "Detailed information on TCP and BGP neighbor connections\n"
10148 "Neighbor to display information about\n"
10149 "Neighbor to display information about\n"
10150 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010151
10152/* old command */
10153DEFUN (ipv6_mbgp_neighbor_received_routes,
10154 ipv6_mbgp_neighbor_received_routes_cmd,
10155 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10156 SHOW_STR
10157 IPV6_STR
10158 MBGP_STR
10159 "Detailed information on TCP and BGP neighbor connections\n"
10160 "Neighbor to display information about\n"
10161 "Neighbor to display information about\n"
10162 "Display the received routes from neighbor\n")
10163{
paulbb46e942003-10-24 19:02:03 +000010164 struct peer *peer;
10165
10166 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10167 if (! peer)
10168 return CMD_WARNING;
10169
10170 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010171}
paulbb46e942003-10-24 19:02:03 +000010172
10173DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10174 show_bgp_view_neighbor_received_prefix_filter_cmd,
10175 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10176 SHOW_STR
10177 BGP_STR
10178 "BGP view\n"
10179 "View name\n"
10180 "Detailed information on TCP and BGP neighbor connections\n"
10181 "Neighbor to display information about\n"
10182 "Neighbor to display information about\n"
10183 "Display information received from a BGP neighbor\n"
10184 "Display the prefixlist filter\n")
10185{
10186 char name[BUFSIZ];
10187 union sockunion *su;
10188 struct peer *peer;
10189 struct bgp *bgp;
10190 int count;
10191
10192 /* BGP structure lookup. */
10193 bgp = bgp_lookup_by_name (argv[0]);
10194 if (bgp == NULL)
10195 {
10196 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10197 return CMD_WARNING;
10198 }
10199
10200 su = sockunion_str2su (argv[1]);
10201 if (su == NULL)
10202 return CMD_WARNING;
10203
10204 peer = peer_lookup (bgp, su);
10205 if (! peer)
10206 return CMD_WARNING;
10207
10208 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10209 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10210 if (count)
10211 {
10212 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10213 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10214 }
10215
10216 return CMD_SUCCESS;
10217}
10218
10219ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10220 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10221 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10222 SHOW_STR
10223 BGP_STR
10224 "BGP view\n"
10225 "View name\n"
10226 "Address family\n"
10227 "Detailed information on TCP and BGP neighbor connections\n"
10228 "Neighbor to display information about\n"
10229 "Neighbor to display information about\n"
10230 "Display information received from a BGP neighbor\n"
10231 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010232#endif /* HAVE_IPV6 */
10233
paul94f2b392005-06-28 12:44:16 +000010234static int
paulbb46e942003-10-24 19:02:03 +000010235bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010236 safi_t safi, enum bgp_show_type type)
10237{
paul718e3742002-12-13 20:15:29 +000010238 if (! peer || ! peer->afc[afi][safi])
10239 {
10240 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010241 return CMD_WARNING;
10242 }
10243
ajs5a646652004-11-05 01:25:55 +000010244 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010245}
10246
10247DEFUN (show_ip_bgp_neighbor_routes,
10248 show_ip_bgp_neighbor_routes_cmd,
10249 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10250 SHOW_STR
10251 IP_STR
10252 BGP_STR
10253 "Detailed information on TCP and BGP neighbor connections\n"
10254 "Neighbor to display information about\n"
10255 "Neighbor to display information about\n"
10256 "Display routes learned from neighbor\n")
10257{
paulbb46e942003-10-24 19:02:03 +000010258 struct peer *peer;
10259
10260 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10261 if (! peer)
10262 return CMD_WARNING;
10263
10264 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010265 bgp_show_type_neighbor);
10266}
10267
10268DEFUN (show_ip_bgp_neighbor_flap,
10269 show_ip_bgp_neighbor_flap_cmd,
10270 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10271 SHOW_STR
10272 IP_STR
10273 BGP_STR
10274 "Detailed information on TCP and BGP neighbor connections\n"
10275 "Neighbor to display information about\n"
10276 "Neighbor to display information about\n"
10277 "Display flap statistics of the routes learned from neighbor\n")
10278{
paulbb46e942003-10-24 19:02:03 +000010279 struct peer *peer;
10280
10281 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10282 if (! peer)
10283 return CMD_WARNING;
10284
10285 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010286 bgp_show_type_flap_neighbor);
10287}
10288
10289DEFUN (show_ip_bgp_neighbor_damp,
10290 show_ip_bgp_neighbor_damp_cmd,
10291 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10292 SHOW_STR
10293 IP_STR
10294 BGP_STR
10295 "Detailed information on TCP and BGP neighbor connections\n"
10296 "Neighbor to display information about\n"
10297 "Neighbor to display information about\n"
10298 "Display the dampened routes received from neighbor\n")
10299{
paulbb46e942003-10-24 19:02:03 +000010300 struct peer *peer;
10301
10302 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10303 if (! peer)
10304 return CMD_WARNING;
10305
10306 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010307 bgp_show_type_damp_neighbor);
10308}
10309
10310DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10311 show_ip_bgp_ipv4_neighbor_routes_cmd,
10312 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10313 SHOW_STR
10314 IP_STR
10315 BGP_STR
10316 "Address family\n"
10317 "Address Family modifier\n"
10318 "Address Family modifier\n"
10319 "Detailed information on TCP and BGP neighbor connections\n"
10320 "Neighbor to display information about\n"
10321 "Neighbor to display information about\n"
10322 "Display routes learned from neighbor\n")
10323{
paulbb46e942003-10-24 19:02:03 +000010324 struct peer *peer;
10325
10326 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10327 if (! peer)
10328 return CMD_WARNING;
10329
paul718e3742002-12-13 20:15:29 +000010330 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010331 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010332 bgp_show_type_neighbor);
10333
paulbb46e942003-10-24 19:02:03 +000010334 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010335 bgp_show_type_neighbor);
10336}
paulbb46e942003-10-24 19:02:03 +000010337
paulfee0f4c2004-09-13 05:12:46 +000010338DEFUN (show_ip_bgp_view_rsclient,
10339 show_ip_bgp_view_rsclient_cmd,
10340 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10341 SHOW_STR
10342 IP_STR
10343 BGP_STR
10344 "BGP view\n"
10345 "BGP view name\n"
10346 "Information about Route Server Client\n"
10347 NEIGHBOR_ADDR_STR)
10348{
10349 struct bgp_table *table;
10350 struct peer *peer;
10351
10352 if (argc == 2)
10353 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10354 else
10355 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10356
10357 if (! peer)
10358 return CMD_WARNING;
10359
10360 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10361 {
10362 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10363 VTY_NEWLINE);
10364 return CMD_WARNING;
10365 }
10366
10367 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10368 PEER_FLAG_RSERVER_CLIENT))
10369 {
10370 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10371 VTY_NEWLINE);
10372 return CMD_WARNING;
10373 }
10374
10375 table = peer->rib[AFI_IP][SAFI_UNICAST];
10376
ajs5a646652004-11-05 01:25:55 +000010377 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010378}
10379
10380ALIAS (show_ip_bgp_view_rsclient,
10381 show_ip_bgp_rsclient_cmd,
10382 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10383 SHOW_STR
10384 IP_STR
10385 BGP_STR
10386 "Information about Route Server Client\n"
10387 NEIGHBOR_ADDR_STR)
10388
10389DEFUN (show_ip_bgp_view_rsclient_route,
10390 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010391 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010392 SHOW_STR
10393 IP_STR
10394 BGP_STR
10395 "BGP view\n"
10396 "BGP view name\n"
10397 "Information about Route Server Client\n"
10398 NEIGHBOR_ADDR_STR
10399 "Network in the BGP routing table to display\n")
10400{
10401 struct bgp *bgp;
10402 struct peer *peer;
10403
10404 /* BGP structure lookup. */
10405 if (argc == 3)
10406 {
10407 bgp = bgp_lookup_by_name (argv[0]);
10408 if (bgp == NULL)
10409 {
10410 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10411 return CMD_WARNING;
10412 }
10413 }
10414 else
10415 {
10416 bgp = bgp_get_default ();
10417 if (bgp == NULL)
10418 {
10419 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10420 return CMD_WARNING;
10421 }
10422 }
10423
10424 if (argc == 3)
10425 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10426 else
10427 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10428
10429 if (! peer)
10430 return CMD_WARNING;
10431
10432 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10433 {
10434 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10435 VTY_NEWLINE);
10436 return CMD_WARNING;
10437}
10438
10439 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10440 PEER_FLAG_RSERVER_CLIENT))
10441 {
10442 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10443 VTY_NEWLINE);
10444 return CMD_WARNING;
10445 }
10446
10447 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10448 (argc == 3) ? argv[2] : argv[1],
10449 AFI_IP, SAFI_UNICAST, NULL, 0);
10450}
10451
10452ALIAS (show_ip_bgp_view_rsclient_route,
10453 show_ip_bgp_rsclient_route_cmd,
10454 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10455 SHOW_STR
10456 IP_STR
10457 BGP_STR
10458 "Information about Route Server Client\n"
10459 NEIGHBOR_ADDR_STR
10460 "Network in the BGP routing table to display\n")
10461
10462DEFUN (show_ip_bgp_view_rsclient_prefix,
10463 show_ip_bgp_view_rsclient_prefix_cmd,
10464 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10465 SHOW_STR
10466 IP_STR
10467 BGP_STR
10468 "BGP view\n"
10469 "BGP view name\n"
10470 "Information about Route Server Client\n"
10471 NEIGHBOR_ADDR_STR
10472 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10473{
10474 struct bgp *bgp;
10475 struct peer *peer;
10476
10477 /* BGP structure lookup. */
10478 if (argc == 3)
10479 {
10480 bgp = bgp_lookup_by_name (argv[0]);
10481 if (bgp == NULL)
10482 {
10483 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10484 return CMD_WARNING;
10485 }
10486 }
10487 else
10488 {
10489 bgp = bgp_get_default ();
10490 if (bgp == NULL)
10491 {
10492 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10493 return CMD_WARNING;
10494 }
10495 }
10496
10497 if (argc == 3)
10498 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10499 else
10500 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10501
10502 if (! peer)
10503 return CMD_WARNING;
10504
10505 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10506 {
10507 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10508 VTY_NEWLINE);
10509 return CMD_WARNING;
10510}
10511
10512 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10513 PEER_FLAG_RSERVER_CLIENT))
10514{
10515 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10516 VTY_NEWLINE);
10517 return CMD_WARNING;
10518 }
10519
10520 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10521 (argc == 3) ? argv[2] : argv[1],
10522 AFI_IP, SAFI_UNICAST, NULL, 1);
10523}
10524
10525ALIAS (show_ip_bgp_view_rsclient_prefix,
10526 show_ip_bgp_rsclient_prefix_cmd,
10527 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10528 SHOW_STR
10529 IP_STR
10530 BGP_STR
10531 "Information about Route Server Client\n"
10532 NEIGHBOR_ADDR_STR
10533 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10534
10535
paul718e3742002-12-13 20:15:29 +000010536#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010537DEFUN (show_bgp_view_neighbor_routes,
10538 show_bgp_view_neighbor_routes_cmd,
10539 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10540 SHOW_STR
10541 BGP_STR
10542 "BGP view\n"
10543 "BGP view name\n"
10544 "Detailed information on TCP and BGP neighbor connections\n"
10545 "Neighbor to display information about\n"
10546 "Neighbor to display information about\n"
10547 "Display routes learned from neighbor\n")
10548{
10549 struct peer *peer;
10550
10551 if (argc == 2)
10552 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10553 else
10554 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10555
10556 if (! peer)
10557 return CMD_WARNING;
10558
10559 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10560 bgp_show_type_neighbor);
10561}
10562
10563ALIAS (show_bgp_view_neighbor_routes,
10564 show_bgp_view_ipv6_neighbor_routes_cmd,
10565 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10566 SHOW_STR
10567 BGP_STR
10568 "BGP view\n"
10569 "BGP view name\n"
10570 "Address family\n"
10571 "Detailed information on TCP and BGP neighbor connections\n"
10572 "Neighbor to display information about\n"
10573 "Neighbor to display information about\n"
10574 "Display routes learned from neighbor\n")
10575
10576DEFUN (show_bgp_view_neighbor_damp,
10577 show_bgp_view_neighbor_damp_cmd,
10578 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10579 SHOW_STR
10580 BGP_STR
10581 "BGP view\n"
10582 "BGP view name\n"
10583 "Detailed information on TCP and BGP neighbor connections\n"
10584 "Neighbor to display information about\n"
10585 "Neighbor to display information about\n"
10586 "Display the dampened routes received from neighbor\n")
10587{
10588 struct peer *peer;
10589
10590 if (argc == 2)
10591 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10592 else
10593 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10594
10595 if (! peer)
10596 return CMD_WARNING;
10597
10598 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10599 bgp_show_type_damp_neighbor);
10600}
10601
10602ALIAS (show_bgp_view_neighbor_damp,
10603 show_bgp_view_ipv6_neighbor_damp_cmd,
10604 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10605 SHOW_STR
10606 BGP_STR
10607 "BGP view\n"
10608 "BGP view name\n"
10609 "Address family\n"
10610 "Detailed information on TCP and BGP neighbor connections\n"
10611 "Neighbor to display information about\n"
10612 "Neighbor to display information about\n"
10613 "Display the dampened routes received from neighbor\n")
10614
10615DEFUN (show_bgp_view_neighbor_flap,
10616 show_bgp_view_neighbor_flap_cmd,
10617 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10618 SHOW_STR
10619 BGP_STR
10620 "BGP view\n"
10621 "BGP view name\n"
10622 "Detailed information on TCP and BGP neighbor connections\n"
10623 "Neighbor to display information about\n"
10624 "Neighbor to display information about\n"
10625 "Display flap statistics of the routes learned from neighbor\n")
10626{
10627 struct peer *peer;
10628
10629 if (argc == 2)
10630 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10631 else
10632 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10633
10634 if (! peer)
10635 return CMD_WARNING;
10636
10637 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10638 bgp_show_type_flap_neighbor);
10639}
10640
10641ALIAS (show_bgp_view_neighbor_flap,
10642 show_bgp_view_ipv6_neighbor_flap_cmd,
10643 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10644 SHOW_STR
10645 BGP_STR
10646 "BGP view\n"
10647 "BGP view name\n"
10648 "Address family\n"
10649 "Detailed information on TCP and BGP neighbor connections\n"
10650 "Neighbor to display information about\n"
10651 "Neighbor to display information about\n"
10652 "Display flap statistics of the routes learned from neighbor\n")
10653
10654ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010655 show_bgp_neighbor_routes_cmd,
10656 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10657 SHOW_STR
10658 BGP_STR
10659 "Detailed information on TCP and BGP neighbor connections\n"
10660 "Neighbor to display information about\n"
10661 "Neighbor to display information about\n"
10662 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010663
paulbb46e942003-10-24 19:02:03 +000010664
10665ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010666 show_bgp_ipv6_neighbor_routes_cmd,
10667 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10668 SHOW_STR
10669 BGP_STR
10670 "Address family\n"
10671 "Detailed information on TCP and BGP neighbor connections\n"
10672 "Neighbor to display information about\n"
10673 "Neighbor to display information about\n"
10674 "Display routes learned from neighbor\n")
10675
10676/* old command */
paulbb46e942003-10-24 19:02:03 +000010677ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010678 ipv6_bgp_neighbor_routes_cmd,
10679 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10680 SHOW_STR
10681 IPV6_STR
10682 BGP_STR
10683 "Detailed information on TCP and BGP neighbor connections\n"
10684 "Neighbor to display information about\n"
10685 "Neighbor to display information about\n"
10686 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010687
10688/* old command */
10689DEFUN (ipv6_mbgp_neighbor_routes,
10690 ipv6_mbgp_neighbor_routes_cmd,
10691 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10692 SHOW_STR
10693 IPV6_STR
10694 MBGP_STR
10695 "Detailed information on TCP and BGP neighbor connections\n"
10696 "Neighbor to display information about\n"
10697 "Neighbor to display information about\n"
10698 "Display routes learned from neighbor\n")
10699{
paulbb46e942003-10-24 19:02:03 +000010700 struct peer *peer;
10701
10702 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10703 if (! peer)
10704 return CMD_WARNING;
10705
10706 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010707 bgp_show_type_neighbor);
10708}
paulbb46e942003-10-24 19:02:03 +000010709
10710ALIAS (show_bgp_view_neighbor_flap,
10711 show_bgp_neighbor_flap_cmd,
10712 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10713 SHOW_STR
10714 BGP_STR
10715 "Detailed information on TCP and BGP neighbor connections\n"
10716 "Neighbor to display information about\n"
10717 "Neighbor to display information about\n"
10718 "Display flap statistics of the routes learned from neighbor\n")
10719
10720ALIAS (show_bgp_view_neighbor_flap,
10721 show_bgp_ipv6_neighbor_flap_cmd,
10722 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10723 SHOW_STR
10724 BGP_STR
10725 "Address family\n"
10726 "Detailed information on TCP and BGP neighbor connections\n"
10727 "Neighbor to display information about\n"
10728 "Neighbor to display information about\n"
10729 "Display flap statistics of the routes learned from neighbor\n")
10730
10731ALIAS (show_bgp_view_neighbor_damp,
10732 show_bgp_neighbor_damp_cmd,
10733 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10734 SHOW_STR
10735 BGP_STR
10736 "Detailed information on TCP and BGP neighbor connections\n"
10737 "Neighbor to display information about\n"
10738 "Neighbor to display information about\n"
10739 "Display the dampened routes received from neighbor\n")
10740
10741ALIAS (show_bgp_view_neighbor_damp,
10742 show_bgp_ipv6_neighbor_damp_cmd,
10743 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10744 SHOW_STR
10745 BGP_STR
10746 "Address family\n"
10747 "Detailed information on TCP and BGP neighbor connections\n"
10748 "Neighbor to display information about\n"
10749 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010750 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010751
10752DEFUN (show_bgp_view_rsclient,
10753 show_bgp_view_rsclient_cmd,
10754 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10755 SHOW_STR
10756 BGP_STR
10757 "BGP view\n"
10758 "BGP view name\n"
10759 "Information about Route Server Client\n"
10760 NEIGHBOR_ADDR_STR)
10761{
10762 struct bgp_table *table;
10763 struct peer *peer;
10764
10765 if (argc == 2)
10766 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10767 else
10768 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10769
10770 if (! peer)
10771 return CMD_WARNING;
10772
10773 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10774 {
10775 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10776 VTY_NEWLINE);
10777 return CMD_WARNING;
10778 }
10779
10780 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10781 PEER_FLAG_RSERVER_CLIENT))
10782 {
10783 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10784 VTY_NEWLINE);
10785 return CMD_WARNING;
10786 }
10787
10788 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10789
ajs5a646652004-11-05 01:25:55 +000010790 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010791}
10792
10793ALIAS (show_bgp_view_rsclient,
10794 show_bgp_rsclient_cmd,
10795 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10796 SHOW_STR
10797 BGP_STR
10798 "Information about Route Server Client\n"
10799 NEIGHBOR_ADDR_STR)
10800
10801DEFUN (show_bgp_view_rsclient_route,
10802 show_bgp_view_rsclient_route_cmd,
10803 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10804 SHOW_STR
10805 BGP_STR
10806 "BGP view\n"
10807 "BGP view name\n"
10808 "Information about Route Server Client\n"
10809 NEIGHBOR_ADDR_STR
10810 "Network in the BGP routing table to display\n")
10811{
10812 struct bgp *bgp;
10813 struct peer *peer;
10814
10815 /* BGP structure lookup. */
10816 if (argc == 3)
10817 {
10818 bgp = bgp_lookup_by_name (argv[0]);
10819 if (bgp == NULL)
10820 {
10821 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10822 return CMD_WARNING;
10823 }
10824 }
10825 else
10826 {
10827 bgp = bgp_get_default ();
10828 if (bgp == NULL)
10829 {
10830 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10831 return CMD_WARNING;
10832 }
10833 }
10834
10835 if (argc == 3)
10836 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10837 else
10838 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10839
10840 if (! peer)
10841 return CMD_WARNING;
10842
10843 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10844 {
10845 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10846 VTY_NEWLINE);
10847 return CMD_WARNING;
10848 }
10849
10850 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10851 PEER_FLAG_RSERVER_CLIENT))
10852 {
10853 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10854 VTY_NEWLINE);
10855 return CMD_WARNING;
10856 }
10857
10858 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10859 (argc == 3) ? argv[2] : argv[1],
10860 AFI_IP6, SAFI_UNICAST, NULL, 0);
10861}
10862
10863ALIAS (show_bgp_view_rsclient_route,
10864 show_bgp_rsclient_route_cmd,
10865 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10866 SHOW_STR
10867 BGP_STR
10868 "Information about Route Server Client\n"
10869 NEIGHBOR_ADDR_STR
10870 "Network in the BGP routing table to display\n")
10871
10872DEFUN (show_bgp_view_rsclient_prefix,
10873 show_bgp_view_rsclient_prefix_cmd,
10874 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10875 SHOW_STR
10876 BGP_STR
10877 "BGP view\n"
10878 "BGP view name\n"
10879 "Information about Route Server Client\n"
10880 NEIGHBOR_ADDR_STR
10881 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10882{
10883 struct bgp *bgp;
10884 struct peer *peer;
10885
10886 /* BGP structure lookup. */
10887 if (argc == 3)
10888 {
10889 bgp = bgp_lookup_by_name (argv[0]);
10890 if (bgp == NULL)
10891 {
10892 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10893 return CMD_WARNING;
10894 }
10895 }
10896 else
10897 {
10898 bgp = bgp_get_default ();
10899 if (bgp == NULL)
10900 {
10901 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10902 return CMD_WARNING;
10903 }
10904 }
10905
10906 if (argc == 3)
10907 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10908 else
10909 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10910
10911 if (! peer)
10912 return CMD_WARNING;
10913
10914 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10915 {
10916 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10917 VTY_NEWLINE);
10918 return CMD_WARNING;
10919 }
10920
10921 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10922 PEER_FLAG_RSERVER_CLIENT))
10923 {
10924 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10925 VTY_NEWLINE);
10926 return CMD_WARNING;
10927 }
10928
10929 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10930 (argc == 3) ? argv[2] : argv[1],
10931 AFI_IP6, SAFI_UNICAST, NULL, 1);
10932}
10933
10934ALIAS (show_bgp_view_rsclient_prefix,
10935 show_bgp_rsclient_prefix_cmd,
10936 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10937 SHOW_STR
10938 BGP_STR
10939 "Information about Route Server Client\n"
10940 NEIGHBOR_ADDR_STR
10941 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10942
paul718e3742002-12-13 20:15:29 +000010943#endif /* HAVE_IPV6 */
10944
10945struct bgp_table *bgp_distance_table;
10946
10947struct bgp_distance
10948{
10949 /* Distance value for the IP source prefix. */
10950 u_char distance;
10951
10952 /* Name of the access-list to be matched. */
10953 char *access_list;
10954};
10955
paul94f2b392005-06-28 12:44:16 +000010956static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010957bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010958{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010959 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010960}
10961
paul94f2b392005-06-28 12:44:16 +000010962static void
paul718e3742002-12-13 20:15:29 +000010963bgp_distance_free (struct bgp_distance *bdistance)
10964{
10965 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10966}
10967
paul94f2b392005-06-28 12:44:16 +000010968static int
paulfd79ac92004-10-13 05:06:08 +000010969bgp_distance_set (struct vty *vty, const char *distance_str,
10970 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010971{
10972 int ret;
10973 struct prefix_ipv4 p;
10974 u_char distance;
10975 struct bgp_node *rn;
10976 struct bgp_distance *bdistance;
10977
10978 ret = str2prefix_ipv4 (ip_str, &p);
10979 if (ret == 0)
10980 {
10981 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10982 return CMD_WARNING;
10983 }
10984
10985 distance = atoi (distance_str);
10986
10987 /* Get BGP distance node. */
10988 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10989 if (rn->info)
10990 {
10991 bdistance = rn->info;
10992 bgp_unlock_node (rn);
10993 }
10994 else
10995 {
10996 bdistance = bgp_distance_new ();
10997 rn->info = bdistance;
10998 }
10999
11000 /* Set distance value. */
11001 bdistance->distance = distance;
11002
11003 /* Reset access-list configuration. */
11004 if (bdistance->access_list)
11005 {
11006 free (bdistance->access_list);
11007 bdistance->access_list = NULL;
11008 }
11009 if (access_list_str)
11010 bdistance->access_list = strdup (access_list_str);
11011
11012 return CMD_SUCCESS;
11013}
11014
paul94f2b392005-06-28 12:44:16 +000011015static int
paulfd79ac92004-10-13 05:06:08 +000011016bgp_distance_unset (struct vty *vty, const char *distance_str,
11017 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011018{
11019 int ret;
11020 struct prefix_ipv4 p;
11021 u_char distance;
11022 struct bgp_node *rn;
11023 struct bgp_distance *bdistance;
11024
11025 ret = str2prefix_ipv4 (ip_str, &p);
11026 if (ret == 0)
11027 {
11028 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11029 return CMD_WARNING;
11030 }
11031
11032 distance = atoi (distance_str);
11033
11034 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11035 if (! rn)
11036 {
11037 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11038 return CMD_WARNING;
11039 }
11040
11041 bdistance = rn->info;
11042
11043 if (bdistance->access_list)
11044 free (bdistance->access_list);
11045 bgp_distance_free (bdistance);
11046
11047 rn->info = NULL;
11048 bgp_unlock_node (rn);
11049 bgp_unlock_node (rn);
11050
11051 return CMD_SUCCESS;
11052}
11053
paul718e3742002-12-13 20:15:29 +000011054/* Apply BGP information to distance method. */
11055u_char
11056bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11057{
11058 struct bgp_node *rn;
11059 struct prefix_ipv4 q;
11060 struct peer *peer;
11061 struct bgp_distance *bdistance;
11062 struct access_list *alist;
11063 struct bgp_static *bgp_static;
11064
11065 if (! bgp)
11066 return 0;
11067
11068 if (p->family != AF_INET)
11069 return 0;
11070
11071 peer = rinfo->peer;
11072
11073 if (peer->su.sa.sa_family != AF_INET)
11074 return 0;
11075
11076 memset (&q, 0, sizeof (struct prefix_ipv4));
11077 q.family = AF_INET;
11078 q.prefix = peer->su.sin.sin_addr;
11079 q.prefixlen = IPV4_MAX_BITLEN;
11080
11081 /* Check source address. */
11082 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11083 if (rn)
11084 {
11085 bdistance = rn->info;
11086 bgp_unlock_node (rn);
11087
11088 if (bdistance->access_list)
11089 {
11090 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11091 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11092 return bdistance->distance;
11093 }
11094 else
11095 return bdistance->distance;
11096 }
11097
11098 /* Backdoor check. */
11099 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11100 if (rn)
11101 {
11102 bgp_static = rn->info;
11103 bgp_unlock_node (rn);
11104
11105 if (bgp_static->backdoor)
11106 {
11107 if (bgp->distance_local)
11108 return bgp->distance_local;
11109 else
11110 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11111 }
11112 }
11113
11114 if (peer_sort (peer) == BGP_PEER_EBGP)
11115 {
11116 if (bgp->distance_ebgp)
11117 return bgp->distance_ebgp;
11118 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11119 }
11120 else
11121 {
11122 if (bgp->distance_ibgp)
11123 return bgp->distance_ibgp;
11124 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11125 }
11126}
11127
11128DEFUN (bgp_distance,
11129 bgp_distance_cmd,
11130 "distance bgp <1-255> <1-255> <1-255>",
11131 "Define an administrative distance\n"
11132 "BGP distance\n"
11133 "Distance for routes external to the AS\n"
11134 "Distance for routes internal to the AS\n"
11135 "Distance for local routes\n")
11136{
11137 struct bgp *bgp;
11138
11139 bgp = vty->index;
11140
11141 bgp->distance_ebgp = atoi (argv[0]);
11142 bgp->distance_ibgp = atoi (argv[1]);
11143 bgp->distance_local = atoi (argv[2]);
11144 return CMD_SUCCESS;
11145}
11146
11147DEFUN (no_bgp_distance,
11148 no_bgp_distance_cmd,
11149 "no distance bgp <1-255> <1-255> <1-255>",
11150 NO_STR
11151 "Define an administrative distance\n"
11152 "BGP distance\n"
11153 "Distance for routes external to the AS\n"
11154 "Distance for routes internal to the AS\n"
11155 "Distance for local routes\n")
11156{
11157 struct bgp *bgp;
11158
11159 bgp = vty->index;
11160
11161 bgp->distance_ebgp= 0;
11162 bgp->distance_ibgp = 0;
11163 bgp->distance_local = 0;
11164 return CMD_SUCCESS;
11165}
11166
11167ALIAS (no_bgp_distance,
11168 no_bgp_distance2_cmd,
11169 "no distance bgp",
11170 NO_STR
11171 "Define an administrative distance\n"
11172 "BGP distance\n")
11173
11174DEFUN (bgp_distance_source,
11175 bgp_distance_source_cmd,
11176 "distance <1-255> A.B.C.D/M",
11177 "Define an administrative distance\n"
11178 "Administrative distance\n"
11179 "IP source prefix\n")
11180{
11181 bgp_distance_set (vty, argv[0], argv[1], NULL);
11182 return CMD_SUCCESS;
11183}
11184
11185DEFUN (no_bgp_distance_source,
11186 no_bgp_distance_source_cmd,
11187 "no distance <1-255> A.B.C.D/M",
11188 NO_STR
11189 "Define an administrative distance\n"
11190 "Administrative distance\n"
11191 "IP source prefix\n")
11192{
11193 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11194 return CMD_SUCCESS;
11195}
11196
11197DEFUN (bgp_distance_source_access_list,
11198 bgp_distance_source_access_list_cmd,
11199 "distance <1-255> A.B.C.D/M WORD",
11200 "Define an administrative distance\n"
11201 "Administrative distance\n"
11202 "IP source prefix\n"
11203 "Access list name\n")
11204{
11205 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11206 return CMD_SUCCESS;
11207}
11208
11209DEFUN (no_bgp_distance_source_access_list,
11210 no_bgp_distance_source_access_list_cmd,
11211 "no distance <1-255> A.B.C.D/M WORD",
11212 NO_STR
11213 "Define an administrative distance\n"
11214 "Administrative distance\n"
11215 "IP source prefix\n"
11216 "Access list name\n")
11217{
11218 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11219 return CMD_SUCCESS;
11220}
11221
11222DEFUN (bgp_damp_set,
11223 bgp_damp_set_cmd,
11224 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11225 "BGP Specific commands\n"
11226 "Enable route-flap dampening\n"
11227 "Half-life time for the penalty\n"
11228 "Value to start reusing a route\n"
11229 "Value to start suppressing a route\n"
11230 "Maximum duration to suppress a stable route\n")
11231{
11232 struct bgp *bgp;
11233 int half = DEFAULT_HALF_LIFE * 60;
11234 int reuse = DEFAULT_REUSE;
11235 int suppress = DEFAULT_SUPPRESS;
11236 int max = 4 * half;
11237
11238 if (argc == 4)
11239 {
11240 half = atoi (argv[0]) * 60;
11241 reuse = atoi (argv[1]);
11242 suppress = atoi (argv[2]);
11243 max = atoi (argv[3]) * 60;
11244 }
11245 else if (argc == 1)
11246 {
11247 half = atoi (argv[0]) * 60;
11248 max = 4 * half;
11249 }
11250
11251 bgp = vty->index;
11252 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11253 half, reuse, suppress, max);
11254}
11255
11256ALIAS (bgp_damp_set,
11257 bgp_damp_set2_cmd,
11258 "bgp dampening <1-45>",
11259 "BGP Specific commands\n"
11260 "Enable route-flap dampening\n"
11261 "Half-life time for the penalty\n")
11262
11263ALIAS (bgp_damp_set,
11264 bgp_damp_set3_cmd,
11265 "bgp dampening",
11266 "BGP Specific commands\n"
11267 "Enable route-flap dampening\n")
11268
11269DEFUN (bgp_damp_unset,
11270 bgp_damp_unset_cmd,
11271 "no bgp dampening",
11272 NO_STR
11273 "BGP Specific commands\n"
11274 "Enable route-flap dampening\n")
11275{
11276 struct bgp *bgp;
11277
11278 bgp = vty->index;
11279 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11280}
11281
11282ALIAS (bgp_damp_unset,
11283 bgp_damp_unset2_cmd,
11284 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11285 NO_STR
11286 "BGP Specific commands\n"
11287 "Enable route-flap dampening\n"
11288 "Half-life time for the penalty\n"
11289 "Value to start reusing a route\n"
11290 "Value to start suppressing a route\n"
11291 "Maximum duration to suppress a stable route\n")
11292
11293DEFUN (show_ip_bgp_dampened_paths,
11294 show_ip_bgp_dampened_paths_cmd,
11295 "show ip bgp dampened-paths",
11296 SHOW_STR
11297 IP_STR
11298 BGP_STR
11299 "Display paths suppressed due to dampening\n")
11300{
ajs5a646652004-11-05 01:25:55 +000011301 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11302 NULL);
paul718e3742002-12-13 20:15:29 +000011303}
11304
11305DEFUN (show_ip_bgp_flap_statistics,
11306 show_ip_bgp_flap_statistics_cmd,
11307 "show ip bgp flap-statistics",
11308 SHOW_STR
11309 IP_STR
11310 BGP_STR
11311 "Display flap statistics of routes\n")
11312{
ajs5a646652004-11-05 01:25:55 +000011313 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11314 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011315}
11316
11317/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011318static int
paulfd79ac92004-10-13 05:06:08 +000011319bgp_clear_damp_route (struct vty *vty, const char *view_name,
11320 const char *ip_str, afi_t afi, safi_t safi,
11321 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011322{
11323 int ret;
11324 struct prefix match;
11325 struct bgp_node *rn;
11326 struct bgp_node *rm;
11327 struct bgp_info *ri;
11328 struct bgp_info *ri_temp;
11329 struct bgp *bgp;
11330 struct bgp_table *table;
11331
11332 /* BGP structure lookup. */
11333 if (view_name)
11334 {
11335 bgp = bgp_lookup_by_name (view_name);
11336 if (bgp == NULL)
11337 {
11338 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11339 return CMD_WARNING;
11340 }
11341 }
11342 else
11343 {
11344 bgp = bgp_get_default ();
11345 if (bgp == NULL)
11346 {
11347 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11348 return CMD_WARNING;
11349 }
11350 }
11351
11352 /* Check IP address argument. */
11353 ret = str2prefix (ip_str, &match);
11354 if (! ret)
11355 {
11356 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11357 return CMD_WARNING;
11358 }
11359
11360 match.family = afi2family (afi);
11361
11362 if (safi == SAFI_MPLS_VPN)
11363 {
11364 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11365 {
11366 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11367 continue;
11368
11369 if ((table = rn->info) != NULL)
11370 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011371 {
11372 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11373 {
11374 ri = rm->info;
11375 while (ri)
11376 {
11377 if (ri->extra && ri->extra->damp_info)
11378 {
11379 ri_temp = ri->next;
11380 bgp_damp_info_free (ri->extra->damp_info, 1);
11381 ri = ri_temp;
11382 }
11383 else
11384 ri = ri->next;
11385 }
11386 }
11387
11388 bgp_unlock_node (rm);
11389 }
paul718e3742002-12-13 20:15:29 +000011390 }
11391 }
11392 else
11393 {
11394 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011395 {
11396 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11397 {
11398 ri = rn->info;
11399 while (ri)
11400 {
11401 if (ri->extra && ri->extra->damp_info)
11402 {
11403 ri_temp = ri->next;
11404 bgp_damp_info_free (ri->extra->damp_info, 1);
11405 ri = ri_temp;
11406 }
11407 else
11408 ri = ri->next;
11409 }
11410 }
11411
11412 bgp_unlock_node (rn);
11413 }
paul718e3742002-12-13 20:15:29 +000011414 }
11415
11416 return CMD_SUCCESS;
11417}
11418
11419DEFUN (clear_ip_bgp_dampening,
11420 clear_ip_bgp_dampening_cmd,
11421 "clear ip bgp dampening",
11422 CLEAR_STR
11423 IP_STR
11424 BGP_STR
11425 "Clear route flap dampening information\n")
11426{
11427 bgp_damp_info_clean ();
11428 return CMD_SUCCESS;
11429}
11430
11431DEFUN (clear_ip_bgp_dampening_prefix,
11432 clear_ip_bgp_dampening_prefix_cmd,
11433 "clear ip bgp dampening A.B.C.D/M",
11434 CLEAR_STR
11435 IP_STR
11436 BGP_STR
11437 "Clear route flap dampening information\n"
11438 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11439{
11440 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11441 SAFI_UNICAST, NULL, 1);
11442}
11443
11444DEFUN (clear_ip_bgp_dampening_address,
11445 clear_ip_bgp_dampening_address_cmd,
11446 "clear ip bgp dampening A.B.C.D",
11447 CLEAR_STR
11448 IP_STR
11449 BGP_STR
11450 "Clear route flap dampening information\n"
11451 "Network to clear damping information\n")
11452{
11453 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11454 SAFI_UNICAST, NULL, 0);
11455}
11456
11457DEFUN (clear_ip_bgp_dampening_address_mask,
11458 clear_ip_bgp_dampening_address_mask_cmd,
11459 "clear ip bgp dampening A.B.C.D A.B.C.D",
11460 CLEAR_STR
11461 IP_STR
11462 BGP_STR
11463 "Clear route flap dampening information\n"
11464 "Network to clear damping information\n"
11465 "Network mask\n")
11466{
11467 int ret;
11468 char prefix_str[BUFSIZ];
11469
11470 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11471 if (! ret)
11472 {
11473 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11474 return CMD_WARNING;
11475 }
11476
11477 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11478 SAFI_UNICAST, NULL, 0);
11479}
11480
paul94f2b392005-06-28 12:44:16 +000011481static int
paul718e3742002-12-13 20:15:29 +000011482bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11483 afi_t afi, safi_t safi, int *write)
11484{
11485 struct bgp_node *prn;
11486 struct bgp_node *rn;
11487 struct bgp_table *table;
11488 struct prefix *p;
11489 struct prefix_rd *prd;
11490 struct bgp_static *bgp_static;
11491 u_int32_t label;
11492 char buf[SU_ADDRSTRLEN];
11493 char rdbuf[RD_ADDRSTRLEN];
11494
11495 /* Network configuration. */
11496 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11497 if ((table = prn->info) != NULL)
11498 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11499 if ((bgp_static = rn->info) != NULL)
11500 {
11501 p = &rn->p;
11502 prd = (struct prefix_rd *) &prn->p;
11503
11504 /* "address-family" display. */
11505 bgp_config_write_family_header (vty, afi, safi, write);
11506
11507 /* "network" configuration display. */
11508 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11509 label = decode_label (bgp_static->tag);
11510
11511 vty_out (vty, " network %s/%d rd %s tag %d",
11512 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11513 p->prefixlen,
11514 rdbuf, label);
11515 vty_out (vty, "%s", VTY_NEWLINE);
11516 }
11517 return 0;
11518}
11519
11520/* Configuration of static route announcement and aggregate
11521 information. */
11522int
11523bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11524 afi_t afi, safi_t safi, int *write)
11525{
11526 struct bgp_node *rn;
11527 struct prefix *p;
11528 struct bgp_static *bgp_static;
11529 struct bgp_aggregate *bgp_aggregate;
11530 char buf[SU_ADDRSTRLEN];
11531
11532 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11533 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11534
11535 /* Network configuration. */
11536 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11537 if ((bgp_static = rn->info) != NULL)
11538 {
11539 p = &rn->p;
11540
11541 /* "address-family" display. */
11542 bgp_config_write_family_header (vty, afi, safi, write);
11543
11544 /* "network" configuration display. */
11545 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11546 {
11547 u_int32_t destination;
11548 struct in_addr netmask;
11549
11550 destination = ntohl (p->u.prefix4.s_addr);
11551 masklen2ip (p->prefixlen, &netmask);
11552 vty_out (vty, " network %s",
11553 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11554
11555 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11556 || (IN_CLASSB (destination) && p->prefixlen == 16)
11557 || (IN_CLASSA (destination) && p->prefixlen == 8)
11558 || p->u.prefix4.s_addr == 0)
11559 {
11560 /* Natural mask is not display. */
11561 }
11562 else
11563 vty_out (vty, " mask %s", inet_ntoa (netmask));
11564 }
11565 else
11566 {
11567 vty_out (vty, " network %s/%d",
11568 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11569 p->prefixlen);
11570 }
11571
11572 if (bgp_static->rmap.name)
11573 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011574 else
11575 {
11576 if (bgp_static->backdoor)
11577 vty_out (vty, " backdoor");
11578 if (bgp_static->ttl)
11579 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11580 }
paul718e3742002-12-13 20:15:29 +000011581
11582 vty_out (vty, "%s", VTY_NEWLINE);
11583 }
11584
11585 /* Aggregate-address configuration. */
11586 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11587 if ((bgp_aggregate = rn->info) != NULL)
11588 {
11589 p = &rn->p;
11590
11591 /* "address-family" display. */
11592 bgp_config_write_family_header (vty, afi, safi, write);
11593
11594 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11595 {
11596 struct in_addr netmask;
11597
11598 masklen2ip (p->prefixlen, &netmask);
11599 vty_out (vty, " aggregate-address %s %s",
11600 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11601 inet_ntoa (netmask));
11602 }
11603 else
11604 {
11605 vty_out (vty, " aggregate-address %s/%d",
11606 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11607 p->prefixlen);
11608 }
11609
11610 if (bgp_aggregate->as_set)
11611 vty_out (vty, " as-set");
11612
11613 if (bgp_aggregate->summary_only)
11614 vty_out (vty, " summary-only");
11615
11616 vty_out (vty, "%s", VTY_NEWLINE);
11617 }
11618
11619 return 0;
11620}
11621
11622int
11623bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11624{
11625 struct bgp_node *rn;
11626 struct bgp_distance *bdistance;
11627
11628 /* Distance configuration. */
11629 if (bgp->distance_ebgp
11630 && bgp->distance_ibgp
11631 && bgp->distance_local
11632 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11633 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11634 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11635 vty_out (vty, " distance bgp %d %d %d%s",
11636 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11637 VTY_NEWLINE);
11638
11639 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11640 if ((bdistance = rn->info) != NULL)
11641 {
11642 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11643 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11644 bdistance->access_list ? bdistance->access_list : "",
11645 VTY_NEWLINE);
11646 }
11647
11648 return 0;
11649}
11650
11651/* Allocate routing table structure and install commands. */
11652void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011653bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011654{
11655 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011656 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011657
11658 /* IPv4 BGP commands. */
11659 install_element (BGP_NODE, &bgp_network_cmd);
11660 install_element (BGP_NODE, &bgp_network_mask_cmd);
11661 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11662 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11663 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11664 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11665 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11666 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11667 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011668 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11669 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11670 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11671 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11672 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11673 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011674 install_element (BGP_NODE, &no_bgp_network_cmd);
11675 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11676 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11677 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11678 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11679 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11680 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11681 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11682 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011683 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11684 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11685 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11686 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11687 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11688 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011689
11690 install_element (BGP_NODE, &aggregate_address_cmd);
11691 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11692 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11693 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11694 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11695 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11696 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11697 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11698 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11699 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11700 install_element (BGP_NODE, &no_aggregate_address_cmd);
11701 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11702 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11703 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11704 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11705 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11706 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11707 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11708 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11709 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11710
11711 /* IPv4 unicast configuration. */
11712 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11713 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11714 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11715 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11716 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11717 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011718 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11719 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11720 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11721 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11722 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11723 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 +000011724 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11725 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11726 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11727 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11728 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011729 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11730 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11731 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11732 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11733 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11734 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 +000011735 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11736 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11737 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11738 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11739 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11740 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11741 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11742 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11743 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11744 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11745 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11746 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11747 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11748 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11749 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11750 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11751 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11752 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11753 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11754 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11755
11756 /* IPv4 multicast configuration. */
11757 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11758 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11759 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11760 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11761 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11762 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011763 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11764 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11765 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11766 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11767 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11768 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 +000011769 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11770 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11771 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11772 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11773 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11774 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011775 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11776 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11777 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11778 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11779 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11780 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 +000011781 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11782 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11783 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11784 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11785 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11786 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11787 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11788 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11789 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11790 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11791 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11792 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11793 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11794 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11795 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11796 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11797 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11798 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11799 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11800 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11801
11802 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11803 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11804 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11805 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11806 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11807 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11808 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11809 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11810 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11811 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11812 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11813 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11814 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11815 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11816 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11817 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11818 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11819 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11820 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11821 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11822 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11823 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11824 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11825 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11826 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11827 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11828 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11829 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11830 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11831 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11832 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11833 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11834 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11835 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11836 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11837 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11838 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11839 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11840 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11841 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11842 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11843 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11844 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11845 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11846 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11847 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11848 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11849 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11850 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11851 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11852 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11853 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11854 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11855 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11856 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11857 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11858 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11859 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11860 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11861 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11862 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11863 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11864 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11865 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11866 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11867 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11868 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011869 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11870 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11871 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011872 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11873 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011874 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11875 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11876 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011877
11878 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11879 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11880 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11881 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11882 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11883 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11884 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11885 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11886 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11887 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11888 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11889 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11890 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11891 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11892 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11893 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11894 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11895 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11896 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11897 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11898 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11899 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11900 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11901 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11902 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11903 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11904 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11905 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11906 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11907 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011908
11909 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11910 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11911 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11912 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11913 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11914 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11915 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11916 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11917 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11918 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11919 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11920 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11921 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11922 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11923 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11924 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11925 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11926 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11927 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11928 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11929 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11930 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11931 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11932 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11933 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11934 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11935 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11936 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11937 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11938 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11939 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11940 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11941 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11942 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11943 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11944 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11945 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11946 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11947 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11948 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11949 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11950 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11951 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11952 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11953 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11954 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11955 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11956 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11957 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11958 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11959 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11960 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11961 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11962 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11963 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11964 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11965 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11966 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11967 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11968 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11969 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11970 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11971 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11972 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11973 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11974 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11975 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011976 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11977 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11978 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011979 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11980 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011981 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11982 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11983 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011984
11985 /* BGP dampening clear commands */
11986 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11987 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11988 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11989 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11990
Paul Jakmaff7924f2006-09-04 01:10:36 +000011991 /* prefix count */
11992 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11993 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11994 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011995#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011996 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11997
paul718e3742002-12-13 20:15:29 +000011998 /* New config IPv6 BGP commands. */
11999 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12000 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000012001 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000012002 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12003 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000012004 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000012005
12006 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12007 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12008 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12009 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12010
12011 /* Old config IPv6 BGP commands. */
12012 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12013 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12014
12015 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12016 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12017 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12018 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12019
12020 install_element (VIEW_NODE, &show_bgp_cmd);
12021 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
12022 install_element (VIEW_NODE, &show_bgp_route_cmd);
12023 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
12024 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12025 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
12026 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12027 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12028 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12029 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12030 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12031 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12032 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12033 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12034 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12035 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12036 install_element (VIEW_NODE, &show_bgp_community_cmd);
12037 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12038 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12039 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12040 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12041 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12042 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12043 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12044 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12045 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12046 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12047 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12048 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12049 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12050 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12051 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12052 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12053 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12054 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12055 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12056 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12057 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12058 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12059 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12060 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12061 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12062 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12063 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12064 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12065 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012066 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12067 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12068 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12069 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012070 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
12071 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
12072 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012073 install_element (VIEW_NODE, &show_bgp_view_cmd);
12074 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12075 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12076 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12077 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12078 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12079 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12080 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12081 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12082 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12083 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12084 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12085 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12086 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12087 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12088 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12089 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12090 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012091 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
12092 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
12093 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012094
12095 /* Restricted:
12096 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12097 */
12098 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12099 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
12100 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12101 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
12102 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12103 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12104 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12105 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12106 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12107 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12108 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12109 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12110 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12111 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12112 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12113 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12114 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12115 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12116 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12117 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12118 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
12119 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
12120 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12121 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12122 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12123 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12124 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12125 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12126 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
12127 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012128
12129 install_element (ENABLE_NODE, &show_bgp_cmd);
12130 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
12131 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12132 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
12133 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12134 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
12135 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12136 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12137 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12138 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12139 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12140 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12141 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12142 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12143 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12144 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12145 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12146 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12147 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12148 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12149 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12150 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12151 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12152 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12153 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12154 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12155 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12156 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12157 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12158 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12159 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12160 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12161 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12162 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12163 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12164 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12165 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12166 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12167 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12168 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12169 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12170 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12171 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12172 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12173 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12174 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012175 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12176 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12177 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12178 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012179 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12180 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12181 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012182 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12183 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12184 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12185 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12186 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12187 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12188 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12189 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12190 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12191 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12192 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12193 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12194 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12195 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12196 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12197 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12198 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12199 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012200 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12201 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12202 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012203
12204 /* Statistics */
12205 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12206 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12207 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12208 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12209
paul718e3742002-12-13 20:15:29 +000012210 /* old command */
12211 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12212 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12213 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12214 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12215 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12216 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12217 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12218 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12219 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12220 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12221 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12222 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12223 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12224 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12225 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12226 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12227 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12228 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12229 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12230 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12231 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12232 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12233 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12234 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12235 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12236 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12237 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12238 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12239 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12240 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12241 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12242 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12243 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12244 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12245 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12246 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012247
paul718e3742002-12-13 20:15:29 +000012248 /* old command */
12249 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12250 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12251 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12252 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12253 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12254 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12255 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12256 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12257 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12258 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12259 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12260 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12261 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12262 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12263 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12264 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12265 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12266 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12267 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12268 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12269 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12270 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12271 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12272 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12273 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12274 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12275 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12276 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12277 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12278 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12279 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12280 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12281 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12282 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12283 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12284 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12285
12286 /* old command */
12287 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12288 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12289 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12290 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12291
12292 /* old command */
12293 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12294 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12295 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12296 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12297
12298 /* old command */
12299 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12300 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12301 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12302 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12303#endif /* HAVE_IPV6 */
12304
12305 install_element (BGP_NODE, &bgp_distance_cmd);
12306 install_element (BGP_NODE, &no_bgp_distance_cmd);
12307 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12308 install_element (BGP_NODE, &bgp_distance_source_cmd);
12309 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12310 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12311 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12312
12313 install_element (BGP_NODE, &bgp_damp_set_cmd);
12314 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12315 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12316 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12317 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12318 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12319 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12320 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12321 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12322 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12323}
Chris Caputo228da422009-07-18 05:44:03 +000012324
12325void
12326bgp_route_finish (void)
12327{
12328 bgp_table_unlock (bgp_distance_table);
12329 bgp_distance_table = NULL;
12330}