blob: fd51ad1a5bac66add9517e9be491c55b11f13957 [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
Stephen Hemminger7badc262010-08-05 10:26:31 -07003283 bgp_attr_dup(&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);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003312 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003313
3314 for (ri = rn->info; ri; ri = ri->next)
3315 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3316 && ri->sub_type == BGP_ROUTE_STATIC)
3317 break;
3318
3319 if (ri)
3320 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003321 if (attrhash_cmp (ri->attr, attr_new) &&
3322 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003323 {
3324 bgp_unlock_node (rn);
3325 bgp_attr_unintern (attr_new);
3326 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003327 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003328 return;
3329 }
3330 else
3331 {
3332 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003333 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003334
3335 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003336 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3337 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003338 bgp_attr_unintern (ri->attr);
3339 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003340 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003341
3342 /* Process change. */
3343 bgp_process (bgp, rn, afi, safi);
3344 bgp_unlock_node (rn);
3345 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003346 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003347 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003348 }
paulfee0f4c2004-09-13 05:12:46 +00003349 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003350
paulfee0f4c2004-09-13 05:12:46 +00003351 /* Make new BGP info. */
3352 new = bgp_info_new ();
3353 new->type = ZEBRA_ROUTE_BGP;
3354 new->sub_type = BGP_ROUTE_STATIC;
3355 new->peer = bgp->peer_self;
3356 SET_FLAG (new->flags, BGP_INFO_VALID);
3357 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003358 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003359
3360 /* Register new BGP information. */
3361 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003362
3363 /* route_node_get lock */
3364 bgp_unlock_node (rn);
3365
paulfee0f4c2004-09-13 05:12:46 +00003366 /* Process change. */
3367 bgp_process (bgp, rn, afi, safi);
3368
3369 /* Unintern original. */
3370 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003371 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003372}
3373
paul94f2b392005-06-28 12:44:16 +00003374static void
paulfee0f4c2004-09-13 05:12:46 +00003375bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003376 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3377{
3378 struct bgp_node *rn;
3379 struct bgp_info *ri;
3380 struct bgp_info *new;
3381 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003382 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003383 struct attr *attr_new;
3384 int ret;
3385
Paul Jakmadd8103a2006-05-12 23:27:30 +00003386 assert (bgp_static);
3387 if (!bgp_static)
3388 return;
3389
paulfee0f4c2004-09-13 05:12:46 +00003390 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003391
3392 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003393
3394 attr.nexthop = bgp_static->igpnexthop;
3395 attr.med = bgp_static->igpmetric;
3396 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003397
Paul Jakma41367172007-08-06 15:24:51 +00003398 if (bgp_static->ttl)
3399 {
3400 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3401 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3402 attr.pathlimit.as = 0;
3403 attr.pathlimit.ttl = bgp_static->ttl;
3404 }
3405
3406 if (bgp_static->atomic)
3407 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3408
paul718e3742002-12-13 20:15:29 +00003409 /* Apply route-map. */
3410 if (bgp_static->rmap.name)
3411 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003412 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003413 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003414 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003415
paulfee0f4c2004-09-13 05:12:46 +00003416 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3417
paul718e3742002-12-13 20:15:29 +00003418 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003419
paulfee0f4c2004-09-13 05:12:46 +00003420 bgp->peer_self->rmap_type = 0;
3421
paul718e3742002-12-13 20:15:29 +00003422 if (ret == RMAP_DENYMATCH)
3423 {
3424 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003425 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003426
3427 /* Unintern original. */
3428 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003429 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003430 bgp_static_withdraw (bgp, p, afi, safi);
3431 return;
3432 }
paul286e1e72003-08-08 00:24:31 +00003433 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003434 }
paul286e1e72003-08-08 00:24:31 +00003435 else
3436 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003437
3438 for (ri = rn->info; ri; ri = ri->next)
3439 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3440 && ri->sub_type == BGP_ROUTE_STATIC)
3441 break;
3442
3443 if (ri)
3444 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003445 if (attrhash_cmp (ri->attr, attr_new) &&
3446 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003447 {
3448 bgp_unlock_node (rn);
3449 bgp_attr_unintern (attr_new);
3450 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003451 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003452 return;
3453 }
3454 else
3455 {
3456 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003457 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003458
3459 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003460 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3461 bgp_info_restore(rn, ri);
3462 else
3463 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003464 bgp_attr_unintern (ri->attr);
3465 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003466 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003467
3468 /* Process change. */
3469 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3470 bgp_process (bgp, rn, afi, safi);
3471 bgp_unlock_node (rn);
3472 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003473 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003474 return;
3475 }
3476 }
3477
3478 /* Make new BGP info. */
3479 new = bgp_info_new ();
3480 new->type = ZEBRA_ROUTE_BGP;
3481 new->sub_type = BGP_ROUTE_STATIC;
3482 new->peer = bgp->peer_self;
3483 SET_FLAG (new->flags, BGP_INFO_VALID);
3484 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003485 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003486
3487 /* Aggregate address increment. */
3488 bgp_aggregate_increment (bgp, p, new, afi, safi);
3489
3490 /* Register new BGP information. */
3491 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003492
3493 /* route_node_get lock */
3494 bgp_unlock_node (rn);
3495
paul718e3742002-12-13 20:15:29 +00003496 /* Process change. */
3497 bgp_process (bgp, rn, afi, safi);
3498
3499 /* Unintern original. */
3500 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003501 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003502}
3503
3504void
paulfee0f4c2004-09-13 05:12:46 +00003505bgp_static_update (struct bgp *bgp, struct prefix *p,
3506 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3507{
3508 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003509 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003510
3511 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3512
paul1eb8ef22005-04-07 07:30:20 +00003513 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003514 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003515 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3516 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003517 }
3518}
3519
paul94f2b392005-06-28 12:44:16 +00003520static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003521bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3522 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003523{
3524 struct bgp_node *rn;
3525 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003526
paulfee0f4c2004-09-13 05:12:46 +00003527 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003528
3529 /* Make new BGP info. */
3530 new = bgp_info_new ();
3531 new->type = ZEBRA_ROUTE_BGP;
3532 new->sub_type = BGP_ROUTE_STATIC;
3533 new->peer = bgp->peer_self;
3534 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3535 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003536 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003537 new->extra = bgp_info_extra_new();
3538 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003539
3540 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003541 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003542
3543 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003544 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003545
paul200df112005-06-01 11:17:05 +00003546 /* route_node_get lock */
3547 bgp_unlock_node (rn);
3548
paul718e3742002-12-13 20:15:29 +00003549 /* Process change. */
3550 bgp_process (bgp, rn, afi, safi);
3551}
3552
3553void
3554bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3555 safi_t safi)
3556{
3557 struct bgp_node *rn;
3558 struct bgp_info *ri;
3559
paulfee0f4c2004-09-13 05:12:46 +00003560 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003561
3562 /* Check selected route and self inserted route. */
3563 for (ri = rn->info; ri; ri = ri->next)
3564 if (ri->peer == bgp->peer_self
3565 && ri->type == ZEBRA_ROUTE_BGP
3566 && ri->sub_type == BGP_ROUTE_STATIC)
3567 break;
3568
3569 /* Withdraw static BGP route from routing table. */
3570 if (ri)
3571 {
3572 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003573 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003574 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003575 }
3576
3577 /* Unlock bgp_node_lookup. */
3578 bgp_unlock_node (rn);
3579}
3580
3581void
paulfee0f4c2004-09-13 05:12:46 +00003582bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3583{
3584 struct bgp_static *bgp_static;
3585 struct bgp *bgp;
3586 struct bgp_node *rn;
3587 struct prefix *p;
3588
3589 bgp = rsclient->bgp;
3590
3591 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3592 if ((bgp_static = rn->info) != NULL)
3593 {
3594 p = &rn->p;
3595
3596 bgp_static_update_rsclient (rsclient, p, bgp_static,
3597 afi, safi);
3598 }
3599}
3600
paul94f2b392005-06-28 12:44:16 +00003601static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003602bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3603 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003604{
3605 struct bgp_node *rn;
3606 struct bgp_info *ri;
3607
paulfee0f4c2004-09-13 05:12:46 +00003608 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003609
3610 /* Check selected route and self inserted route. */
3611 for (ri = rn->info; ri; ri = ri->next)
3612 if (ri->peer == bgp->peer_self
3613 && ri->type == ZEBRA_ROUTE_BGP
3614 && ri->sub_type == BGP_ROUTE_STATIC)
3615 break;
3616
3617 /* Withdraw static BGP route from routing table. */
3618 if (ri)
3619 {
3620 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003621 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003622 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003623 }
3624
3625 /* Unlock bgp_node_lookup. */
3626 bgp_unlock_node (rn);
3627}
3628
Paul Jakma41367172007-08-06 15:24:51 +00003629static void
3630bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3631 int ttl_edge)
3632{
3633 struct bgp_node *parent = rn;
3634 struct bgp_static *sp;
3635
3636 /* Existing static changed TTL, search parents and adjust their atomic */
3637 while ((parent = parent->parent))
3638 if ((sp = parent->info))
3639 {
3640 int sp_level = (sp->atomic ? 1 : 0);
3641 ttl_edge ? sp->atomic++ : sp->atomic--;
3642
3643 /* did we change state of parent whether atomic is set or not? */
3644 if (sp_level != (sp->atomic ? 1 : 0))
3645 {
3646 bgp_static_update (bgp, &parent->p, sp,
3647 rn->table->afi, rn->table->safi);
3648 }
3649 }
3650}
3651
paul718e3742002-12-13 20:15:29 +00003652/* Configure static BGP network. When user don't run zebra, static
3653 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003654static int
paulfd79ac92004-10-13 05:06:08 +00003655bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003656 afi_t afi, safi_t safi, const char *rmap, int backdoor,
Paul Jakma41367172007-08-06 15:24:51 +00003657 u_char ttl)
paul718e3742002-12-13 20:15:29 +00003658{
3659 int ret;
3660 struct prefix p;
3661 struct bgp_static *bgp_static;
3662 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003663 u_char need_update = 0;
3664 u_char ttl_change = 0;
3665 u_char ttl_edge = (ttl ? 1 : 0);
3666 u_char new = 0;
paul718e3742002-12-13 20:15:29 +00003667
3668 /* Convert IP prefix string to struct prefix. */
3669 ret = str2prefix (ip_str, &p);
3670 if (! ret)
3671 {
3672 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3673 return CMD_WARNING;
3674 }
3675#ifdef HAVE_IPV6
3676 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3677 {
3678 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3679 VTY_NEWLINE);
3680 return CMD_WARNING;
3681 }
3682#endif /* HAVE_IPV6 */
3683
3684 apply_mask (&p);
3685
3686 /* Set BGP static route configuration. */
3687 rn = bgp_node_get (bgp->route[afi][safi], &p);
3688
3689 if (rn->info)
3690 {
3691 /* Configuration change. */
3692 bgp_static = rn->info;
3693
3694 /* Check previous routes are installed into BGP. */
Paul Jakma41367172007-08-06 15:24:51 +00003695 if (bgp_static->valid)
3696 {
3697 if (bgp_static->backdoor != backdoor
3698 || bgp_static->ttl != ttl)
3699 need_update = 1;
3700 }
3701
3702 /* need to catch TTL set/unset transitions for handling of
3703 * ATOMIC_AGGREGATE
3704 */
3705 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3706 ttl_change = 1;
3707
paul718e3742002-12-13 20:15:29 +00003708 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003709 bgp_static->ttl = ttl;
3710
paul718e3742002-12-13 20:15:29 +00003711 if (rmap)
3712 {
3713 if (bgp_static->rmap.name)
3714 free (bgp_static->rmap.name);
3715 bgp_static->rmap.name = strdup (rmap);
3716 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3717 }
3718 else
3719 {
3720 if (bgp_static->rmap.name)
3721 free (bgp_static->rmap.name);
3722 bgp_static->rmap.name = NULL;
3723 bgp_static->rmap.map = NULL;
3724 bgp_static->valid = 0;
3725 }
3726 bgp_unlock_node (rn);
3727 }
3728 else
3729 {
3730 /* New configuration. */
3731 bgp_static = bgp_static_new ();
3732 bgp_static->backdoor = backdoor;
3733 bgp_static->valid = 0;
3734 bgp_static->igpmetric = 0;
3735 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003736 bgp_static->ttl = ttl;
3737 ttl_change = ttl_edge;
3738 new = 1;
3739
paul718e3742002-12-13 20:15:29 +00003740 if (rmap)
3741 {
3742 if (bgp_static->rmap.name)
3743 free (bgp_static->rmap.name);
3744 bgp_static->rmap.name = strdup (rmap);
3745 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3746 }
3747 rn->info = bgp_static;
3748 }
3749
Paul Jakma41367172007-08-06 15:24:51 +00003750 /* ".. sites that choose to advertise the
3751 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3752 * all less specific covering prefixes as well as the more specific
3753 * prefixes."
3754 *
3755 * So:
3756 * Prefix that has just had pathlimit set/unset:
3757 * - Must bump ATOMIC refcount on all parents.
3758 *
3759 * To catch less specific prefixes:
3760 * - Must search children for ones with TTL, bump atomic refcount
3761 * (we dont care if we're deleting a less specific prefix..)
3762 */
3763 if (ttl_change)
3764 {
3765 /* Existing static changed TTL, search parents and adjust their atomic */
3766 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3767 }
3768
3769 if (new)
3770 {
3771 struct bgp_node *child;
3772 struct bgp_static *sc;
3773
3774 /* New static, search children and bump this statics atomic.. */
3775 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3776 while ((child = bgp_route_next_until (child, rn)))
3777 {
3778 if ((sc = child->info) && sc->ttl)
3779 bgp_static->atomic++;
3780 }
3781 }
3782
paul718e3742002-12-13 20:15:29 +00003783 /* If BGP scan is not enabled, we should install this route here. */
3784 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3785 {
3786 bgp_static->valid = 1;
3787
3788 if (need_update)
3789 bgp_static_withdraw (bgp, &p, afi, safi);
3790
3791 if (! bgp_static->backdoor)
3792 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3793 }
3794
3795 return CMD_SUCCESS;
3796}
3797
3798/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003799static int
paulfd79ac92004-10-13 05:06:08 +00003800bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003801 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003802{
3803 int ret;
3804 struct prefix p;
3805 struct bgp_static *bgp_static;
3806 struct bgp_node *rn;
3807
3808 /* Convert IP prefix string to struct prefix. */
3809 ret = str2prefix (ip_str, &p);
3810 if (! ret)
3811 {
3812 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3813 return CMD_WARNING;
3814 }
3815#ifdef HAVE_IPV6
3816 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3817 {
3818 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3819 VTY_NEWLINE);
3820 return CMD_WARNING;
3821 }
3822#endif /* HAVE_IPV6 */
3823
3824 apply_mask (&p);
3825
3826 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3827 if (! rn)
3828 {
3829 vty_out (vty, "%% Can't find specified static route configuration.%s",
3830 VTY_NEWLINE);
3831 return CMD_WARNING;
3832 }
3833
3834 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003835
3836 /* decrement atomic in parents, see bgp_static_set */
3837 bgp_pathlimit_update_parents (bgp, rn, 0);
3838
paul718e3742002-12-13 20:15:29 +00003839 /* Update BGP RIB. */
3840 if (! bgp_static->backdoor)
3841 bgp_static_withdraw (bgp, &p, afi, safi);
3842
3843 /* Clear configuration. */
3844 bgp_static_free (bgp_static);
3845 rn->info = NULL;
3846 bgp_unlock_node (rn);
3847 bgp_unlock_node (rn);
3848
3849 return CMD_SUCCESS;
3850}
3851
3852/* Called from bgp_delete(). Delete all static routes from the BGP
3853 instance. */
3854void
3855bgp_static_delete (struct bgp *bgp)
3856{
3857 afi_t afi;
3858 safi_t safi;
3859 struct bgp_node *rn;
3860 struct bgp_node *rm;
3861 struct bgp_table *table;
3862 struct bgp_static *bgp_static;
3863
3864 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3865 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3866 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3867 if (rn->info != NULL)
3868 {
3869 if (safi == SAFI_MPLS_VPN)
3870 {
3871 table = rn->info;
3872
3873 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3874 {
3875 bgp_static = rn->info;
3876 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3877 AFI_IP, SAFI_MPLS_VPN,
3878 (struct prefix_rd *)&rn->p,
3879 bgp_static->tag);
3880 bgp_static_free (bgp_static);
3881 rn->info = NULL;
3882 bgp_unlock_node (rn);
3883 }
3884 }
3885 else
3886 {
3887 bgp_static = rn->info;
3888 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3889 bgp_static_free (bgp_static);
3890 rn->info = NULL;
3891 bgp_unlock_node (rn);
3892 }
3893 }
3894}
3895
3896int
paulfd79ac92004-10-13 05:06:08 +00003897bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3898 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003899{
3900 int ret;
3901 struct prefix p;
3902 struct prefix_rd prd;
3903 struct bgp *bgp;
3904 struct bgp_node *prn;
3905 struct bgp_node *rn;
3906 struct bgp_table *table;
3907 struct bgp_static *bgp_static;
3908 u_char tag[3];
3909
3910 bgp = vty->index;
3911
3912 ret = str2prefix (ip_str, &p);
3913 if (! ret)
3914 {
3915 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3916 return CMD_WARNING;
3917 }
3918 apply_mask (&p);
3919
3920 ret = str2prefix_rd (rd_str, &prd);
3921 if (! ret)
3922 {
3923 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3924 return CMD_WARNING;
3925 }
3926
3927 ret = str2tag (tag_str, tag);
3928 if (! ret)
3929 {
3930 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3931 return CMD_WARNING;
3932 }
3933
3934 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3935 (struct prefix *)&prd);
3936 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003937 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003938 else
3939 bgp_unlock_node (prn);
3940 table = prn->info;
3941
3942 rn = bgp_node_get (table, &p);
3943
3944 if (rn->info)
3945 {
3946 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3947 bgp_unlock_node (rn);
3948 }
3949 else
3950 {
3951 /* New configuration. */
3952 bgp_static = bgp_static_new ();
3953 bgp_static->valid = 1;
3954 memcpy (bgp_static->tag, tag, 3);
3955 rn->info = bgp_static;
3956
3957 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3958 }
3959
3960 return CMD_SUCCESS;
3961}
3962
3963/* Configure static BGP network. */
3964int
paulfd79ac92004-10-13 05:06:08 +00003965bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3966 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003967{
3968 int ret;
3969 struct bgp *bgp;
3970 struct prefix p;
3971 struct prefix_rd prd;
3972 struct bgp_node *prn;
3973 struct bgp_node *rn;
3974 struct bgp_table *table;
3975 struct bgp_static *bgp_static;
3976 u_char tag[3];
3977
3978 bgp = vty->index;
3979
3980 /* Convert IP prefix string to struct prefix. */
3981 ret = str2prefix (ip_str, &p);
3982 if (! ret)
3983 {
3984 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3985 return CMD_WARNING;
3986 }
3987 apply_mask (&p);
3988
3989 ret = str2prefix_rd (rd_str, &prd);
3990 if (! ret)
3991 {
3992 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3993 return CMD_WARNING;
3994 }
3995
3996 ret = str2tag (tag_str, tag);
3997 if (! ret)
3998 {
3999 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4000 return CMD_WARNING;
4001 }
4002
4003 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4004 (struct prefix *)&prd);
4005 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004006 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004007 else
4008 bgp_unlock_node (prn);
4009 table = prn->info;
4010
4011 rn = bgp_node_lookup (table, &p);
4012
4013 if (rn)
4014 {
4015 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4016
4017 bgp_static = rn->info;
4018 bgp_static_free (bgp_static);
4019 rn->info = NULL;
4020 bgp_unlock_node (rn);
4021 bgp_unlock_node (rn);
4022 }
4023 else
4024 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4025
4026 return CMD_SUCCESS;
4027}
4028
4029DEFUN (bgp_network,
4030 bgp_network_cmd,
4031 "network A.B.C.D/M",
4032 "Specify a network to announce via BGP\n"
4033 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4034{
Paul Jakma41367172007-08-06 15:24:51 +00004035 u_char ttl = 0;
4036
4037 if (argc == 2)
4038 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4039
paul718e3742002-12-13 20:15:29 +00004040 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004041 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004042}
4043
Paul Jakma41367172007-08-06 15:24:51 +00004044ALIAS (bgp_network,
4045 bgp_network_ttl_cmd,
4046 "network A.B.C.D/M pathlimit <0-255>",
4047 "Specify a network to announce via BGP\n"
4048 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4049 "AS-Path hopcount limit attribute\n"
4050 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4051
paul718e3742002-12-13 20:15:29 +00004052DEFUN (bgp_network_route_map,
4053 bgp_network_route_map_cmd,
4054 "network A.B.C.D/M route-map WORD",
4055 "Specify a network to announce via BGP\n"
4056 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4057 "Route-map to modify the attributes\n"
4058 "Name of the route map\n")
4059{
4060 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004061 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004062}
4063
4064DEFUN (bgp_network_backdoor,
4065 bgp_network_backdoor_cmd,
4066 "network A.B.C.D/M backdoor",
4067 "Specify a network to announce via BGP\n"
4068 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4069 "Specify a BGP backdoor route\n")
4070{
Paul Jakma41367172007-08-06 15:24:51 +00004071 u_char ttl = 0;
4072
4073 if (argc == 2)
4074 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4075
4076 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4077 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004078}
4079
Paul Jakma41367172007-08-06 15:24:51 +00004080ALIAS (bgp_network_backdoor,
4081 bgp_network_backdoor_ttl_cmd,
4082 "network A.B.C.D/M backdoor pathlimit <0-255>",
4083 "Specify a network to announce via BGP\n"
4084 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4085 "Specify a BGP backdoor route\n"
4086 "AS-Path hopcount limit attribute\n"
4087 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4088
paul718e3742002-12-13 20:15:29 +00004089DEFUN (bgp_network_mask,
4090 bgp_network_mask_cmd,
4091 "network A.B.C.D mask A.B.C.D",
4092 "Specify a network to announce via BGP\n"
4093 "Network number\n"
4094 "Network mask\n"
4095 "Network mask\n")
4096{
4097 int ret;
4098 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004099 u_char ttl = 0;
4100
4101 if (argc == 3)
4102 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4103
paul718e3742002-12-13 20:15:29 +00004104 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4105 if (! ret)
4106 {
4107 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4108 return CMD_WARNING;
4109 }
4110
4111 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004112 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004113}
4114
Paul Jakma41367172007-08-06 15:24:51 +00004115ALIAS (bgp_network_mask,
4116 bgp_network_mask_ttl_cmd,
4117 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4118 "Specify a network to announce via BGP\n"
4119 "Network number\n"
4120 "Network mask\n"
4121 "Network mask\n"
4122 "AS-Path hopcount limit attribute\n"
4123 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4124
paul718e3742002-12-13 20:15:29 +00004125DEFUN (bgp_network_mask_route_map,
4126 bgp_network_mask_route_map_cmd,
4127 "network A.B.C.D mask A.B.C.D route-map WORD",
4128 "Specify a network to announce via BGP\n"
4129 "Network number\n"
4130 "Network mask\n"
4131 "Network mask\n"
4132 "Route-map to modify the attributes\n"
4133 "Name of the route map\n")
4134{
4135 int ret;
4136 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004137
paul718e3742002-12-13 20:15:29 +00004138 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4139 if (! ret)
4140 {
4141 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4142 return CMD_WARNING;
4143 }
4144
4145 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004146 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
paul718e3742002-12-13 20:15:29 +00004147}
4148
4149DEFUN (bgp_network_mask_backdoor,
4150 bgp_network_mask_backdoor_cmd,
4151 "network A.B.C.D mask A.B.C.D backdoor",
4152 "Specify a network to announce via BGP\n"
4153 "Network number\n"
4154 "Network mask\n"
4155 "Network mask\n"
4156 "Specify a BGP backdoor route\n")
4157{
4158 int ret;
4159 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004160 u_char ttl = 0;
4161
4162 if (argc == 3)
4163 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
paul718e3742002-12-13 20:15:29 +00004164
4165 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4166 if (! ret)
4167 {
4168 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4169 return CMD_WARNING;
4170 }
4171
Paul Jakma41367172007-08-06 15:24:51 +00004172 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4173 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004174}
4175
Paul Jakma41367172007-08-06 15:24:51 +00004176ALIAS (bgp_network_mask_backdoor,
4177 bgp_network_mask_backdoor_ttl_cmd,
4178 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4179 "Specify a network to announce via BGP\n"
4180 "Network number\n"
4181 "Network mask\n"
4182 "Network mask\n"
4183 "Specify a BGP backdoor route\n"
4184 "AS-Path hopcount limit attribute\n"
4185 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4186
paul718e3742002-12-13 20:15:29 +00004187DEFUN (bgp_network_mask_natural,
4188 bgp_network_mask_natural_cmd,
4189 "network A.B.C.D",
4190 "Specify a network to announce via BGP\n"
4191 "Network number\n")
4192{
4193 int ret;
4194 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004195 u_char ttl = 0;
4196
4197 if (argc == 2)
4198 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004199
4200 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4201 if (! ret)
4202 {
4203 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4204 return CMD_WARNING;
4205 }
4206
4207 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004208 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004209}
4210
Paul Jakma41367172007-08-06 15:24:51 +00004211ALIAS (bgp_network_mask_natural,
4212 bgp_network_mask_natural_ttl_cmd,
4213 "network A.B.C.D pathlimit <0-255>",
4214 "Specify a network to announce via BGP\n"
4215 "Network number\n"
4216 "AS-Path hopcount limit attribute\n"
4217 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4218
paul718e3742002-12-13 20:15:29 +00004219DEFUN (bgp_network_mask_natural_route_map,
4220 bgp_network_mask_natural_route_map_cmd,
4221 "network A.B.C.D route-map WORD",
4222 "Specify a network to announce via BGP\n"
4223 "Network number\n"
4224 "Route-map to modify the attributes\n"
4225 "Name of the route map\n")
4226{
4227 int ret;
4228 char prefix_str[BUFSIZ];
4229
4230 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4231 if (! ret)
4232 {
4233 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4234 return CMD_WARNING;
4235 }
4236
4237 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004238 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004239}
4240
4241DEFUN (bgp_network_mask_natural_backdoor,
4242 bgp_network_mask_natural_backdoor_cmd,
4243 "network A.B.C.D backdoor",
4244 "Specify a network to announce via BGP\n"
4245 "Network number\n"
4246 "Specify a BGP backdoor route\n")
4247{
4248 int ret;
4249 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004250 u_char ttl = 0;
4251
4252 if (argc == 2)
4253 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004254
4255 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4256 if (! ret)
4257 {
4258 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4259 return CMD_WARNING;
4260 }
4261
Paul Jakma41367172007-08-06 15:24:51 +00004262 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4263 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004264}
4265
Paul Jakma41367172007-08-06 15:24:51 +00004266ALIAS (bgp_network_mask_natural_backdoor,
4267 bgp_network_mask_natural_backdoor_ttl_cmd,
4268 "network A.B.C.D backdoor pathlimit (1-255>",
4269 "Specify a network to announce via BGP\n"
4270 "Network number\n"
4271 "Specify a BGP backdoor route\n"
4272 "AS-Path hopcount limit attribute\n"
4273 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4274
paul718e3742002-12-13 20:15:29 +00004275DEFUN (no_bgp_network,
4276 no_bgp_network_cmd,
4277 "no network A.B.C.D/M",
4278 NO_STR
4279 "Specify a network to announce via BGP\n"
4280 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4281{
4282 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4283 bgp_node_safi (vty));
4284}
4285
4286ALIAS (no_bgp_network,
Paul Jakma41367172007-08-06 15:24:51 +00004287 no_bgp_network_ttl_cmd,
4288 "no network A.B.C.D/M pathlimit <0-255>",
4289 NO_STR
4290 "Specify a network to announce via BGP\n"
4291 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4292 "AS-Path hopcount limit attribute\n"
4293 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4294
4295ALIAS (no_bgp_network,
paul718e3742002-12-13 20:15:29 +00004296 no_bgp_network_route_map_cmd,
4297 "no network A.B.C.D/M route-map WORD",
4298 NO_STR
4299 "Specify a network to announce via BGP\n"
4300 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4301 "Route-map to modify the attributes\n"
4302 "Name of the route map\n")
4303
4304ALIAS (no_bgp_network,
4305 no_bgp_network_backdoor_cmd,
4306 "no network A.B.C.D/M backdoor",
4307 NO_STR
4308 "Specify a network to announce via BGP\n"
4309 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4310 "Specify a BGP backdoor route\n")
4311
Paul Jakma41367172007-08-06 15:24:51 +00004312ALIAS (no_bgp_network,
4313 no_bgp_network_backdoor_ttl_cmd,
4314 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4315 NO_STR
4316 "Specify a network to announce via BGP\n"
4317 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4318 "Specify a BGP backdoor route\n"
4319 "AS-Path hopcount limit attribute\n"
4320 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4321
paul718e3742002-12-13 20:15:29 +00004322DEFUN (no_bgp_network_mask,
4323 no_bgp_network_mask_cmd,
4324 "no network A.B.C.D mask A.B.C.D",
4325 NO_STR
4326 "Specify a network to announce via BGP\n"
4327 "Network number\n"
4328 "Network mask\n"
4329 "Network mask\n")
4330{
4331 int ret;
4332 char prefix_str[BUFSIZ];
4333
4334 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4335 if (! ret)
4336 {
4337 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4338 return CMD_WARNING;
4339 }
4340
4341 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4342 bgp_node_safi (vty));
4343}
4344
Paul Jakma41367172007-08-06 15:24:51 +00004345ALIAS (no_bgp_network,
4346 no_bgp_network_mask_ttl_cmd,
4347 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4348 NO_STR
4349 "Specify a network to announce via BGP\n"
4350 "Network number\n"
4351 "Network mask\n"
4352 "Network mask\n"
4353 "AS-Path hopcount limit attribute\n"
4354 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4355
paul718e3742002-12-13 20:15:29 +00004356ALIAS (no_bgp_network_mask,
4357 no_bgp_network_mask_route_map_cmd,
4358 "no network A.B.C.D mask A.B.C.D route-map WORD",
4359 NO_STR
4360 "Specify a network to announce via BGP\n"
4361 "Network number\n"
4362 "Network mask\n"
4363 "Network mask\n"
4364 "Route-map to modify the attributes\n"
4365 "Name of the route map\n")
4366
4367ALIAS (no_bgp_network_mask,
4368 no_bgp_network_mask_backdoor_cmd,
4369 "no network A.B.C.D mask A.B.C.D backdoor",
4370 NO_STR
4371 "Specify a network to announce via BGP\n"
4372 "Network number\n"
4373 "Network mask\n"
4374 "Network mask\n"
4375 "Specify a BGP backdoor route\n")
4376
Paul Jakma41367172007-08-06 15:24:51 +00004377ALIAS (no_bgp_network_mask,
4378 no_bgp_network_mask_backdoor_ttl_cmd,
4379 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4380 NO_STR
4381 "Specify a network to announce via BGP\n"
4382 "Network number\n"
4383 "Network mask\n"
4384 "Network mask\n"
4385 "Specify a BGP backdoor route\n"
4386 "AS-Path hopcount limit attribute\n"
4387 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4388
paul718e3742002-12-13 20:15:29 +00004389DEFUN (no_bgp_network_mask_natural,
4390 no_bgp_network_mask_natural_cmd,
4391 "no network A.B.C.D",
4392 NO_STR
4393 "Specify a network to announce via BGP\n"
4394 "Network number\n")
4395{
4396 int ret;
4397 char prefix_str[BUFSIZ];
4398
4399 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4400 if (! ret)
4401 {
4402 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4403 return CMD_WARNING;
4404 }
4405
4406 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4407 bgp_node_safi (vty));
4408}
4409
4410ALIAS (no_bgp_network_mask_natural,
4411 no_bgp_network_mask_natural_route_map_cmd,
4412 "no network A.B.C.D route-map WORD",
4413 NO_STR
4414 "Specify a network to announce via BGP\n"
4415 "Network number\n"
4416 "Route-map to modify the attributes\n"
4417 "Name of the route map\n")
4418
4419ALIAS (no_bgp_network_mask_natural,
4420 no_bgp_network_mask_natural_backdoor_cmd,
4421 "no network A.B.C.D backdoor",
4422 NO_STR
4423 "Specify a network to announce via BGP\n"
4424 "Network number\n"
4425 "Specify a BGP backdoor route\n")
4426
Paul Jakma41367172007-08-06 15:24:51 +00004427ALIAS (no_bgp_network_mask_natural,
4428 no_bgp_network_mask_natural_ttl_cmd,
4429 "no network A.B.C.D pathlimit <0-255>",
4430 NO_STR
4431 "Specify a network to announce via BGP\n"
4432 "Network number\n"
4433 "AS-Path hopcount limit attribute\n"
4434 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4435
4436ALIAS (no_bgp_network_mask_natural,
4437 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4438 "no network A.B.C.D backdoor pathlimit <0-255>",
4439 NO_STR
4440 "Specify a network to announce via BGP\n"
4441 "Network number\n"
4442 "Specify a BGP backdoor route\n"
4443 "AS-Path hopcount limit attribute\n"
4444 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4445
paul718e3742002-12-13 20:15:29 +00004446#ifdef HAVE_IPV6
4447DEFUN (ipv6_bgp_network,
4448 ipv6_bgp_network_cmd,
4449 "network X:X::X:X/M",
4450 "Specify a network to announce via BGP\n"
4451 "IPv6 prefix <network>/<length>\n")
4452{
Paul Jakma41367172007-08-06 15:24:51 +00004453 u_char ttl = 0;
4454
4455 if (argc == 2)
4456 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4457
4458 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4459 NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004460}
4461
Paul Jakma41367172007-08-06 15:24:51 +00004462ALIAS (ipv6_bgp_network,
4463 ipv6_bgp_network_ttl_cmd,
4464 "network X:X::X:X/M pathlimit <0-255>",
4465 "Specify a network to announce via BGP\n"
4466 "IPv6 prefix <network>/<length>\n"
4467 "AS-Path hopcount limit attribute\n"
4468 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4469
paul718e3742002-12-13 20:15:29 +00004470DEFUN (ipv6_bgp_network_route_map,
4471 ipv6_bgp_network_route_map_cmd,
4472 "network X:X::X:X/M route-map WORD",
4473 "Specify a network to announce via BGP\n"
4474 "IPv6 prefix <network>/<length>\n"
4475 "Route-map to modify the attributes\n"
4476 "Name of the route map\n")
4477{
4478 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakma41367172007-08-06 15:24:51 +00004479 bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004480}
4481
4482DEFUN (no_ipv6_bgp_network,
4483 no_ipv6_bgp_network_cmd,
4484 "no network X:X::X:X/M",
4485 NO_STR
4486 "Specify a network to announce via BGP\n"
4487 "IPv6 prefix <network>/<length>\n")
4488{
4489 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4490}
4491
4492ALIAS (no_ipv6_bgp_network,
4493 no_ipv6_bgp_network_route_map_cmd,
4494 "no network X:X::X:X/M route-map WORD",
4495 NO_STR
4496 "Specify a network to announce via BGP\n"
4497 "IPv6 prefix <network>/<length>\n"
4498 "Route-map to modify the attributes\n"
4499 "Name of the route map\n")
4500
Paul Jakma41367172007-08-06 15:24:51 +00004501ALIAS (no_ipv6_bgp_network,
4502 no_ipv6_bgp_network_ttl_cmd,
4503 "no network X:X::X:X/M pathlimit <0-255>",
4504 NO_STR
4505 "Specify a network to announce via BGP\n"
4506 "IPv6 prefix <network>/<length>\n"
4507 "AS-Path hopcount limit attribute\n"
4508 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4509
paul718e3742002-12-13 20:15:29 +00004510ALIAS (ipv6_bgp_network,
4511 old_ipv6_bgp_network_cmd,
4512 "ipv6 bgp network X:X::X:X/M",
4513 IPV6_STR
4514 BGP_STR
4515 "Specify a network to announce via BGP\n"
4516 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4517
4518ALIAS (no_ipv6_bgp_network,
4519 old_no_ipv6_bgp_network_cmd,
4520 "no ipv6 bgp network X:X::X:X/M",
4521 NO_STR
4522 IPV6_STR
4523 BGP_STR
4524 "Specify a network to announce via BGP\n"
4525 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4526#endif /* HAVE_IPV6 */
4527
4528/* Aggreagete address:
4529
4530 advertise-map Set condition to advertise attribute
4531 as-set Generate AS set path information
4532 attribute-map Set attributes of aggregate
4533 route-map Set parameters of aggregate
4534 summary-only Filter more specific routes from updates
4535 suppress-map Conditionally filter more specific routes from updates
4536 <cr>
4537 */
4538struct bgp_aggregate
4539{
4540 /* Summary-only flag. */
4541 u_char summary_only;
4542
4543 /* AS set generation. */
4544 u_char as_set;
4545
4546 /* Route-map for aggregated route. */
4547 struct route_map *map;
4548
4549 /* Suppress-count. */
4550 unsigned long count;
4551
4552 /* SAFI configuration. */
4553 safi_t safi;
4554};
4555
paul94f2b392005-06-28 12:44:16 +00004556static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004557bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004558{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004559 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004560}
4561
paul94f2b392005-06-28 12:44:16 +00004562static void
paul718e3742002-12-13 20:15:29 +00004563bgp_aggregate_free (struct bgp_aggregate *aggregate)
4564{
4565 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4566}
4567
paul94f2b392005-06-28 12:44:16 +00004568static void
paul718e3742002-12-13 20:15:29 +00004569bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4570 afi_t afi, safi_t safi, struct bgp_info *del,
4571 struct bgp_aggregate *aggregate)
4572{
4573 struct bgp_table *table;
4574 struct bgp_node *top;
4575 struct bgp_node *rn;
4576 u_char origin;
4577 struct aspath *aspath = NULL;
4578 struct aspath *asmerge = NULL;
4579 struct community *community = NULL;
4580 struct community *commerge = NULL;
4581 struct in_addr nexthop;
4582 u_int32_t med = 0;
4583 struct bgp_info *ri;
4584 struct bgp_info *new;
4585 int first = 1;
4586 unsigned long match = 0;
4587
4588 /* Record adding route's nexthop and med. */
4589 if (rinew)
4590 {
4591 nexthop = rinew->attr->nexthop;
4592 med = rinew->attr->med;
4593 }
4594
4595 /* ORIGIN attribute: If at least one route among routes that are
4596 aggregated has ORIGIN with the value INCOMPLETE, then the
4597 aggregated route must have the ORIGIN attribute with the value
4598 INCOMPLETE. Otherwise, if at least one route among routes that
4599 are aggregated has ORIGIN with the value EGP, then the aggregated
4600 route must have the origin attribute with the value EGP. In all
4601 other case the value of the ORIGIN attribute of the aggregated
4602 route is INTERNAL. */
4603 origin = BGP_ORIGIN_IGP;
4604
4605 table = bgp->rib[afi][safi];
4606
4607 top = bgp_node_get (table, p);
4608 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4609 if (rn->p.prefixlen > p->prefixlen)
4610 {
4611 match = 0;
4612
4613 for (ri = rn->info; ri; ri = ri->next)
4614 {
4615 if (BGP_INFO_HOLDDOWN (ri))
4616 continue;
4617
4618 if (del && ri == del)
4619 continue;
4620
4621 if (! rinew && first)
4622 {
4623 nexthop = ri->attr->nexthop;
4624 med = ri->attr->med;
4625 first = 0;
4626 }
4627
4628#ifdef AGGREGATE_NEXTHOP_CHECK
4629 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4630 || ri->attr->med != med)
4631 {
4632 if (aspath)
4633 aspath_free (aspath);
4634 if (community)
4635 community_free (community);
4636 bgp_unlock_node (rn);
4637 bgp_unlock_node (top);
4638 return;
4639 }
4640#endif /* AGGREGATE_NEXTHOP_CHECK */
4641
4642 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4643 {
4644 if (aggregate->summary_only)
4645 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004646 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004647 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004648 match++;
4649 }
4650
4651 aggregate->count++;
4652
4653 if (aggregate->as_set)
4654 {
4655 if (origin < ri->attr->origin)
4656 origin = ri->attr->origin;
4657
4658 if (aspath)
4659 {
4660 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4661 aspath_free (aspath);
4662 aspath = asmerge;
4663 }
4664 else
4665 aspath = aspath_dup (ri->attr->aspath);
4666
4667 if (ri->attr->community)
4668 {
4669 if (community)
4670 {
4671 commerge = community_merge (community,
4672 ri->attr->community);
4673 community = community_uniq_sort (commerge);
4674 community_free (commerge);
4675 }
4676 else
4677 community = community_dup (ri->attr->community);
4678 }
4679 }
4680 }
4681 }
4682 if (match)
4683 bgp_process (bgp, rn, afi, safi);
4684 }
4685 bgp_unlock_node (top);
4686
4687 if (rinew)
4688 {
4689 aggregate->count++;
4690
4691 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004692 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004693
4694 if (aggregate->as_set)
4695 {
4696 if (origin < rinew->attr->origin)
4697 origin = rinew->attr->origin;
4698
4699 if (aspath)
4700 {
4701 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4702 aspath_free (aspath);
4703 aspath = asmerge;
4704 }
4705 else
4706 aspath = aspath_dup (rinew->attr->aspath);
4707
4708 if (rinew->attr->community)
4709 {
4710 if (community)
4711 {
4712 commerge = community_merge (community,
4713 rinew->attr->community);
4714 community = community_uniq_sort (commerge);
4715 community_free (commerge);
4716 }
4717 else
4718 community = community_dup (rinew->attr->community);
4719 }
4720 }
4721 }
4722
4723 if (aggregate->count > 0)
4724 {
4725 rn = bgp_node_get (table, p);
4726 new = bgp_info_new ();
4727 new->type = ZEBRA_ROUTE_BGP;
4728 new->sub_type = BGP_ROUTE_AGGREGATE;
4729 new->peer = bgp->peer_self;
4730 SET_FLAG (new->flags, BGP_INFO_VALID);
4731 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004732 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004733
4734 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004735 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004736 bgp_process (bgp, rn, afi, safi);
4737 }
4738 else
4739 {
4740 if (aspath)
4741 aspath_free (aspath);
4742 if (community)
4743 community_free (community);
4744 }
4745}
4746
4747void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4748 struct bgp_aggregate *);
4749
4750void
4751bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4752 struct bgp_info *ri, afi_t afi, safi_t safi)
4753{
4754 struct bgp_node *child;
4755 struct bgp_node *rn;
4756 struct bgp_aggregate *aggregate;
4757
4758 /* MPLS-VPN aggregation is not yet supported. */
4759 if (safi == SAFI_MPLS_VPN)
4760 return;
4761
4762 if (p->prefixlen == 0)
4763 return;
4764
4765 if (BGP_INFO_HOLDDOWN (ri))
4766 return;
4767
4768 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4769
4770 /* Aggregate address configuration check. */
4771 for (rn = child; rn; rn = rn->parent)
4772 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4773 {
4774 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004775 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004776 }
4777 bgp_unlock_node (child);
4778}
4779
4780void
4781bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4782 struct bgp_info *del, afi_t afi, safi_t safi)
4783{
4784 struct bgp_node *child;
4785 struct bgp_node *rn;
4786 struct bgp_aggregate *aggregate;
4787
4788 /* MPLS-VPN aggregation is not yet supported. */
4789 if (safi == SAFI_MPLS_VPN)
4790 return;
4791
4792 if (p->prefixlen == 0)
4793 return;
4794
4795 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4796
4797 /* Aggregate address configuration check. */
4798 for (rn = child; rn; rn = rn->parent)
4799 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4800 {
4801 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004802 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004803 }
4804 bgp_unlock_node (child);
4805}
4806
paul94f2b392005-06-28 12:44:16 +00004807static void
paul718e3742002-12-13 20:15:29 +00004808bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4809 struct bgp_aggregate *aggregate)
4810{
4811 struct bgp_table *table;
4812 struct bgp_node *top;
4813 struct bgp_node *rn;
4814 struct bgp_info *new;
4815 struct bgp_info *ri;
4816 unsigned long match;
4817 u_char origin = BGP_ORIGIN_IGP;
4818 struct aspath *aspath = NULL;
4819 struct aspath *asmerge = NULL;
4820 struct community *community = NULL;
4821 struct community *commerge = NULL;
4822
4823 table = bgp->rib[afi][safi];
4824
4825 /* Sanity check. */
4826 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4827 return;
4828 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4829 return;
4830
4831 /* If routes exists below this node, generate aggregate routes. */
4832 top = bgp_node_get (table, p);
4833 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4834 if (rn->p.prefixlen > p->prefixlen)
4835 {
4836 match = 0;
4837
4838 for (ri = rn->info; ri; ri = ri->next)
4839 {
4840 if (BGP_INFO_HOLDDOWN (ri))
4841 continue;
4842
4843 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4844 {
4845 /* summary-only aggregate route suppress aggregated
4846 route announcement. */
4847 if (aggregate->summary_only)
4848 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004849 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004850 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004851 match++;
4852 }
4853 /* as-set aggregate route generate origin, as path,
4854 community aggregation. */
4855 if (aggregate->as_set)
4856 {
4857 if (origin < ri->attr->origin)
4858 origin = ri->attr->origin;
4859
4860 if (aspath)
4861 {
4862 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4863 aspath_free (aspath);
4864 aspath = asmerge;
4865 }
4866 else
4867 aspath = aspath_dup (ri->attr->aspath);
4868
4869 if (ri->attr->community)
4870 {
4871 if (community)
4872 {
4873 commerge = community_merge (community,
4874 ri->attr->community);
4875 community = community_uniq_sort (commerge);
4876 community_free (commerge);
4877 }
4878 else
4879 community = community_dup (ri->attr->community);
4880 }
4881 }
4882 aggregate->count++;
4883 }
4884 }
4885
4886 /* If this node is suppressed, process the change. */
4887 if (match)
4888 bgp_process (bgp, rn, afi, safi);
4889 }
4890 bgp_unlock_node (top);
4891
4892 /* Add aggregate route to BGP table. */
4893 if (aggregate->count)
4894 {
4895 rn = bgp_node_get (table, p);
4896
4897 new = bgp_info_new ();
4898 new->type = ZEBRA_ROUTE_BGP;
4899 new->sub_type = BGP_ROUTE_AGGREGATE;
4900 new->peer = bgp->peer_self;
4901 SET_FLAG (new->flags, BGP_INFO_VALID);
4902 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004903 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004904
4905 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004906 bgp_unlock_node (rn);
4907
paul718e3742002-12-13 20:15:29 +00004908 /* Process change. */
4909 bgp_process (bgp, rn, afi, safi);
4910 }
4911}
4912
4913void
4914bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4915 safi_t safi, struct bgp_aggregate *aggregate)
4916{
4917 struct bgp_table *table;
4918 struct bgp_node *top;
4919 struct bgp_node *rn;
4920 struct bgp_info *ri;
4921 unsigned long match;
4922
4923 table = bgp->rib[afi][safi];
4924
4925 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4926 return;
4927 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4928 return;
4929
4930 /* If routes exists below this node, generate aggregate routes. */
4931 top = bgp_node_get (table, p);
4932 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4933 if (rn->p.prefixlen > p->prefixlen)
4934 {
4935 match = 0;
4936
4937 for (ri = rn->info; ri; ri = ri->next)
4938 {
4939 if (BGP_INFO_HOLDDOWN (ri))
4940 continue;
4941
4942 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4943 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004944 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004945 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004946 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004947
Paul Jakmafb982c22007-05-04 20:15:47 +00004948 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004949 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004950 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004951 match++;
4952 }
4953 }
4954 aggregate->count--;
4955 }
4956 }
4957
Paul Jakmafb982c22007-05-04 20:15:47 +00004958 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004959 if (match)
4960 bgp_process (bgp, rn, afi, safi);
4961 }
4962 bgp_unlock_node (top);
4963
4964 /* Delete aggregate route from BGP table. */
4965 rn = bgp_node_get (table, p);
4966
4967 for (ri = rn->info; ri; ri = ri->next)
4968 if (ri->peer == bgp->peer_self
4969 && ri->type == ZEBRA_ROUTE_BGP
4970 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4971 break;
4972
4973 /* Withdraw static BGP route from routing table. */
4974 if (ri)
4975 {
paul718e3742002-12-13 20:15:29 +00004976 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004977 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004978 }
4979
4980 /* Unlock bgp_node_lookup. */
4981 bgp_unlock_node (rn);
4982}
4983
4984/* Aggregate route attribute. */
4985#define AGGREGATE_SUMMARY_ONLY 1
4986#define AGGREGATE_AS_SET 1
4987
paul94f2b392005-06-28 12:44:16 +00004988static int
Robert Baysf6269b42010-08-05 10:26:28 -07004989bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4990 afi_t afi, safi_t safi)
4991{
4992 int ret;
4993 struct prefix p;
4994 struct bgp_node *rn;
4995 struct bgp *bgp;
4996 struct bgp_aggregate *aggregate;
4997
4998 /* Convert string to prefix structure. */
4999 ret = str2prefix (prefix_str, &p);
5000 if (!ret)
5001 {
5002 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5003 return CMD_WARNING;
5004 }
5005 apply_mask (&p);
5006
5007 /* Get BGP structure. */
5008 bgp = vty->index;
5009
5010 /* Old configuration check. */
5011 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5012 if (! rn)
5013 {
5014 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5015 VTY_NEWLINE);
5016 return CMD_WARNING;
5017 }
5018
5019 aggregate = rn->info;
5020 if (aggregate->safi & SAFI_UNICAST)
5021 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5022 if (aggregate->safi & SAFI_MULTICAST)
5023 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5024
5025 /* Unlock aggregate address configuration. */
5026 rn->info = NULL;
5027 bgp_aggregate_free (aggregate);
5028 bgp_unlock_node (rn);
5029 bgp_unlock_node (rn);
5030
5031 return CMD_SUCCESS;
5032}
5033
5034static int
5035bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005036 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005037 u_char summary_only, u_char as_set)
5038{
5039 int ret;
5040 struct prefix p;
5041 struct bgp_node *rn;
5042 struct bgp *bgp;
5043 struct bgp_aggregate *aggregate;
5044
5045 /* Convert string to prefix structure. */
5046 ret = str2prefix (prefix_str, &p);
5047 if (!ret)
5048 {
5049 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5050 return CMD_WARNING;
5051 }
5052 apply_mask (&p);
5053
5054 /* Get BGP structure. */
5055 bgp = vty->index;
5056
5057 /* Old configuration check. */
5058 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5059
5060 if (rn->info)
5061 {
5062 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005063 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005064 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5065 if (ret)
5066 {
Robert Bays368473f2010-08-05 10:26:29 -07005067 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5068 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005069 return CMD_WARNING;
5070 }
paul718e3742002-12-13 20:15:29 +00005071 }
5072
5073 /* Make aggregate address structure. */
5074 aggregate = bgp_aggregate_new ();
5075 aggregate->summary_only = summary_only;
5076 aggregate->as_set = as_set;
5077 aggregate->safi = safi;
5078 rn->info = aggregate;
5079
5080 /* Aggregate address insert into BGP routing table. */
5081 if (safi & SAFI_UNICAST)
5082 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5083 if (safi & SAFI_MULTICAST)
5084 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5085
5086 return CMD_SUCCESS;
5087}
5088
paul718e3742002-12-13 20:15:29 +00005089DEFUN (aggregate_address,
5090 aggregate_address_cmd,
5091 "aggregate-address A.B.C.D/M",
5092 "Configure BGP aggregate entries\n"
5093 "Aggregate prefix\n")
5094{
5095 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5096}
5097
5098DEFUN (aggregate_address_mask,
5099 aggregate_address_mask_cmd,
5100 "aggregate-address A.B.C.D A.B.C.D",
5101 "Configure BGP aggregate entries\n"
5102 "Aggregate address\n"
5103 "Aggregate mask\n")
5104{
5105 int ret;
5106 char prefix_str[BUFSIZ];
5107
5108 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5109
5110 if (! ret)
5111 {
5112 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5113 return CMD_WARNING;
5114 }
5115
5116 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5117 0, 0);
5118}
5119
5120DEFUN (aggregate_address_summary_only,
5121 aggregate_address_summary_only_cmd,
5122 "aggregate-address A.B.C.D/M summary-only",
5123 "Configure BGP aggregate entries\n"
5124 "Aggregate prefix\n"
5125 "Filter more specific routes from updates\n")
5126{
5127 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5128 AGGREGATE_SUMMARY_ONLY, 0);
5129}
5130
5131DEFUN (aggregate_address_mask_summary_only,
5132 aggregate_address_mask_summary_only_cmd,
5133 "aggregate-address A.B.C.D A.B.C.D summary-only",
5134 "Configure BGP aggregate entries\n"
5135 "Aggregate address\n"
5136 "Aggregate mask\n"
5137 "Filter more specific routes from updates\n")
5138{
5139 int ret;
5140 char prefix_str[BUFSIZ];
5141
5142 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5143
5144 if (! ret)
5145 {
5146 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5147 return CMD_WARNING;
5148 }
5149
5150 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5151 AGGREGATE_SUMMARY_ONLY, 0);
5152}
5153
5154DEFUN (aggregate_address_as_set,
5155 aggregate_address_as_set_cmd,
5156 "aggregate-address A.B.C.D/M as-set",
5157 "Configure BGP aggregate entries\n"
5158 "Aggregate prefix\n"
5159 "Generate AS set path information\n")
5160{
5161 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5162 0, AGGREGATE_AS_SET);
5163}
5164
5165DEFUN (aggregate_address_mask_as_set,
5166 aggregate_address_mask_as_set_cmd,
5167 "aggregate-address A.B.C.D A.B.C.D as-set",
5168 "Configure BGP aggregate entries\n"
5169 "Aggregate address\n"
5170 "Aggregate mask\n"
5171 "Generate AS set path information\n")
5172{
5173 int ret;
5174 char prefix_str[BUFSIZ];
5175
5176 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5177
5178 if (! ret)
5179 {
5180 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5181 return CMD_WARNING;
5182 }
5183
5184 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5185 0, AGGREGATE_AS_SET);
5186}
5187
5188
5189DEFUN (aggregate_address_as_set_summary,
5190 aggregate_address_as_set_summary_cmd,
5191 "aggregate-address A.B.C.D/M as-set summary-only",
5192 "Configure BGP aggregate entries\n"
5193 "Aggregate prefix\n"
5194 "Generate AS set path information\n"
5195 "Filter more specific routes from updates\n")
5196{
5197 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5198 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5199}
5200
5201ALIAS (aggregate_address_as_set_summary,
5202 aggregate_address_summary_as_set_cmd,
5203 "aggregate-address A.B.C.D/M summary-only as-set",
5204 "Configure BGP aggregate entries\n"
5205 "Aggregate prefix\n"
5206 "Filter more specific routes from updates\n"
5207 "Generate AS set path information\n")
5208
5209DEFUN (aggregate_address_mask_as_set_summary,
5210 aggregate_address_mask_as_set_summary_cmd,
5211 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5212 "Configure BGP aggregate entries\n"
5213 "Aggregate address\n"
5214 "Aggregate mask\n"
5215 "Generate AS set path information\n"
5216 "Filter more specific routes from updates\n")
5217{
5218 int ret;
5219 char prefix_str[BUFSIZ];
5220
5221 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5222
5223 if (! ret)
5224 {
5225 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5226 return CMD_WARNING;
5227 }
5228
5229 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5230 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5231}
5232
5233ALIAS (aggregate_address_mask_as_set_summary,
5234 aggregate_address_mask_summary_as_set_cmd,
5235 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5236 "Configure BGP aggregate entries\n"
5237 "Aggregate address\n"
5238 "Aggregate mask\n"
5239 "Filter more specific routes from updates\n"
5240 "Generate AS set path information\n")
5241
5242DEFUN (no_aggregate_address,
5243 no_aggregate_address_cmd,
5244 "no aggregate-address A.B.C.D/M",
5245 NO_STR
5246 "Configure BGP aggregate entries\n"
5247 "Aggregate prefix\n")
5248{
5249 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5250}
5251
5252ALIAS (no_aggregate_address,
5253 no_aggregate_address_summary_only_cmd,
5254 "no aggregate-address A.B.C.D/M summary-only",
5255 NO_STR
5256 "Configure BGP aggregate entries\n"
5257 "Aggregate prefix\n"
5258 "Filter more specific routes from updates\n")
5259
5260ALIAS (no_aggregate_address,
5261 no_aggregate_address_as_set_cmd,
5262 "no aggregate-address A.B.C.D/M as-set",
5263 NO_STR
5264 "Configure BGP aggregate entries\n"
5265 "Aggregate prefix\n"
5266 "Generate AS set path information\n")
5267
5268ALIAS (no_aggregate_address,
5269 no_aggregate_address_as_set_summary_cmd,
5270 "no aggregate-address A.B.C.D/M as-set summary-only",
5271 NO_STR
5272 "Configure BGP aggregate entries\n"
5273 "Aggregate prefix\n"
5274 "Generate AS set path information\n"
5275 "Filter more specific routes from updates\n")
5276
5277ALIAS (no_aggregate_address,
5278 no_aggregate_address_summary_as_set_cmd,
5279 "no aggregate-address A.B.C.D/M summary-only as-set",
5280 NO_STR
5281 "Configure BGP aggregate entries\n"
5282 "Aggregate prefix\n"
5283 "Filter more specific routes from updates\n"
5284 "Generate AS set path information\n")
5285
5286DEFUN (no_aggregate_address_mask,
5287 no_aggregate_address_mask_cmd,
5288 "no aggregate-address A.B.C.D A.B.C.D",
5289 NO_STR
5290 "Configure BGP aggregate entries\n"
5291 "Aggregate address\n"
5292 "Aggregate mask\n")
5293{
5294 int ret;
5295 char prefix_str[BUFSIZ];
5296
5297 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5298
5299 if (! ret)
5300 {
5301 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5302 return CMD_WARNING;
5303 }
5304
5305 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5306}
5307
5308ALIAS (no_aggregate_address_mask,
5309 no_aggregate_address_mask_summary_only_cmd,
5310 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5311 NO_STR
5312 "Configure BGP aggregate entries\n"
5313 "Aggregate address\n"
5314 "Aggregate mask\n"
5315 "Filter more specific routes from updates\n")
5316
5317ALIAS (no_aggregate_address_mask,
5318 no_aggregate_address_mask_as_set_cmd,
5319 "no aggregate-address A.B.C.D A.B.C.D as-set",
5320 NO_STR
5321 "Configure BGP aggregate entries\n"
5322 "Aggregate address\n"
5323 "Aggregate mask\n"
5324 "Generate AS set path information\n")
5325
5326ALIAS (no_aggregate_address_mask,
5327 no_aggregate_address_mask_as_set_summary_cmd,
5328 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5329 NO_STR
5330 "Configure BGP aggregate entries\n"
5331 "Aggregate address\n"
5332 "Aggregate mask\n"
5333 "Generate AS set path information\n"
5334 "Filter more specific routes from updates\n")
5335
5336ALIAS (no_aggregate_address_mask,
5337 no_aggregate_address_mask_summary_as_set_cmd,
5338 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5339 NO_STR
5340 "Configure BGP aggregate entries\n"
5341 "Aggregate address\n"
5342 "Aggregate mask\n"
5343 "Filter more specific routes from updates\n"
5344 "Generate AS set path information\n")
5345
5346#ifdef HAVE_IPV6
5347DEFUN (ipv6_aggregate_address,
5348 ipv6_aggregate_address_cmd,
5349 "aggregate-address X:X::X:X/M",
5350 "Configure BGP aggregate entries\n"
5351 "Aggregate prefix\n")
5352{
5353 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5354}
5355
5356DEFUN (ipv6_aggregate_address_summary_only,
5357 ipv6_aggregate_address_summary_only_cmd,
5358 "aggregate-address X:X::X:X/M summary-only",
5359 "Configure BGP aggregate entries\n"
5360 "Aggregate prefix\n"
5361 "Filter more specific routes from updates\n")
5362{
5363 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5364 AGGREGATE_SUMMARY_ONLY, 0);
5365}
5366
5367DEFUN (no_ipv6_aggregate_address,
5368 no_ipv6_aggregate_address_cmd,
5369 "no aggregate-address X:X::X:X/M",
5370 NO_STR
5371 "Configure BGP aggregate entries\n"
5372 "Aggregate prefix\n")
5373{
5374 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5375}
5376
5377DEFUN (no_ipv6_aggregate_address_summary_only,
5378 no_ipv6_aggregate_address_summary_only_cmd,
5379 "no aggregate-address X:X::X:X/M summary-only",
5380 NO_STR
5381 "Configure BGP aggregate entries\n"
5382 "Aggregate prefix\n"
5383 "Filter more specific routes from updates\n")
5384{
5385 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5386}
5387
5388ALIAS (ipv6_aggregate_address,
5389 old_ipv6_aggregate_address_cmd,
5390 "ipv6 bgp aggregate-address X:X::X:X/M",
5391 IPV6_STR
5392 BGP_STR
5393 "Configure BGP aggregate entries\n"
5394 "Aggregate prefix\n")
5395
5396ALIAS (ipv6_aggregate_address_summary_only,
5397 old_ipv6_aggregate_address_summary_only_cmd,
5398 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5399 IPV6_STR
5400 BGP_STR
5401 "Configure BGP aggregate entries\n"
5402 "Aggregate prefix\n"
5403 "Filter more specific routes from updates\n")
5404
5405ALIAS (no_ipv6_aggregate_address,
5406 old_no_ipv6_aggregate_address_cmd,
5407 "no ipv6 bgp aggregate-address X:X::X:X/M",
5408 NO_STR
5409 IPV6_STR
5410 BGP_STR
5411 "Configure BGP aggregate entries\n"
5412 "Aggregate prefix\n")
5413
5414ALIAS (no_ipv6_aggregate_address_summary_only,
5415 old_no_ipv6_aggregate_address_summary_only_cmd,
5416 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5417 NO_STR
5418 IPV6_STR
5419 BGP_STR
5420 "Configure BGP aggregate entries\n"
5421 "Aggregate prefix\n"
5422 "Filter more specific routes from updates\n")
5423#endif /* HAVE_IPV6 */
5424
5425/* Redistribute route treatment. */
5426void
5427bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5428 u_int32_t metric, u_char type)
5429{
5430 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005431 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005432 struct bgp_info *new;
5433 struct bgp_info *bi;
5434 struct bgp_info info;
5435 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005436 struct attr attr = { 0 };
5437 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005438 struct attr *new_attr;
5439 afi_t afi;
5440 int ret;
5441
5442 /* Make default attribute. */
5443 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5444 if (nexthop)
5445 attr.nexthop = *nexthop;
5446
5447 attr.med = metric;
5448 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5449
paul1eb8ef22005-04-07 07:30:20 +00005450 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005451 {
5452 afi = family2afi (p->family);
5453
5454 if (bgp->redist[afi][type])
5455 {
5456 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005457 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005458
5459 if (bgp->redist_metric_flag[afi][type])
5460 attr_new.med = bgp->redist_metric[afi][type];
5461
5462 /* Apply route-map. */
5463 if (bgp->rmap[afi][type].map)
5464 {
5465 info.peer = bgp->peer_self;
5466 info.attr = &attr_new;
5467
paulfee0f4c2004-09-13 05:12:46 +00005468 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5469
paul718e3742002-12-13 20:15:29 +00005470 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5471 &info);
paulfee0f4c2004-09-13 05:12:46 +00005472
5473 bgp->peer_self->rmap_type = 0;
5474
paul718e3742002-12-13 20:15:29 +00005475 if (ret == RMAP_DENYMATCH)
5476 {
5477 /* Free uninterned attribute. */
5478 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005479 bgp_attr_extra_free (&attr_new);
5480
paul718e3742002-12-13 20:15:29 +00005481 /* Unintern original. */
5482 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005483 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005484 bgp_redistribute_delete (p, type);
5485 return;
5486 }
5487 }
5488
Paul Jakmafb982c22007-05-04 20:15:47 +00005489 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5490 afi, SAFI_UNICAST, p, NULL);
5491
paul718e3742002-12-13 20:15:29 +00005492 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005493 bgp_attr_extra_free (&attr_new);
5494
paul718e3742002-12-13 20:15:29 +00005495 for (bi = bn->info; bi; bi = bi->next)
5496 if (bi->peer == bgp->peer_self
5497 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5498 break;
5499
5500 if (bi)
5501 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005502 if (attrhash_cmp (bi->attr, new_attr) &&
5503 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005504 {
5505 bgp_attr_unintern (new_attr);
5506 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005507 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005508 bgp_unlock_node (bn);
5509 return;
5510 }
5511 else
5512 {
5513 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005514 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005515
5516 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005517 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5518 bgp_info_restore(bn, bi);
5519 else
5520 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005521 bgp_attr_unintern (bi->attr);
5522 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005523 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005524
5525 /* Process change. */
5526 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5527 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5528 bgp_unlock_node (bn);
5529 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005530 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005531 return;
5532 }
5533 }
5534
5535 new = bgp_info_new ();
5536 new->type = type;
5537 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5538 new->peer = bgp->peer_self;
5539 SET_FLAG (new->flags, BGP_INFO_VALID);
5540 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005541 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005542
5543 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5544 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005545 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005546 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5547 }
5548 }
5549
5550 /* Unintern original. */
5551 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005552 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005553}
5554
5555void
5556bgp_redistribute_delete (struct prefix *p, u_char type)
5557{
5558 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005559 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005560 afi_t afi;
5561 struct bgp_node *rn;
5562 struct bgp_info *ri;
5563
paul1eb8ef22005-04-07 07:30:20 +00005564 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005565 {
5566 afi = family2afi (p->family);
5567
5568 if (bgp->redist[afi][type])
5569 {
paulfee0f4c2004-09-13 05:12:46 +00005570 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005571
5572 for (ri = rn->info; ri; ri = ri->next)
5573 if (ri->peer == bgp->peer_self
5574 && ri->type == type)
5575 break;
5576
5577 if (ri)
5578 {
5579 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005580 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005581 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005582 }
5583 bgp_unlock_node (rn);
5584 }
5585 }
5586}
5587
5588/* Withdraw specified route type's route. */
5589void
5590bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5591{
5592 struct bgp_node *rn;
5593 struct bgp_info *ri;
5594 struct bgp_table *table;
5595
5596 table = bgp->rib[afi][SAFI_UNICAST];
5597
5598 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5599 {
5600 for (ri = rn->info; ri; ri = ri->next)
5601 if (ri->peer == bgp->peer_self
5602 && ri->type == type)
5603 break;
5604
5605 if (ri)
5606 {
5607 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005608 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005609 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005610 }
5611 }
5612}
5613
5614/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005615static void
paul718e3742002-12-13 20:15:29 +00005616route_vty_out_route (struct prefix *p, struct vty *vty)
5617{
5618 int len;
5619 u_int32_t destination;
5620 char buf[BUFSIZ];
5621
5622 if (p->family == AF_INET)
5623 {
5624 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5625 destination = ntohl (p->u.prefix4.s_addr);
5626
5627 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5628 || (IN_CLASSB (destination) && p->prefixlen == 16)
5629 || (IN_CLASSA (destination) && p->prefixlen == 8)
5630 || p->u.prefix4.s_addr == 0)
5631 {
5632 /* When mask is natural, mask is not displayed. */
5633 }
5634 else
5635 len += vty_out (vty, "/%d", p->prefixlen);
5636 }
5637 else
5638 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5639 p->prefixlen);
5640
5641 len = 17 - len;
5642 if (len < 1)
5643 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5644 else
5645 vty_out (vty, "%*s", len, " ");
5646}
5647
paul718e3742002-12-13 20:15:29 +00005648enum bgp_display_type
5649{
5650 normal_list,
5651};
5652
paulb40d9392005-08-22 22:34:41 +00005653/* Print the short form route status for a bgp_info */
5654static void
5655route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005656{
paulb40d9392005-08-22 22:34:41 +00005657 /* Route status display. */
5658 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5659 vty_out (vty, "R");
5660 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005661 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005662 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005663 vty_out (vty, "s");
5664 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5665 vty_out (vty, "*");
5666 else
5667 vty_out (vty, " ");
5668
5669 /* Selected */
5670 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5671 vty_out (vty, "h");
5672 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5673 vty_out (vty, "d");
5674 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5675 vty_out (vty, ">");
5676 else
5677 vty_out (vty, " ");
5678
5679 /* Internal route. */
5680 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5681 vty_out (vty, "i");
5682 else
paulb40d9392005-08-22 22:34:41 +00005683 vty_out (vty, " ");
5684}
5685
5686/* called from terminal list command */
5687void
5688route_vty_out (struct vty *vty, struct prefix *p,
5689 struct bgp_info *binfo, int display, safi_t safi)
5690{
5691 struct attr *attr;
5692
5693 /* short status lead text */
5694 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005695
5696 /* print prefix and mask */
5697 if (! display)
5698 route_vty_out_route (p, vty);
5699 else
5700 vty_out (vty, "%*s", 17, " ");
5701
5702 /* Print attribute */
5703 attr = binfo->attr;
5704 if (attr)
5705 {
5706 if (p->family == AF_INET)
5707 {
5708 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005709 vty_out (vty, "%-16s",
5710 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005711 else
5712 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5713 }
5714#ifdef HAVE_IPV6
5715 else if (p->family == AF_INET6)
5716 {
5717 int len;
5718 char buf[BUFSIZ];
5719
5720 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005721 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5722 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005723 len = 16 - len;
5724 if (len < 1)
5725 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5726 else
5727 vty_out (vty, "%*s", len, " ");
5728 }
5729#endif /* HAVE_IPV6 */
5730
5731 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5732 vty_out (vty, "%10d", attr->med);
5733 else
5734 vty_out (vty, " ");
5735
5736 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5737 vty_out (vty, "%7d", attr->local_pref);
5738 else
5739 vty_out (vty, " ");
5740
Paul Jakmafb982c22007-05-04 20:15:47 +00005741 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005742
Paul Jakmab2518c12006-05-12 23:48:40 +00005743 /* Print aspath */
5744 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005745 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005746
Paul Jakmab2518c12006-05-12 23:48:40 +00005747 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005748 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005749 }
paul718e3742002-12-13 20:15:29 +00005750 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005751}
5752
5753/* called from terminal list command */
5754void
5755route_vty_out_tmp (struct vty *vty, struct prefix *p,
5756 struct attr *attr, safi_t safi)
5757{
5758 /* Route status display. */
5759 vty_out (vty, "*");
5760 vty_out (vty, ">");
5761 vty_out (vty, " ");
5762
5763 /* print prefix and mask */
5764 route_vty_out_route (p, vty);
5765
5766 /* Print attribute */
5767 if (attr)
5768 {
5769 if (p->family == AF_INET)
5770 {
5771 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005772 vty_out (vty, "%-16s",
5773 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005774 else
5775 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5776 }
5777#ifdef HAVE_IPV6
5778 else if (p->family == AF_INET6)
5779 {
5780 int len;
5781 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005782
5783 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005784
5785 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005786 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5787 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005788 len = 16 - len;
5789 if (len < 1)
5790 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5791 else
5792 vty_out (vty, "%*s", len, " ");
5793 }
5794#endif /* HAVE_IPV6 */
5795
5796 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5797 vty_out (vty, "%10d", attr->med);
5798 else
5799 vty_out (vty, " ");
5800
5801 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5802 vty_out (vty, "%7d", attr->local_pref);
5803 else
5804 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005805
5806 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5807
Paul Jakmab2518c12006-05-12 23:48:40 +00005808 /* Print aspath */
5809 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005810 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005811
Paul Jakmab2518c12006-05-12 23:48:40 +00005812 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005813 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005814 }
paul718e3742002-12-13 20:15:29 +00005815
5816 vty_out (vty, "%s", VTY_NEWLINE);
5817}
5818
ajs5a646652004-11-05 01:25:55 +00005819void
paul718e3742002-12-13 20:15:29 +00005820route_vty_out_tag (struct vty *vty, struct prefix *p,
5821 struct bgp_info *binfo, int display, safi_t safi)
5822{
5823 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005824 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005825
5826 if (!binfo->extra)
5827 return;
5828
paulb40d9392005-08-22 22:34:41 +00005829 /* short status lead text */
5830 route_vty_short_status_out (vty, binfo);
5831
paul718e3742002-12-13 20:15:29 +00005832 /* print prefix and mask */
5833 if (! display)
5834 route_vty_out_route (p, vty);
5835 else
5836 vty_out (vty, "%*s", 17, " ");
5837
5838 /* Print attribute */
5839 attr = binfo->attr;
5840 if (attr)
5841 {
5842 if (p->family == AF_INET)
5843 {
5844 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005845 vty_out (vty, "%-16s",
5846 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005847 else
5848 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5849 }
5850#ifdef HAVE_IPV6
5851 else if (p->family == AF_INET6)
5852 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005853 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005854 char buf[BUFSIZ];
5855 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005856 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005857 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005858 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5859 buf, BUFSIZ));
5860 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005861 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005862 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5863 buf, BUFSIZ),
5864 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5865 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005866
5867 }
5868#endif /* HAVE_IPV6 */
5869 }
5870
Paul Jakmafb982c22007-05-04 20:15:47 +00005871 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005872
5873 vty_out (vty, "notag/%d", label);
5874
5875 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005876}
5877
5878/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005879static void
paul718e3742002-12-13 20:15:29 +00005880damp_route_vty_out (struct vty *vty, struct prefix *p,
5881 struct bgp_info *binfo, int display, safi_t safi)
5882{
5883 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005884 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005885 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005886
paulb40d9392005-08-22 22:34:41 +00005887 /* short status lead text */
5888 route_vty_short_status_out (vty, binfo);
5889
paul718e3742002-12-13 20:15:29 +00005890 /* print prefix and mask */
5891 if (! display)
5892 route_vty_out_route (p, vty);
5893 else
5894 vty_out (vty, "%*s", 17, " ");
5895
5896 len = vty_out (vty, "%s", binfo->peer->host);
5897 len = 17 - len;
5898 if (len < 1)
5899 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5900 else
5901 vty_out (vty, "%*s", len, " ");
5902
Chris Caputo50aef6f2009-06-23 06:06:49 +00005903 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005904
5905 /* Print attribute */
5906 attr = binfo->attr;
5907 if (attr)
5908 {
5909 /* Print aspath */
5910 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005911 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005912
5913 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005914 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005915 }
5916 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005917}
5918
paul718e3742002-12-13 20:15:29 +00005919/* flap route */
ajs5a646652004-11-05 01:25:55 +00005920static void
paul718e3742002-12-13 20:15:29 +00005921flap_route_vty_out (struct vty *vty, struct prefix *p,
5922 struct bgp_info *binfo, int display, safi_t safi)
5923{
5924 struct attr *attr;
5925 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005926 char timebuf[BGP_UPTIME_LEN];
5927 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005928
5929 if (!binfo->extra)
5930 return;
5931
5932 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005933
paulb40d9392005-08-22 22:34:41 +00005934 /* short status lead text */
5935 route_vty_short_status_out (vty, binfo);
5936
paul718e3742002-12-13 20:15:29 +00005937 /* print prefix and mask */
5938 if (! display)
5939 route_vty_out_route (p, vty);
5940 else
5941 vty_out (vty, "%*s", 17, " ");
5942
5943 len = vty_out (vty, "%s", binfo->peer->host);
5944 len = 16 - len;
5945 if (len < 1)
5946 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5947 else
5948 vty_out (vty, "%*s", len, " ");
5949
5950 len = vty_out (vty, "%d", bdi->flap);
5951 len = 5 - len;
5952 if (len < 1)
5953 vty_out (vty, " ");
5954 else
5955 vty_out (vty, "%*s ", len, " ");
5956
5957 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5958 timebuf, BGP_UPTIME_LEN));
5959
5960 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5961 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005962 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005963 else
5964 vty_out (vty, "%*s ", 8, " ");
5965
5966 /* Print attribute */
5967 attr = binfo->attr;
5968 if (attr)
5969 {
5970 /* Print aspath */
5971 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005972 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005973
5974 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005975 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005976 }
5977 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005978}
5979
paul94f2b392005-06-28 12:44:16 +00005980static void
paul718e3742002-12-13 20:15:29 +00005981route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5982 struct bgp_info *binfo, afi_t afi, safi_t safi)
5983{
5984 char buf[INET6_ADDRSTRLEN];
5985 char buf1[BUFSIZ];
5986 struct attr *attr;
5987 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005988#ifdef HAVE_CLOCK_MONOTONIC
5989 time_t tbuf;
5990#endif
paul718e3742002-12-13 20:15:29 +00005991
5992 attr = binfo->attr;
5993
5994 if (attr)
5995 {
5996 /* Line1 display AS-path, Aggregator */
5997 if (attr->aspath)
5998 {
5999 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006000 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006001 vty_out (vty, "Local");
6002 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006003 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006004 }
6005
paulb40d9392005-08-22 22:34:41 +00006006 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6007 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006008 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6009 vty_out (vty, ", (stale)");
6010 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006011 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006012 attr->extra->aggregator_as,
6013 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006014 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6015 vty_out (vty, ", (Received from a RR-client)");
6016 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6017 vty_out (vty, ", (Received from a RS-client)");
6018 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6019 vty_out (vty, ", (history entry)");
6020 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6021 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006022 vty_out (vty, "%s", VTY_NEWLINE);
6023
6024 /* Line2 display Next-hop, Neighbor, Router-id */
6025 if (p->family == AF_INET)
6026 {
6027 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006028 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006029 inet_ntoa (attr->nexthop));
6030 }
6031#ifdef HAVE_IPV6
6032 else
6033 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006034 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006035 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006036 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006037 buf, INET6_ADDRSTRLEN));
6038 }
6039#endif /* HAVE_IPV6 */
6040
6041 if (binfo->peer == bgp->peer_self)
6042 {
6043 vty_out (vty, " from %s ",
6044 p->family == AF_INET ? "0.0.0.0" : "::");
6045 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6046 }
6047 else
6048 {
6049 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6050 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006051 else if (binfo->extra && binfo->extra->igpmetric)
6052 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006053 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006054 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006055 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006056 else
6057 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6058 }
6059 vty_out (vty, "%s", VTY_NEWLINE);
6060
6061#ifdef HAVE_IPV6
6062 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006063 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006064 {
6065 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006066 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006067 buf, INET6_ADDRSTRLEN),
6068 VTY_NEWLINE);
6069 }
6070#endif /* HAVE_IPV6 */
6071
6072 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6073 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6074
6075 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6076 vty_out (vty, ", metric %d", attr->med);
6077
6078 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6079 vty_out (vty, ", localpref %d", attr->local_pref);
6080 else
6081 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6082
Paul Jakmafb982c22007-05-04 20:15:47 +00006083 if (attr->extra && attr->extra->weight != 0)
6084 vty_out (vty, ", weight %d", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006085
6086 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6087 vty_out (vty, ", valid");
6088
6089 if (binfo->peer != bgp->peer_self)
6090 {
6091 if (binfo->peer->as == binfo->peer->local_as)
6092 vty_out (vty, ", internal");
6093 else
6094 vty_out (vty, ", %s",
6095 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6096 }
6097 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6098 vty_out (vty, ", aggregated, local");
6099 else if (binfo->type != ZEBRA_ROUTE_BGP)
6100 vty_out (vty, ", sourced");
6101 else
6102 vty_out (vty, ", sourced, local");
6103
6104 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6105 vty_out (vty, ", atomic-aggregate");
6106
6107 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6108 vty_out (vty, ", best");
6109
6110 vty_out (vty, "%s", VTY_NEWLINE);
6111
6112 /* Line 4 display Community */
6113 if (attr->community)
6114 vty_out (vty, " Community: %s%s", attr->community->str,
6115 VTY_NEWLINE);
6116
6117 /* Line 5 display Extended-community */
6118 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006119 vty_out (vty, " Extended Community: %s%s",
6120 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006121
6122 /* Line 6 display Originator, Cluster-id */
6123 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6124 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6125 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006126 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006127 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006128 vty_out (vty, " Originator: %s",
6129 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006130
6131 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6132 {
6133 int i;
6134 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006135 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6136 vty_out (vty, "%s ",
6137 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006138 }
6139 vty_out (vty, "%s", VTY_NEWLINE);
6140 }
Paul Jakma41367172007-08-06 15:24:51 +00006141
6142 /* 7: AS Pathlimit */
6143 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6144 {
6145
6146 vty_out (vty, " AS-Pathlimit: %u",
6147 attr->pathlimit.ttl);
6148 if (attr->pathlimit.as)
6149 vty_out (vty, " (%u)", attr->pathlimit.as);
6150 vty_out (vty, "%s", VTY_NEWLINE);
6151 }
6152
Paul Jakmafb982c22007-05-04 20:15:47 +00006153 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006154 bgp_damp_info_vty (vty, binfo);
6155
6156 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006157#ifdef HAVE_CLOCK_MONOTONIC
6158 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006159 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006160#else
6161 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6162#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006163 }
6164 vty_out (vty, "%s", VTY_NEWLINE);
6165}
6166
paulb40d9392005-08-22 22:34:41 +00006167#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 +00006168#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006169#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6170#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6171#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6172
6173enum bgp_show_type
6174{
6175 bgp_show_type_normal,
6176 bgp_show_type_regexp,
6177 bgp_show_type_prefix_list,
6178 bgp_show_type_filter_list,
6179 bgp_show_type_route_map,
6180 bgp_show_type_neighbor,
6181 bgp_show_type_cidr_only,
6182 bgp_show_type_prefix_longer,
6183 bgp_show_type_community_all,
6184 bgp_show_type_community,
6185 bgp_show_type_community_exact,
6186 bgp_show_type_community_list,
6187 bgp_show_type_community_list_exact,
6188 bgp_show_type_flap_statistics,
6189 bgp_show_type_flap_address,
6190 bgp_show_type_flap_prefix,
6191 bgp_show_type_flap_cidr_only,
6192 bgp_show_type_flap_regexp,
6193 bgp_show_type_flap_filter_list,
6194 bgp_show_type_flap_prefix_list,
6195 bgp_show_type_flap_prefix_longer,
6196 bgp_show_type_flap_route_map,
6197 bgp_show_type_flap_neighbor,
6198 bgp_show_type_dampend_paths,
6199 bgp_show_type_damp_neighbor
6200};
6201
ajs5a646652004-11-05 01:25:55 +00006202static int
paulfee0f4c2004-09-13 05:12:46 +00006203bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006204 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006205{
paul718e3742002-12-13 20:15:29 +00006206 struct bgp_info *ri;
6207 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006208 int header = 1;
paul718e3742002-12-13 20:15:29 +00006209 int display;
ajs5a646652004-11-05 01:25:55 +00006210 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006211
6212 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006213 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006214
paul718e3742002-12-13 20:15:29 +00006215 /* Start processing of routes. */
6216 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6217 if (rn->info != NULL)
6218 {
6219 display = 0;
6220
6221 for (ri = rn->info; ri; ri = ri->next)
6222 {
ajs5a646652004-11-05 01:25:55 +00006223 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006224 || type == bgp_show_type_flap_address
6225 || type == bgp_show_type_flap_prefix
6226 || type == bgp_show_type_flap_cidr_only
6227 || type == bgp_show_type_flap_regexp
6228 || type == bgp_show_type_flap_filter_list
6229 || type == bgp_show_type_flap_prefix_list
6230 || type == bgp_show_type_flap_prefix_longer
6231 || type == bgp_show_type_flap_route_map
6232 || type == bgp_show_type_flap_neighbor
6233 || type == bgp_show_type_dampend_paths
6234 || type == bgp_show_type_damp_neighbor)
6235 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006236 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006237 continue;
6238 }
6239 if (type == bgp_show_type_regexp
6240 || type == bgp_show_type_flap_regexp)
6241 {
ajs5a646652004-11-05 01:25:55 +00006242 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006243
6244 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6245 continue;
6246 }
6247 if (type == bgp_show_type_prefix_list
6248 || type == bgp_show_type_flap_prefix_list)
6249 {
ajs5a646652004-11-05 01:25:55 +00006250 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006251
6252 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6253 continue;
6254 }
6255 if (type == bgp_show_type_filter_list
6256 || type == bgp_show_type_flap_filter_list)
6257 {
ajs5a646652004-11-05 01:25:55 +00006258 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006259
6260 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6261 continue;
6262 }
6263 if (type == bgp_show_type_route_map
6264 || type == bgp_show_type_flap_route_map)
6265 {
ajs5a646652004-11-05 01:25:55 +00006266 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006267 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006268 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006269 int ret;
6270
Paul Jakmafb982c22007-05-04 20:15:47 +00006271 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006272 binfo.peer = ri->peer;
6273 binfo.attr = &dummy_attr;
6274
6275 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006276
6277 bgp_attr_extra_free (&dummy_attr);
6278
paul718e3742002-12-13 20:15:29 +00006279 if (ret == RMAP_DENYMATCH)
6280 continue;
6281 }
6282 if (type == bgp_show_type_neighbor
6283 || type == bgp_show_type_flap_neighbor
6284 || type == bgp_show_type_damp_neighbor)
6285 {
ajs5a646652004-11-05 01:25:55 +00006286 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006287
6288 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6289 continue;
6290 }
6291 if (type == bgp_show_type_cidr_only
6292 || type == bgp_show_type_flap_cidr_only)
6293 {
6294 u_int32_t destination;
6295
6296 destination = ntohl (rn->p.u.prefix4.s_addr);
6297 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6298 continue;
6299 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6300 continue;
6301 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6302 continue;
6303 }
6304 if (type == bgp_show_type_prefix_longer
6305 || type == bgp_show_type_flap_prefix_longer)
6306 {
ajs5a646652004-11-05 01:25:55 +00006307 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006308
6309 if (! prefix_match (p, &rn->p))
6310 continue;
6311 }
6312 if (type == bgp_show_type_community_all)
6313 {
6314 if (! ri->attr->community)
6315 continue;
6316 }
6317 if (type == bgp_show_type_community)
6318 {
ajs5a646652004-11-05 01:25:55 +00006319 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006320
6321 if (! ri->attr->community ||
6322 ! community_match (ri->attr->community, com))
6323 continue;
6324 }
6325 if (type == bgp_show_type_community_exact)
6326 {
ajs5a646652004-11-05 01:25:55 +00006327 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006328
6329 if (! ri->attr->community ||
6330 ! community_cmp (ri->attr->community, com))
6331 continue;
6332 }
6333 if (type == bgp_show_type_community_list)
6334 {
ajs5a646652004-11-05 01:25:55 +00006335 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006336
6337 if (! community_list_match (ri->attr->community, list))
6338 continue;
6339 }
6340 if (type == bgp_show_type_community_list_exact)
6341 {
ajs5a646652004-11-05 01:25:55 +00006342 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006343
6344 if (! community_list_exact_match (ri->attr->community, list))
6345 continue;
6346 }
6347 if (type == bgp_show_type_flap_address
6348 || type == bgp_show_type_flap_prefix)
6349 {
ajs5a646652004-11-05 01:25:55 +00006350 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006351
6352 if (! prefix_match (&rn->p, p))
6353 continue;
6354
6355 if (type == bgp_show_type_flap_prefix)
6356 if (p->prefixlen != rn->p.prefixlen)
6357 continue;
6358 }
6359 if (type == bgp_show_type_dampend_paths
6360 || type == bgp_show_type_damp_neighbor)
6361 {
6362 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6363 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6364 continue;
6365 }
6366
6367 if (header)
6368 {
hasso93406d82005-02-02 14:40:33 +00006369 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6370 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6371 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006372 if (type == bgp_show_type_dampend_paths
6373 || type == bgp_show_type_damp_neighbor)
6374 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6375 else if (type == bgp_show_type_flap_statistics
6376 || type == bgp_show_type_flap_address
6377 || type == bgp_show_type_flap_prefix
6378 || type == bgp_show_type_flap_cidr_only
6379 || type == bgp_show_type_flap_regexp
6380 || type == bgp_show_type_flap_filter_list
6381 || type == bgp_show_type_flap_prefix_list
6382 || type == bgp_show_type_flap_prefix_longer
6383 || type == bgp_show_type_flap_route_map
6384 || type == bgp_show_type_flap_neighbor)
6385 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6386 else
6387 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006388 header = 0;
6389 }
6390
6391 if (type == bgp_show_type_dampend_paths
6392 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006393 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006394 else if (type == bgp_show_type_flap_statistics
6395 || type == bgp_show_type_flap_address
6396 || type == bgp_show_type_flap_prefix
6397 || type == bgp_show_type_flap_cidr_only
6398 || type == bgp_show_type_flap_regexp
6399 || type == bgp_show_type_flap_filter_list
6400 || type == bgp_show_type_flap_prefix_list
6401 || type == bgp_show_type_flap_prefix_longer
6402 || type == bgp_show_type_flap_route_map
6403 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006404 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006405 else
ajs5a646652004-11-05 01:25:55 +00006406 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006407 display++;
6408 }
6409 if (display)
ajs5a646652004-11-05 01:25:55 +00006410 output_count++;
paul718e3742002-12-13 20:15:29 +00006411 }
6412
6413 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006414 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006415 {
6416 if (type == bgp_show_type_normal)
6417 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6418 }
6419 else
6420 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006421 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006422
6423 return CMD_SUCCESS;
6424}
6425
ajs5a646652004-11-05 01:25:55 +00006426static int
paulfee0f4c2004-09-13 05:12:46 +00006427bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006428 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006429{
6430 struct bgp_table *table;
6431
6432 if (bgp == NULL) {
6433 bgp = bgp_get_default ();
6434 }
6435
6436 if (bgp == NULL)
6437 {
6438 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6439 return CMD_WARNING;
6440 }
6441
6442
6443 table = bgp->rib[afi][safi];
6444
ajs5a646652004-11-05 01:25:55 +00006445 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006446}
6447
paul718e3742002-12-13 20:15:29 +00006448/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006449static void
paul718e3742002-12-13 20:15:29 +00006450route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6451 struct bgp_node *rn,
6452 struct prefix_rd *prd, afi_t afi, safi_t safi)
6453{
6454 struct bgp_info *ri;
6455 struct prefix *p;
6456 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006457 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006458 char buf1[INET6_ADDRSTRLEN];
6459 char buf2[INET6_ADDRSTRLEN];
6460 int count = 0;
6461 int best = 0;
6462 int suppress = 0;
6463 int no_export = 0;
6464 int no_advertise = 0;
6465 int local_as = 0;
6466 int first = 0;
6467
6468 p = &rn->p;
6469 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6470 (safi == SAFI_MPLS_VPN ?
6471 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6472 safi == SAFI_MPLS_VPN ? ":" : "",
6473 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6474 p->prefixlen, VTY_NEWLINE);
6475
6476 for (ri = rn->info; ri; ri = ri->next)
6477 {
6478 count++;
6479 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6480 {
6481 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006482 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006483 suppress = 1;
6484 if (ri->attr->community != NULL)
6485 {
6486 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6487 no_advertise = 1;
6488 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6489 no_export = 1;
6490 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6491 local_as = 1;
6492 }
6493 }
6494 }
6495
6496 vty_out (vty, "Paths: (%d available", count);
6497 if (best)
6498 {
6499 vty_out (vty, ", best #%d", best);
6500 if (safi == SAFI_UNICAST)
6501 vty_out (vty, ", table Default-IP-Routing-Table");
6502 }
6503 else
6504 vty_out (vty, ", no best path");
6505 if (no_advertise)
6506 vty_out (vty, ", not advertised to any peer");
6507 else if (no_export)
6508 vty_out (vty, ", not advertised to EBGP peer");
6509 else if (local_as)
6510 vty_out (vty, ", not advertised outside local AS");
6511 if (suppress)
6512 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6513 vty_out (vty, ")%s", VTY_NEWLINE);
6514
6515 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006516 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006517 {
6518 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6519 {
6520 if (! first)
6521 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6522 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6523 first = 1;
6524 }
6525 }
6526 if (! first)
6527 vty_out (vty, " Not advertised to any peer");
6528 vty_out (vty, "%s", VTY_NEWLINE);
6529}
6530
6531/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006532static int
paulfee0f4c2004-09-13 05:12:46 +00006533bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006534 struct bgp_table *rib, const char *ip_str,
6535 afi_t afi, safi_t safi, struct prefix_rd *prd,
6536 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006537{
6538 int ret;
6539 int header;
6540 int display = 0;
6541 struct prefix match;
6542 struct bgp_node *rn;
6543 struct bgp_node *rm;
6544 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006545 struct bgp_table *table;
6546
paul718e3742002-12-13 20:15:29 +00006547 /* Check IP address argument. */
6548 ret = str2prefix (ip_str, &match);
6549 if (! ret)
6550 {
6551 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6552 return CMD_WARNING;
6553 }
6554
6555 match.family = afi2family (afi);
6556
6557 if (safi == SAFI_MPLS_VPN)
6558 {
paulfee0f4c2004-09-13 05:12:46 +00006559 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006560 {
6561 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6562 continue;
6563
6564 if ((table = rn->info) != NULL)
6565 {
6566 header = 1;
6567
6568 if ((rm = bgp_node_match (table, &match)) != NULL)
6569 {
6570 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006571 {
6572 bgp_unlock_node (rm);
6573 continue;
6574 }
paul718e3742002-12-13 20:15:29 +00006575
6576 for (ri = rm->info; ri; ri = ri->next)
6577 {
6578 if (header)
6579 {
6580 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6581 AFI_IP, SAFI_MPLS_VPN);
6582
6583 header = 0;
6584 }
6585 display++;
6586 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6587 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006588
6589 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006590 }
6591 }
6592 }
6593 }
6594 else
6595 {
6596 header = 1;
6597
paulfee0f4c2004-09-13 05:12:46 +00006598 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006599 {
6600 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6601 {
6602 for (ri = rn->info; ri; ri = ri->next)
6603 {
6604 if (header)
6605 {
6606 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6607 header = 0;
6608 }
6609 display++;
6610 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6611 }
6612 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006613
6614 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006615 }
6616 }
6617
6618 if (! display)
6619 {
6620 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6621 return CMD_WARNING;
6622 }
6623
6624 return CMD_SUCCESS;
6625}
6626
paulfee0f4c2004-09-13 05:12:46 +00006627/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006628static int
paulfd79ac92004-10-13 05:06:08 +00006629bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006630 afi_t afi, safi_t safi, struct prefix_rd *prd,
6631 int prefix_check)
6632{
6633 struct bgp *bgp;
6634
6635 /* BGP structure lookup. */
6636 if (view_name)
6637 {
6638 bgp = bgp_lookup_by_name (view_name);
6639 if (bgp == NULL)
6640 {
6641 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6642 return CMD_WARNING;
6643 }
6644 }
6645 else
6646 {
6647 bgp = bgp_get_default ();
6648 if (bgp == NULL)
6649 {
6650 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6651 return CMD_WARNING;
6652 }
6653 }
6654
6655 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6656 afi, safi, prd, prefix_check);
6657}
6658
paul718e3742002-12-13 20:15:29 +00006659/* BGP route print out function. */
6660DEFUN (show_ip_bgp,
6661 show_ip_bgp_cmd,
6662 "show ip bgp",
6663 SHOW_STR
6664 IP_STR
6665 BGP_STR)
6666{
ajs5a646652004-11-05 01:25:55 +00006667 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006668}
6669
6670DEFUN (show_ip_bgp_ipv4,
6671 show_ip_bgp_ipv4_cmd,
6672 "show ip bgp ipv4 (unicast|multicast)",
6673 SHOW_STR
6674 IP_STR
6675 BGP_STR
6676 "Address family\n"
6677 "Address Family modifier\n"
6678 "Address Family modifier\n")
6679{
6680 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006681 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6682 NULL);
paul718e3742002-12-13 20:15:29 +00006683
ajs5a646652004-11-05 01:25:55 +00006684 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006685}
6686
6687DEFUN (show_ip_bgp_route,
6688 show_ip_bgp_route_cmd,
6689 "show ip bgp A.B.C.D",
6690 SHOW_STR
6691 IP_STR
6692 BGP_STR
6693 "Network in the BGP routing table to display\n")
6694{
6695 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6696}
6697
6698DEFUN (show_ip_bgp_ipv4_route,
6699 show_ip_bgp_ipv4_route_cmd,
6700 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6701 SHOW_STR
6702 IP_STR
6703 BGP_STR
6704 "Address family\n"
6705 "Address Family modifier\n"
6706 "Address Family modifier\n"
6707 "Network in the BGP routing table to display\n")
6708{
6709 if (strncmp (argv[0], "m", 1) == 0)
6710 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6711
6712 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6713}
6714
6715DEFUN (show_ip_bgp_vpnv4_all_route,
6716 show_ip_bgp_vpnv4_all_route_cmd,
6717 "show ip bgp vpnv4 all A.B.C.D",
6718 SHOW_STR
6719 IP_STR
6720 BGP_STR
6721 "Display VPNv4 NLRI specific information\n"
6722 "Display information about all VPNv4 NLRIs\n"
6723 "Network in the BGP routing table to display\n")
6724{
6725 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6726}
6727
6728DEFUN (show_ip_bgp_vpnv4_rd_route,
6729 show_ip_bgp_vpnv4_rd_route_cmd,
6730 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6731 SHOW_STR
6732 IP_STR
6733 BGP_STR
6734 "Display VPNv4 NLRI specific information\n"
6735 "Display information for a route distinguisher\n"
6736 "VPN Route Distinguisher\n"
6737 "Network in the BGP routing table to display\n")
6738{
6739 int ret;
6740 struct prefix_rd prd;
6741
6742 ret = str2prefix_rd (argv[0], &prd);
6743 if (! ret)
6744 {
6745 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6746 return CMD_WARNING;
6747 }
6748 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6749}
6750
6751DEFUN (show_ip_bgp_prefix,
6752 show_ip_bgp_prefix_cmd,
6753 "show ip bgp A.B.C.D/M",
6754 SHOW_STR
6755 IP_STR
6756 BGP_STR
6757 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6758{
6759 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6760}
6761
6762DEFUN (show_ip_bgp_ipv4_prefix,
6763 show_ip_bgp_ipv4_prefix_cmd,
6764 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6765 SHOW_STR
6766 IP_STR
6767 BGP_STR
6768 "Address family\n"
6769 "Address Family modifier\n"
6770 "Address Family modifier\n"
6771 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6772{
6773 if (strncmp (argv[0], "m", 1) == 0)
6774 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6775
6776 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6777}
6778
6779DEFUN (show_ip_bgp_vpnv4_all_prefix,
6780 show_ip_bgp_vpnv4_all_prefix_cmd,
6781 "show ip bgp vpnv4 all A.B.C.D/M",
6782 SHOW_STR
6783 IP_STR
6784 BGP_STR
6785 "Display VPNv4 NLRI specific information\n"
6786 "Display information about all VPNv4 NLRIs\n"
6787 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6788{
6789 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6790}
6791
6792DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6793 show_ip_bgp_vpnv4_rd_prefix_cmd,
6794 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6795 SHOW_STR
6796 IP_STR
6797 BGP_STR
6798 "Display VPNv4 NLRI specific information\n"
6799 "Display information for a route distinguisher\n"
6800 "VPN Route Distinguisher\n"
6801 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6802{
6803 int ret;
6804 struct prefix_rd prd;
6805
6806 ret = str2prefix_rd (argv[0], &prd);
6807 if (! ret)
6808 {
6809 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6810 return CMD_WARNING;
6811 }
6812 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6813}
6814
6815DEFUN (show_ip_bgp_view,
6816 show_ip_bgp_view_cmd,
6817 "show ip bgp view WORD",
6818 SHOW_STR
6819 IP_STR
6820 BGP_STR
6821 "BGP view\n"
6822 "BGP view name\n")
6823{
paulbb46e942003-10-24 19:02:03 +00006824 struct bgp *bgp;
6825
6826 /* BGP structure lookup. */
6827 bgp = bgp_lookup_by_name (argv[0]);
6828 if (bgp == NULL)
6829 {
6830 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6831 return CMD_WARNING;
6832 }
6833
ajs5a646652004-11-05 01:25:55 +00006834 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006835}
6836
6837DEFUN (show_ip_bgp_view_route,
6838 show_ip_bgp_view_route_cmd,
6839 "show ip bgp view WORD A.B.C.D",
6840 SHOW_STR
6841 IP_STR
6842 BGP_STR
6843 "BGP view\n"
6844 "BGP view name\n"
6845 "Network in the BGP routing table to display\n")
6846{
6847 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6848}
6849
6850DEFUN (show_ip_bgp_view_prefix,
6851 show_ip_bgp_view_prefix_cmd,
6852 "show ip bgp view WORD A.B.C.D/M",
6853 SHOW_STR
6854 IP_STR
6855 BGP_STR
6856 "BGP view\n"
6857 "BGP view name\n"
6858 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6859{
6860 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6861}
6862
6863#ifdef HAVE_IPV6
6864DEFUN (show_bgp,
6865 show_bgp_cmd,
6866 "show bgp",
6867 SHOW_STR
6868 BGP_STR)
6869{
ajs5a646652004-11-05 01:25:55 +00006870 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6871 NULL);
paul718e3742002-12-13 20:15:29 +00006872}
6873
6874ALIAS (show_bgp,
6875 show_bgp_ipv6_cmd,
6876 "show bgp ipv6",
6877 SHOW_STR
6878 BGP_STR
6879 "Address family\n")
6880
6881/* old command */
6882DEFUN (show_ipv6_bgp,
6883 show_ipv6_bgp_cmd,
6884 "show ipv6 bgp",
6885 SHOW_STR
6886 IP_STR
6887 BGP_STR)
6888{
ajs5a646652004-11-05 01:25:55 +00006889 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6890 NULL);
paul718e3742002-12-13 20:15:29 +00006891}
6892
6893DEFUN (show_bgp_route,
6894 show_bgp_route_cmd,
6895 "show bgp X:X::X:X",
6896 SHOW_STR
6897 BGP_STR
6898 "Network in the BGP routing table to display\n")
6899{
6900 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6901}
6902
6903ALIAS (show_bgp_route,
6904 show_bgp_ipv6_route_cmd,
6905 "show bgp ipv6 X:X::X:X",
6906 SHOW_STR
6907 BGP_STR
6908 "Address family\n"
6909 "Network in the BGP routing table to display\n")
6910
6911/* old command */
6912DEFUN (show_ipv6_bgp_route,
6913 show_ipv6_bgp_route_cmd,
6914 "show ipv6 bgp X:X::X:X",
6915 SHOW_STR
6916 IP_STR
6917 BGP_STR
6918 "Network in the BGP routing table to display\n")
6919{
6920 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6921}
6922
6923DEFUN (show_bgp_prefix,
6924 show_bgp_prefix_cmd,
6925 "show bgp X:X::X:X/M",
6926 SHOW_STR
6927 BGP_STR
6928 "IPv6 prefix <network>/<length>\n")
6929{
6930 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6931}
6932
6933ALIAS (show_bgp_prefix,
6934 show_bgp_ipv6_prefix_cmd,
6935 "show bgp ipv6 X:X::X:X/M",
6936 SHOW_STR
6937 BGP_STR
6938 "Address family\n"
6939 "IPv6 prefix <network>/<length>\n")
6940
6941/* old command */
6942DEFUN (show_ipv6_bgp_prefix,
6943 show_ipv6_bgp_prefix_cmd,
6944 "show ipv6 bgp X:X::X:X/M",
6945 SHOW_STR
6946 IP_STR
6947 BGP_STR
6948 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6949{
6950 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6951}
6952
paulbb46e942003-10-24 19:02:03 +00006953DEFUN (show_bgp_view,
6954 show_bgp_view_cmd,
6955 "show bgp view WORD",
6956 SHOW_STR
6957 BGP_STR
6958 "BGP view\n"
6959 "View name\n")
6960{
6961 struct bgp *bgp;
6962
6963 /* BGP structure lookup. */
6964 bgp = bgp_lookup_by_name (argv[0]);
6965 if (bgp == NULL)
6966 {
6967 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6968 return CMD_WARNING;
6969 }
6970
ajs5a646652004-11-05 01:25:55 +00006971 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006972}
6973
6974ALIAS (show_bgp_view,
6975 show_bgp_view_ipv6_cmd,
6976 "show bgp view WORD ipv6",
6977 SHOW_STR
6978 BGP_STR
6979 "BGP view\n"
6980 "View name\n"
6981 "Address family\n")
6982
6983DEFUN (show_bgp_view_route,
6984 show_bgp_view_route_cmd,
6985 "show bgp view WORD X:X::X:X",
6986 SHOW_STR
6987 BGP_STR
6988 "BGP view\n"
6989 "View name\n"
6990 "Network in the BGP routing table to display\n")
6991{
6992 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6993}
6994
6995ALIAS (show_bgp_view_route,
6996 show_bgp_view_ipv6_route_cmd,
6997 "show bgp view WORD ipv6 X:X::X:X",
6998 SHOW_STR
6999 BGP_STR
7000 "BGP view\n"
7001 "View name\n"
7002 "Address family\n"
7003 "Network in the BGP routing table to display\n")
7004
7005DEFUN (show_bgp_view_prefix,
7006 show_bgp_view_prefix_cmd,
7007 "show bgp view WORD X:X::X:X/M",
7008 SHOW_STR
7009 BGP_STR
7010 "BGP view\n"
7011 "View name\n"
7012 "IPv6 prefix <network>/<length>\n")
7013{
7014 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7015}
7016
7017ALIAS (show_bgp_view_prefix,
7018 show_bgp_view_ipv6_prefix_cmd,
7019 "show bgp view WORD ipv6 X:X::X:X/M",
7020 SHOW_STR
7021 BGP_STR
7022 "BGP view\n"
7023 "View name\n"
7024 "Address family\n"
7025 "IPv6 prefix <network>/<length>\n")
7026
paul718e3742002-12-13 20:15:29 +00007027/* old command */
7028DEFUN (show_ipv6_mbgp,
7029 show_ipv6_mbgp_cmd,
7030 "show ipv6 mbgp",
7031 SHOW_STR
7032 IP_STR
7033 MBGP_STR)
7034{
ajs5a646652004-11-05 01:25:55 +00007035 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7036 NULL);
paul718e3742002-12-13 20:15:29 +00007037}
7038
7039/* old command */
7040DEFUN (show_ipv6_mbgp_route,
7041 show_ipv6_mbgp_route_cmd,
7042 "show ipv6 mbgp X:X::X:X",
7043 SHOW_STR
7044 IP_STR
7045 MBGP_STR
7046 "Network in the MBGP routing table to display\n")
7047{
7048 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7049}
7050
7051/* old command */
7052DEFUN (show_ipv6_mbgp_prefix,
7053 show_ipv6_mbgp_prefix_cmd,
7054 "show ipv6 mbgp X:X::X:X/M",
7055 SHOW_STR
7056 IP_STR
7057 MBGP_STR
7058 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7059{
7060 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7061}
7062#endif
7063
paul718e3742002-12-13 20:15:29 +00007064
paul94f2b392005-06-28 12:44:16 +00007065static int
paulfd79ac92004-10-13 05:06:08 +00007066bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007067 safi_t safi, enum bgp_show_type type)
7068{
7069 int i;
7070 struct buffer *b;
7071 char *regstr;
7072 int first;
7073 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007074 int rc;
paul718e3742002-12-13 20:15:29 +00007075
7076 first = 0;
7077 b = buffer_new (1024);
7078 for (i = 0; i < argc; i++)
7079 {
7080 if (first)
7081 buffer_putc (b, ' ');
7082 else
7083 {
7084 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7085 continue;
7086 first = 1;
7087 }
7088
7089 buffer_putstr (b, argv[i]);
7090 }
7091 buffer_putc (b, '\0');
7092
7093 regstr = buffer_getstr (b);
7094 buffer_free (b);
7095
7096 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007097 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007098 if (! regex)
7099 {
7100 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7101 VTY_NEWLINE);
7102 return CMD_WARNING;
7103 }
7104
ajs5a646652004-11-05 01:25:55 +00007105 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7106 bgp_regex_free (regex);
7107 return rc;
paul718e3742002-12-13 20:15:29 +00007108}
7109
7110DEFUN (show_ip_bgp_regexp,
7111 show_ip_bgp_regexp_cmd,
7112 "show ip bgp regexp .LINE",
7113 SHOW_STR
7114 IP_STR
7115 BGP_STR
7116 "Display routes matching the AS path regular expression\n"
7117 "A regular-expression to match the BGP AS paths\n")
7118{
7119 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7120 bgp_show_type_regexp);
7121}
7122
7123DEFUN (show_ip_bgp_flap_regexp,
7124 show_ip_bgp_flap_regexp_cmd,
7125 "show ip bgp flap-statistics regexp .LINE",
7126 SHOW_STR
7127 IP_STR
7128 BGP_STR
7129 "Display flap statistics of routes\n"
7130 "Display routes matching the AS path regular expression\n"
7131 "A regular-expression to match the BGP AS paths\n")
7132{
7133 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7134 bgp_show_type_flap_regexp);
7135}
7136
7137DEFUN (show_ip_bgp_ipv4_regexp,
7138 show_ip_bgp_ipv4_regexp_cmd,
7139 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7140 SHOW_STR
7141 IP_STR
7142 BGP_STR
7143 "Address family\n"
7144 "Address Family modifier\n"
7145 "Address Family modifier\n"
7146 "Display routes matching the AS path regular expression\n"
7147 "A regular-expression to match the BGP AS paths\n")
7148{
7149 if (strncmp (argv[0], "m", 1) == 0)
7150 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7151 bgp_show_type_regexp);
7152
7153 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7154 bgp_show_type_regexp);
7155}
7156
7157#ifdef HAVE_IPV6
7158DEFUN (show_bgp_regexp,
7159 show_bgp_regexp_cmd,
7160 "show bgp regexp .LINE",
7161 SHOW_STR
7162 BGP_STR
7163 "Display routes matching the AS path regular expression\n"
7164 "A regular-expression to match the BGP AS paths\n")
7165{
7166 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7167 bgp_show_type_regexp);
7168}
7169
7170ALIAS (show_bgp_regexp,
7171 show_bgp_ipv6_regexp_cmd,
7172 "show bgp ipv6 regexp .LINE",
7173 SHOW_STR
7174 BGP_STR
7175 "Address family\n"
7176 "Display routes matching the AS path regular expression\n"
7177 "A regular-expression to match the BGP AS paths\n")
7178
7179/* old command */
7180DEFUN (show_ipv6_bgp_regexp,
7181 show_ipv6_bgp_regexp_cmd,
7182 "show ipv6 bgp regexp .LINE",
7183 SHOW_STR
7184 IP_STR
7185 BGP_STR
7186 "Display routes matching the AS path regular expression\n"
7187 "A regular-expression to match the BGP AS paths\n")
7188{
7189 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7190 bgp_show_type_regexp);
7191}
7192
7193/* old command */
7194DEFUN (show_ipv6_mbgp_regexp,
7195 show_ipv6_mbgp_regexp_cmd,
7196 "show ipv6 mbgp regexp .LINE",
7197 SHOW_STR
7198 IP_STR
7199 BGP_STR
7200 "Display routes matching the AS path regular expression\n"
7201 "A regular-expression to match the MBGP AS paths\n")
7202{
7203 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7204 bgp_show_type_regexp);
7205}
7206#endif /* HAVE_IPV6 */
7207
paul94f2b392005-06-28 12:44:16 +00007208static int
paulfd79ac92004-10-13 05:06:08 +00007209bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007210 safi_t safi, enum bgp_show_type type)
7211{
7212 struct prefix_list *plist;
7213
7214 plist = prefix_list_lookup (afi, prefix_list_str);
7215 if (plist == NULL)
7216 {
7217 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7218 prefix_list_str, VTY_NEWLINE);
7219 return CMD_WARNING;
7220 }
7221
ajs5a646652004-11-05 01:25:55 +00007222 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007223}
7224
7225DEFUN (show_ip_bgp_prefix_list,
7226 show_ip_bgp_prefix_list_cmd,
7227 "show ip bgp prefix-list WORD",
7228 SHOW_STR
7229 IP_STR
7230 BGP_STR
7231 "Display routes conforming to the prefix-list\n"
7232 "IP prefix-list name\n")
7233{
7234 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7235 bgp_show_type_prefix_list);
7236}
7237
7238DEFUN (show_ip_bgp_flap_prefix_list,
7239 show_ip_bgp_flap_prefix_list_cmd,
7240 "show ip bgp flap-statistics prefix-list WORD",
7241 SHOW_STR
7242 IP_STR
7243 BGP_STR
7244 "Display flap statistics of routes\n"
7245 "Display routes conforming to the prefix-list\n"
7246 "IP prefix-list name\n")
7247{
7248 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7249 bgp_show_type_flap_prefix_list);
7250}
7251
7252DEFUN (show_ip_bgp_ipv4_prefix_list,
7253 show_ip_bgp_ipv4_prefix_list_cmd,
7254 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7255 SHOW_STR
7256 IP_STR
7257 BGP_STR
7258 "Address family\n"
7259 "Address Family modifier\n"
7260 "Address Family modifier\n"
7261 "Display routes conforming to the prefix-list\n"
7262 "IP prefix-list name\n")
7263{
7264 if (strncmp (argv[0], "m", 1) == 0)
7265 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7266 bgp_show_type_prefix_list);
7267
7268 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7269 bgp_show_type_prefix_list);
7270}
7271
7272#ifdef HAVE_IPV6
7273DEFUN (show_bgp_prefix_list,
7274 show_bgp_prefix_list_cmd,
7275 "show bgp prefix-list WORD",
7276 SHOW_STR
7277 BGP_STR
7278 "Display routes conforming to the prefix-list\n"
7279 "IPv6 prefix-list name\n")
7280{
7281 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7282 bgp_show_type_prefix_list);
7283}
7284
7285ALIAS (show_bgp_prefix_list,
7286 show_bgp_ipv6_prefix_list_cmd,
7287 "show bgp ipv6 prefix-list WORD",
7288 SHOW_STR
7289 BGP_STR
7290 "Address family\n"
7291 "Display routes conforming to the prefix-list\n"
7292 "IPv6 prefix-list name\n")
7293
7294/* old command */
7295DEFUN (show_ipv6_bgp_prefix_list,
7296 show_ipv6_bgp_prefix_list_cmd,
7297 "show ipv6 bgp prefix-list WORD",
7298 SHOW_STR
7299 IPV6_STR
7300 BGP_STR
7301 "Display routes matching the prefix-list\n"
7302 "IPv6 prefix-list name\n")
7303{
7304 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7305 bgp_show_type_prefix_list);
7306}
7307
7308/* old command */
7309DEFUN (show_ipv6_mbgp_prefix_list,
7310 show_ipv6_mbgp_prefix_list_cmd,
7311 "show ipv6 mbgp prefix-list WORD",
7312 SHOW_STR
7313 IPV6_STR
7314 MBGP_STR
7315 "Display routes matching the prefix-list\n"
7316 "IPv6 prefix-list name\n")
7317{
7318 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7319 bgp_show_type_prefix_list);
7320}
7321#endif /* HAVE_IPV6 */
7322
paul94f2b392005-06-28 12:44:16 +00007323static int
paulfd79ac92004-10-13 05:06:08 +00007324bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007325 safi_t safi, enum bgp_show_type type)
7326{
7327 struct as_list *as_list;
7328
7329 as_list = as_list_lookup (filter);
7330 if (as_list == NULL)
7331 {
7332 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7333 return CMD_WARNING;
7334 }
7335
ajs5a646652004-11-05 01:25:55 +00007336 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007337}
7338
7339DEFUN (show_ip_bgp_filter_list,
7340 show_ip_bgp_filter_list_cmd,
7341 "show ip bgp filter-list WORD",
7342 SHOW_STR
7343 IP_STR
7344 BGP_STR
7345 "Display routes conforming to the filter-list\n"
7346 "Regular expression access list name\n")
7347{
7348 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7349 bgp_show_type_filter_list);
7350}
7351
7352DEFUN (show_ip_bgp_flap_filter_list,
7353 show_ip_bgp_flap_filter_list_cmd,
7354 "show ip bgp flap-statistics filter-list WORD",
7355 SHOW_STR
7356 IP_STR
7357 BGP_STR
7358 "Display flap statistics of routes\n"
7359 "Display routes conforming to the filter-list\n"
7360 "Regular expression access list name\n")
7361{
7362 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7363 bgp_show_type_flap_filter_list);
7364}
7365
7366DEFUN (show_ip_bgp_ipv4_filter_list,
7367 show_ip_bgp_ipv4_filter_list_cmd,
7368 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7369 SHOW_STR
7370 IP_STR
7371 BGP_STR
7372 "Address family\n"
7373 "Address Family modifier\n"
7374 "Address Family modifier\n"
7375 "Display routes conforming to the filter-list\n"
7376 "Regular expression access list name\n")
7377{
7378 if (strncmp (argv[0], "m", 1) == 0)
7379 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7380 bgp_show_type_filter_list);
7381
7382 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7383 bgp_show_type_filter_list);
7384}
7385
7386#ifdef HAVE_IPV6
7387DEFUN (show_bgp_filter_list,
7388 show_bgp_filter_list_cmd,
7389 "show bgp filter-list WORD",
7390 SHOW_STR
7391 BGP_STR
7392 "Display routes conforming to the filter-list\n"
7393 "Regular expression access list name\n")
7394{
7395 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7396 bgp_show_type_filter_list);
7397}
7398
7399ALIAS (show_bgp_filter_list,
7400 show_bgp_ipv6_filter_list_cmd,
7401 "show bgp ipv6 filter-list WORD",
7402 SHOW_STR
7403 BGP_STR
7404 "Address family\n"
7405 "Display routes conforming to the filter-list\n"
7406 "Regular expression access list name\n")
7407
7408/* old command */
7409DEFUN (show_ipv6_bgp_filter_list,
7410 show_ipv6_bgp_filter_list_cmd,
7411 "show ipv6 bgp filter-list WORD",
7412 SHOW_STR
7413 IPV6_STR
7414 BGP_STR
7415 "Display routes conforming to the filter-list\n"
7416 "Regular expression access list name\n")
7417{
7418 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7419 bgp_show_type_filter_list);
7420}
7421
7422/* old command */
7423DEFUN (show_ipv6_mbgp_filter_list,
7424 show_ipv6_mbgp_filter_list_cmd,
7425 "show ipv6 mbgp filter-list WORD",
7426 SHOW_STR
7427 IPV6_STR
7428 MBGP_STR
7429 "Display routes conforming to the filter-list\n"
7430 "Regular expression access list name\n")
7431{
7432 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7433 bgp_show_type_filter_list);
7434}
7435#endif /* HAVE_IPV6 */
7436
paul94f2b392005-06-28 12:44:16 +00007437static int
paulfd79ac92004-10-13 05:06:08 +00007438bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007439 safi_t safi, enum bgp_show_type type)
7440{
7441 struct route_map *rmap;
7442
7443 rmap = route_map_lookup_by_name (rmap_str);
7444 if (! rmap)
7445 {
7446 vty_out (vty, "%% %s is not a valid route-map name%s",
7447 rmap_str, VTY_NEWLINE);
7448 return CMD_WARNING;
7449 }
7450
ajs5a646652004-11-05 01:25:55 +00007451 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007452}
7453
7454DEFUN (show_ip_bgp_route_map,
7455 show_ip_bgp_route_map_cmd,
7456 "show ip bgp route-map WORD",
7457 SHOW_STR
7458 IP_STR
7459 BGP_STR
7460 "Display routes matching the route-map\n"
7461 "A route-map to match on\n")
7462{
7463 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7464 bgp_show_type_route_map);
7465}
7466
7467DEFUN (show_ip_bgp_flap_route_map,
7468 show_ip_bgp_flap_route_map_cmd,
7469 "show ip bgp flap-statistics route-map WORD",
7470 SHOW_STR
7471 IP_STR
7472 BGP_STR
7473 "Display flap statistics of routes\n"
7474 "Display routes matching the route-map\n"
7475 "A route-map to match on\n")
7476{
7477 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7478 bgp_show_type_flap_route_map);
7479}
7480
7481DEFUN (show_ip_bgp_ipv4_route_map,
7482 show_ip_bgp_ipv4_route_map_cmd,
7483 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7484 SHOW_STR
7485 IP_STR
7486 BGP_STR
7487 "Address family\n"
7488 "Address Family modifier\n"
7489 "Address Family modifier\n"
7490 "Display routes matching the route-map\n"
7491 "A route-map to match on\n")
7492{
7493 if (strncmp (argv[0], "m", 1) == 0)
7494 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7495 bgp_show_type_route_map);
7496
7497 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7498 bgp_show_type_route_map);
7499}
7500
7501DEFUN (show_bgp_route_map,
7502 show_bgp_route_map_cmd,
7503 "show bgp route-map WORD",
7504 SHOW_STR
7505 BGP_STR
7506 "Display routes matching the route-map\n"
7507 "A route-map to match on\n")
7508{
7509 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7510 bgp_show_type_route_map);
7511}
7512
7513ALIAS (show_bgp_route_map,
7514 show_bgp_ipv6_route_map_cmd,
7515 "show bgp ipv6 route-map WORD",
7516 SHOW_STR
7517 BGP_STR
7518 "Address family\n"
7519 "Display routes matching the route-map\n"
7520 "A route-map to match on\n")
7521
7522DEFUN (show_ip_bgp_cidr_only,
7523 show_ip_bgp_cidr_only_cmd,
7524 "show ip bgp cidr-only",
7525 SHOW_STR
7526 IP_STR
7527 BGP_STR
7528 "Display only routes with non-natural netmasks\n")
7529{
7530 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007531 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007532}
7533
7534DEFUN (show_ip_bgp_flap_cidr_only,
7535 show_ip_bgp_flap_cidr_only_cmd,
7536 "show ip bgp flap-statistics cidr-only",
7537 SHOW_STR
7538 IP_STR
7539 BGP_STR
7540 "Display flap statistics of routes\n"
7541 "Display only routes with non-natural netmasks\n")
7542{
7543 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007544 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007545}
7546
7547DEFUN (show_ip_bgp_ipv4_cidr_only,
7548 show_ip_bgp_ipv4_cidr_only_cmd,
7549 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7550 SHOW_STR
7551 IP_STR
7552 BGP_STR
7553 "Address family\n"
7554 "Address Family modifier\n"
7555 "Address Family modifier\n"
7556 "Display only routes with non-natural netmasks\n")
7557{
7558 if (strncmp (argv[0], "m", 1) == 0)
7559 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007560 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007561
7562 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007563 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007564}
7565
7566DEFUN (show_ip_bgp_community_all,
7567 show_ip_bgp_community_all_cmd,
7568 "show ip bgp community",
7569 SHOW_STR
7570 IP_STR
7571 BGP_STR
7572 "Display routes matching the communities\n")
7573{
7574 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007575 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007576}
7577
7578DEFUN (show_ip_bgp_ipv4_community_all,
7579 show_ip_bgp_ipv4_community_all_cmd,
7580 "show ip bgp ipv4 (unicast|multicast) community",
7581 SHOW_STR
7582 IP_STR
7583 BGP_STR
7584 "Address family\n"
7585 "Address Family modifier\n"
7586 "Address Family modifier\n"
7587 "Display routes matching the communities\n")
7588{
7589 if (strncmp (argv[0], "m", 1) == 0)
7590 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007591 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007592
7593 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007594 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007595}
7596
7597#ifdef HAVE_IPV6
7598DEFUN (show_bgp_community_all,
7599 show_bgp_community_all_cmd,
7600 "show bgp community",
7601 SHOW_STR
7602 BGP_STR
7603 "Display routes matching the communities\n")
7604{
7605 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007606 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007607}
7608
7609ALIAS (show_bgp_community_all,
7610 show_bgp_ipv6_community_all_cmd,
7611 "show bgp ipv6 community",
7612 SHOW_STR
7613 BGP_STR
7614 "Address family\n"
7615 "Display routes matching the communities\n")
7616
7617/* old command */
7618DEFUN (show_ipv6_bgp_community_all,
7619 show_ipv6_bgp_community_all_cmd,
7620 "show ipv6 bgp community",
7621 SHOW_STR
7622 IPV6_STR
7623 BGP_STR
7624 "Display routes matching the communities\n")
7625{
7626 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007627 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007628}
7629
7630/* old command */
7631DEFUN (show_ipv6_mbgp_community_all,
7632 show_ipv6_mbgp_community_all_cmd,
7633 "show ipv6 mbgp community",
7634 SHOW_STR
7635 IPV6_STR
7636 MBGP_STR
7637 "Display routes matching the communities\n")
7638{
7639 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007640 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007641}
7642#endif /* HAVE_IPV6 */
7643
paul94f2b392005-06-28 12:44:16 +00007644static int
paulfd79ac92004-10-13 05:06:08 +00007645bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04007646 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007647{
7648 struct community *com;
7649 struct buffer *b;
7650 int i;
7651 char *str;
7652 int first = 0;
7653
7654 b = buffer_new (1024);
7655 for (i = 0; i < argc; i++)
7656 {
7657 if (first)
7658 buffer_putc (b, ' ');
7659 else
7660 {
7661 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7662 continue;
7663 first = 1;
7664 }
7665
7666 buffer_putstr (b, argv[i]);
7667 }
7668 buffer_putc (b, '\0');
7669
7670 str = buffer_getstr (b);
7671 buffer_free (b);
7672
7673 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007674 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007675 if (! com)
7676 {
7677 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7678 return CMD_WARNING;
7679 }
7680
ajs5a646652004-11-05 01:25:55 +00007681 return bgp_show (vty, NULL, afi, safi,
7682 (exact ? bgp_show_type_community_exact :
7683 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007684}
7685
7686DEFUN (show_ip_bgp_community,
7687 show_ip_bgp_community_cmd,
7688 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7689 SHOW_STR
7690 IP_STR
7691 BGP_STR
7692 "Display routes matching the communities\n"
7693 "community number\n"
7694 "Do not send outside local AS (well-known community)\n"
7695 "Do not advertise to any peer (well-known community)\n"
7696 "Do not export to next AS (well-known community)\n")
7697{
7698 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7699}
7700
7701ALIAS (show_ip_bgp_community,
7702 show_ip_bgp_community2_cmd,
7703 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7704 SHOW_STR
7705 IP_STR
7706 BGP_STR
7707 "Display routes matching the communities\n"
7708 "community number\n"
7709 "Do not send outside local AS (well-known community)\n"
7710 "Do not advertise to any peer (well-known community)\n"
7711 "Do not export to next AS (well-known community)\n"
7712 "community number\n"
7713 "Do not send outside local AS (well-known community)\n"
7714 "Do not advertise to any peer (well-known community)\n"
7715 "Do not export to next AS (well-known community)\n")
7716
7717ALIAS (show_ip_bgp_community,
7718 show_ip_bgp_community3_cmd,
7719 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7720 SHOW_STR
7721 IP_STR
7722 BGP_STR
7723 "Display routes matching the communities\n"
7724 "community number\n"
7725 "Do not send outside local AS (well-known community)\n"
7726 "Do not advertise to any peer (well-known community)\n"
7727 "Do not export to next AS (well-known community)\n"
7728 "community number\n"
7729 "Do not send outside local AS (well-known community)\n"
7730 "Do not advertise to any peer (well-known community)\n"
7731 "Do not export to next AS (well-known community)\n"
7732 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\n")
7736
7737ALIAS (show_ip_bgp_community,
7738 show_ip_bgp_community4_cmd,
7739 "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)",
7740 SHOW_STR
7741 IP_STR
7742 BGP_STR
7743 "Display routes matching the communities\n"
7744 "community number\n"
7745 "Do not send outside local AS (well-known community)\n"
7746 "Do not advertise to any peer (well-known community)\n"
7747 "Do not export to next AS (well-known community)\n"
7748 "community number\n"
7749 "Do not send outside local AS (well-known community)\n"
7750 "Do not advertise to any peer (well-known community)\n"
7751 "Do not export to next AS (well-known community)\n"
7752 "community number\n"
7753 "Do not send outside local AS (well-known community)\n"
7754 "Do not advertise to any peer (well-known community)\n"
7755 "Do not export to next AS (well-known community)\n"
7756 "community number\n"
7757 "Do not send outside local AS (well-known community)\n"
7758 "Do not advertise to any peer (well-known community)\n"
7759 "Do not export to next AS (well-known community)\n")
7760
7761DEFUN (show_ip_bgp_ipv4_community,
7762 show_ip_bgp_ipv4_community_cmd,
7763 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7764 SHOW_STR
7765 IP_STR
7766 BGP_STR
7767 "Address family\n"
7768 "Address Family modifier\n"
7769 "Address Family modifier\n"
7770 "Display routes matching the communities\n"
7771 "community number\n"
7772 "Do not send outside local AS (well-known community)\n"
7773 "Do not advertise to any peer (well-known community)\n"
7774 "Do not export to next AS (well-known community)\n")
7775{
7776 if (strncmp (argv[0], "m", 1) == 0)
7777 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7778
7779 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7780}
7781
7782ALIAS (show_ip_bgp_ipv4_community,
7783 show_ip_bgp_ipv4_community2_cmd,
7784 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7785 SHOW_STR
7786 IP_STR
7787 BGP_STR
7788 "Address family\n"
7789 "Address Family modifier\n"
7790 "Address Family modifier\n"
7791 "Display routes matching the communities\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n")
7800
7801ALIAS (show_ip_bgp_ipv4_community,
7802 show_ip_bgp_ipv4_community3_cmd,
7803 "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)",
7804 SHOW_STR
7805 IP_STR
7806 BGP_STR
7807 "Address family\n"
7808 "Address Family modifier\n"
7809 "Address Family modifier\n"
7810 "Display routes matching the communities\n"
7811 "community number\n"
7812 "Do not send outside local AS (well-known community)\n"
7813 "Do not advertise to any peer (well-known community)\n"
7814 "Do not export to next AS (well-known community)\n"
7815 "community number\n"
7816 "Do not send outside local AS (well-known community)\n"
7817 "Do not advertise to any peer (well-known community)\n"
7818 "Do not export to next AS (well-known community)\n"
7819 "community number\n"
7820 "Do not send outside local AS (well-known community)\n"
7821 "Do not advertise to any peer (well-known community)\n"
7822 "Do not export to next AS (well-known community)\n")
7823
7824ALIAS (show_ip_bgp_ipv4_community,
7825 show_ip_bgp_ipv4_community4_cmd,
7826 "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)",
7827 SHOW_STR
7828 IP_STR
7829 BGP_STR
7830 "Address family\n"
7831 "Address Family modifier\n"
7832 "Address Family modifier\n"
7833 "Display routes matching the communities\n"
7834 "community number\n"
7835 "Do not send outside local AS (well-known community)\n"
7836 "Do not advertise to any peer (well-known community)\n"
7837 "Do not export to next AS (well-known community)\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n"
7842 "community number\n"
7843 "Do not send outside local AS (well-known community)\n"
7844 "Do not advertise to any peer (well-known community)\n"
7845 "Do not export to next AS (well-known community)\n"
7846 "community number\n"
7847 "Do not send outside local AS (well-known community)\n"
7848 "Do not advertise to any peer (well-known community)\n"
7849 "Do not export to next AS (well-known community)\n")
7850
7851DEFUN (show_ip_bgp_community_exact,
7852 show_ip_bgp_community_exact_cmd,
7853 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7854 SHOW_STR
7855 IP_STR
7856 BGP_STR
7857 "Display routes matching the communities\n"
7858 "community number\n"
7859 "Do not send outside local AS (well-known community)\n"
7860 "Do not advertise to any peer (well-known community)\n"
7861 "Do not export to next AS (well-known community)\n"
7862 "Exact match of the communities")
7863{
7864 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7865}
7866
7867ALIAS (show_ip_bgp_community_exact,
7868 show_ip_bgp_community2_exact_cmd,
7869 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7870 SHOW_STR
7871 IP_STR
7872 BGP_STR
7873 "Display routes matching the communities\n"
7874 "community number\n"
7875 "Do not send outside local AS (well-known community)\n"
7876 "Do not advertise to any peer (well-known community)\n"
7877 "Do not export to next AS (well-known community)\n"
7878 "community number\n"
7879 "Do not send outside local AS (well-known community)\n"
7880 "Do not advertise to any peer (well-known community)\n"
7881 "Do not export to next AS (well-known community)\n"
7882 "Exact match of the communities")
7883
7884ALIAS (show_ip_bgp_community_exact,
7885 show_ip_bgp_community3_exact_cmd,
7886 "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",
7887 SHOW_STR
7888 IP_STR
7889 BGP_STR
7890 "Display routes matching the communities\n"
7891 "community number\n"
7892 "Do not send outside local AS (well-known community)\n"
7893 "Do not advertise to any peer (well-known community)\n"
7894 "Do not export to next AS (well-known community)\n"
7895 "community number\n"
7896 "Do not send outside local AS (well-known community)\n"
7897 "Do not advertise to any peer (well-known community)\n"
7898 "Do not export to next AS (well-known community)\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n"
7903 "Exact match of the communities")
7904
7905ALIAS (show_ip_bgp_community_exact,
7906 show_ip_bgp_community4_exact_cmd,
7907 "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",
7908 SHOW_STR
7909 IP_STR
7910 BGP_STR
7911 "Display routes matching the communities\n"
7912 "community number\n"
7913 "Do not send outside local AS (well-known community)\n"
7914 "Do not advertise to any peer (well-known community)\n"
7915 "Do not export to next AS (well-known community)\n"
7916 "community number\n"
7917 "Do not send outside local AS (well-known community)\n"
7918 "Do not advertise to any peer (well-known community)\n"
7919 "Do not export to next AS (well-known community)\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n"
7928 "Exact match of the communities")
7929
7930DEFUN (show_ip_bgp_ipv4_community_exact,
7931 show_ip_bgp_ipv4_community_exact_cmd,
7932 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7933 SHOW_STR
7934 IP_STR
7935 BGP_STR
7936 "Address family\n"
7937 "Address Family modifier\n"
7938 "Address Family modifier\n"
7939 "Display routes matching the communities\n"
7940 "community number\n"
7941 "Do not send outside local AS (well-known community)\n"
7942 "Do not advertise to any peer (well-known community)\n"
7943 "Do not export to next AS (well-known community)\n"
7944 "Exact match of the communities")
7945{
7946 if (strncmp (argv[0], "m", 1) == 0)
7947 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7948
7949 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7950}
7951
7952ALIAS (show_ip_bgp_ipv4_community_exact,
7953 show_ip_bgp_ipv4_community2_exact_cmd,
7954 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7955 SHOW_STR
7956 IP_STR
7957 BGP_STR
7958 "Address family\n"
7959 "Address Family modifier\n"
7960 "Address Family modifier\n"
7961 "Display routes matching the communities\n"
7962 "community number\n"
7963 "Do not send outside local AS (well-known community)\n"
7964 "Do not advertise to any peer (well-known community)\n"
7965 "Do not export to next AS (well-known community)\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n"
7970 "Exact match of the communities")
7971
7972ALIAS (show_ip_bgp_ipv4_community_exact,
7973 show_ip_bgp_ipv4_community3_exact_cmd,
7974 "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",
7975 SHOW_STR
7976 IP_STR
7977 BGP_STR
7978 "Address family\n"
7979 "Address Family modifier\n"
7980 "Address Family modifier\n"
7981 "Display routes matching the communities\n"
7982 "community number\n"
7983 "Do not send outside local AS (well-known community)\n"
7984 "Do not advertise to any peer (well-known community)\n"
7985 "Do not export to next AS (well-known community)\n"
7986 "community number\n"
7987 "Do not send outside local AS (well-known community)\n"
7988 "Do not advertise to any peer (well-known community)\n"
7989 "Do not export to next AS (well-known community)\n"
7990 "community number\n"
7991 "Do not send outside local AS (well-known community)\n"
7992 "Do not advertise to any peer (well-known community)\n"
7993 "Do not export to next AS (well-known community)\n"
7994 "Exact match of the communities")
7995
7996ALIAS (show_ip_bgp_ipv4_community_exact,
7997 show_ip_bgp_ipv4_community4_exact_cmd,
7998 "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",
7999 SHOW_STR
8000 IP_STR
8001 BGP_STR
8002 "Address family\n"
8003 "Address Family modifier\n"
8004 "Address Family modifier\n"
8005 "Display routes matching the communities\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n"
8010 "community number\n"
8011 "Do not send outside local AS (well-known community)\n"
8012 "Do not advertise to any peer (well-known community)\n"
8013 "Do not export to next AS (well-known community)\n"
8014 "community number\n"
8015 "Do not send outside local AS (well-known community)\n"
8016 "Do not advertise to any peer (well-known community)\n"
8017 "Do not export to next AS (well-known community)\n"
8018 "community number\n"
8019 "Do not send outside local AS (well-known community)\n"
8020 "Do not advertise to any peer (well-known community)\n"
8021 "Do not export to next AS (well-known community)\n"
8022 "Exact match of the communities")
8023
8024#ifdef HAVE_IPV6
8025DEFUN (show_bgp_community,
8026 show_bgp_community_cmd,
8027 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8028 SHOW_STR
8029 BGP_STR
8030 "Display routes matching the communities\n"
8031 "community number\n"
8032 "Do not send outside local AS (well-known community)\n"
8033 "Do not advertise to any peer (well-known community)\n"
8034 "Do not export to next AS (well-known community)\n")
8035{
8036 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8037}
8038
8039ALIAS (show_bgp_community,
8040 show_bgp_ipv6_community_cmd,
8041 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8042 SHOW_STR
8043 BGP_STR
8044 "Address family\n"
8045 "Display routes matching the communities\n"
8046 "community number\n"
8047 "Do not send outside local AS (well-known community)\n"
8048 "Do not advertise to any peer (well-known community)\n"
8049 "Do not export to next AS (well-known community)\n")
8050
8051ALIAS (show_bgp_community,
8052 show_bgp_community2_cmd,
8053 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8054 SHOW_STR
8055 BGP_STR
8056 "Display routes matching the communities\n"
8057 "community number\n"
8058 "Do not send outside local AS (well-known community)\n"
8059 "Do not advertise to any peer (well-known community)\n"
8060 "Do not export to next AS (well-known community)\n"
8061 "community number\n"
8062 "Do not send outside local AS (well-known community)\n"
8063 "Do not advertise to any peer (well-known community)\n"
8064 "Do not export to next AS (well-known community)\n")
8065
8066ALIAS (show_bgp_community,
8067 show_bgp_ipv6_community2_cmd,
8068 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8069 SHOW_STR
8070 BGP_STR
8071 "Address family\n"
8072 "Display routes matching the communities\n"
8073 "community number\n"
8074 "Do not send outside local AS (well-known community)\n"
8075 "Do not advertise to any peer (well-known community)\n"
8076 "Do not export to next AS (well-known community)\n"
8077 "community number\n"
8078 "Do not send outside local AS (well-known community)\n"
8079 "Do not advertise to any peer (well-known community)\n"
8080 "Do not export to next AS (well-known community)\n")
8081
8082ALIAS (show_bgp_community,
8083 show_bgp_community3_cmd,
8084 "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)",
8085 SHOW_STR
8086 BGP_STR
8087 "Display routes matching the communities\n"
8088 "community number\n"
8089 "Do not send outside local AS (well-known community)\n"
8090 "Do not advertise to any peer (well-known community)\n"
8091 "Do not export to next AS (well-known community)\n"
8092 "community number\n"
8093 "Do not send outside local AS (well-known community)\n"
8094 "Do not advertise to any peer (well-known community)\n"
8095 "Do not export to next AS (well-known community)\n"
8096 "community number\n"
8097 "Do not send outside local AS (well-known community)\n"
8098 "Do not advertise to any peer (well-known community)\n"
8099 "Do not export to next AS (well-known community)\n")
8100
8101ALIAS (show_bgp_community,
8102 show_bgp_ipv6_community3_cmd,
8103 "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)",
8104 SHOW_STR
8105 BGP_STR
8106 "Address family\n"
8107 "Display routes matching the communities\n"
8108 "community number\n"
8109 "Do not send outside local AS (well-known community)\n"
8110 "Do not advertise to any peer (well-known community)\n"
8111 "Do not export to next AS (well-known community)\n"
8112 "community number\n"
8113 "Do not send outside local AS (well-known community)\n"
8114 "Do not advertise to any peer (well-known community)\n"
8115 "Do not export to next AS (well-known community)\n"
8116 "community number\n"
8117 "Do not send outside local AS (well-known community)\n"
8118 "Do not advertise to any peer (well-known community)\n"
8119 "Do not export to next AS (well-known community)\n")
8120
8121ALIAS (show_bgp_community,
8122 show_bgp_community4_cmd,
8123 "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)",
8124 SHOW_STR
8125 BGP_STR
8126 "Display routes matching the communities\n"
8127 "community number\n"
8128 "Do not send outside local AS (well-known community)\n"
8129 "Do not advertise to any peer (well-known community)\n"
8130 "Do not export to next AS (well-known community)\n"
8131 "community number\n"
8132 "Do not send outside local AS (well-known community)\n"
8133 "Do not advertise to any peer (well-known community)\n"
8134 "Do not export to next AS (well-known community)\n"
8135 "community number\n"
8136 "Do not send outside local AS (well-known community)\n"
8137 "Do not advertise to any peer (well-known community)\n"
8138 "Do not export to next AS (well-known community)\n"
8139 "community number\n"
8140 "Do not send outside local AS (well-known community)\n"
8141 "Do not advertise to any peer (well-known community)\n"
8142 "Do not export to next AS (well-known community)\n")
8143
8144ALIAS (show_bgp_community,
8145 show_bgp_ipv6_community4_cmd,
8146 "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)",
8147 SHOW_STR
8148 BGP_STR
8149 "Address family\n"
8150 "Display routes matching the communities\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n"
8163 "community number\n"
8164 "Do not send outside local AS (well-known community)\n"
8165 "Do not advertise to any peer (well-known community)\n"
8166 "Do not export to next AS (well-known community)\n")
8167
8168/* old command */
8169DEFUN (show_ipv6_bgp_community,
8170 show_ipv6_bgp_community_cmd,
8171 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8172 SHOW_STR
8173 IPV6_STR
8174 BGP_STR
8175 "Display routes matching the communities\n"
8176 "community number\n"
8177 "Do not send outside local AS (well-known community)\n"
8178 "Do not advertise to any peer (well-known community)\n"
8179 "Do not export to next AS (well-known community)\n")
8180{
8181 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8182}
8183
8184/* old command */
8185ALIAS (show_ipv6_bgp_community,
8186 show_ipv6_bgp_community2_cmd,
8187 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8188 SHOW_STR
8189 IPV6_STR
8190 BGP_STR
8191 "Display routes matching the communities\n"
8192 "community number\n"
8193 "Do not send outside local AS (well-known community)\n"
8194 "Do not advertise to any peer (well-known community)\n"
8195 "Do not export to next AS (well-known community)\n"
8196 "community number\n"
8197 "Do not send outside local AS (well-known community)\n"
8198 "Do not advertise to any peer (well-known community)\n"
8199 "Do not export to next AS (well-known community)\n")
8200
8201/* old command */
8202ALIAS (show_ipv6_bgp_community,
8203 show_ipv6_bgp_community3_cmd,
8204 "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)",
8205 SHOW_STR
8206 IPV6_STR
8207 BGP_STR
8208 "Display routes matching the communities\n"
8209 "community number\n"
8210 "Do not send outside local AS (well-known community)\n"
8211 "Do not advertise to any peer (well-known community)\n"
8212 "Do not export to next AS (well-known community)\n"
8213 "community number\n"
8214 "Do not send outside local AS (well-known community)\n"
8215 "Do not advertise to any peer (well-known community)\n"
8216 "Do not export to next AS (well-known community)\n"
8217 "community number\n"
8218 "Do not send outside local AS (well-known community)\n"
8219 "Do not advertise to any peer (well-known community)\n"
8220 "Do not export to next AS (well-known community)\n")
8221
8222/* old command */
8223ALIAS (show_ipv6_bgp_community,
8224 show_ipv6_bgp_community4_cmd,
8225 "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)",
8226 SHOW_STR
8227 IPV6_STR
8228 BGP_STR
8229 "Display routes matching the communities\n"
8230 "community number\n"
8231 "Do not send outside local AS (well-known community)\n"
8232 "Do not advertise to any peer (well-known community)\n"
8233 "Do not export to next AS (well-known community)\n"
8234 "community number\n"
8235 "Do not send outside local AS (well-known community)\n"
8236 "Do not advertise to any peer (well-known community)\n"
8237 "Do not export to next AS (well-known community)\n"
8238 "community number\n"
8239 "Do not send outside local AS (well-known community)\n"
8240 "Do not advertise to any peer (well-known community)\n"
8241 "Do not export to next AS (well-known community)\n"
8242 "community number\n"
8243 "Do not send outside local AS (well-known community)\n"
8244 "Do not advertise to any peer (well-known community)\n"
8245 "Do not export to next AS (well-known community)\n")
8246
8247DEFUN (show_bgp_community_exact,
8248 show_bgp_community_exact_cmd,
8249 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8250 SHOW_STR
8251 BGP_STR
8252 "Display routes matching the communities\n"
8253 "community number\n"
8254 "Do not send outside local AS (well-known community)\n"
8255 "Do not advertise to any peer (well-known community)\n"
8256 "Do not export to next AS (well-known community)\n"
8257 "Exact match of the communities")
8258{
8259 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8260}
8261
8262ALIAS (show_bgp_community_exact,
8263 show_bgp_ipv6_community_exact_cmd,
8264 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8265 SHOW_STR
8266 BGP_STR
8267 "Address family\n"
8268 "Display routes matching the communities\n"
8269 "community number\n"
8270 "Do not send outside local AS (well-known community)\n"
8271 "Do not advertise to any peer (well-known community)\n"
8272 "Do not export to next AS (well-known community)\n"
8273 "Exact match of the communities")
8274
8275ALIAS (show_bgp_community_exact,
8276 show_bgp_community2_exact_cmd,
8277 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8278 SHOW_STR
8279 BGP_STR
8280 "Display routes matching the communities\n"
8281 "community number\n"
8282 "Do not send outside local AS (well-known community)\n"
8283 "Do not advertise to any peer (well-known community)\n"
8284 "Do not export to next AS (well-known community)\n"
8285 "community number\n"
8286 "Do not send outside local AS (well-known community)\n"
8287 "Do not advertise to any peer (well-known community)\n"
8288 "Do not export to next AS (well-known community)\n"
8289 "Exact match of the communities")
8290
8291ALIAS (show_bgp_community_exact,
8292 show_bgp_ipv6_community2_exact_cmd,
8293 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8294 SHOW_STR
8295 BGP_STR
8296 "Address family\n"
8297 "Display routes matching the communities\n"
8298 "community number\n"
8299 "Do not send outside local AS (well-known community)\n"
8300 "Do not advertise to any peer (well-known community)\n"
8301 "Do not export to next AS (well-known community)\n"
8302 "community number\n"
8303 "Do not send outside local AS (well-known community)\n"
8304 "Do not advertise to any peer (well-known community)\n"
8305 "Do not export to next AS (well-known community)\n"
8306 "Exact match of the communities")
8307
8308ALIAS (show_bgp_community_exact,
8309 show_bgp_community3_exact_cmd,
8310 "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",
8311 SHOW_STR
8312 BGP_STR
8313 "Display routes matching the communities\n"
8314 "community number\n"
8315 "Do not send outside local AS (well-known community)\n"
8316 "Do not advertise to any peer (well-known community)\n"
8317 "Do not export to next AS (well-known community)\n"
8318 "community number\n"
8319 "Do not send outside local AS (well-known community)\n"
8320 "Do not advertise to any peer (well-known community)\n"
8321 "Do not export to next AS (well-known community)\n"
8322 "community number\n"
8323 "Do not send outside local AS (well-known community)\n"
8324 "Do not advertise to any peer (well-known community)\n"
8325 "Do not export to next AS (well-known community)\n"
8326 "Exact match of the communities")
8327
8328ALIAS (show_bgp_community_exact,
8329 show_bgp_ipv6_community3_exact_cmd,
8330 "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",
8331 SHOW_STR
8332 BGP_STR
8333 "Address family\n"
8334 "Display routes matching the communities\n"
8335 "community number\n"
8336 "Do not send outside local AS (well-known community)\n"
8337 "Do not advertise to any peer (well-known community)\n"
8338 "Do not export to next AS (well-known community)\n"
8339 "community number\n"
8340 "Do not send outside local AS (well-known community)\n"
8341 "Do not advertise to any peer (well-known community)\n"
8342 "Do not export to next AS (well-known community)\n"
8343 "community number\n"
8344 "Do not send outside local AS (well-known community)\n"
8345 "Do not advertise to any peer (well-known community)\n"
8346 "Do not export to next AS (well-known community)\n"
8347 "Exact match of the communities")
8348
8349ALIAS (show_bgp_community_exact,
8350 show_bgp_community4_exact_cmd,
8351 "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",
8352 SHOW_STR
8353 BGP_STR
8354 "Display routes matching the communities\n"
8355 "community number\n"
8356 "Do not send outside local AS (well-known community)\n"
8357 "Do not advertise to any peer (well-known community)\n"
8358 "Do not export to next AS (well-known community)\n"
8359 "community number\n"
8360 "Do not send outside local AS (well-known community)\n"
8361 "Do not advertise to any peer (well-known community)\n"
8362 "Do not export to next AS (well-known community)\n"
8363 "community number\n"
8364 "Do not send outside local AS (well-known community)\n"
8365 "Do not advertise to any peer (well-known community)\n"
8366 "Do not export to next AS (well-known community)\n"
8367 "community number\n"
8368 "Do not send outside local AS (well-known community)\n"
8369 "Do not advertise to any peer (well-known community)\n"
8370 "Do not export to next AS (well-known community)\n"
8371 "Exact match of the communities")
8372
8373ALIAS (show_bgp_community_exact,
8374 show_bgp_ipv6_community4_exact_cmd,
8375 "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",
8376 SHOW_STR
8377 BGP_STR
8378 "Address family\n"
8379 "Display routes matching the communities\n"
8380 "community number\n"
8381 "Do not send outside local AS (well-known community)\n"
8382 "Do not advertise to any peer (well-known community)\n"
8383 "Do not export to next AS (well-known community)\n"
8384 "community number\n"
8385 "Do not send outside local AS (well-known community)\n"
8386 "Do not advertise to any peer (well-known community)\n"
8387 "Do not export to next AS (well-known community)\n"
8388 "community number\n"
8389 "Do not send outside local AS (well-known community)\n"
8390 "Do not advertise to any peer (well-known community)\n"
8391 "Do not export to next AS (well-known community)\n"
8392 "community number\n"
8393 "Do not send outside local AS (well-known community)\n"
8394 "Do not advertise to any peer (well-known community)\n"
8395 "Do not export to next AS (well-known community)\n"
8396 "Exact match of the communities")
8397
8398/* old command */
8399DEFUN (show_ipv6_bgp_community_exact,
8400 show_ipv6_bgp_community_exact_cmd,
8401 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8402 SHOW_STR
8403 IPV6_STR
8404 BGP_STR
8405 "Display routes matching the communities\n"
8406 "community number\n"
8407 "Do not send outside local AS (well-known community)\n"
8408 "Do not advertise to any peer (well-known community)\n"
8409 "Do not export to next AS (well-known community)\n"
8410 "Exact match of the communities")
8411{
8412 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8413}
8414
8415/* old command */
8416ALIAS (show_ipv6_bgp_community_exact,
8417 show_ipv6_bgp_community2_exact_cmd,
8418 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8419 SHOW_STR
8420 IPV6_STR
8421 BGP_STR
8422 "Display routes matching the communities\n"
8423 "community number\n"
8424 "Do not send outside local AS (well-known community)\n"
8425 "Do not advertise to any peer (well-known community)\n"
8426 "Do not export to next AS (well-known community)\n"
8427 "community number\n"
8428 "Do not send outside local AS (well-known community)\n"
8429 "Do not advertise to any peer (well-known community)\n"
8430 "Do not export to next AS (well-known community)\n"
8431 "Exact match of the communities")
8432
8433/* old command */
8434ALIAS (show_ipv6_bgp_community_exact,
8435 show_ipv6_bgp_community3_exact_cmd,
8436 "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",
8437 SHOW_STR
8438 IPV6_STR
8439 BGP_STR
8440 "Display routes matching the communities\n"
8441 "community number\n"
8442 "Do not send outside local AS (well-known community)\n"
8443 "Do not advertise to any peer (well-known community)\n"
8444 "Do not export to next AS (well-known community)\n"
8445 "community number\n"
8446 "Do not send outside local AS (well-known community)\n"
8447 "Do not advertise to any peer (well-known community)\n"
8448 "Do not export to next AS (well-known community)\n"
8449 "community number\n"
8450 "Do not send outside local AS (well-known community)\n"
8451 "Do not advertise to any peer (well-known community)\n"
8452 "Do not export to next AS (well-known community)\n"
8453 "Exact match of the communities")
8454
8455/* old command */
8456ALIAS (show_ipv6_bgp_community_exact,
8457 show_ipv6_bgp_community4_exact_cmd,
8458 "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",
8459 SHOW_STR
8460 IPV6_STR
8461 BGP_STR
8462 "Display routes matching the communities\n"
8463 "community number\n"
8464 "Do not send outside local AS (well-known community)\n"
8465 "Do not advertise to any peer (well-known community)\n"
8466 "Do not export to next AS (well-known community)\n"
8467 "community number\n"
8468 "Do not send outside local AS (well-known community)\n"
8469 "Do not advertise to any peer (well-known community)\n"
8470 "Do not export to next AS (well-known community)\n"
8471 "community number\n"
8472 "Do not send outside local AS (well-known community)\n"
8473 "Do not advertise to any peer (well-known community)\n"
8474 "Do not export to next AS (well-known community)\n"
8475 "community number\n"
8476 "Do not send outside local AS (well-known community)\n"
8477 "Do not advertise to any peer (well-known community)\n"
8478 "Do not export to next AS (well-known community)\n"
8479 "Exact match of the communities")
8480
8481/* old command */
8482DEFUN (show_ipv6_mbgp_community,
8483 show_ipv6_mbgp_community_cmd,
8484 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8485 SHOW_STR
8486 IPV6_STR
8487 MBGP_STR
8488 "Display routes matching the communities\n"
8489 "community number\n"
8490 "Do not send outside local AS (well-known community)\n"
8491 "Do not advertise to any peer (well-known community)\n"
8492 "Do not export to next AS (well-known community)\n")
8493{
8494 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8495}
8496
8497/* old command */
8498ALIAS (show_ipv6_mbgp_community,
8499 show_ipv6_mbgp_community2_cmd,
8500 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8501 SHOW_STR
8502 IPV6_STR
8503 MBGP_STR
8504 "Display routes matching the communities\n"
8505 "community number\n"
8506 "Do not send outside local AS (well-known community)\n"
8507 "Do not advertise to any peer (well-known community)\n"
8508 "Do not export to next AS (well-known community)\n"
8509 "community number\n"
8510 "Do not send outside local AS (well-known community)\n"
8511 "Do not advertise to any peer (well-known community)\n"
8512 "Do not export to next AS (well-known community)\n")
8513
8514/* old command */
8515ALIAS (show_ipv6_mbgp_community,
8516 show_ipv6_mbgp_community3_cmd,
8517 "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)",
8518 SHOW_STR
8519 IPV6_STR
8520 MBGP_STR
8521 "Display routes matching the communities\n"
8522 "community number\n"
8523 "Do not send outside local AS (well-known community)\n"
8524 "Do not advertise to any peer (well-known community)\n"
8525 "Do not export to next AS (well-known community)\n"
8526 "community number\n"
8527 "Do not send outside local AS (well-known community)\n"
8528 "Do not advertise to any peer (well-known community)\n"
8529 "Do not export to next AS (well-known community)\n"
8530 "community number\n"
8531 "Do not send outside local AS (well-known community)\n"
8532 "Do not advertise to any peer (well-known community)\n"
8533 "Do not export to next AS (well-known community)\n")
8534
8535/* old command */
8536ALIAS (show_ipv6_mbgp_community,
8537 show_ipv6_mbgp_community4_cmd,
8538 "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)",
8539 SHOW_STR
8540 IPV6_STR
8541 MBGP_STR
8542 "Display routes matching the communities\n"
8543 "community number\n"
8544 "Do not send outside local AS (well-known community)\n"
8545 "Do not advertise to any peer (well-known community)\n"
8546 "Do not export to next AS (well-known community)\n"
8547 "community number\n"
8548 "Do not send outside local AS (well-known community)\n"
8549 "Do not advertise to any peer (well-known community)\n"
8550 "Do not export to next AS (well-known community)\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n")
8559
8560/* old command */
8561DEFUN (show_ipv6_mbgp_community_exact,
8562 show_ipv6_mbgp_community_exact_cmd,
8563 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8564 SHOW_STR
8565 IPV6_STR
8566 MBGP_STR
8567 "Display routes matching the communities\n"
8568 "community number\n"
8569 "Do not send outside local AS (well-known community)\n"
8570 "Do not advertise to any peer (well-known community)\n"
8571 "Do not export to next AS (well-known community)\n"
8572 "Exact match of the communities")
8573{
8574 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8575}
8576
8577/* old command */
8578ALIAS (show_ipv6_mbgp_community_exact,
8579 show_ipv6_mbgp_community2_exact_cmd,
8580 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8581 SHOW_STR
8582 IPV6_STR
8583 MBGP_STR
8584 "Display routes matching the communities\n"
8585 "community number\n"
8586 "Do not send outside local AS (well-known community)\n"
8587 "Do not advertise to any peer (well-known community)\n"
8588 "Do not export to next AS (well-known community)\n"
8589 "community number\n"
8590 "Do not send outside local AS (well-known community)\n"
8591 "Do not advertise to any peer (well-known community)\n"
8592 "Do not export to next AS (well-known community)\n"
8593 "Exact match of the communities")
8594
8595/* old command */
8596ALIAS (show_ipv6_mbgp_community_exact,
8597 show_ipv6_mbgp_community3_exact_cmd,
8598 "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",
8599 SHOW_STR
8600 IPV6_STR
8601 MBGP_STR
8602 "Display routes matching the communities\n"
8603 "community number\n"
8604 "Do not send outside local AS (well-known community)\n"
8605 "Do not advertise to any peer (well-known community)\n"
8606 "Do not export to next AS (well-known community)\n"
8607 "community number\n"
8608 "Do not send outside local AS (well-known community)\n"
8609 "Do not advertise to any peer (well-known community)\n"
8610 "Do not export to next AS (well-known community)\n"
8611 "community number\n"
8612 "Do not send outside local AS (well-known community)\n"
8613 "Do not advertise to any peer (well-known community)\n"
8614 "Do not export to next AS (well-known community)\n"
8615 "Exact match of the communities")
8616
8617/* old command */
8618ALIAS (show_ipv6_mbgp_community_exact,
8619 show_ipv6_mbgp_community4_exact_cmd,
8620 "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",
8621 SHOW_STR
8622 IPV6_STR
8623 MBGP_STR
8624 "Display routes matching the communities\n"
8625 "community number\n"
8626 "Do not send outside local AS (well-known community)\n"
8627 "Do not advertise to any peer (well-known community)\n"
8628 "Do not export to next AS (well-known community)\n"
8629 "community number\n"
8630 "Do not send outside local AS (well-known community)\n"
8631 "Do not advertise to any peer (well-known community)\n"
8632 "Do not export to next AS (well-known community)\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "community number\n"
8638 "Do not send outside local AS (well-known community)\n"
8639 "Do not advertise to any peer (well-known community)\n"
8640 "Do not export to next AS (well-known community)\n"
8641 "Exact match of the communities")
8642#endif /* HAVE_IPV6 */
8643
paul94f2b392005-06-28 12:44:16 +00008644static int
paulfd79ac92004-10-13 05:06:08 +00008645bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008646 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008647{
8648 struct community_list *list;
8649
hassofee6e4e2005-02-02 16:29:31 +00008650 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008651 if (list == NULL)
8652 {
8653 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8654 VTY_NEWLINE);
8655 return CMD_WARNING;
8656 }
8657
ajs5a646652004-11-05 01:25:55 +00008658 return bgp_show (vty, NULL, afi, safi,
8659 (exact ? bgp_show_type_community_list_exact :
8660 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008661}
8662
8663DEFUN (show_ip_bgp_community_list,
8664 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008665 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008666 SHOW_STR
8667 IP_STR
8668 BGP_STR
8669 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008670 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008671 "community-list name\n")
8672{
8673 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8674}
8675
8676DEFUN (show_ip_bgp_ipv4_community_list,
8677 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008678 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008679 SHOW_STR
8680 IP_STR
8681 BGP_STR
8682 "Address family\n"
8683 "Address Family modifier\n"
8684 "Address Family modifier\n"
8685 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008686 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008687 "community-list name\n")
8688{
8689 if (strncmp (argv[0], "m", 1) == 0)
8690 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8691
8692 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8693}
8694
8695DEFUN (show_ip_bgp_community_list_exact,
8696 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008697 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008698 SHOW_STR
8699 IP_STR
8700 BGP_STR
8701 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008702 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008703 "community-list name\n"
8704 "Exact match of the communities\n")
8705{
8706 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8707}
8708
8709DEFUN (show_ip_bgp_ipv4_community_list_exact,
8710 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008711 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008712 SHOW_STR
8713 IP_STR
8714 BGP_STR
8715 "Address family\n"
8716 "Address Family modifier\n"
8717 "Address Family modifier\n"
8718 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008719 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008720 "community-list name\n"
8721 "Exact match of the communities\n")
8722{
8723 if (strncmp (argv[0], "m", 1) == 0)
8724 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8725
8726 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8727}
8728
8729#ifdef HAVE_IPV6
8730DEFUN (show_bgp_community_list,
8731 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008732 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008733 SHOW_STR
8734 BGP_STR
8735 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008736 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008737 "community-list name\n")
8738{
8739 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8740}
8741
8742ALIAS (show_bgp_community_list,
8743 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008744 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008745 SHOW_STR
8746 BGP_STR
8747 "Address family\n"
8748 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008749 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008750 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008751
8752/* old command */
8753DEFUN (show_ipv6_bgp_community_list,
8754 show_ipv6_bgp_community_list_cmd,
8755 "show ipv6 bgp community-list WORD",
8756 SHOW_STR
8757 IPV6_STR
8758 BGP_STR
8759 "Display routes matching the community-list\n"
8760 "community-list name\n")
8761{
8762 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8763}
8764
8765/* old command */
8766DEFUN (show_ipv6_mbgp_community_list,
8767 show_ipv6_mbgp_community_list_cmd,
8768 "show ipv6 mbgp community-list WORD",
8769 SHOW_STR
8770 IPV6_STR
8771 MBGP_STR
8772 "Display routes matching the community-list\n"
8773 "community-list name\n")
8774{
8775 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8776}
8777
8778DEFUN (show_bgp_community_list_exact,
8779 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008780 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008781 SHOW_STR
8782 BGP_STR
8783 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008784 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008785 "community-list name\n"
8786 "Exact match of the communities\n")
8787{
8788 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8789}
8790
8791ALIAS (show_bgp_community_list_exact,
8792 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008793 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008794 SHOW_STR
8795 BGP_STR
8796 "Address family\n"
8797 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008798 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008799 "community-list name\n"
8800 "Exact match of the communities\n")
8801
8802/* old command */
8803DEFUN (show_ipv6_bgp_community_list_exact,
8804 show_ipv6_bgp_community_list_exact_cmd,
8805 "show ipv6 bgp community-list WORD exact-match",
8806 SHOW_STR
8807 IPV6_STR
8808 BGP_STR
8809 "Display routes matching the community-list\n"
8810 "community-list name\n"
8811 "Exact match of the communities\n")
8812{
8813 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8814}
8815
8816/* old command */
8817DEFUN (show_ipv6_mbgp_community_list_exact,
8818 show_ipv6_mbgp_community_list_exact_cmd,
8819 "show ipv6 mbgp community-list WORD exact-match",
8820 SHOW_STR
8821 IPV6_STR
8822 MBGP_STR
8823 "Display routes matching the community-list\n"
8824 "community-list name\n"
8825 "Exact match of the communities\n")
8826{
8827 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8828}
8829#endif /* HAVE_IPV6 */
8830
paul94f2b392005-06-28 12:44:16 +00008831static int
paulfd79ac92004-10-13 05:06:08 +00008832bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008833 safi_t safi, enum bgp_show_type type)
8834{
8835 int ret;
8836 struct prefix *p;
8837
8838 p = prefix_new();
8839
8840 ret = str2prefix (prefix, p);
8841 if (! ret)
8842 {
8843 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8844 return CMD_WARNING;
8845 }
8846
ajs5a646652004-11-05 01:25:55 +00008847 ret = bgp_show (vty, NULL, afi, safi, type, p);
8848 prefix_free(p);
8849 return ret;
paul718e3742002-12-13 20:15:29 +00008850}
8851
8852DEFUN (show_ip_bgp_prefix_longer,
8853 show_ip_bgp_prefix_longer_cmd,
8854 "show ip bgp A.B.C.D/M longer-prefixes",
8855 SHOW_STR
8856 IP_STR
8857 BGP_STR
8858 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8859 "Display route and more specific routes\n")
8860{
8861 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8862 bgp_show_type_prefix_longer);
8863}
8864
8865DEFUN (show_ip_bgp_flap_prefix_longer,
8866 show_ip_bgp_flap_prefix_longer_cmd,
8867 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8868 SHOW_STR
8869 IP_STR
8870 BGP_STR
8871 "Display flap statistics of routes\n"
8872 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8873 "Display route and more specific routes\n")
8874{
8875 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8876 bgp_show_type_flap_prefix_longer);
8877}
8878
8879DEFUN (show_ip_bgp_ipv4_prefix_longer,
8880 show_ip_bgp_ipv4_prefix_longer_cmd,
8881 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8882 SHOW_STR
8883 IP_STR
8884 BGP_STR
8885 "Address family\n"
8886 "Address Family modifier\n"
8887 "Address Family modifier\n"
8888 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8889 "Display route and more specific routes\n")
8890{
8891 if (strncmp (argv[0], "m", 1) == 0)
8892 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8893 bgp_show_type_prefix_longer);
8894
8895 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8896 bgp_show_type_prefix_longer);
8897}
8898
8899DEFUN (show_ip_bgp_flap_address,
8900 show_ip_bgp_flap_address_cmd,
8901 "show ip bgp flap-statistics A.B.C.D",
8902 SHOW_STR
8903 IP_STR
8904 BGP_STR
8905 "Display flap statistics of routes\n"
8906 "Network in the BGP routing table to display\n")
8907{
8908 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8909 bgp_show_type_flap_address);
8910}
8911
8912DEFUN (show_ip_bgp_flap_prefix,
8913 show_ip_bgp_flap_prefix_cmd,
8914 "show ip bgp flap-statistics A.B.C.D/M",
8915 SHOW_STR
8916 IP_STR
8917 BGP_STR
8918 "Display flap statistics of routes\n"
8919 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8920{
8921 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8922 bgp_show_type_flap_prefix);
8923}
8924#ifdef HAVE_IPV6
8925DEFUN (show_bgp_prefix_longer,
8926 show_bgp_prefix_longer_cmd,
8927 "show bgp X:X::X:X/M longer-prefixes",
8928 SHOW_STR
8929 BGP_STR
8930 "IPv6 prefix <network>/<length>\n"
8931 "Display route and more specific routes\n")
8932{
8933 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8934 bgp_show_type_prefix_longer);
8935}
8936
8937ALIAS (show_bgp_prefix_longer,
8938 show_bgp_ipv6_prefix_longer_cmd,
8939 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8940 SHOW_STR
8941 BGP_STR
8942 "Address family\n"
8943 "IPv6 prefix <network>/<length>\n"
8944 "Display route and more specific routes\n")
8945
8946/* old command */
8947DEFUN (show_ipv6_bgp_prefix_longer,
8948 show_ipv6_bgp_prefix_longer_cmd,
8949 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8950 SHOW_STR
8951 IPV6_STR
8952 BGP_STR
8953 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8954 "Display route and more specific routes\n")
8955{
8956 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8957 bgp_show_type_prefix_longer);
8958}
8959
8960/* old command */
8961DEFUN (show_ipv6_mbgp_prefix_longer,
8962 show_ipv6_mbgp_prefix_longer_cmd,
8963 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8964 SHOW_STR
8965 IPV6_STR
8966 MBGP_STR
8967 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8968 "Display route and more specific routes\n")
8969{
8970 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8971 bgp_show_type_prefix_longer);
8972}
8973#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008974
paul94f2b392005-06-28 12:44:16 +00008975static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008976peer_lookup_in_view (struct vty *vty, const char *view_name,
8977 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008978{
8979 int ret;
8980 struct bgp *bgp;
8981 struct peer *peer;
8982 union sockunion su;
8983
8984 /* BGP structure lookup. */
8985 if (view_name)
8986 {
8987 bgp = bgp_lookup_by_name (view_name);
8988 if (! bgp)
8989 {
8990 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8991 return NULL;
8992 }
8993 }
paul5228ad22004-06-04 17:58:18 +00008994 else
paulbb46e942003-10-24 19:02:03 +00008995 {
8996 bgp = bgp_get_default ();
8997 if (! bgp)
8998 {
8999 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9000 return NULL;
9001 }
9002 }
9003
9004 /* Get peer sockunion. */
9005 ret = str2sockunion (ip_str, &su);
9006 if (ret < 0)
9007 {
9008 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9009 return NULL;
9010 }
9011
9012 /* Peer structure lookup. */
9013 peer = peer_lookup (bgp, &su);
9014 if (! peer)
9015 {
9016 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9017 return NULL;
9018 }
9019
9020 return peer;
9021}
Paul Jakma2815e612006-09-14 02:56:07 +00009022
9023enum bgp_stats
9024{
9025 BGP_STATS_MAXBITLEN = 0,
9026 BGP_STATS_RIB,
9027 BGP_STATS_PREFIXES,
9028 BGP_STATS_TOTPLEN,
9029 BGP_STATS_UNAGGREGATEABLE,
9030 BGP_STATS_MAX_AGGREGATEABLE,
9031 BGP_STATS_AGGREGATES,
9032 BGP_STATS_SPACE,
9033 BGP_STATS_ASPATH_COUNT,
9034 BGP_STATS_ASPATH_MAXHOPS,
9035 BGP_STATS_ASPATH_TOTHOPS,
9036 BGP_STATS_ASPATH_MAXSIZE,
9037 BGP_STATS_ASPATH_TOTSIZE,
9038 BGP_STATS_ASN_HIGHEST,
9039 BGP_STATS_MAX,
9040};
paulbb46e942003-10-24 19:02:03 +00009041
Paul Jakma2815e612006-09-14 02:56:07 +00009042static const char *table_stats_strs[] =
9043{
9044 [BGP_STATS_PREFIXES] = "Total Prefixes",
9045 [BGP_STATS_TOTPLEN] = "Average prefix length",
9046 [BGP_STATS_RIB] = "Total Advertisements",
9047 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9048 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9049 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9050 [BGP_STATS_SPACE] = "Address space advertised",
9051 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9052 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9053 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9054 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9055 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9056 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9057 [BGP_STATS_MAX] = NULL,
9058};
9059
9060struct bgp_table_stats
9061{
9062 struct bgp_table *table;
9063 unsigned long long counts[BGP_STATS_MAX];
9064};
9065
9066#if 0
9067#define TALLY_SIGFIG 100000
9068static unsigned long
9069ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9070{
9071 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9072 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9073 unsigned long ret = newtot / count;
9074
9075 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9076 return ret + 1;
9077 else
9078 return ret;
9079}
9080#endif
9081
9082static int
9083bgp_table_stats_walker (struct thread *t)
9084{
9085 struct bgp_node *rn;
9086 struct bgp_node *top;
9087 struct bgp_table_stats *ts = THREAD_ARG (t);
9088 unsigned int space = 0;
9089
Paul Jakma53d9f672006-10-15 23:41:16 +00009090 if (!(top = bgp_table_top (ts->table)))
9091 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009092
9093 switch (top->p.family)
9094 {
9095 case AF_INET:
9096 space = IPV4_MAX_BITLEN;
9097 break;
9098 case AF_INET6:
9099 space = IPV6_MAX_BITLEN;
9100 break;
9101 }
9102
9103 ts->counts[BGP_STATS_MAXBITLEN] = space;
9104
9105 for (rn = top; rn; rn = bgp_route_next (rn))
9106 {
9107 struct bgp_info *ri;
9108 struct bgp_node *prn = rn->parent;
9109 unsigned int rinum = 0;
9110
9111 if (rn == top)
9112 continue;
9113
9114 if (!rn->info)
9115 continue;
9116
9117 ts->counts[BGP_STATS_PREFIXES]++;
9118 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9119
9120#if 0
9121 ts->counts[BGP_STATS_AVGPLEN]
9122 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9123 ts->counts[BGP_STATS_AVGPLEN],
9124 rn->p.prefixlen);
9125#endif
9126
9127 /* check if the prefix is included by any other announcements */
9128 while (prn && !prn->info)
9129 prn = prn->parent;
9130
9131 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009132 {
9133 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9134 /* announced address space */
9135 if (space)
9136 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9137 }
Paul Jakma2815e612006-09-14 02:56:07 +00009138 else if (prn->info)
9139 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9140
Paul Jakma2815e612006-09-14 02:56:07 +00009141 for (ri = rn->info; ri; ri = ri->next)
9142 {
9143 rinum++;
9144 ts->counts[BGP_STATS_RIB]++;
9145
9146 if (ri->attr &&
9147 (CHECK_FLAG (ri->attr->flag,
9148 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9149 ts->counts[BGP_STATS_AGGREGATES]++;
9150
9151 /* as-path stats */
9152 if (ri->attr && ri->attr->aspath)
9153 {
9154 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9155 unsigned int size = aspath_size (ri->attr->aspath);
9156 as_t highest = aspath_highest (ri->attr->aspath);
9157
9158 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9159
9160 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9161 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9162
9163 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9164 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9165
9166 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9167 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9168#if 0
9169 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9170 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9171 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9172 hops);
9173 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9174 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9175 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9176 size);
9177#endif
9178 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9179 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9180 }
9181 }
9182 }
9183 return 0;
9184}
9185
9186static int
9187bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9188{
9189 struct bgp_table_stats ts;
9190 unsigned int i;
9191
9192 if (!bgp->rib[afi][safi])
9193 {
9194 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9195 return CMD_WARNING;
9196 }
9197
9198 memset (&ts, 0, sizeof (ts));
9199 ts.table = bgp->rib[afi][safi];
9200 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9201
9202 vty_out (vty, "BGP %s RIB statistics%s%s",
9203 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9204
9205 for (i = 0; i < BGP_STATS_MAX; i++)
9206 {
9207 if (!table_stats_strs[i])
9208 continue;
9209
9210 switch (i)
9211 {
9212#if 0
9213 case BGP_STATS_ASPATH_AVGHOPS:
9214 case BGP_STATS_ASPATH_AVGSIZE:
9215 case BGP_STATS_AVGPLEN:
9216 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9217 vty_out (vty, "%12.2f",
9218 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9219 break;
9220#endif
9221 case BGP_STATS_ASPATH_TOTHOPS:
9222 case BGP_STATS_ASPATH_TOTSIZE:
9223 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9224 vty_out (vty, "%12.2f",
9225 ts.counts[i] ?
9226 (float)ts.counts[i] /
9227 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9228 : 0);
9229 break;
9230 case BGP_STATS_TOTPLEN:
9231 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9232 vty_out (vty, "%12.2f",
9233 ts.counts[i] ?
9234 (float)ts.counts[i] /
9235 (float)ts.counts[BGP_STATS_PREFIXES]
9236 : 0);
9237 break;
9238 case BGP_STATS_SPACE:
9239 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9240 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9241 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9242 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009243 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009244 vty_out (vty, "%12.2f%s",
9245 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009246 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009247 VTY_NEWLINE);
9248 vty_out (vty, "%30s: ", "/8 equivalent ");
9249 vty_out (vty, "%12.2f%s",
9250 (float)ts.counts[BGP_STATS_SPACE] /
9251 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9252 VTY_NEWLINE);
9253 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9254 break;
9255 vty_out (vty, "%30s: ", "/24 equivalent ");
9256 vty_out (vty, "%12.2f",
9257 (float)ts.counts[BGP_STATS_SPACE] /
9258 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9259 break;
9260 default:
9261 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9262 vty_out (vty, "%12llu", ts.counts[i]);
9263 }
9264
9265 vty_out (vty, "%s", VTY_NEWLINE);
9266 }
9267 return CMD_SUCCESS;
9268}
9269
9270static int
9271bgp_table_stats_vty (struct vty *vty, const char *name,
9272 const char *afi_str, const char *safi_str)
9273{
9274 struct bgp *bgp;
9275 afi_t afi;
9276 safi_t safi;
9277
9278 if (name)
9279 bgp = bgp_lookup_by_name (name);
9280 else
9281 bgp = bgp_get_default ();
9282
9283 if (!bgp)
9284 {
9285 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9286 return CMD_WARNING;
9287 }
9288 if (strncmp (afi_str, "ipv", 3) == 0)
9289 {
9290 if (strncmp (afi_str, "ipv4", 4) == 0)
9291 afi = AFI_IP;
9292 else if (strncmp (afi_str, "ipv6", 4) == 0)
9293 afi = AFI_IP6;
9294 else
9295 {
9296 vty_out (vty, "%% Invalid address family %s%s",
9297 afi_str, VTY_NEWLINE);
9298 return CMD_WARNING;
9299 }
9300 if (strncmp (safi_str, "m", 1) == 0)
9301 safi = SAFI_MULTICAST;
9302 else if (strncmp (safi_str, "u", 1) == 0)
9303 safi = SAFI_UNICAST;
9304 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9305 safi = BGP_SAFI_VPNV4;
9306 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9307 safi = BGP_SAFI_VPNV6;
9308 else
9309 {
9310 vty_out (vty, "%% Invalid subsequent address family %s%s",
9311 safi_str, VTY_NEWLINE);
9312 return CMD_WARNING;
9313 }
9314 }
9315 else
9316 {
9317 vty_out (vty, "%% Invalid address family %s%s",
9318 afi_str, VTY_NEWLINE);
9319 return CMD_WARNING;
9320 }
9321
9322 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9323 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9324 {
9325 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9326 afi_str, safi_str, VTY_NEWLINE);
9327 return CMD_WARNING;
9328 }
9329 return bgp_table_stats (vty, bgp, afi, safi);
9330}
9331
9332DEFUN (show_bgp_statistics,
9333 show_bgp_statistics_cmd,
9334 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9335 SHOW_STR
9336 BGP_STR
9337 "Address family\n"
9338 "Address family\n"
9339 "Address Family modifier\n"
9340 "Address Family modifier\n"
9341 "BGP RIB advertisement statistics\n")
9342{
9343 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9344}
9345
9346ALIAS (show_bgp_statistics,
9347 show_bgp_statistics_vpnv4_cmd,
9348 "show bgp (ipv4) (vpnv4) statistics",
9349 SHOW_STR
9350 BGP_STR
9351 "Address family\n"
9352 "Address Family modifier\n"
9353 "BGP RIB advertisement statistics\n")
9354
9355DEFUN (show_bgp_statistics_view,
9356 show_bgp_statistics_view_cmd,
9357 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9358 SHOW_STR
9359 BGP_STR
9360 "BGP view\n"
9361 "Address family\n"
9362 "Address family\n"
9363 "Address Family modifier\n"
9364 "Address Family modifier\n"
9365 "BGP RIB advertisement statistics\n")
9366{
9367 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9368}
9369
9370ALIAS (show_bgp_statistics_view,
9371 show_bgp_statistics_view_vpnv4_cmd,
9372 "show bgp view WORD (ipv4) (vpnv4) statistics",
9373 SHOW_STR
9374 BGP_STR
9375 "BGP view\n"
9376 "Address family\n"
9377 "Address Family modifier\n"
9378 "BGP RIB advertisement statistics\n")
9379
Paul Jakmaff7924f2006-09-04 01:10:36 +00009380enum bgp_pcounts
9381{
9382 PCOUNT_ADJ_IN = 0,
9383 PCOUNT_DAMPED,
9384 PCOUNT_REMOVED,
9385 PCOUNT_HISTORY,
9386 PCOUNT_STALE,
9387 PCOUNT_VALID,
9388 PCOUNT_ALL,
9389 PCOUNT_COUNTED,
9390 PCOUNT_PFCNT, /* the figure we display to users */
9391 PCOUNT_MAX,
9392};
9393
9394static const char *pcount_strs[] =
9395{
9396 [PCOUNT_ADJ_IN] = "Adj-in",
9397 [PCOUNT_DAMPED] = "Damped",
9398 [PCOUNT_REMOVED] = "Removed",
9399 [PCOUNT_HISTORY] = "History",
9400 [PCOUNT_STALE] = "Stale",
9401 [PCOUNT_VALID] = "Valid",
9402 [PCOUNT_ALL] = "All RIB",
9403 [PCOUNT_COUNTED] = "PfxCt counted",
9404 [PCOUNT_PFCNT] = "Useable",
9405 [PCOUNT_MAX] = NULL,
9406};
9407
Paul Jakma2815e612006-09-14 02:56:07 +00009408struct peer_pcounts
9409{
9410 unsigned int count[PCOUNT_MAX];
9411 const struct peer *peer;
9412 const struct bgp_table *table;
9413};
9414
Paul Jakmaff7924f2006-09-04 01:10:36 +00009415static int
Paul Jakma2815e612006-09-14 02:56:07 +00009416bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009417{
9418 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009419 struct peer_pcounts *pc = THREAD_ARG (t);
9420 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009421
Paul Jakma2815e612006-09-14 02:56:07 +00009422 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009423 {
9424 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009425 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009426
9427 for (ain = rn->adj_in; ain; ain = ain->next)
9428 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009429 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009430
Paul Jakmaff7924f2006-09-04 01:10:36 +00009431 for (ri = rn->info; ri; ri = ri->next)
9432 {
9433 char buf[SU_ADDRSTRLEN];
9434
9435 if (ri->peer != peer)
9436 continue;
9437
Paul Jakma2815e612006-09-14 02:56:07 +00009438 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009439
9440 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009441 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009442 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009443 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009444 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009445 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009446 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009447 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009448 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009449 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009450 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009451 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009452
9453 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9454 {
Paul Jakma2815e612006-09-14 02:56:07 +00009455 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009456 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009457 plog_warn (peer->log,
9458 "%s [pcount] %s/%d is counted but flags 0x%x",
9459 peer->host,
9460 inet_ntop(rn->p.family, &rn->p.u.prefix,
9461 buf, SU_ADDRSTRLEN),
9462 rn->p.prefixlen,
9463 ri->flags);
9464 }
9465 else
9466 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009467 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009468 plog_warn (peer->log,
9469 "%s [pcount] %s/%d not counted but flags 0x%x",
9470 peer->host,
9471 inet_ntop(rn->p.family, &rn->p.u.prefix,
9472 buf, SU_ADDRSTRLEN),
9473 rn->p.prefixlen,
9474 ri->flags);
9475 }
9476 }
9477 }
Paul Jakma2815e612006-09-14 02:56:07 +00009478 return 0;
9479}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009480
Paul Jakma2815e612006-09-14 02:56:07 +00009481static int
9482bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9483{
9484 struct peer_pcounts pcounts = { .peer = peer };
9485 unsigned int i;
9486
9487 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9488 || !peer->bgp->rib[afi][safi])
9489 {
9490 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9491 return CMD_WARNING;
9492 }
9493
9494 memset (&pcounts, 0, sizeof(pcounts));
9495 pcounts.peer = peer;
9496 pcounts.table = peer->bgp->rib[afi][safi];
9497
9498 /* in-place call via thread subsystem so as to record execution time
9499 * stats for the thread-walk (i.e. ensure this can't be blamed on
9500 * on just vty_read()).
9501 */
9502 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9503
Paul Jakmaff7924f2006-09-04 01:10:36 +00009504 vty_out (vty, "Prefix counts for %s, %s%s",
9505 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9506 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9507 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9508 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9509
9510 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009511 vty_out (vty, "%20s: %-10d%s",
9512 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009513
Paul Jakma2815e612006-09-14 02:56:07 +00009514 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009515 {
9516 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9517 peer->host, VTY_NEWLINE);
9518 vty_out (vty, "Please report this bug, with the above command output%s",
9519 VTY_NEWLINE);
9520 }
9521
9522 return CMD_SUCCESS;
9523}
9524
9525DEFUN (show_ip_bgp_neighbor_prefix_counts,
9526 show_ip_bgp_neighbor_prefix_counts_cmd,
9527 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9528 SHOW_STR
9529 IP_STR
9530 BGP_STR
9531 "Detailed information on TCP and BGP neighbor connections\n"
9532 "Neighbor to display information about\n"
9533 "Neighbor to display information about\n"
9534 "Display detailed prefix count information\n")
9535{
9536 struct peer *peer;
9537
9538 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9539 if (! peer)
9540 return CMD_WARNING;
9541
9542 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9543}
9544
9545DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9546 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9547 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9548 SHOW_STR
9549 BGP_STR
9550 "Address family\n"
9551 "Detailed information on TCP and BGP neighbor connections\n"
9552 "Neighbor to display information about\n"
9553 "Neighbor to display information about\n"
9554 "Display detailed prefix count information\n")
9555{
9556 struct peer *peer;
9557
9558 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9559 if (! peer)
9560 return CMD_WARNING;
9561
9562 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9563}
9564
9565DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9566 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9567 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9568 SHOW_STR
9569 IP_STR
9570 BGP_STR
9571 "Address family\n"
9572 "Address Family modifier\n"
9573 "Address Family modifier\n"
9574 "Detailed information on TCP and BGP neighbor connections\n"
9575 "Neighbor to display information about\n"
9576 "Neighbor to display information about\n"
9577 "Display detailed prefix count information\n")
9578{
9579 struct peer *peer;
9580
9581 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9582 if (! peer)
9583 return CMD_WARNING;
9584
9585 if (strncmp (argv[0], "m", 1) == 0)
9586 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9587
9588 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9589}
9590
9591DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9592 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9593 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9594 SHOW_STR
9595 IP_STR
9596 BGP_STR
9597 "Address family\n"
9598 "Address Family modifier\n"
9599 "Address Family modifier\n"
9600 "Detailed information on TCP and BGP neighbor connections\n"
9601 "Neighbor to display information about\n"
9602 "Neighbor to display information about\n"
9603 "Display detailed prefix count information\n")
9604{
9605 struct peer *peer;
9606
9607 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9608 if (! peer)
9609 return CMD_WARNING;
9610
9611 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9612}
9613
9614
paul94f2b392005-06-28 12:44:16 +00009615static void
paul718e3742002-12-13 20:15:29 +00009616show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9617 int in)
9618{
9619 struct bgp_table *table;
9620 struct bgp_adj_in *ain;
9621 struct bgp_adj_out *adj;
9622 unsigned long output_count;
9623 struct bgp_node *rn;
9624 int header1 = 1;
9625 struct bgp *bgp;
9626 int header2 = 1;
9627
paulbb46e942003-10-24 19:02:03 +00009628 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009629
9630 if (! bgp)
9631 return;
9632
9633 table = bgp->rib[afi][safi];
9634
9635 output_count = 0;
9636
9637 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9638 PEER_STATUS_DEFAULT_ORIGINATE))
9639 {
9640 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 +00009641 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9642 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009643
9644 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9645 VTY_NEWLINE, VTY_NEWLINE);
9646 header1 = 0;
9647 }
9648
9649 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9650 if (in)
9651 {
9652 for (ain = rn->adj_in; ain; ain = ain->next)
9653 if (ain->peer == peer)
9654 {
9655 if (header1)
9656 {
9657 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 +00009658 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9659 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009660 header1 = 0;
9661 }
9662 if (header2)
9663 {
9664 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9665 header2 = 0;
9666 }
9667 if (ain->attr)
9668 {
9669 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9670 output_count++;
9671 }
9672 }
9673 }
9674 else
9675 {
9676 for (adj = rn->adj_out; adj; adj = adj->next)
9677 if (adj->peer == peer)
9678 {
9679 if (header1)
9680 {
9681 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 +00009682 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9683 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009684 header1 = 0;
9685 }
9686 if (header2)
9687 {
9688 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9689 header2 = 0;
9690 }
9691 if (adj->attr)
9692 {
9693 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9694 output_count++;
9695 }
9696 }
9697 }
9698
9699 if (output_count != 0)
9700 vty_out (vty, "%sTotal number of prefixes %ld%s",
9701 VTY_NEWLINE, output_count, VTY_NEWLINE);
9702}
9703
paul94f2b392005-06-28 12:44:16 +00009704static int
paulbb46e942003-10-24 19:02:03 +00009705peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9706{
paul718e3742002-12-13 20:15:29 +00009707 if (! peer || ! peer->afc[afi][safi])
9708 {
9709 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9710 return CMD_WARNING;
9711 }
9712
9713 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9714 {
9715 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9716 VTY_NEWLINE);
9717 return CMD_WARNING;
9718 }
9719
9720 show_adj_route (vty, peer, afi, safi, in);
9721
9722 return CMD_SUCCESS;
9723}
9724
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009725DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9726 show_ip_bgp_view_neighbor_advertised_route_cmd,
9727 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9728 SHOW_STR
9729 IP_STR
9730 BGP_STR
9731 "BGP view\n"
9732 "View name\n"
9733 "Detailed information on TCP and BGP neighbor connections\n"
9734 "Neighbor to display information about\n"
9735 "Neighbor to display information about\n"
9736 "Display the routes advertised to a BGP neighbor\n")
9737{
9738 struct peer *peer;
9739
9740 if (argc == 2)
9741 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9742 else
9743 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9744
9745 if (! peer)
9746 return CMD_WARNING;
9747
9748 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9749}
9750
9751ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009752 show_ip_bgp_neighbor_advertised_route_cmd,
9753 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9754 SHOW_STR
9755 IP_STR
9756 BGP_STR
9757 "Detailed information on TCP and BGP neighbor connections\n"
9758 "Neighbor to display information about\n"
9759 "Neighbor to display information about\n"
9760 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009761
9762DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9763 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9764 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9765 SHOW_STR
9766 IP_STR
9767 BGP_STR
9768 "Address family\n"
9769 "Address Family modifier\n"
9770 "Address Family modifier\n"
9771 "Detailed information on TCP and BGP neighbor connections\n"
9772 "Neighbor to display information about\n"
9773 "Neighbor to display information about\n"
9774 "Display the routes advertised to a BGP neighbor\n")
9775{
paulbb46e942003-10-24 19:02:03 +00009776 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009777
paulbb46e942003-10-24 19:02:03 +00009778 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9779 if (! peer)
9780 return CMD_WARNING;
9781
9782 if (strncmp (argv[0], "m", 1) == 0)
9783 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9784
9785 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009786}
9787
9788#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009789DEFUN (show_bgp_view_neighbor_advertised_route,
9790 show_bgp_view_neighbor_advertised_route_cmd,
9791 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9792 SHOW_STR
9793 BGP_STR
9794 "BGP view\n"
9795 "View name\n"
9796 "Detailed information on TCP and BGP neighbor connections\n"
9797 "Neighbor to display information about\n"
9798 "Neighbor to display information about\n"
9799 "Display the routes advertised to a BGP neighbor\n")
9800{
9801 struct peer *peer;
9802
9803 if (argc == 2)
9804 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9805 else
9806 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9807
9808 if (! peer)
9809 return CMD_WARNING;
9810
9811 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9812}
9813
9814ALIAS (show_bgp_view_neighbor_advertised_route,
9815 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9816 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9817 SHOW_STR
9818 BGP_STR
9819 "BGP view\n"
9820 "View name\n"
9821 "Address family\n"
9822 "Detailed information on TCP and BGP neighbor connections\n"
9823 "Neighbor to display information about\n"
9824 "Neighbor to display information about\n"
9825 "Display the routes advertised to a BGP neighbor\n")
9826
9827DEFUN (show_bgp_view_neighbor_received_routes,
9828 show_bgp_view_neighbor_received_routes_cmd,
9829 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9830 SHOW_STR
9831 BGP_STR
9832 "BGP view\n"
9833 "View name\n"
9834 "Detailed information on TCP and BGP neighbor connections\n"
9835 "Neighbor to display information about\n"
9836 "Neighbor to display information about\n"
9837 "Display the received routes from neighbor\n")
9838{
9839 struct peer *peer;
9840
9841 if (argc == 2)
9842 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9843 else
9844 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9845
9846 if (! peer)
9847 return CMD_WARNING;
9848
9849 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9850}
9851
9852ALIAS (show_bgp_view_neighbor_received_routes,
9853 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9854 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9855 SHOW_STR
9856 BGP_STR
9857 "BGP view\n"
9858 "View name\n"
9859 "Address family\n"
9860 "Detailed information on TCP and BGP neighbor connections\n"
9861 "Neighbor to display information about\n"
9862 "Neighbor to display information about\n"
9863 "Display the received routes from neighbor\n")
9864
9865ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009866 show_bgp_neighbor_advertised_route_cmd,
9867 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9868 SHOW_STR
9869 BGP_STR
9870 "Detailed information on TCP and BGP neighbor connections\n"
9871 "Neighbor to display information about\n"
9872 "Neighbor to display information about\n"
9873 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009874
9875ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009876 show_bgp_ipv6_neighbor_advertised_route_cmd,
9877 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9878 SHOW_STR
9879 BGP_STR
9880 "Address family\n"
9881 "Detailed information on TCP and BGP neighbor connections\n"
9882 "Neighbor to display information about\n"
9883 "Neighbor to display information about\n"
9884 "Display the routes advertised to a BGP neighbor\n")
9885
9886/* old command */
paulbb46e942003-10-24 19:02:03 +00009887ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009888 ipv6_bgp_neighbor_advertised_route_cmd,
9889 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9890 SHOW_STR
9891 IPV6_STR
9892 BGP_STR
9893 "Detailed information on TCP and BGP neighbor connections\n"
9894 "Neighbor to display information about\n"
9895 "Neighbor to display information about\n"
9896 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009897
paul718e3742002-12-13 20:15:29 +00009898/* old command */
9899DEFUN (ipv6_mbgp_neighbor_advertised_route,
9900 ipv6_mbgp_neighbor_advertised_route_cmd,
9901 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9902 SHOW_STR
9903 IPV6_STR
9904 MBGP_STR
9905 "Detailed information on TCP and BGP neighbor connections\n"
9906 "Neighbor to display information about\n"
9907 "Neighbor to display information about\n"
9908 "Display the routes advertised to a BGP neighbor\n")
9909{
paulbb46e942003-10-24 19:02:03 +00009910 struct peer *peer;
9911
9912 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9913 if (! peer)
9914 return CMD_WARNING;
9915
9916 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009917}
9918#endif /* HAVE_IPV6 */
9919
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009920DEFUN (show_ip_bgp_view_neighbor_received_routes,
9921 show_ip_bgp_view_neighbor_received_routes_cmd,
9922 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9923 SHOW_STR
9924 IP_STR
9925 BGP_STR
9926 "BGP view\n"
9927 "View name\n"
9928 "Detailed information on TCP and BGP neighbor connections\n"
9929 "Neighbor to display information about\n"
9930 "Neighbor to display information about\n"
9931 "Display the received routes from neighbor\n")
9932{
9933 struct peer *peer;
9934
9935 if (argc == 2)
9936 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9937 else
9938 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9939
9940 if (! peer)
9941 return CMD_WARNING;
9942
9943 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9944}
9945
9946ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009947 show_ip_bgp_neighbor_received_routes_cmd,
9948 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9949 SHOW_STR
9950 IP_STR
9951 BGP_STR
9952 "Detailed information on TCP and BGP neighbor connections\n"
9953 "Neighbor to display information about\n"
9954 "Neighbor to display information about\n"
9955 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009956
9957DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9958 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9959 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9960 SHOW_STR
9961 IP_STR
9962 BGP_STR
9963 "Address family\n"
9964 "Address Family modifier\n"
9965 "Address Family modifier\n"
9966 "Detailed information on TCP and BGP neighbor connections\n"
9967 "Neighbor to display information about\n"
9968 "Neighbor to display information about\n"
9969 "Display the received routes from neighbor\n")
9970{
paulbb46e942003-10-24 19:02:03 +00009971 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009972
paulbb46e942003-10-24 19:02:03 +00009973 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9974 if (! peer)
9975 return CMD_WARNING;
9976
9977 if (strncmp (argv[0], "m", 1) == 0)
9978 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9979
9980 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009981}
9982
9983DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9984 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9985 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9986 SHOW_STR
9987 IP_STR
9988 BGP_STR
9989 "Detailed information on TCP and BGP neighbor connections\n"
9990 "Neighbor to display information about\n"
9991 "Neighbor to display information about\n"
9992 "Display information received from a BGP neighbor\n"
9993 "Display the prefixlist filter\n")
9994{
9995 char name[BUFSIZ];
9996 union sockunion *su;
9997 struct peer *peer;
9998 int count;
9999
10000 su = sockunion_str2su (argv[0]);
10001 if (su == NULL)
10002 return CMD_WARNING;
10003
10004 peer = peer_lookup (NULL, su);
10005 if (! peer)
10006 return CMD_WARNING;
10007
10008 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10009 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10010 if (count)
10011 {
10012 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10013 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10014 }
10015
10016 return CMD_SUCCESS;
10017}
10018
10019DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10020 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10021 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10022 SHOW_STR
10023 IP_STR
10024 BGP_STR
10025 "Address family\n"
10026 "Address Family modifier\n"
10027 "Address Family modifier\n"
10028 "Detailed information on TCP and BGP neighbor connections\n"
10029 "Neighbor to display information about\n"
10030 "Neighbor to display information about\n"
10031 "Display information received from a BGP neighbor\n"
10032 "Display the prefixlist filter\n")
10033{
10034 char name[BUFSIZ];
10035 union sockunion *su;
10036 struct peer *peer;
10037 int count;
10038
10039 su = sockunion_str2su (argv[1]);
10040 if (su == NULL)
10041 return CMD_WARNING;
10042
10043 peer = peer_lookup (NULL, su);
10044 if (! peer)
10045 return CMD_WARNING;
10046
10047 if (strncmp (argv[0], "m", 1) == 0)
10048 {
10049 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10050 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10051 if (count)
10052 {
10053 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10054 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10055 }
10056 }
10057 else
10058 {
10059 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10060 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10061 if (count)
10062 {
10063 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10064 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10065 }
10066 }
10067
10068 return CMD_SUCCESS;
10069}
10070
10071
10072#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010073ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010074 show_bgp_neighbor_received_routes_cmd,
10075 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10076 SHOW_STR
10077 BGP_STR
10078 "Detailed information on TCP and BGP neighbor connections\n"
10079 "Neighbor to display information about\n"
10080 "Neighbor to display information about\n"
10081 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010082
paulbb46e942003-10-24 19:02:03 +000010083ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010084 show_bgp_ipv6_neighbor_received_routes_cmd,
10085 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10086 SHOW_STR
10087 BGP_STR
10088 "Address family\n"
10089 "Detailed information on TCP and BGP neighbor connections\n"
10090 "Neighbor to display information about\n"
10091 "Neighbor to display information about\n"
10092 "Display the received routes from neighbor\n")
10093
10094DEFUN (show_bgp_neighbor_received_prefix_filter,
10095 show_bgp_neighbor_received_prefix_filter_cmd,
10096 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10097 SHOW_STR
10098 BGP_STR
10099 "Detailed information on TCP and BGP neighbor connections\n"
10100 "Neighbor to display information about\n"
10101 "Neighbor to display information about\n"
10102 "Display information received from a BGP neighbor\n"
10103 "Display the prefixlist filter\n")
10104{
10105 char name[BUFSIZ];
10106 union sockunion *su;
10107 struct peer *peer;
10108 int count;
10109
10110 su = sockunion_str2su (argv[0]);
10111 if (su == NULL)
10112 return CMD_WARNING;
10113
10114 peer = peer_lookup (NULL, su);
10115 if (! peer)
10116 return CMD_WARNING;
10117
10118 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10119 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10120 if (count)
10121 {
10122 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10123 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10124 }
10125
10126 return CMD_SUCCESS;
10127}
10128
10129ALIAS (show_bgp_neighbor_received_prefix_filter,
10130 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10131 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10132 SHOW_STR
10133 BGP_STR
10134 "Address family\n"
10135 "Detailed information on TCP and BGP neighbor connections\n"
10136 "Neighbor to display information about\n"
10137 "Neighbor to display information about\n"
10138 "Display information received from a BGP neighbor\n"
10139 "Display the prefixlist filter\n")
10140
10141/* old command */
paulbb46e942003-10-24 19:02:03 +000010142ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010143 ipv6_bgp_neighbor_received_routes_cmd,
10144 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10145 SHOW_STR
10146 IPV6_STR
10147 BGP_STR
10148 "Detailed information on TCP and BGP neighbor connections\n"
10149 "Neighbor to display information about\n"
10150 "Neighbor to display information about\n"
10151 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010152
10153/* old command */
10154DEFUN (ipv6_mbgp_neighbor_received_routes,
10155 ipv6_mbgp_neighbor_received_routes_cmd,
10156 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10157 SHOW_STR
10158 IPV6_STR
10159 MBGP_STR
10160 "Detailed information on TCP and BGP neighbor connections\n"
10161 "Neighbor to display information about\n"
10162 "Neighbor to display information about\n"
10163 "Display the received routes from neighbor\n")
10164{
paulbb46e942003-10-24 19:02:03 +000010165 struct peer *peer;
10166
10167 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10168 if (! peer)
10169 return CMD_WARNING;
10170
10171 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010172}
paulbb46e942003-10-24 19:02:03 +000010173
10174DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10175 show_bgp_view_neighbor_received_prefix_filter_cmd,
10176 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10177 SHOW_STR
10178 BGP_STR
10179 "BGP view\n"
10180 "View name\n"
10181 "Detailed information on TCP and BGP neighbor connections\n"
10182 "Neighbor to display information about\n"
10183 "Neighbor to display information about\n"
10184 "Display information received from a BGP neighbor\n"
10185 "Display the prefixlist filter\n")
10186{
10187 char name[BUFSIZ];
10188 union sockunion *su;
10189 struct peer *peer;
10190 struct bgp *bgp;
10191 int count;
10192
10193 /* BGP structure lookup. */
10194 bgp = bgp_lookup_by_name (argv[0]);
10195 if (bgp == NULL)
10196 {
10197 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10198 return CMD_WARNING;
10199 }
10200
10201 su = sockunion_str2su (argv[1]);
10202 if (su == NULL)
10203 return CMD_WARNING;
10204
10205 peer = peer_lookup (bgp, su);
10206 if (! peer)
10207 return CMD_WARNING;
10208
10209 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10210 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10211 if (count)
10212 {
10213 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10214 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10215 }
10216
10217 return CMD_SUCCESS;
10218}
10219
10220ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10221 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10222 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10223 SHOW_STR
10224 BGP_STR
10225 "BGP view\n"
10226 "View name\n"
10227 "Address family\n"
10228 "Detailed information on TCP and BGP neighbor connections\n"
10229 "Neighbor to display information about\n"
10230 "Neighbor to display information about\n"
10231 "Display information received from a BGP neighbor\n"
10232 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010233#endif /* HAVE_IPV6 */
10234
paul94f2b392005-06-28 12:44:16 +000010235static int
paulbb46e942003-10-24 19:02:03 +000010236bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010237 safi_t safi, enum bgp_show_type type)
10238{
paul718e3742002-12-13 20:15:29 +000010239 if (! peer || ! peer->afc[afi][safi])
10240 {
10241 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010242 return CMD_WARNING;
10243 }
10244
ajs5a646652004-11-05 01:25:55 +000010245 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010246}
10247
10248DEFUN (show_ip_bgp_neighbor_routes,
10249 show_ip_bgp_neighbor_routes_cmd,
10250 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10251 SHOW_STR
10252 IP_STR
10253 BGP_STR
10254 "Detailed information on TCP and BGP neighbor connections\n"
10255 "Neighbor to display information about\n"
10256 "Neighbor to display information about\n"
10257 "Display routes learned from neighbor\n")
10258{
paulbb46e942003-10-24 19:02:03 +000010259 struct peer *peer;
10260
10261 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10262 if (! peer)
10263 return CMD_WARNING;
10264
10265 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010266 bgp_show_type_neighbor);
10267}
10268
10269DEFUN (show_ip_bgp_neighbor_flap,
10270 show_ip_bgp_neighbor_flap_cmd,
10271 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10272 SHOW_STR
10273 IP_STR
10274 BGP_STR
10275 "Detailed information on TCP and BGP neighbor connections\n"
10276 "Neighbor to display information about\n"
10277 "Neighbor to display information about\n"
10278 "Display flap statistics of the routes learned from neighbor\n")
10279{
paulbb46e942003-10-24 19:02:03 +000010280 struct peer *peer;
10281
10282 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10283 if (! peer)
10284 return CMD_WARNING;
10285
10286 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010287 bgp_show_type_flap_neighbor);
10288}
10289
10290DEFUN (show_ip_bgp_neighbor_damp,
10291 show_ip_bgp_neighbor_damp_cmd,
10292 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10293 SHOW_STR
10294 IP_STR
10295 BGP_STR
10296 "Detailed information on TCP and BGP neighbor connections\n"
10297 "Neighbor to display information about\n"
10298 "Neighbor to display information about\n"
10299 "Display the dampened routes received from neighbor\n")
10300{
paulbb46e942003-10-24 19:02:03 +000010301 struct peer *peer;
10302
10303 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10304 if (! peer)
10305 return CMD_WARNING;
10306
10307 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010308 bgp_show_type_damp_neighbor);
10309}
10310
10311DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10312 show_ip_bgp_ipv4_neighbor_routes_cmd,
10313 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10314 SHOW_STR
10315 IP_STR
10316 BGP_STR
10317 "Address family\n"
10318 "Address Family modifier\n"
10319 "Address Family modifier\n"
10320 "Detailed information on TCP and BGP neighbor connections\n"
10321 "Neighbor to display information about\n"
10322 "Neighbor to display information about\n"
10323 "Display routes learned from neighbor\n")
10324{
paulbb46e942003-10-24 19:02:03 +000010325 struct peer *peer;
10326
10327 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10328 if (! peer)
10329 return CMD_WARNING;
10330
paul718e3742002-12-13 20:15:29 +000010331 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010332 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010333 bgp_show_type_neighbor);
10334
paulbb46e942003-10-24 19:02:03 +000010335 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010336 bgp_show_type_neighbor);
10337}
paulbb46e942003-10-24 19:02:03 +000010338
paulfee0f4c2004-09-13 05:12:46 +000010339DEFUN (show_ip_bgp_view_rsclient,
10340 show_ip_bgp_view_rsclient_cmd,
10341 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10342 SHOW_STR
10343 IP_STR
10344 BGP_STR
10345 "BGP view\n"
10346 "BGP view name\n"
10347 "Information about Route Server Client\n"
10348 NEIGHBOR_ADDR_STR)
10349{
10350 struct bgp_table *table;
10351 struct peer *peer;
10352
10353 if (argc == 2)
10354 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10355 else
10356 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10357
10358 if (! peer)
10359 return CMD_WARNING;
10360
10361 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10362 {
10363 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10364 VTY_NEWLINE);
10365 return CMD_WARNING;
10366 }
10367
10368 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10369 PEER_FLAG_RSERVER_CLIENT))
10370 {
10371 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10372 VTY_NEWLINE);
10373 return CMD_WARNING;
10374 }
10375
10376 table = peer->rib[AFI_IP][SAFI_UNICAST];
10377
ajs5a646652004-11-05 01:25:55 +000010378 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010379}
10380
10381ALIAS (show_ip_bgp_view_rsclient,
10382 show_ip_bgp_rsclient_cmd,
10383 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10384 SHOW_STR
10385 IP_STR
10386 BGP_STR
10387 "Information about Route Server Client\n"
10388 NEIGHBOR_ADDR_STR)
10389
10390DEFUN (show_ip_bgp_view_rsclient_route,
10391 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010392 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010393 SHOW_STR
10394 IP_STR
10395 BGP_STR
10396 "BGP view\n"
10397 "BGP view name\n"
10398 "Information about Route Server Client\n"
10399 NEIGHBOR_ADDR_STR
10400 "Network in the BGP routing table to display\n")
10401{
10402 struct bgp *bgp;
10403 struct peer *peer;
10404
10405 /* BGP structure lookup. */
10406 if (argc == 3)
10407 {
10408 bgp = bgp_lookup_by_name (argv[0]);
10409 if (bgp == NULL)
10410 {
10411 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10412 return CMD_WARNING;
10413 }
10414 }
10415 else
10416 {
10417 bgp = bgp_get_default ();
10418 if (bgp == NULL)
10419 {
10420 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10421 return CMD_WARNING;
10422 }
10423 }
10424
10425 if (argc == 3)
10426 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10427 else
10428 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10429
10430 if (! peer)
10431 return CMD_WARNING;
10432
10433 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10434 {
10435 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10436 VTY_NEWLINE);
10437 return CMD_WARNING;
10438}
10439
10440 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10441 PEER_FLAG_RSERVER_CLIENT))
10442 {
10443 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10444 VTY_NEWLINE);
10445 return CMD_WARNING;
10446 }
10447
10448 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10449 (argc == 3) ? argv[2] : argv[1],
10450 AFI_IP, SAFI_UNICAST, NULL, 0);
10451}
10452
10453ALIAS (show_ip_bgp_view_rsclient_route,
10454 show_ip_bgp_rsclient_route_cmd,
10455 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10456 SHOW_STR
10457 IP_STR
10458 BGP_STR
10459 "Information about Route Server Client\n"
10460 NEIGHBOR_ADDR_STR
10461 "Network in the BGP routing table to display\n")
10462
10463DEFUN (show_ip_bgp_view_rsclient_prefix,
10464 show_ip_bgp_view_rsclient_prefix_cmd,
10465 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10466 SHOW_STR
10467 IP_STR
10468 BGP_STR
10469 "BGP view\n"
10470 "BGP view name\n"
10471 "Information about Route Server Client\n"
10472 NEIGHBOR_ADDR_STR
10473 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10474{
10475 struct bgp *bgp;
10476 struct peer *peer;
10477
10478 /* BGP structure lookup. */
10479 if (argc == 3)
10480 {
10481 bgp = bgp_lookup_by_name (argv[0]);
10482 if (bgp == NULL)
10483 {
10484 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10485 return CMD_WARNING;
10486 }
10487 }
10488 else
10489 {
10490 bgp = bgp_get_default ();
10491 if (bgp == NULL)
10492 {
10493 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10494 return CMD_WARNING;
10495 }
10496 }
10497
10498 if (argc == 3)
10499 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10500 else
10501 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10502
10503 if (! peer)
10504 return CMD_WARNING;
10505
10506 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10507 {
10508 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10509 VTY_NEWLINE);
10510 return CMD_WARNING;
10511}
10512
10513 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10514 PEER_FLAG_RSERVER_CLIENT))
10515{
10516 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10517 VTY_NEWLINE);
10518 return CMD_WARNING;
10519 }
10520
10521 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10522 (argc == 3) ? argv[2] : argv[1],
10523 AFI_IP, SAFI_UNICAST, NULL, 1);
10524}
10525
10526ALIAS (show_ip_bgp_view_rsclient_prefix,
10527 show_ip_bgp_rsclient_prefix_cmd,
10528 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10529 SHOW_STR
10530 IP_STR
10531 BGP_STR
10532 "Information about Route Server Client\n"
10533 NEIGHBOR_ADDR_STR
10534 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10535
10536
paul718e3742002-12-13 20:15:29 +000010537#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010538DEFUN (show_bgp_view_neighbor_routes,
10539 show_bgp_view_neighbor_routes_cmd,
10540 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10541 SHOW_STR
10542 BGP_STR
10543 "BGP view\n"
10544 "BGP view name\n"
10545 "Detailed information on TCP and BGP neighbor connections\n"
10546 "Neighbor to display information about\n"
10547 "Neighbor to display information about\n"
10548 "Display routes learned from neighbor\n")
10549{
10550 struct peer *peer;
10551
10552 if (argc == 2)
10553 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10554 else
10555 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10556
10557 if (! peer)
10558 return CMD_WARNING;
10559
10560 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10561 bgp_show_type_neighbor);
10562}
10563
10564ALIAS (show_bgp_view_neighbor_routes,
10565 show_bgp_view_ipv6_neighbor_routes_cmd,
10566 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10567 SHOW_STR
10568 BGP_STR
10569 "BGP view\n"
10570 "BGP view name\n"
10571 "Address family\n"
10572 "Detailed information on TCP and BGP neighbor connections\n"
10573 "Neighbor to display information about\n"
10574 "Neighbor to display information about\n"
10575 "Display routes learned from neighbor\n")
10576
10577DEFUN (show_bgp_view_neighbor_damp,
10578 show_bgp_view_neighbor_damp_cmd,
10579 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10580 SHOW_STR
10581 BGP_STR
10582 "BGP view\n"
10583 "BGP view name\n"
10584 "Detailed information on TCP and BGP neighbor connections\n"
10585 "Neighbor to display information about\n"
10586 "Neighbor to display information about\n"
10587 "Display the dampened routes received from neighbor\n")
10588{
10589 struct peer *peer;
10590
10591 if (argc == 2)
10592 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10593 else
10594 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10595
10596 if (! peer)
10597 return CMD_WARNING;
10598
10599 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10600 bgp_show_type_damp_neighbor);
10601}
10602
10603ALIAS (show_bgp_view_neighbor_damp,
10604 show_bgp_view_ipv6_neighbor_damp_cmd,
10605 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10606 SHOW_STR
10607 BGP_STR
10608 "BGP view\n"
10609 "BGP view name\n"
10610 "Address family\n"
10611 "Detailed information on TCP and BGP neighbor connections\n"
10612 "Neighbor to display information about\n"
10613 "Neighbor to display information about\n"
10614 "Display the dampened routes received from neighbor\n")
10615
10616DEFUN (show_bgp_view_neighbor_flap,
10617 show_bgp_view_neighbor_flap_cmd,
10618 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10619 SHOW_STR
10620 BGP_STR
10621 "BGP view\n"
10622 "BGP view name\n"
10623 "Detailed information on TCP and BGP neighbor connections\n"
10624 "Neighbor to display information about\n"
10625 "Neighbor to display information about\n"
10626 "Display flap statistics of the routes learned from neighbor\n")
10627{
10628 struct peer *peer;
10629
10630 if (argc == 2)
10631 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10632 else
10633 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10634
10635 if (! peer)
10636 return CMD_WARNING;
10637
10638 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10639 bgp_show_type_flap_neighbor);
10640}
10641
10642ALIAS (show_bgp_view_neighbor_flap,
10643 show_bgp_view_ipv6_neighbor_flap_cmd,
10644 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10645 SHOW_STR
10646 BGP_STR
10647 "BGP view\n"
10648 "BGP view name\n"
10649 "Address family\n"
10650 "Detailed information on TCP and BGP neighbor connections\n"
10651 "Neighbor to display information about\n"
10652 "Neighbor to display information about\n"
10653 "Display flap statistics of the routes learned from neighbor\n")
10654
10655ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010656 show_bgp_neighbor_routes_cmd,
10657 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10658 SHOW_STR
10659 BGP_STR
10660 "Detailed information on TCP and BGP neighbor connections\n"
10661 "Neighbor to display information about\n"
10662 "Neighbor to display information about\n"
10663 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010664
paulbb46e942003-10-24 19:02:03 +000010665
10666ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010667 show_bgp_ipv6_neighbor_routes_cmd,
10668 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10669 SHOW_STR
10670 BGP_STR
10671 "Address family\n"
10672 "Detailed information on TCP and BGP neighbor connections\n"
10673 "Neighbor to display information about\n"
10674 "Neighbor to display information about\n"
10675 "Display routes learned from neighbor\n")
10676
10677/* old command */
paulbb46e942003-10-24 19:02:03 +000010678ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010679 ipv6_bgp_neighbor_routes_cmd,
10680 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10681 SHOW_STR
10682 IPV6_STR
10683 BGP_STR
10684 "Detailed information on TCP and BGP neighbor connections\n"
10685 "Neighbor to display information about\n"
10686 "Neighbor to display information about\n"
10687 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010688
10689/* old command */
10690DEFUN (ipv6_mbgp_neighbor_routes,
10691 ipv6_mbgp_neighbor_routes_cmd,
10692 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10693 SHOW_STR
10694 IPV6_STR
10695 MBGP_STR
10696 "Detailed information on TCP and BGP neighbor connections\n"
10697 "Neighbor to display information about\n"
10698 "Neighbor to display information about\n"
10699 "Display routes learned from neighbor\n")
10700{
paulbb46e942003-10-24 19:02:03 +000010701 struct peer *peer;
10702
10703 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10704 if (! peer)
10705 return CMD_WARNING;
10706
10707 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010708 bgp_show_type_neighbor);
10709}
paulbb46e942003-10-24 19:02:03 +000010710
10711ALIAS (show_bgp_view_neighbor_flap,
10712 show_bgp_neighbor_flap_cmd,
10713 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10714 SHOW_STR
10715 BGP_STR
10716 "Detailed information on TCP and BGP neighbor connections\n"
10717 "Neighbor to display information about\n"
10718 "Neighbor to display information about\n"
10719 "Display flap statistics of the routes learned from neighbor\n")
10720
10721ALIAS (show_bgp_view_neighbor_flap,
10722 show_bgp_ipv6_neighbor_flap_cmd,
10723 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10724 SHOW_STR
10725 BGP_STR
10726 "Address family\n"
10727 "Detailed information on TCP and BGP neighbor connections\n"
10728 "Neighbor to display information about\n"
10729 "Neighbor to display information about\n"
10730 "Display flap statistics of the routes learned from neighbor\n")
10731
10732ALIAS (show_bgp_view_neighbor_damp,
10733 show_bgp_neighbor_damp_cmd,
10734 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10735 SHOW_STR
10736 BGP_STR
10737 "Detailed information on TCP and BGP neighbor connections\n"
10738 "Neighbor to display information about\n"
10739 "Neighbor to display information about\n"
10740 "Display the dampened routes received from neighbor\n")
10741
10742ALIAS (show_bgp_view_neighbor_damp,
10743 show_bgp_ipv6_neighbor_damp_cmd,
10744 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10745 SHOW_STR
10746 BGP_STR
10747 "Address family\n"
10748 "Detailed information on TCP and BGP neighbor connections\n"
10749 "Neighbor to display information about\n"
10750 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010751 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010752
10753DEFUN (show_bgp_view_rsclient,
10754 show_bgp_view_rsclient_cmd,
10755 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10756 SHOW_STR
10757 BGP_STR
10758 "BGP view\n"
10759 "BGP view name\n"
10760 "Information about Route Server Client\n"
10761 NEIGHBOR_ADDR_STR)
10762{
10763 struct bgp_table *table;
10764 struct peer *peer;
10765
10766 if (argc == 2)
10767 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10768 else
10769 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10770
10771 if (! peer)
10772 return CMD_WARNING;
10773
10774 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10775 {
10776 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10777 VTY_NEWLINE);
10778 return CMD_WARNING;
10779 }
10780
10781 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10782 PEER_FLAG_RSERVER_CLIENT))
10783 {
10784 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10785 VTY_NEWLINE);
10786 return CMD_WARNING;
10787 }
10788
10789 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10790
ajs5a646652004-11-05 01:25:55 +000010791 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010792}
10793
10794ALIAS (show_bgp_view_rsclient,
10795 show_bgp_rsclient_cmd,
10796 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10797 SHOW_STR
10798 BGP_STR
10799 "Information about Route Server Client\n"
10800 NEIGHBOR_ADDR_STR)
10801
10802DEFUN (show_bgp_view_rsclient_route,
10803 show_bgp_view_rsclient_route_cmd,
10804 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10805 SHOW_STR
10806 BGP_STR
10807 "BGP view\n"
10808 "BGP view name\n"
10809 "Information about Route Server Client\n"
10810 NEIGHBOR_ADDR_STR
10811 "Network in the BGP routing table to display\n")
10812{
10813 struct bgp *bgp;
10814 struct peer *peer;
10815
10816 /* BGP structure lookup. */
10817 if (argc == 3)
10818 {
10819 bgp = bgp_lookup_by_name (argv[0]);
10820 if (bgp == NULL)
10821 {
10822 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10823 return CMD_WARNING;
10824 }
10825 }
10826 else
10827 {
10828 bgp = bgp_get_default ();
10829 if (bgp == NULL)
10830 {
10831 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10832 return CMD_WARNING;
10833 }
10834 }
10835
10836 if (argc == 3)
10837 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10838 else
10839 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10840
10841 if (! peer)
10842 return CMD_WARNING;
10843
10844 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10845 {
10846 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10847 VTY_NEWLINE);
10848 return CMD_WARNING;
10849 }
10850
10851 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10852 PEER_FLAG_RSERVER_CLIENT))
10853 {
10854 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10855 VTY_NEWLINE);
10856 return CMD_WARNING;
10857 }
10858
10859 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10860 (argc == 3) ? argv[2] : argv[1],
10861 AFI_IP6, SAFI_UNICAST, NULL, 0);
10862}
10863
10864ALIAS (show_bgp_view_rsclient_route,
10865 show_bgp_rsclient_route_cmd,
10866 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10867 SHOW_STR
10868 BGP_STR
10869 "Information about Route Server Client\n"
10870 NEIGHBOR_ADDR_STR
10871 "Network in the BGP routing table to display\n")
10872
10873DEFUN (show_bgp_view_rsclient_prefix,
10874 show_bgp_view_rsclient_prefix_cmd,
10875 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10876 SHOW_STR
10877 BGP_STR
10878 "BGP view\n"
10879 "BGP view name\n"
10880 "Information about Route Server Client\n"
10881 NEIGHBOR_ADDR_STR
10882 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10883{
10884 struct bgp *bgp;
10885 struct peer *peer;
10886
10887 /* BGP structure lookup. */
10888 if (argc == 3)
10889 {
10890 bgp = bgp_lookup_by_name (argv[0]);
10891 if (bgp == NULL)
10892 {
10893 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10894 return CMD_WARNING;
10895 }
10896 }
10897 else
10898 {
10899 bgp = bgp_get_default ();
10900 if (bgp == NULL)
10901 {
10902 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10903 return CMD_WARNING;
10904 }
10905 }
10906
10907 if (argc == 3)
10908 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10909 else
10910 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10911
10912 if (! peer)
10913 return CMD_WARNING;
10914
10915 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10916 {
10917 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10918 VTY_NEWLINE);
10919 return CMD_WARNING;
10920 }
10921
10922 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10923 PEER_FLAG_RSERVER_CLIENT))
10924 {
10925 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10926 VTY_NEWLINE);
10927 return CMD_WARNING;
10928 }
10929
10930 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10931 (argc == 3) ? argv[2] : argv[1],
10932 AFI_IP6, SAFI_UNICAST, NULL, 1);
10933}
10934
10935ALIAS (show_bgp_view_rsclient_prefix,
10936 show_bgp_rsclient_prefix_cmd,
10937 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10938 SHOW_STR
10939 BGP_STR
10940 "Information about Route Server Client\n"
10941 NEIGHBOR_ADDR_STR
10942 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10943
paul718e3742002-12-13 20:15:29 +000010944#endif /* HAVE_IPV6 */
10945
10946struct bgp_table *bgp_distance_table;
10947
10948struct bgp_distance
10949{
10950 /* Distance value for the IP source prefix. */
10951 u_char distance;
10952
10953 /* Name of the access-list to be matched. */
10954 char *access_list;
10955};
10956
paul94f2b392005-06-28 12:44:16 +000010957static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010958bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010959{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010960 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010961}
10962
paul94f2b392005-06-28 12:44:16 +000010963static void
paul718e3742002-12-13 20:15:29 +000010964bgp_distance_free (struct bgp_distance *bdistance)
10965{
10966 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10967}
10968
paul94f2b392005-06-28 12:44:16 +000010969static int
paulfd79ac92004-10-13 05:06:08 +000010970bgp_distance_set (struct vty *vty, const char *distance_str,
10971 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010972{
10973 int ret;
10974 struct prefix_ipv4 p;
10975 u_char distance;
10976 struct bgp_node *rn;
10977 struct bgp_distance *bdistance;
10978
10979 ret = str2prefix_ipv4 (ip_str, &p);
10980 if (ret == 0)
10981 {
10982 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10983 return CMD_WARNING;
10984 }
10985
10986 distance = atoi (distance_str);
10987
10988 /* Get BGP distance node. */
10989 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10990 if (rn->info)
10991 {
10992 bdistance = rn->info;
10993 bgp_unlock_node (rn);
10994 }
10995 else
10996 {
10997 bdistance = bgp_distance_new ();
10998 rn->info = bdistance;
10999 }
11000
11001 /* Set distance value. */
11002 bdistance->distance = distance;
11003
11004 /* Reset access-list configuration. */
11005 if (bdistance->access_list)
11006 {
11007 free (bdistance->access_list);
11008 bdistance->access_list = NULL;
11009 }
11010 if (access_list_str)
11011 bdistance->access_list = strdup (access_list_str);
11012
11013 return CMD_SUCCESS;
11014}
11015
paul94f2b392005-06-28 12:44:16 +000011016static int
paulfd79ac92004-10-13 05:06:08 +000011017bgp_distance_unset (struct vty *vty, const char *distance_str,
11018 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011019{
11020 int ret;
11021 struct prefix_ipv4 p;
11022 u_char distance;
11023 struct bgp_node *rn;
11024 struct bgp_distance *bdistance;
11025
11026 ret = str2prefix_ipv4 (ip_str, &p);
11027 if (ret == 0)
11028 {
11029 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11030 return CMD_WARNING;
11031 }
11032
11033 distance = atoi (distance_str);
11034
11035 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11036 if (! rn)
11037 {
11038 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11039 return CMD_WARNING;
11040 }
11041
11042 bdistance = rn->info;
11043
11044 if (bdistance->access_list)
11045 free (bdistance->access_list);
11046 bgp_distance_free (bdistance);
11047
11048 rn->info = NULL;
11049 bgp_unlock_node (rn);
11050 bgp_unlock_node (rn);
11051
11052 return CMD_SUCCESS;
11053}
11054
paul718e3742002-12-13 20:15:29 +000011055/* Apply BGP information to distance method. */
11056u_char
11057bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11058{
11059 struct bgp_node *rn;
11060 struct prefix_ipv4 q;
11061 struct peer *peer;
11062 struct bgp_distance *bdistance;
11063 struct access_list *alist;
11064 struct bgp_static *bgp_static;
11065
11066 if (! bgp)
11067 return 0;
11068
11069 if (p->family != AF_INET)
11070 return 0;
11071
11072 peer = rinfo->peer;
11073
11074 if (peer->su.sa.sa_family != AF_INET)
11075 return 0;
11076
11077 memset (&q, 0, sizeof (struct prefix_ipv4));
11078 q.family = AF_INET;
11079 q.prefix = peer->su.sin.sin_addr;
11080 q.prefixlen = IPV4_MAX_BITLEN;
11081
11082 /* Check source address. */
11083 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11084 if (rn)
11085 {
11086 bdistance = rn->info;
11087 bgp_unlock_node (rn);
11088
11089 if (bdistance->access_list)
11090 {
11091 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11092 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11093 return bdistance->distance;
11094 }
11095 else
11096 return bdistance->distance;
11097 }
11098
11099 /* Backdoor check. */
11100 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11101 if (rn)
11102 {
11103 bgp_static = rn->info;
11104 bgp_unlock_node (rn);
11105
11106 if (bgp_static->backdoor)
11107 {
11108 if (bgp->distance_local)
11109 return bgp->distance_local;
11110 else
11111 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11112 }
11113 }
11114
11115 if (peer_sort (peer) == BGP_PEER_EBGP)
11116 {
11117 if (bgp->distance_ebgp)
11118 return bgp->distance_ebgp;
11119 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11120 }
11121 else
11122 {
11123 if (bgp->distance_ibgp)
11124 return bgp->distance_ibgp;
11125 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11126 }
11127}
11128
11129DEFUN (bgp_distance,
11130 bgp_distance_cmd,
11131 "distance bgp <1-255> <1-255> <1-255>",
11132 "Define an administrative distance\n"
11133 "BGP distance\n"
11134 "Distance for routes external to the AS\n"
11135 "Distance for routes internal to the AS\n"
11136 "Distance for local routes\n")
11137{
11138 struct bgp *bgp;
11139
11140 bgp = vty->index;
11141
11142 bgp->distance_ebgp = atoi (argv[0]);
11143 bgp->distance_ibgp = atoi (argv[1]);
11144 bgp->distance_local = atoi (argv[2]);
11145 return CMD_SUCCESS;
11146}
11147
11148DEFUN (no_bgp_distance,
11149 no_bgp_distance_cmd,
11150 "no distance bgp <1-255> <1-255> <1-255>",
11151 NO_STR
11152 "Define an administrative distance\n"
11153 "BGP distance\n"
11154 "Distance for routes external to the AS\n"
11155 "Distance for routes internal to the AS\n"
11156 "Distance for local routes\n")
11157{
11158 struct bgp *bgp;
11159
11160 bgp = vty->index;
11161
11162 bgp->distance_ebgp= 0;
11163 bgp->distance_ibgp = 0;
11164 bgp->distance_local = 0;
11165 return CMD_SUCCESS;
11166}
11167
11168ALIAS (no_bgp_distance,
11169 no_bgp_distance2_cmd,
11170 "no distance bgp",
11171 NO_STR
11172 "Define an administrative distance\n"
11173 "BGP distance\n")
11174
11175DEFUN (bgp_distance_source,
11176 bgp_distance_source_cmd,
11177 "distance <1-255> A.B.C.D/M",
11178 "Define an administrative distance\n"
11179 "Administrative distance\n"
11180 "IP source prefix\n")
11181{
11182 bgp_distance_set (vty, argv[0], argv[1], NULL);
11183 return CMD_SUCCESS;
11184}
11185
11186DEFUN (no_bgp_distance_source,
11187 no_bgp_distance_source_cmd,
11188 "no distance <1-255> A.B.C.D/M",
11189 NO_STR
11190 "Define an administrative distance\n"
11191 "Administrative distance\n"
11192 "IP source prefix\n")
11193{
11194 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11195 return CMD_SUCCESS;
11196}
11197
11198DEFUN (bgp_distance_source_access_list,
11199 bgp_distance_source_access_list_cmd,
11200 "distance <1-255> A.B.C.D/M WORD",
11201 "Define an administrative distance\n"
11202 "Administrative distance\n"
11203 "IP source prefix\n"
11204 "Access list name\n")
11205{
11206 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11207 return CMD_SUCCESS;
11208}
11209
11210DEFUN (no_bgp_distance_source_access_list,
11211 no_bgp_distance_source_access_list_cmd,
11212 "no distance <1-255> A.B.C.D/M WORD",
11213 NO_STR
11214 "Define an administrative distance\n"
11215 "Administrative distance\n"
11216 "IP source prefix\n"
11217 "Access list name\n")
11218{
11219 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11220 return CMD_SUCCESS;
11221}
11222
11223DEFUN (bgp_damp_set,
11224 bgp_damp_set_cmd,
11225 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11226 "BGP Specific commands\n"
11227 "Enable route-flap dampening\n"
11228 "Half-life time for the penalty\n"
11229 "Value to start reusing a route\n"
11230 "Value to start suppressing a route\n"
11231 "Maximum duration to suppress a stable route\n")
11232{
11233 struct bgp *bgp;
11234 int half = DEFAULT_HALF_LIFE * 60;
11235 int reuse = DEFAULT_REUSE;
11236 int suppress = DEFAULT_SUPPRESS;
11237 int max = 4 * half;
11238
11239 if (argc == 4)
11240 {
11241 half = atoi (argv[0]) * 60;
11242 reuse = atoi (argv[1]);
11243 suppress = atoi (argv[2]);
11244 max = atoi (argv[3]) * 60;
11245 }
11246 else if (argc == 1)
11247 {
11248 half = atoi (argv[0]) * 60;
11249 max = 4 * half;
11250 }
11251
11252 bgp = vty->index;
11253 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11254 half, reuse, suppress, max);
11255}
11256
11257ALIAS (bgp_damp_set,
11258 bgp_damp_set2_cmd,
11259 "bgp dampening <1-45>",
11260 "BGP Specific commands\n"
11261 "Enable route-flap dampening\n"
11262 "Half-life time for the penalty\n")
11263
11264ALIAS (bgp_damp_set,
11265 bgp_damp_set3_cmd,
11266 "bgp dampening",
11267 "BGP Specific commands\n"
11268 "Enable route-flap dampening\n")
11269
11270DEFUN (bgp_damp_unset,
11271 bgp_damp_unset_cmd,
11272 "no bgp dampening",
11273 NO_STR
11274 "BGP Specific commands\n"
11275 "Enable route-flap dampening\n")
11276{
11277 struct bgp *bgp;
11278
11279 bgp = vty->index;
11280 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11281}
11282
11283ALIAS (bgp_damp_unset,
11284 bgp_damp_unset2_cmd,
11285 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11286 NO_STR
11287 "BGP Specific commands\n"
11288 "Enable route-flap dampening\n"
11289 "Half-life time for the penalty\n"
11290 "Value to start reusing a route\n"
11291 "Value to start suppressing a route\n"
11292 "Maximum duration to suppress a stable route\n")
11293
11294DEFUN (show_ip_bgp_dampened_paths,
11295 show_ip_bgp_dampened_paths_cmd,
11296 "show ip bgp dampened-paths",
11297 SHOW_STR
11298 IP_STR
11299 BGP_STR
11300 "Display paths suppressed due to dampening\n")
11301{
ajs5a646652004-11-05 01:25:55 +000011302 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11303 NULL);
paul718e3742002-12-13 20:15:29 +000011304}
11305
11306DEFUN (show_ip_bgp_flap_statistics,
11307 show_ip_bgp_flap_statistics_cmd,
11308 "show ip bgp flap-statistics",
11309 SHOW_STR
11310 IP_STR
11311 BGP_STR
11312 "Display flap statistics of routes\n")
11313{
ajs5a646652004-11-05 01:25:55 +000011314 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11315 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011316}
11317
11318/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011319static int
paulfd79ac92004-10-13 05:06:08 +000011320bgp_clear_damp_route (struct vty *vty, const char *view_name,
11321 const char *ip_str, afi_t afi, safi_t safi,
11322 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011323{
11324 int ret;
11325 struct prefix match;
11326 struct bgp_node *rn;
11327 struct bgp_node *rm;
11328 struct bgp_info *ri;
11329 struct bgp_info *ri_temp;
11330 struct bgp *bgp;
11331 struct bgp_table *table;
11332
11333 /* BGP structure lookup. */
11334 if (view_name)
11335 {
11336 bgp = bgp_lookup_by_name (view_name);
11337 if (bgp == NULL)
11338 {
11339 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11340 return CMD_WARNING;
11341 }
11342 }
11343 else
11344 {
11345 bgp = bgp_get_default ();
11346 if (bgp == NULL)
11347 {
11348 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11349 return CMD_WARNING;
11350 }
11351 }
11352
11353 /* Check IP address argument. */
11354 ret = str2prefix (ip_str, &match);
11355 if (! ret)
11356 {
11357 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11358 return CMD_WARNING;
11359 }
11360
11361 match.family = afi2family (afi);
11362
11363 if (safi == SAFI_MPLS_VPN)
11364 {
11365 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11366 {
11367 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11368 continue;
11369
11370 if ((table = rn->info) != NULL)
11371 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011372 {
11373 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11374 {
11375 ri = rm->info;
11376 while (ri)
11377 {
11378 if (ri->extra && ri->extra->damp_info)
11379 {
11380 ri_temp = ri->next;
11381 bgp_damp_info_free (ri->extra->damp_info, 1);
11382 ri = ri_temp;
11383 }
11384 else
11385 ri = ri->next;
11386 }
11387 }
11388
11389 bgp_unlock_node (rm);
11390 }
paul718e3742002-12-13 20:15:29 +000011391 }
11392 }
11393 else
11394 {
11395 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011396 {
11397 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11398 {
11399 ri = rn->info;
11400 while (ri)
11401 {
11402 if (ri->extra && ri->extra->damp_info)
11403 {
11404 ri_temp = ri->next;
11405 bgp_damp_info_free (ri->extra->damp_info, 1);
11406 ri = ri_temp;
11407 }
11408 else
11409 ri = ri->next;
11410 }
11411 }
11412
11413 bgp_unlock_node (rn);
11414 }
paul718e3742002-12-13 20:15:29 +000011415 }
11416
11417 return CMD_SUCCESS;
11418}
11419
11420DEFUN (clear_ip_bgp_dampening,
11421 clear_ip_bgp_dampening_cmd,
11422 "clear ip bgp dampening",
11423 CLEAR_STR
11424 IP_STR
11425 BGP_STR
11426 "Clear route flap dampening information\n")
11427{
11428 bgp_damp_info_clean ();
11429 return CMD_SUCCESS;
11430}
11431
11432DEFUN (clear_ip_bgp_dampening_prefix,
11433 clear_ip_bgp_dampening_prefix_cmd,
11434 "clear ip bgp dampening A.B.C.D/M",
11435 CLEAR_STR
11436 IP_STR
11437 BGP_STR
11438 "Clear route flap dampening information\n"
11439 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11440{
11441 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11442 SAFI_UNICAST, NULL, 1);
11443}
11444
11445DEFUN (clear_ip_bgp_dampening_address,
11446 clear_ip_bgp_dampening_address_cmd,
11447 "clear ip bgp dampening A.B.C.D",
11448 CLEAR_STR
11449 IP_STR
11450 BGP_STR
11451 "Clear route flap dampening information\n"
11452 "Network to clear damping information\n")
11453{
11454 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11455 SAFI_UNICAST, NULL, 0);
11456}
11457
11458DEFUN (clear_ip_bgp_dampening_address_mask,
11459 clear_ip_bgp_dampening_address_mask_cmd,
11460 "clear ip bgp dampening A.B.C.D A.B.C.D",
11461 CLEAR_STR
11462 IP_STR
11463 BGP_STR
11464 "Clear route flap dampening information\n"
11465 "Network to clear damping information\n"
11466 "Network mask\n")
11467{
11468 int ret;
11469 char prefix_str[BUFSIZ];
11470
11471 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11472 if (! ret)
11473 {
11474 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11475 return CMD_WARNING;
11476 }
11477
11478 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11479 SAFI_UNICAST, NULL, 0);
11480}
11481
paul94f2b392005-06-28 12:44:16 +000011482static int
paul718e3742002-12-13 20:15:29 +000011483bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11484 afi_t afi, safi_t safi, int *write)
11485{
11486 struct bgp_node *prn;
11487 struct bgp_node *rn;
11488 struct bgp_table *table;
11489 struct prefix *p;
11490 struct prefix_rd *prd;
11491 struct bgp_static *bgp_static;
11492 u_int32_t label;
11493 char buf[SU_ADDRSTRLEN];
11494 char rdbuf[RD_ADDRSTRLEN];
11495
11496 /* Network configuration. */
11497 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11498 if ((table = prn->info) != NULL)
11499 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11500 if ((bgp_static = rn->info) != NULL)
11501 {
11502 p = &rn->p;
11503 prd = (struct prefix_rd *) &prn->p;
11504
11505 /* "address-family" display. */
11506 bgp_config_write_family_header (vty, afi, safi, write);
11507
11508 /* "network" configuration display. */
11509 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11510 label = decode_label (bgp_static->tag);
11511
11512 vty_out (vty, " network %s/%d rd %s tag %d",
11513 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11514 p->prefixlen,
11515 rdbuf, label);
11516 vty_out (vty, "%s", VTY_NEWLINE);
11517 }
11518 return 0;
11519}
11520
11521/* Configuration of static route announcement and aggregate
11522 information. */
11523int
11524bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11525 afi_t afi, safi_t safi, int *write)
11526{
11527 struct bgp_node *rn;
11528 struct prefix *p;
11529 struct bgp_static *bgp_static;
11530 struct bgp_aggregate *bgp_aggregate;
11531 char buf[SU_ADDRSTRLEN];
11532
11533 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11534 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11535
11536 /* Network configuration. */
11537 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11538 if ((bgp_static = rn->info) != NULL)
11539 {
11540 p = &rn->p;
11541
11542 /* "address-family" display. */
11543 bgp_config_write_family_header (vty, afi, safi, write);
11544
11545 /* "network" configuration display. */
11546 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11547 {
11548 u_int32_t destination;
11549 struct in_addr netmask;
11550
11551 destination = ntohl (p->u.prefix4.s_addr);
11552 masklen2ip (p->prefixlen, &netmask);
11553 vty_out (vty, " network %s",
11554 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11555
11556 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11557 || (IN_CLASSB (destination) && p->prefixlen == 16)
11558 || (IN_CLASSA (destination) && p->prefixlen == 8)
11559 || p->u.prefix4.s_addr == 0)
11560 {
11561 /* Natural mask is not display. */
11562 }
11563 else
11564 vty_out (vty, " mask %s", inet_ntoa (netmask));
11565 }
11566 else
11567 {
11568 vty_out (vty, " network %s/%d",
11569 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11570 p->prefixlen);
11571 }
11572
11573 if (bgp_static->rmap.name)
11574 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011575 else
11576 {
11577 if (bgp_static->backdoor)
11578 vty_out (vty, " backdoor");
11579 if (bgp_static->ttl)
11580 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11581 }
paul718e3742002-12-13 20:15:29 +000011582
11583 vty_out (vty, "%s", VTY_NEWLINE);
11584 }
11585
11586 /* Aggregate-address configuration. */
11587 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11588 if ((bgp_aggregate = rn->info) != NULL)
11589 {
11590 p = &rn->p;
11591
11592 /* "address-family" display. */
11593 bgp_config_write_family_header (vty, afi, safi, write);
11594
11595 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11596 {
11597 struct in_addr netmask;
11598
11599 masklen2ip (p->prefixlen, &netmask);
11600 vty_out (vty, " aggregate-address %s %s",
11601 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11602 inet_ntoa (netmask));
11603 }
11604 else
11605 {
11606 vty_out (vty, " aggregate-address %s/%d",
11607 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11608 p->prefixlen);
11609 }
11610
11611 if (bgp_aggregate->as_set)
11612 vty_out (vty, " as-set");
11613
11614 if (bgp_aggregate->summary_only)
11615 vty_out (vty, " summary-only");
11616
11617 vty_out (vty, "%s", VTY_NEWLINE);
11618 }
11619
11620 return 0;
11621}
11622
11623int
11624bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11625{
11626 struct bgp_node *rn;
11627 struct bgp_distance *bdistance;
11628
11629 /* Distance configuration. */
11630 if (bgp->distance_ebgp
11631 && bgp->distance_ibgp
11632 && bgp->distance_local
11633 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11634 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11635 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11636 vty_out (vty, " distance bgp %d %d %d%s",
11637 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11638 VTY_NEWLINE);
11639
11640 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11641 if ((bdistance = rn->info) != NULL)
11642 {
11643 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11644 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11645 bdistance->access_list ? bdistance->access_list : "",
11646 VTY_NEWLINE);
11647 }
11648
11649 return 0;
11650}
11651
11652/* Allocate routing table structure and install commands. */
11653void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011654bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011655{
11656 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011657 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011658
11659 /* IPv4 BGP commands. */
11660 install_element (BGP_NODE, &bgp_network_cmd);
11661 install_element (BGP_NODE, &bgp_network_mask_cmd);
11662 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11663 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11664 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11665 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11666 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11667 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11668 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011669 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11670 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11671 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11672 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11673 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11674 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011675 install_element (BGP_NODE, &no_bgp_network_cmd);
11676 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11677 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11678 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11679 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11680 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11681 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11682 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11683 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011684 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11685 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11686 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11687 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11688 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11689 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011690
11691 install_element (BGP_NODE, &aggregate_address_cmd);
11692 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11693 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11694 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11695 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11696 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11697 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11698 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11699 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11700 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11701 install_element (BGP_NODE, &no_aggregate_address_cmd);
11702 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11703 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11704 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11705 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11706 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11707 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11708 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11709 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11710 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11711
11712 /* IPv4 unicast configuration. */
11713 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11714 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11715 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11716 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11717 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11718 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011719 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11720 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11721 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11722 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11723 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11724 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 +000011725 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11726 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11727 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11728 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11729 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011730 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11731 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11732 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11733 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11734 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11735 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 +000011736 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11737 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11738 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11739 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11740 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11741 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11742 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11743 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11744 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11745 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11746 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11747 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11748 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11749 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11750 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11751 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11752 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11753 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11754 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11755 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11756
11757 /* IPv4 multicast configuration. */
11758 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11759 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11760 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11761 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11762 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11763 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011764 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11765 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11766 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11767 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11768 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11769 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 +000011770 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11771 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11772 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11773 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11774 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11775 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011776 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11777 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11778 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11779 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11780 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11781 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 +000011782 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11783 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11784 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11785 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11786 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11787 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11788 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11789 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11790 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11791 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11792 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11793 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11794 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11795 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11796 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11797 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11798 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11799 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11800 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11801 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11802
11803 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11804 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11805 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11806 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11807 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11808 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11809 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11810 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11811 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11812 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11813 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11814 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11815 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11816 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11817 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11818 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11819 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11820 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11821 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11822 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11823 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11824 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11825 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11826 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11827 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11828 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11829 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11830 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11831 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11832 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11833 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11834 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11835 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11836 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11837 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11838 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11839 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11840 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11841 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11842 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11843 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11844 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11845 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11846 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11847 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11848 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11849 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11850 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11851 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11852 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11853 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11854 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11855 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11856 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11857 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11858 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11859 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11860 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11861 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11862 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11863 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11864 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11865 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11866 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11867 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11868 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11869 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011870 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11871 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11872 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011873 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11874 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011875 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11876 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11877 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011878
11879 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11880 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11881 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11882 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11883 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11884 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11885 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11886 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11887 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11888 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11889 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11890 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11891 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11892 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11893 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11894 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11895 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11896 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11897 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11898 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11899 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11900 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11901 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11902 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11903 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11904 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11905 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11906 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11907 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11908 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011909
11910 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11911 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11912 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11913 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11914 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11915 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11916 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11917 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11918 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11919 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11920 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11921 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11922 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11923 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11924 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11925 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11926 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11927 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11928 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11929 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11930 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11931 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11932 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11933 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11934 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11935 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11936 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11937 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11938 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11939 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11940 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11941 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11942 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11943 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11944 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11945 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11946 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11947 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11948 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11949 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11950 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11951 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11952 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11953 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11954 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11955 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11956 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11957 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11958 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11959 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11960 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11961 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11962 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11963 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11964 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11965 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11966 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11967 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11968 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11969 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11970 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11971 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11972 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11973 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11974 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11975 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11976 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011977 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11978 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11979 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011980 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11981 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011982 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11983 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11984 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011985
11986 /* BGP dampening clear commands */
11987 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11988 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11989 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11990 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11991
Paul Jakmaff7924f2006-09-04 01:10:36 +000011992 /* prefix count */
11993 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11994 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11995 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011996#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011997 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11998
paul718e3742002-12-13 20:15:29 +000011999 /* New config IPv6 BGP commands. */
12000 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12001 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000012002 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000012003 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12004 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000012005 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000012006
12007 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12008 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12009 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12010 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12011
12012 /* Old config IPv6 BGP commands. */
12013 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12014 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12015
12016 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12017 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12018 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12019 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12020
12021 install_element (VIEW_NODE, &show_bgp_cmd);
12022 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
12023 install_element (VIEW_NODE, &show_bgp_route_cmd);
12024 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
12025 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12026 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
12027 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12028 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12029 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12030 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12031 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12032 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12033 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12034 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12035 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12036 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12037 install_element (VIEW_NODE, &show_bgp_community_cmd);
12038 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12039 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12040 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12041 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12042 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12043 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12044 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12045 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12046 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12047 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12048 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12049 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12050 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12051 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12052 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12053 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12054 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12055 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12056 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12057 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12058 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12059 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12060 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12061 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12062 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12063 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12064 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12065 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12066 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012067 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12068 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12069 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12070 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012071 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
12072 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
12073 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012074 install_element (VIEW_NODE, &show_bgp_view_cmd);
12075 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12076 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12077 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12078 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12079 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12080 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12081 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12082 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12083 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12084 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12085 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12086 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12087 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12088 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12089 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12090 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12091 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012092 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
12093 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
12094 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012095
12096 /* Restricted:
12097 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12098 */
12099 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12100 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
12101 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12102 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
12103 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12104 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12105 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12106 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12107 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12108 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12109 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12110 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12111 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12112 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12113 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12114 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12115 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12116 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12117 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12118 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12119 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
12120 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
12121 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12122 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12123 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12124 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12125 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12126 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12127 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
12128 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012129
12130 install_element (ENABLE_NODE, &show_bgp_cmd);
12131 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
12132 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12133 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
12134 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12135 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
12136 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12137 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12138 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12139 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12140 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12141 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12142 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12143 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12144 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12145 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12146 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12147 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12148 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12149 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12150 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12151 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12152 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12153 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12154 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12155 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12156 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12157 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12158 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12159 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12160 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12161 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12162 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12163 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12164 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12165 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12166 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12167 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12168 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12169 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12170 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12171 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12172 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12173 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12174 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12175 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012176 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12177 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12178 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12179 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012180 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12181 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12182 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012183 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12184 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12185 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12186 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12187 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12188 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12189 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12190 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12191 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12192 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12193 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12194 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12195 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12196 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12197 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12198 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12199 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12200 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012201 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12202 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12203 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012204
12205 /* Statistics */
12206 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12207 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12208 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12209 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12210
paul718e3742002-12-13 20:15:29 +000012211 /* old command */
12212 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12213 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12214 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12215 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12216 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12217 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12218 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12219 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12220 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12221 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12222 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12223 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12224 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12225 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12226 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12227 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12228 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12229 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12230 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12231 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12232 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12233 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12234 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12235 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12236 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12237 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12238 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12239 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12240 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12241 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12242 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12243 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12244 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12245 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12246 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12247 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012248
paul718e3742002-12-13 20:15:29 +000012249 /* old command */
12250 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12251 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12252 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12253 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12254 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12255 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12256 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12257 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12258 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12259 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12260 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12261 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12262 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12263 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12264 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12265 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12266 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12267 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12268 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12269 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12270 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12271 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12272 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12273 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12274 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12275 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12276 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12277 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12278 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12279 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12280 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12281 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12282 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12283 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12284 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12285 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12286
12287 /* old command */
12288 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12289 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12290 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12291 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12292
12293 /* old command */
12294 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12295 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12296 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12297 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12298
12299 /* old command */
12300 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12301 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12302 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12303 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12304#endif /* HAVE_IPV6 */
12305
12306 install_element (BGP_NODE, &bgp_distance_cmd);
12307 install_element (BGP_NODE, &no_bgp_distance_cmd);
12308 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12309 install_element (BGP_NODE, &bgp_distance_source_cmd);
12310 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12311 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12312 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12313
12314 install_element (BGP_NODE, &bgp_damp_set_cmd);
12315 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12316 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12317 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12318 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12319 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12320 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12321 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12322 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12323 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12324}
Chris Caputo228da422009-07-18 05:44:03 +000012325
12326void
12327bgp_route_finish (void)
12328{
12329 bgp_table_unlock (bgp_distance_table);
12330 bgp_distance_table = NULL;
12331}