blob: d08cb1e17cbaf9b9b9556db2e2be0bdf672a6b5c [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
paul718e3742002-12-13 20:15:29 +000057
58/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070059extern const char *bgp_origin_str[];
60extern const char *bgp_origin_long_str[];
paul718e3742002-12-13 20:15:29 +000061
paul94f2b392005-06-28 12:44:16 +000062static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000063bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000064 struct prefix_rd *prd)
65{
66 struct bgp_node *rn;
67 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000068
69 assert (table);
70 if (!table)
71 return NULL;
72
paul718e3742002-12-13 20:15:29 +000073 if (safi == SAFI_MPLS_VPN)
74 {
paulfee0f4c2004-09-13 05:12:46 +000075 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000076
77 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000078 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000079 else
80 bgp_unlock_node (prn);
81 table = prn->info;
82 }
paul718e3742002-12-13 20:15:29 +000083
84 rn = bgp_node_get (table, p);
85
86 if (safi == SAFI_MPLS_VPN)
87 rn->prn = prn;
88
89 return rn;
90}
91
Paul Jakmafb982c22007-05-04 20:15:47 +000092/* Allocate bgp_info_extra */
93static struct bgp_info_extra *
94bgp_info_extra_new (void)
95{
96 struct bgp_info_extra *new;
97 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
98 return new;
99}
100
101static void
102bgp_info_extra_free (struct bgp_info_extra **extra)
103{
104 if (extra && *extra)
105 {
106 if ((*extra)->damp_info)
107 bgp_damp_info_free ((*extra)->damp_info, 0);
108
109 (*extra)->damp_info = NULL;
110
111 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
112
113 *extra = NULL;
114 }
115}
116
117/* Get bgp_info extra information for the given bgp_info, lazy allocated
118 * if required.
119 */
120struct bgp_info_extra *
121bgp_info_extra_get (struct bgp_info *ri)
122{
123 if (!ri->extra)
124 ri->extra = bgp_info_extra_new();
125 return ri->extra;
126}
127
paul718e3742002-12-13 20:15:29 +0000128/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000129static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800130bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000131{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700132 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000133}
134
135/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000136static void
paul718e3742002-12-13 20:15:29 +0000137bgp_info_free (struct bgp_info *binfo)
138{
139 if (binfo->attr)
140 bgp_attr_unintern (binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000141
142 bgp_info_extra_free (&binfo->extra);
paul718e3742002-12-13 20:15:29 +0000143
paul200df112005-06-01 11:17:05 +0000144 peer_unlock (binfo->peer); /* bgp_info peer reference */
145
paul718e3742002-12-13 20:15:29 +0000146 XFREE (MTYPE_BGP_ROUTE, binfo);
147}
148
paul200df112005-06-01 11:17:05 +0000149struct bgp_info *
150bgp_info_lock (struct bgp_info *binfo)
151{
152 binfo->lock++;
153 return binfo;
154}
155
156struct bgp_info *
157bgp_info_unlock (struct bgp_info *binfo)
158{
159 assert (binfo && binfo->lock > 0);
160 binfo->lock--;
161
162 if (binfo->lock == 0)
163 {
164#if 0
165 zlog_debug ("%s: unlocked and freeing", __func__);
166 zlog_backtrace (LOG_DEBUG);
167#endif
168 bgp_info_free (binfo);
169 return NULL;
170 }
171
172#if 0
173 if (binfo->lock == 1)
174 {
175 zlog_debug ("%s: unlocked to 1", __func__);
176 zlog_backtrace (LOG_DEBUG);
177 }
178#endif
179
180 return binfo;
181}
182
paul718e3742002-12-13 20:15:29 +0000183void
184bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
185{
186 struct bgp_info *top;
187
188 top = rn->info;
paul200df112005-06-01 11:17:05 +0000189
paul718e3742002-12-13 20:15:29 +0000190 ri->next = rn->info;
191 ri->prev = NULL;
192 if (top)
193 top->prev = ri;
194 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000195
196 bgp_info_lock (ri);
197 bgp_lock_node (rn);
198 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000199}
200
paulb40d9392005-08-22 22:34:41 +0000201/* Do the actual removal of info from RIB, for use by bgp_process
202 completion callback *only* */
203static void
204bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000205{
206 if (ri->next)
207 ri->next->prev = ri->prev;
208 if (ri->prev)
209 ri->prev->next = ri->next;
210 else
211 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000212
213 bgp_info_unlock (ri);
214 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000215}
216
paulb40d9392005-08-22 22:34:41 +0000217void
218bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
219{
Paul Jakma1a392d42006-09-07 00:24:49 +0000220 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
221 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000222 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
223}
224
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000225/* undo the effects of a previous call to bgp_info_delete; typically
226 called when a route is deleted and then quickly re-added before the
227 deletion has been processed */
228static void
229bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
230{
231 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
232 /* unset of previous already took care of pcount */
233 SET_FLAG (ri->flags, BGP_INFO_VALID);
234}
235
Paul Jakma1a392d42006-09-07 00:24:49 +0000236/* Adjust pcount as required */
237static void
238bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
239{
Paul Jakma6f585442006-10-22 19:13:07 +0000240 assert (rn && rn->table);
241 assert (ri && ri->peer && ri->peer->bgp);
242
Paul Jakma1a392d42006-09-07 00:24:49 +0000243 /* Ignore 'pcount' for RS-client tables */
244 if (rn->table->type != BGP_TABLE_MAIN
245 || ri->peer == ri->peer->bgp->peer_self)
246 return;
247
248 if (BGP_INFO_HOLDDOWN (ri)
249 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
250 {
251
252 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
253
254 /* slight hack, but more robust against errors. */
255 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
256 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
257 else
258 {
259 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
260 __func__, ri->peer->host);
261 zlog_backtrace (LOG_WARNING);
262 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
263 }
264 }
265 else if (!BGP_INFO_HOLDDOWN (ri)
266 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
267 {
268 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
269 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
270 }
271}
272
273
274/* Set/unset bgp_info flags, adjusting any other state as needed.
275 * This is here primarily to keep prefix-count in check.
276 */
277void
278bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
279{
280 SET_FLAG (ri->flags, flag);
281
282 /* early bath if we know it's not a flag that changes useability state */
283 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
284 return;
285
286 bgp_pcount_adjust (rn, ri);
287}
288
289void
290bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
291{
292 UNSET_FLAG (ri->flags, flag);
293
294 /* early bath if we know it's not a flag that changes useability state */
295 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
296 return;
297
298 bgp_pcount_adjust (rn, ri);
299}
300
paul718e3742002-12-13 20:15:29 +0000301/* Get MED value. If MED value is missing and "bgp bestpath
302 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000303static u_int32_t
paul718e3742002-12-13 20:15:29 +0000304bgp_med_value (struct attr *attr, struct bgp *bgp)
305{
306 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
307 return attr->med;
308 else
309 {
310 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000311 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000312 else
313 return 0;
314 }
315}
316
317/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000318static int
paul718e3742002-12-13 20:15:29 +0000319bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
320{
321 u_int32_t new_pref;
322 u_int32_t exist_pref;
323 u_int32_t new_med;
324 u_int32_t exist_med;
Paul Jakmafb982c22007-05-04 20:15:47 +0000325 u_int32_t new_weight = 0;
326 u_int32_t exist_weight = 0;
paul718e3742002-12-13 20:15:29 +0000327 struct in_addr new_id;
328 struct in_addr exist_id;
329 int new_cluster;
330 int exist_cluster;
331 int internal_as_route = 0;
332 int confed_as_route = 0;
333 int ret;
334
335 /* 0. Null check. */
336 if (new == NULL)
337 return 0;
338 if (exist == NULL)
339 return 1;
340
341 /* 1. Weight check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000342 if (new->attr->extra)
343 new_weight = new->attr->extra->weight;
344 if (exist->attr->extra)
345 exist_weight = exist->attr->extra->weight;
346 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000347 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000348 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000349 return 0;
350
351 /* 2. Local preference check. */
352 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
353 new_pref = new->attr->local_pref;
354 else
355 new_pref = bgp->default_local_pref;
356
357 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
358 exist_pref = exist->attr->local_pref;
359 else
360 exist_pref = bgp->default_local_pref;
361
362 if (new_pref > exist_pref)
363 return 1;
364 if (new_pref < exist_pref)
365 return 0;
366
367 /* 3. Local route check. */
368 if (new->sub_type == BGP_ROUTE_STATIC)
369 return 1;
370 if (exist->sub_type == BGP_ROUTE_STATIC)
371 return 0;
372
373 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
374 return 1;
375 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
376 return 0;
377
378 if (new->sub_type == BGP_ROUTE_AGGREGATE)
379 return 1;
380 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
381 return 0;
382
383 /* 4. AS path length check. */
384 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
385 {
paulfe69a502005-09-10 16:55:02 +0000386 int exist_hops = aspath_count_hops (exist->attr->aspath);
387 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
388
hasso68118452005-04-08 15:40:36 +0000389 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
390 {
paulfe69a502005-09-10 16:55:02 +0000391 int aspath_hops;
392
393 aspath_hops = aspath_count_hops (new->attr->aspath);
394 aspath_hops += aspath_count_confeds (new->attr->aspath);
395
396 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000397 return 1;
paulfe69a502005-09-10 16:55:02 +0000398 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000399 return 0;
400 }
401 else
402 {
paulfe69a502005-09-10 16:55:02 +0000403 int newhops = aspath_count_hops (new->attr->aspath);
404
405 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000406 return 1;
paulfe69a502005-09-10 16:55:02 +0000407 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000408 return 0;
409 }
paul718e3742002-12-13 20:15:29 +0000410 }
411
412 /* 5. Origin check. */
413 if (new->attr->origin < exist->attr->origin)
414 return 1;
415 if (new->attr->origin > exist->attr->origin)
416 return 0;
417
418 /* 6. MED check. */
paulfe69a502005-09-10 16:55:02 +0000419 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
420 && aspath_count_hops (exist->attr->aspath) == 0);
421 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
422 && aspath_count_confeds (exist->attr->aspath) > 0
423 && aspath_count_hops (new->attr->aspath) == 0
424 && aspath_count_hops (exist->attr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000425
426 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
427 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
428 && confed_as_route)
429 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
430 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
431 || internal_as_route)
432 {
433 new_med = bgp_med_value (new->attr, bgp);
434 exist_med = bgp_med_value (exist->attr, bgp);
435
436 if (new_med < exist_med)
437 return 1;
438 if (new_med > exist_med)
439 return 0;
440 }
441
442 /* 7. Peer type check. */
443 if (peer_sort (new->peer) == BGP_PEER_EBGP
444 && peer_sort (exist->peer) == BGP_PEER_IBGP)
445 return 1;
446 if (peer_sort (new->peer) == BGP_PEER_EBGP
447 && peer_sort (exist->peer) == BGP_PEER_CONFED)
448 return 1;
449 if (peer_sort (new->peer) == BGP_PEER_IBGP
450 && peer_sort (exist->peer) == BGP_PEER_EBGP)
451 return 0;
452 if (peer_sort (new->peer) == BGP_PEER_CONFED
453 && peer_sort (exist->peer) == BGP_PEER_EBGP)
454 return 0;
455
456 /* 8. IGP metric check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000457 if (new->extra || exist->extra)
458 {
459 uint32_t newm = (new->extra ? new->extra->igpmetric : 0);
460 uint32_t existm = (exist->extra ? exist->extra->igpmetric : 0);
461
462 if (newm < existm)
463 return 1;
464 if (newm > existm)
465 return 0;
466 }
paul718e3742002-12-13 20:15:29 +0000467
468 /* 9. Maximum path check. */
469
470 /* 10. If both paths are external, prefer the path that was received
471 first (the oldest one). This step minimizes route-flap, since a
472 newer path won't displace an older one, even if it was the
473 preferred route based on the additional decision criteria below. */
474 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
475 && peer_sort (new->peer) == BGP_PEER_EBGP
476 && peer_sort (exist->peer) == BGP_PEER_EBGP)
477 {
478 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
479 return 1;
480 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
481 return 0;
482 }
483
484 /* 11. Rourter-ID comparision. */
485 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000486 new_id.s_addr = new->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000487 else
488 new_id.s_addr = new->peer->remote_id.s_addr;
489 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000490 exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000491 else
492 exist_id.s_addr = exist->peer->remote_id.s_addr;
493
494 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
495 return 1;
496 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
497 return 0;
498
499 /* 12. Cluster length comparision. */
500 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000501 new_cluster = new->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000502 else
503 new_cluster = 0;
504 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000505 exist_cluster = exist->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000506 else
507 exist_cluster = 0;
508
509 if (new_cluster < exist_cluster)
510 return 1;
511 if (new_cluster > exist_cluster)
512 return 0;
513
514 /* 13. Neighbor address comparision. */
515 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
516
517 if (ret == 1)
518 return 0;
519 if (ret == -1)
520 return 1;
521
522 return 1;
523}
524
paul94f2b392005-06-28 12:44:16 +0000525static enum filter_type
paul718e3742002-12-13 20:15:29 +0000526bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
527 afi_t afi, safi_t safi)
528{
529 struct bgp_filter *filter;
530
531 filter = &peer->filter[afi][safi];
532
Paul Jakma650f76c2009-06-25 18:06:31 +0100533#define FILTER_EXIST_WARN(F,f,filter) \
534 if (BGP_DEBUG (update, UPDATE_IN) \
535 && !(F ## _IN (filter))) \
536 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
537 peer->host, #f, F ## _IN_NAME(filter));
538
539 if (DISTRIBUTE_IN_NAME (filter)) {
540 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
541
paul718e3742002-12-13 20:15:29 +0000542 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
543 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100544 }
paul718e3742002-12-13 20:15:29 +0000545
Paul Jakma650f76c2009-06-25 18:06:31 +0100546 if (PREFIX_LIST_IN_NAME (filter)) {
547 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
548
paul718e3742002-12-13 20:15:29 +0000549 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
550 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100551 }
paul718e3742002-12-13 20:15:29 +0000552
Paul Jakma650f76c2009-06-25 18:06:31 +0100553 if (FILTER_LIST_IN_NAME (filter)) {
554 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
555
paul718e3742002-12-13 20:15:29 +0000556 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
557 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100558 }
559
paul718e3742002-12-13 20:15:29 +0000560 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100561#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000562}
563
paul94f2b392005-06-28 12:44:16 +0000564static enum filter_type
paul718e3742002-12-13 20:15:29 +0000565bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
566 afi_t afi, safi_t safi)
567{
568 struct bgp_filter *filter;
569
570 filter = &peer->filter[afi][safi];
571
Paul Jakma650f76c2009-06-25 18:06:31 +0100572#define FILTER_EXIST_WARN(F,f,filter) \
573 if (BGP_DEBUG (update, UPDATE_OUT) \
574 && !(F ## _OUT (filter))) \
575 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
576 peer->host, #f, F ## _OUT_NAME(filter));
577
578 if (DISTRIBUTE_OUT_NAME (filter)) {
579 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
580
paul718e3742002-12-13 20:15:29 +0000581 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
582 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100583 }
paul718e3742002-12-13 20:15:29 +0000584
Paul Jakma650f76c2009-06-25 18:06:31 +0100585 if (PREFIX_LIST_OUT_NAME (filter)) {
586 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
587
paul718e3742002-12-13 20:15:29 +0000588 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
589 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100590 }
paul718e3742002-12-13 20:15:29 +0000591
Paul Jakma650f76c2009-06-25 18:06:31 +0100592 if (FILTER_LIST_OUT_NAME (filter)) {
593 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
594
paul718e3742002-12-13 20:15:29 +0000595 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
596 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100597 }
paul718e3742002-12-13 20:15:29 +0000598
599 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100600#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000601}
602
603/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000604static int
paul718e3742002-12-13 20:15:29 +0000605bgp_community_filter (struct peer *peer, struct attr *attr)
606{
607 if (attr->community)
608 {
609 /* NO_ADVERTISE check. */
610 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
611 return 1;
612
613 /* NO_EXPORT check. */
614 if (peer_sort (peer) == BGP_PEER_EBGP &&
615 community_include (attr->community, COMMUNITY_NO_EXPORT))
616 return 1;
617
618 /* NO_EXPORT_SUBCONFED check. */
619 if (peer_sort (peer) == BGP_PEER_EBGP
620 || peer_sort (peer) == BGP_PEER_CONFED)
621 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
622 return 1;
623 }
624 return 0;
625}
626
627/* Route reflection loop check. */
628static int
629bgp_cluster_filter (struct peer *peer, struct attr *attr)
630{
631 struct in_addr cluster_id;
632
Paul Jakmafb982c22007-05-04 20:15:47 +0000633 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000634 {
635 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
636 cluster_id = peer->bgp->cluster_id;
637 else
638 cluster_id = peer->bgp->router_id;
639
Paul Jakmafb982c22007-05-04 20:15:47 +0000640 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000641 return 1;
642 }
643 return 0;
644}
645
paul94f2b392005-06-28 12:44:16 +0000646static int
paul718e3742002-12-13 20:15:29 +0000647bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
648 afi_t afi, safi_t safi)
649{
650 struct bgp_filter *filter;
651 struct bgp_info info;
652 route_map_result_t ret;
653
654 filter = &peer->filter[afi][safi];
655
656 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000657 if (peer->weight)
658 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000659
660 /* Route map apply. */
661 if (ROUTE_MAP_IN_NAME (filter))
662 {
663 /* Duplicate current value to new strucutre for modification. */
664 info.peer = peer;
665 info.attr = attr;
666
paulac41b2a2003-08-12 05:32:27 +0000667 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
668
paul718e3742002-12-13 20:15:29 +0000669 /* Apply BGP route map to the attribute. */
670 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000671
672 peer->rmap_type = 0;
673
paul718e3742002-12-13 20:15:29 +0000674 if (ret == RMAP_DENYMATCH)
675 {
676 /* Free newly generated AS path and community by route-map. */
677 bgp_attr_flush (attr);
678 return RMAP_DENY;
679 }
680 }
681 return RMAP_PERMIT;
682}
683
paul94f2b392005-06-28 12:44:16 +0000684static int
paulfee0f4c2004-09-13 05:12:46 +0000685bgp_export_modifier (struct peer *rsclient, struct peer *peer,
686 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
687{
688 struct bgp_filter *filter;
689 struct bgp_info info;
690 route_map_result_t ret;
691
692 filter = &peer->filter[afi][safi];
693
694 /* Route map apply. */
695 if (ROUTE_MAP_EXPORT_NAME (filter))
696 {
697 /* Duplicate current value to new strucutre for modification. */
698 info.peer = rsclient;
699 info.attr = attr;
700
701 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
702
703 /* Apply BGP route map to the attribute. */
704 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
705
706 rsclient->rmap_type = 0;
707
708 if (ret == RMAP_DENYMATCH)
709 {
710 /* Free newly generated AS path and community by route-map. */
711 bgp_attr_flush (attr);
712 return RMAP_DENY;
713 }
714 }
715 return RMAP_PERMIT;
716}
717
paul94f2b392005-06-28 12:44:16 +0000718static int
paulfee0f4c2004-09-13 05:12:46 +0000719bgp_import_modifier (struct peer *rsclient, struct peer *peer,
720 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
721{
722 struct bgp_filter *filter;
723 struct bgp_info info;
724 route_map_result_t ret;
725
726 filter = &rsclient->filter[afi][safi];
727
728 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000729 if (peer->weight)
730 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000731
732 /* Route map apply. */
733 if (ROUTE_MAP_IMPORT_NAME (filter))
734 {
735 /* Duplicate current value to new strucutre for modification. */
736 info.peer = peer;
737 info.attr = attr;
738
739 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
740
741 /* Apply BGP route map to the attribute. */
742 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
743
744 peer->rmap_type = 0;
745
746 if (ret == RMAP_DENYMATCH)
747 {
748 /* Free newly generated AS path and community by route-map. */
749 bgp_attr_flush (attr);
750 return RMAP_DENY;
751 }
752 }
753 return RMAP_PERMIT;
754}
755
paul94f2b392005-06-28 12:44:16 +0000756static int
paul718e3742002-12-13 20:15:29 +0000757bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
758 struct attr *attr, afi_t afi, safi_t safi)
759{
760 int ret;
761 char buf[SU_ADDRSTRLEN];
762 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000763 struct peer *from;
764 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000765 int transparent;
766 int reflect;
767
768 from = ri->peer;
769 filter = &peer->filter[afi][safi];
770 bgp = peer->bgp;
771
Paul Jakma750e8142008-07-22 21:11:48 +0000772 if (DISABLE_BGP_ANNOUNCE)
773 return 0;
paul718e3742002-12-13 20:15:29 +0000774
paulfee0f4c2004-09-13 05:12:46 +0000775 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
776 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
777 return 0;
778
paul718e3742002-12-13 20:15:29 +0000779 /* Do not send back route to sender. */
780 if (from == peer)
781 return 0;
782
paul35be31b2004-05-01 18:17:04 +0000783 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
784 if (p->family == AF_INET
785 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
786 return 0;
787#ifdef HAVE_IPV6
788 if (p->family == AF_INET6
789 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
790 return 0;
791#endif
792
paul718e3742002-12-13 20:15:29 +0000793 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000794 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000795 if (! UNSUPPRESS_MAP_NAME (filter))
796 return 0;
797
798 /* Default route check. */
799 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
800 {
801 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
802 return 0;
803#ifdef HAVE_IPV6
804 else if (p->family == AF_INET6 && p->prefixlen == 0)
805 return 0;
806#endif /* HAVE_IPV6 */
807 }
808
paul286e1e72003-08-08 00:24:31 +0000809 /* Transparency check. */
810 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
811 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
812 transparent = 1;
813 else
814 transparent = 0;
815
paul718e3742002-12-13 20:15:29 +0000816 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000817 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000818 return 0;
819
820 /* If the attribute has originator-id and it is same as remote
821 peer's id. */
822 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
823 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000824 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000825 {
826 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000827 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000828 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
829 peer->host,
830 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
831 p->prefixlen);
832 return 0;
833 }
834 }
835
836 /* ORF prefix-list filter check */
837 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
838 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
839 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
840 if (peer->orf_plist[afi][safi])
841 {
842 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
843 return 0;
844 }
845
846 /* Output filter check. */
847 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
848 {
849 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000850 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000851 "%s [Update:SEND] %s/%d is filtered",
852 peer->host,
853 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
854 p->prefixlen);
855 return 0;
856 }
857
858#ifdef BGP_SEND_ASPATH_CHECK
859 /* AS path loop check. */
860 if (aspath_loop_check (ri->attr->aspath, peer->as))
861 {
862 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000863 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400864 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000865 peer->host, peer->as);
866 return 0;
867 }
868#endif /* BGP_SEND_ASPATH_CHECK */
869
870 /* If we're a CONFED we need to loop check the CONFED ID too */
871 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
872 {
873 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
874 {
875 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000876 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400877 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000878 peer->host,
879 bgp->confed_id);
880 return 0;
881 }
882 }
883
884 /* Route-Reflect check. */
885 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
886 reflect = 1;
887 else
888 reflect = 0;
889
890 /* IBGP reflection check. */
891 if (reflect)
892 {
893 /* A route from a Client peer. */
894 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
895 {
896 /* Reflect to all the Non-Client peers and also to the
897 Client peers other than the originator. Originator check
898 is already done. So there is noting to do. */
899 /* no bgp client-to-client reflection check. */
900 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
901 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
902 return 0;
903 }
904 else
905 {
906 /* A route from a Non-client peer. Reflect to all other
907 clients. */
908 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
909 return 0;
910 }
911 }
Paul Jakma41367172007-08-06 15:24:51 +0000912
913 /* AS-Pathlimit check */
914 if (ri->attr->pathlimit.ttl && peer_sort (peer) == BGP_PEER_EBGP)
915 /* Our ASN has not yet been pre-pended, that's done in packet_attribute
916 * on output. Hence the test here is for >=.
917 */
918 if (aspath_count_hops (ri->attr->aspath) >= ri->attr->pathlimit.ttl)
919 {
920 if (BGP_DEBUG (filter, FILTER))
921 zlog_info ("%s [Update:SEND] suppressed, AS-Pathlimit TTL %u exceeded",
922 peer->host, ri->attr->pathlimit.ttl);
923 return 0;
924 }
925
paul718e3742002-12-13 20:15:29 +0000926 /* For modify attribute, copy it to temporary structure. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000927 bgp_attr_dup (attr, ri->attr);
928
paul718e3742002-12-13 20:15:29 +0000929 /* If local-preference is not set. */
930 if ((peer_sort (peer) == BGP_PEER_IBGP
931 || peer_sort (peer) == BGP_PEER_CONFED)
932 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
933 {
934 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
935 attr->local_pref = bgp->default_local_pref;
936 }
937
paul718e3742002-12-13 20:15:29 +0000938 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
939 if (peer_sort (peer) == BGP_PEER_EBGP
940 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
941 {
942 if (ri->peer != bgp->peer_self && ! transparent
943 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
944 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
945 }
946
947 /* next-hop-set */
948 if (transparent || reflect
949 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
950 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000951#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000952 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000953 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000954#endif /* HAVE_IPV6 */
955 )))
paul718e3742002-12-13 20:15:29 +0000956 {
957 /* NEXT-HOP Unchanged. */
958 }
959 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
960 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
961#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000962 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000963 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000964#endif /* HAVE_IPV6 */
965 || (peer_sort (peer) == BGP_PEER_EBGP
966 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
967 {
968 /* Set IPv4 nexthop. */
969 if (p->family == AF_INET)
970 {
971 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000972 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
973 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000974 else
975 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
976 }
977#ifdef HAVE_IPV6
978 /* Set IPv6 nexthop. */
979 if (p->family == AF_INET6)
980 {
981 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000982 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +0000983 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000984 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000985 }
986#endif /* HAVE_IPV6 */
987 }
988
989#ifdef HAVE_IPV6
990 if (p->family == AF_INET6)
991 {
paulfee0f4c2004-09-13 05:12:46 +0000992 /* Left nexthop_local unchanged if so configured. */
993 if ( CHECK_FLAG (peer->af_flags[afi][safi],
994 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
995 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000996 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
997 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +0000998 else
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001000 }
1001
1002 /* Default nexthop_local treatment for non-RS-Clients */
1003 else
1004 {
paul718e3742002-12-13 20:15:29 +00001005 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001006 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001007
1008 /* Set link-local address for shared network peer. */
1009 if (peer->shared_network
1010 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1011 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001012 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001013 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001014 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001015 }
1016
1017 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1018 address.*/
1019 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001020 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001021
1022 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1023 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001024 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001025 }
paulfee0f4c2004-09-13 05:12:46 +00001026
1027 }
paul718e3742002-12-13 20:15:29 +00001028#endif /* HAVE_IPV6 */
1029
Paul Jakma41367172007-08-06 15:24:51 +00001030 /* AS-Pathlimit: Check ASN for private/confed */
1031 if (attr->pathlimit.ttl)
1032 {
1033 /* locally originated update */
1034 if (!attr->pathlimit.as)
1035 attr->pathlimit.as = peer->local_as;
1036
1037 /* if the AS_PATHLIMIT attribute is attached to a prefix by a
1038 member of a confederation, then when the prefix is advertised outside
1039 of the confederation boundary, then the AS number of the
1040 confederation member inside of the AS_PATHLIMIT attribute should be
1041 replaced by the confederation's AS number. */
1042 if (peer_sort (from) == BGP_PEER_CONFED
1043 && peer_sort (peer) != BGP_PEER_CONFED)
1044 attr->pathlimit.as = peer->local_as;
1045
1046 /* Private ASN should be updated whenever announcement leaves
1047 * private space. This is deliberately done after simple confed
1048 * based update..
1049 */
1050 if (attr->pathlimit.as >= BGP_PRIVATE_AS_MIN
1051 && attr->pathlimit.as <= BGP_PRIVATE_AS_MAX)
1052 {
1053 if (peer->local_as < BGP_PRIVATE_AS_MIN
1054 || peer->local_as > BGP_PRIVATE_AS_MAX)
1055 attr->pathlimit.as = peer->local_as;
1056 /* Ours is private, try using theirs.. */
1057 else if (peer->as < BGP_PRIVATE_AS_MIN
1058 || peer->local_as > BGP_PRIVATE_AS_MAX)
1059 attr->pathlimit.as = peer->as;
1060 }
1061 }
1062
paul718e3742002-12-13 20:15:29 +00001063 /* If this is EBGP peer and remove-private-AS is set. */
1064 if (peer_sort (peer) == BGP_PEER_EBGP
1065 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1066 && aspath_private_as_check (attr->aspath))
1067 attr->aspath = aspath_empty_get ();
1068
1069 /* Route map & unsuppress-map apply. */
1070 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001071 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001072 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001073 struct bgp_info info;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001074 struct attr dummy_attr = { 0 };
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001075
paul718e3742002-12-13 20:15:29 +00001076 info.peer = peer;
1077 info.attr = attr;
1078
1079 /* The route reflector is not allowed to modify the attributes
1080 of the reflected IBGP routes. */
1081 if (peer_sort (from) == BGP_PEER_IBGP
1082 && peer_sort (peer) == BGP_PEER_IBGP)
1083 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001084 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001085 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001086 }
paulac41b2a2003-08-12 05:32:27 +00001087
1088 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1089
Paul Jakmafb982c22007-05-04 20:15:47 +00001090 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001091 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1092 else
1093 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1094
paulac41b2a2003-08-12 05:32:27 +00001095 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001096
Paul Jakma9eda90c2007-08-30 13:36:17 +00001097 if (dummy_attr.extra)
1098 bgp_attr_extra_free (&dummy_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001099
paul718e3742002-12-13 20:15:29 +00001100 if (ret == RMAP_DENYMATCH)
1101 {
1102 bgp_attr_flush (attr);
1103 return 0;
1104 }
1105 }
1106 return 1;
1107}
1108
paul94f2b392005-06-28 12:44:16 +00001109static int
paulfee0f4c2004-09-13 05:12:46 +00001110bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1111 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001112{
paulfee0f4c2004-09-13 05:12:46 +00001113 int ret;
1114 char buf[SU_ADDRSTRLEN];
1115 struct bgp_filter *filter;
1116 struct bgp_info info;
1117 struct peer *from;
1118 struct bgp *bgp;
1119
1120 from = ri->peer;
1121 filter = &rsclient->filter[afi][safi];
1122 bgp = rsclient->bgp;
1123
Paul Jakma750e8142008-07-22 21:11:48 +00001124 if (DISABLE_BGP_ANNOUNCE)
1125 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001126
1127 /* Do not send back route to sender. */
1128 if (from == rsclient)
1129 return 0;
1130
1131 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001132 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001133 if (! UNSUPPRESS_MAP_NAME (filter))
1134 return 0;
1135
1136 /* Default route check. */
1137 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1138 PEER_STATUS_DEFAULT_ORIGINATE))
1139 {
1140 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1141 return 0;
1142#ifdef HAVE_IPV6
1143 else if (p->family == AF_INET6 && p->prefixlen == 0)
1144 return 0;
1145#endif /* HAVE_IPV6 */
1146 }
1147
1148 /* If the attribute has originator-id and it is same as remote
1149 peer's id. */
1150 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1151 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001152 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1153 &ri->attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001154 {
1155 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001156 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001157 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1158 rsclient->host,
1159 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1160 p->prefixlen);
1161 return 0;
1162 }
1163 }
1164
1165 /* ORF prefix-list filter check */
1166 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1167 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1168 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1169 if (rsclient->orf_plist[afi][safi])
1170 {
1171 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1172 return 0;
1173 }
1174
1175 /* Output filter check. */
1176 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1177 {
1178 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001179 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001180 "%s [Update:SEND] %s/%d is filtered",
1181 rsclient->host,
1182 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1183 p->prefixlen);
1184 return 0;
1185 }
1186
1187#ifdef BGP_SEND_ASPATH_CHECK
1188 /* AS path loop check. */
1189 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1190 {
1191 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001192 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001193 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001194 rsclient->host, rsclient->as);
1195 return 0;
1196 }
1197#endif /* BGP_SEND_ASPATH_CHECK */
1198
1199 /* For modify attribute, copy it to temporary structure. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001200 bgp_attr_dup (attr, ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001201
1202 /* next-hop-set */
1203 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1204#ifdef HAVE_IPV6
1205 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001206 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001207#endif /* HAVE_IPV6 */
1208 )
1209 {
1210 /* Set IPv4 nexthop. */
1211 if (p->family == AF_INET)
1212 {
1213 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001214 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001215 IPV4_MAX_BYTELEN);
1216 else
1217 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1218 }
1219#ifdef HAVE_IPV6
1220 /* Set IPv6 nexthop. */
1221 if (p->family == AF_INET6)
1222 {
1223 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001224 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001225 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001226 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001227 }
1228#endif /* HAVE_IPV6 */
1229 }
1230
1231#ifdef HAVE_IPV6
1232 if (p->family == AF_INET6)
1233 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 struct attr_extra *attre = attr->extra;
1235
1236 assert (attr->extra);
1237
paulfee0f4c2004-09-13 05:12:46 +00001238 /* Left nexthop_local unchanged if so configured. */
1239 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1240 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1241 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001242 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1243 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001244 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001245 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001246 }
1247
1248 /* Default nexthop_local treatment for RS-Clients */
1249 else
1250 {
1251 /* Announcer and RS-Client are both in the same network */
1252 if (rsclient->shared_network && from->shared_network &&
1253 (rsclient->ifindex == from->ifindex))
1254 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001255 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1256 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001257 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001258 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001259 }
1260
1261 /* Set link-local address for shared network peer. */
1262 else if (rsclient->shared_network
1263 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1264 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001265 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001266 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001267 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001268 }
1269
1270 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001271 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001272 }
1273
1274 }
1275#endif /* HAVE_IPV6 */
1276
1277
1278 /* If this is EBGP peer and remove-private-AS is set. */
1279 if (peer_sort (rsclient) == BGP_PEER_EBGP
1280 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1281 && aspath_private_as_check (attr->aspath))
1282 attr->aspath = aspath_empty_get ();
1283
1284 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001285 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001286 {
1287 info.peer = rsclient;
1288 info.attr = attr;
1289
1290 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1291
Paul Jakmafb982c22007-05-04 20:15:47 +00001292 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001293 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1294 else
1295 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1296
1297 rsclient->rmap_type = 0;
1298
1299 if (ret == RMAP_DENYMATCH)
1300 {
1301 bgp_attr_flush (attr);
1302 return 0;
1303 }
1304 }
1305
1306 return 1;
1307}
1308
1309struct bgp_info_pair
1310{
1311 struct bgp_info *old;
1312 struct bgp_info *new;
1313};
1314
paul94f2b392005-06-28 12:44:16 +00001315static void
paulfee0f4c2004-09-13 05:12:46 +00001316bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1317{
paul718e3742002-12-13 20:15:29 +00001318 struct bgp_info *new_select;
1319 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001320 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001321 struct bgp_info *ri1;
1322 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001323 struct bgp_info *nextri = NULL;
1324
paul718e3742002-12-13 20:15:29 +00001325 /* bgp deterministic-med */
1326 new_select = NULL;
1327 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1328 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1329 {
1330 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1331 continue;
1332 if (BGP_INFO_HOLDDOWN (ri1))
1333 continue;
1334
1335 new_select = ri1;
1336 if (ri1->next)
1337 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1338 {
1339 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1340 continue;
1341 if (BGP_INFO_HOLDDOWN (ri2))
1342 continue;
1343
1344 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1345 || aspath_cmp_left_confed (ri1->attr->aspath,
1346 ri2->attr->aspath))
1347 {
1348 if (bgp_info_cmp (bgp, ri2, new_select))
1349 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001350 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001351 new_select = ri2;
1352 }
1353
Paul Jakma1a392d42006-09-07 00:24:49 +00001354 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001355 }
1356 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1358 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001359 }
1360
1361 /* Check old selected route and new selected route. */
1362 old_select = NULL;
1363 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001364 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001365 {
1366 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1367 old_select = ri;
1368
1369 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001370 {
1371 /* reap REMOVED routes, if needs be
1372 * selected route must stay for a while longer though
1373 */
1374 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1375 && (ri != old_select))
1376 bgp_info_reap (rn, ri);
1377
1378 continue;
1379 }
paul718e3742002-12-13 20:15:29 +00001380
1381 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1382 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1383 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001384 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001385 continue;
1386 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001387 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1388 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001389
1390 if (bgp_info_cmp (bgp, ri, new_select))
1391 new_select = ri;
1392 }
paulb40d9392005-08-22 22:34:41 +00001393
paulfee0f4c2004-09-13 05:12:46 +00001394 result->old = old_select;
1395 result->new = new_select;
1396
1397 return;
1398}
1399
paul94f2b392005-06-28 12:44:16 +00001400static int
paulfee0f4c2004-09-13 05:12:46 +00001401bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001402 struct bgp_node *rn, afi_t afi, safi_t safi)
1403{
paulfee0f4c2004-09-13 05:12:46 +00001404 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001405 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001406
1407 p = &rn->p;
1408
Paul Jakma9eda90c2007-08-30 13:36:17 +00001409 /* Announce route to Established peer. */
1410 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001411 return 0;
1412
Paul Jakma9eda90c2007-08-30 13:36:17 +00001413 /* Address family configuration check. */
1414 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001415 return 0;
1416
Paul Jakma9eda90c2007-08-30 13:36:17 +00001417 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001418 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1419 PEER_STATUS_ORF_WAIT_REFRESH))
1420 return 0;
1421
1422 switch (rn->table->type)
1423 {
1424 case BGP_TABLE_MAIN:
1425 /* Announcement to peer->conf. If the route is filtered,
1426 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001427 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1428 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001429 else
1430 bgp_adj_out_unset (rn, peer, p, afi, safi);
1431 break;
1432 case BGP_TABLE_RSCLIENT:
1433 /* Announcement to peer->conf. If the route is filtered,
1434 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001435 if (selected &&
1436 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1437 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1438 else
1439 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001440 break;
1441 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001442
1443 bgp_attr_extra_free (&attr);
1444
paulfee0f4c2004-09-13 05:12:46 +00001445 return 0;
paul200df112005-06-01 11:17:05 +00001446}
paulfee0f4c2004-09-13 05:12:46 +00001447
paul200df112005-06-01 11:17:05 +00001448struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001449{
paul200df112005-06-01 11:17:05 +00001450 struct bgp *bgp;
1451 struct bgp_node *rn;
1452 afi_t afi;
1453 safi_t safi;
1454};
1455
1456static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001457bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001458{
paul0fb58d52005-11-14 14:31:49 +00001459 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001460 struct bgp *bgp = pq->bgp;
1461 struct bgp_node *rn = pq->rn;
1462 afi_t afi = pq->afi;
1463 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001464 struct bgp_info *new_select;
1465 struct bgp_info *old_select;
1466 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001467 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001468 struct peer *rsclient = rn->table->owner;
1469
paulfee0f4c2004-09-13 05:12:46 +00001470 /* Best path selection. */
1471 bgp_best_selection (bgp, rn, &old_and_new);
1472 new_select = old_and_new.new;
1473 old_select = old_and_new.old;
1474
paul200df112005-06-01 11:17:05 +00001475 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1476 {
Chris Caputo228da422009-07-18 05:44:03 +00001477 if (rsclient->group)
1478 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1479 {
1480 /* Nothing to do. */
1481 if (old_select && old_select == new_select)
1482 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1483 continue;
paulfee0f4c2004-09-13 05:12:46 +00001484
Chris Caputo228da422009-07-18 05:44:03 +00001485 if (old_select)
1486 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1487 if (new_select)
1488 {
1489 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1490 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1491 }
paulfee0f4c2004-09-13 05:12:46 +00001492
Chris Caputo228da422009-07-18 05:44:03 +00001493 bgp_process_announce_selected (rsclient, new_select, rn,
1494 afi, safi);
1495 }
paul200df112005-06-01 11:17:05 +00001496 }
1497 else
1498 {
hassob7395792005-08-26 12:58:38 +00001499 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001500 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001501 if (new_select)
1502 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001503 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1504 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001505 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001506 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001507 }
paulfee0f4c2004-09-13 05:12:46 +00001508
paulb40d9392005-08-22 22:34:41 +00001509 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1510 bgp_info_reap (rn, old_select);
1511
paul200df112005-06-01 11:17:05 +00001512 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1513 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001514}
1515
paul200df112005-06-01 11:17:05 +00001516static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001517bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001518{
paul0fb58d52005-11-14 14:31:49 +00001519 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001520 struct bgp *bgp = pq->bgp;
1521 struct bgp_node *rn = pq->rn;
1522 afi_t afi = pq->afi;
1523 safi_t safi = pq->safi;
1524 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001525 struct bgp_info *new_select;
1526 struct bgp_info *old_select;
1527 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001528 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001529 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001530
paulfee0f4c2004-09-13 05:12:46 +00001531 /* Best path selection. */
1532 bgp_best_selection (bgp, rn, &old_and_new);
1533 old_select = old_and_new.old;
1534 new_select = old_and_new.new;
1535
1536 /* Nothing to do. */
1537 if (old_select && old_select == new_select)
1538 {
1539 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001540 {
1541 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1542 bgp_zebra_announce (p, old_select, bgp);
1543
1544 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1545 return WQ_SUCCESS;
1546 }
paulfee0f4c2004-09-13 05:12:46 +00001547 }
paul718e3742002-12-13 20:15:29 +00001548
hasso338b3422005-02-23 14:27:24 +00001549 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001550 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001551 if (new_select)
1552 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001553 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1554 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001555 }
1556
1557
paul718e3742002-12-13 20:15:29 +00001558 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001559 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001560 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001561 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001562 }
1563
1564 /* FIB update. */
1565 if (safi == SAFI_UNICAST && ! bgp->name &&
1566 ! bgp_option_check (BGP_OPT_NO_FIB))
1567 {
1568 if (new_select
1569 && new_select->type == ZEBRA_ROUTE_BGP
1570 && new_select->sub_type == BGP_ROUTE_NORMAL)
1571 bgp_zebra_announce (p, new_select, bgp);
1572 else
1573 {
1574 /* Withdraw the route from the kernel. */
1575 if (old_select
1576 && old_select->type == ZEBRA_ROUTE_BGP
1577 && old_select->sub_type == BGP_ROUTE_NORMAL)
1578 bgp_zebra_withdraw (p, old_select);
1579 }
1580 }
paulb40d9392005-08-22 22:34:41 +00001581
1582 /* Reap old select bgp_info, it it has been removed */
1583 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1584 bgp_info_reap (rn, old_select);
1585
paul200df112005-06-01 11:17:05 +00001586 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1587 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001588}
1589
paul200df112005-06-01 11:17:05 +00001590static void
paul0fb58d52005-11-14 14:31:49 +00001591bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001592{
paul0fb58d52005-11-14 14:31:49 +00001593 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001594 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001595
Chris Caputo228da422009-07-18 05:44:03 +00001596 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001597 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001598 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001599 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1600}
1601
1602static void
1603bgp_process_queue_init (void)
1604{
1605 bm->process_main_queue
1606 = work_queue_new (bm->master, "process_main_queue");
1607 bm->process_rsclient_queue
1608 = work_queue_new (bm->master, "process_rsclient_queue");
1609
1610 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1611 {
1612 zlog_err ("%s: Failed to allocate work queue", __func__);
1613 exit (1);
1614 }
1615
1616 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1617 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1618 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1619 bm->process_rsclient_queue->spec.del_item_data
1620 = bm->process_main_queue->spec.del_item_data;
1621 bm->process_main_queue->spec.max_retries
1622 = bm->process_main_queue->spec.max_retries = 0;
1623 bm->process_rsclient_queue->spec.hold
Paul Jakma09dd5612006-09-14 03:38:16 +00001624 = bm->process_main_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001625}
1626
1627void
paulfee0f4c2004-09-13 05:12:46 +00001628bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1629{
paul200df112005-06-01 11:17:05 +00001630 struct bgp_process_queue *pqnode;
1631
1632 /* already scheduled for processing? */
1633 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1634 return;
1635
1636 if ( (bm->process_main_queue == NULL) ||
1637 (bm->process_rsclient_queue == NULL) )
1638 bgp_process_queue_init ();
1639
1640 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1641 sizeof (struct bgp_process_queue));
1642 if (!pqnode)
1643 return;
Chris Caputo228da422009-07-18 05:44:03 +00001644
1645 /* all unlocked in bgp_processq_del */
1646 bgp_table_lock (rn->table);
1647 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001648 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001649 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001650 pqnode->afi = afi;
1651 pqnode->safi = safi;
1652
paulfee0f4c2004-09-13 05:12:46 +00001653 switch (rn->table->type)
1654 {
paul200df112005-06-01 11:17:05 +00001655 case BGP_TABLE_MAIN:
1656 work_queue_add (bm->process_main_queue, pqnode);
1657 break;
1658 case BGP_TABLE_RSCLIENT:
1659 work_queue_add (bm->process_rsclient_queue, pqnode);
1660 break;
paulfee0f4c2004-09-13 05:12:46 +00001661 }
paul200df112005-06-01 11:17:05 +00001662
1663 return;
paulfee0f4c2004-09-13 05:12:46 +00001664}
hasso0a486e52005-02-01 20:57:17 +00001665
paul94f2b392005-06-28 12:44:16 +00001666static int
hasso0a486e52005-02-01 20:57:17 +00001667bgp_maximum_prefix_restart_timer (struct thread *thread)
1668{
1669 struct peer *peer;
1670
1671 peer = THREAD_ARG (thread);
1672 peer->t_pmax_restart = NULL;
1673
1674 if (BGP_DEBUG (events, EVENTS))
1675 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1676 peer->host);
1677
1678 peer_clear (peer);
1679
1680 return 0;
1681}
1682
paulfee0f4c2004-09-13 05:12:46 +00001683int
paul5228ad22004-06-04 17:58:18 +00001684bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1685 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001686{
hassoe0701b72004-05-20 09:19:34 +00001687 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1688 return 0;
1689
1690 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001691 {
hassoe0701b72004-05-20 09:19:34 +00001692 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1693 && ! always)
1694 return 0;
paul718e3742002-12-13 20:15:29 +00001695
hassoe0701b72004-05-20 09:19:34 +00001696 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001697 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1698 "limit %ld", afi_safi_print (afi, safi), peer->host,
1699 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001700 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001701
hassoe0701b72004-05-20 09:19:34 +00001702 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1703 return 0;
paul718e3742002-12-13 20:15:29 +00001704
hassoe0701b72004-05-20 09:19:34 +00001705 {
paul5228ad22004-06-04 17:58:18 +00001706 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001707
1708 if (safi == SAFI_MPLS_VPN)
1709 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001710
1711 ndata[0] = (afi >> 8);
1712 ndata[1] = afi;
1713 ndata[2] = safi;
1714 ndata[3] = (peer->pmax[afi][safi] >> 24);
1715 ndata[4] = (peer->pmax[afi][safi] >> 16);
1716 ndata[5] = (peer->pmax[afi][safi] >> 8);
1717 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001718
1719 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1720 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1721 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1722 }
hasso0a486e52005-02-01 20:57:17 +00001723
1724 /* restart timer start */
1725 if (peer->pmax_restart[afi][safi])
1726 {
1727 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1728
1729 if (BGP_DEBUG (events, EVENTS))
1730 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1731 peer->host, peer->v_pmax_restart);
1732
1733 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1734 peer->v_pmax_restart);
1735 }
1736
hassoe0701b72004-05-20 09:19:34 +00001737 return 1;
paul718e3742002-12-13 20:15:29 +00001738 }
hassoe0701b72004-05-20 09:19:34 +00001739 else
1740 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1741
1742 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1743 {
1744 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1745 && ! always)
1746 return 0;
1747
1748 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001749 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1750 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1751 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001752 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1753 }
1754 else
1755 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001756 return 0;
1757}
1758
paulb40d9392005-08-22 22:34:41 +00001759/* Unconditionally remove the route from the RIB, without taking
1760 * damping into consideration (eg, because the session went down)
1761 */
paul94f2b392005-06-28 12:44:16 +00001762static void
paul718e3742002-12-13 20:15:29 +00001763bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1764 afi_t afi, safi_t safi)
1765{
paul902212c2006-02-05 17:51:19 +00001766 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1767
1768 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1769 bgp_info_delete (rn, ri); /* keep historical info */
1770
paulb40d9392005-08-22 22:34:41 +00001771 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001772}
1773
paul94f2b392005-06-28 12:44:16 +00001774static void
paul718e3742002-12-13 20:15:29 +00001775bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001776 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001777{
paul718e3742002-12-13 20:15:29 +00001778 int status = BGP_DAMP_NONE;
1779
paulb40d9392005-08-22 22:34:41 +00001780 /* apply dampening, if result is suppressed, we'll be retaining
1781 * the bgp_info in the RIB for historical reference.
1782 */
1783 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1784 && peer_sort (peer) == BGP_PEER_EBGP)
1785 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1786 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001787 {
paul902212c2006-02-05 17:51:19 +00001788 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1789 return;
1790 }
1791
1792 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001793}
1794
paul94f2b392005-06-28 12:44:16 +00001795static void
paulfee0f4c2004-09-13 05:12:46 +00001796bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1797 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1798 int sub_type, struct prefix_rd *prd, u_char *tag)
1799{
1800 struct bgp_node *rn;
1801 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001802 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001803 struct attr *attr_new;
1804 struct attr *attr_new2;
1805 struct bgp_info *ri;
1806 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001807 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001808 char buf[SU_ADDRSTRLEN];
1809
1810 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1811 if (peer == rsclient)
1812 return;
1813
1814 bgp = peer->bgp;
1815 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1816
1817 /* Check previously received route. */
1818 for (ri = rn->info; ri; ri = ri->next)
1819 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1820 break;
1821
1822 /* AS path loop check. */
1823 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1824 {
1825 reason = "as-path contains our own AS;";
1826 goto filtered;
1827 }
1828
1829 /* Route reflector originator ID check. */
1830 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001831 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001832 {
1833 reason = "originator is us;";
1834 goto filtered;
1835 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001836
1837 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001838
1839 /* Apply export policy. */
1840 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1841 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1842 {
1843 reason = "export-policy;";
1844 goto filtered;
1845 }
1846
1847 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001848
paulfee0f4c2004-09-13 05:12:46 +00001849 /* Apply import policy. */
1850 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1851 {
1852 bgp_attr_unintern (attr_new2);
1853
1854 reason = "import-policy;";
1855 goto filtered;
1856 }
1857
1858 attr_new = bgp_attr_intern (&new_attr);
1859 bgp_attr_unintern (attr_new2);
1860
1861 /* IPv4 unicast next hop check. */
1862 if (afi == AFI_IP && safi == SAFI_UNICAST)
1863 {
1864 /* Next hop must not be 0.0.0.0 nor Class E address. */
1865 if (new_attr.nexthop.s_addr == 0
1866 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1867 {
1868 bgp_attr_unintern (attr_new);
1869
1870 reason = "martian next-hop;";
1871 goto filtered;
1872 }
1873 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001874
1875 /* new_attr isn't passed to any functions after here */
1876 bgp_attr_extra_free (&new_attr);
1877
paulfee0f4c2004-09-13 05:12:46 +00001878 /* If the update is implicit withdraw. */
1879 if (ri)
1880 {
1881 ri->uptime = time (NULL);
1882
1883 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001884 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1885 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001886 {
1887
Paul Jakma1a392d42006-09-07 00:24:49 +00001888 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001889
1890 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001891 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001892 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1893 peer->host,
1894 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1895 p->prefixlen, rsclient->host);
1896
Chris Caputo228da422009-07-18 05:44:03 +00001897 bgp_unlock_node (rn);
1898 bgp_attr_unintern (attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001899
Chris Caputo228da422009-07-18 05:44:03 +00001900 return;
paulfee0f4c2004-09-13 05:12:46 +00001901 }
1902
Paul Jakma16d2e242007-04-10 19:32:10 +00001903 /* Withdraw/Announce before we fully processed the withdraw */
1904 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1905 bgp_info_restore (rn, ri);
1906
paulfee0f4c2004-09-13 05:12:46 +00001907 /* Received Logging. */
1908 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001909 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001910 peer->host,
1911 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1912 p->prefixlen, rsclient->host);
1913
1914 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001915 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001916
1917 /* Update to new attribute. */
1918 bgp_attr_unintern (ri->attr);
1919 ri->attr = attr_new;
1920
1921 /* Update MPLS tag. */
1922 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001923 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001924
Paul Jakma1a392d42006-09-07 00:24:49 +00001925 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001926
1927 /* Process change. */
1928 bgp_process (bgp, rn, afi, safi);
1929 bgp_unlock_node (rn);
1930
1931 return;
1932 }
1933
1934 /* Received Logging. */
1935 if (BGP_DEBUG (update, UPDATE_IN))
1936 {
ajsd2c1f162004-12-08 21:10:20 +00001937 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001938 peer->host,
1939 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1940 p->prefixlen, rsclient->host);
1941 }
1942
1943 /* Make new BGP info. */
1944 new = bgp_info_new ();
1945 new->type = type;
1946 new->sub_type = sub_type;
1947 new->peer = peer;
1948 new->attr = attr_new;
1949 new->uptime = time (NULL);
1950
1951 /* Update MPLS tag. */
1952 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001953 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001954
Paul Jakma1a392d42006-09-07 00:24:49 +00001955 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001956
1957 /* Register new BGP information. */
1958 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001959
1960 /* route_node_get lock */
1961 bgp_unlock_node (rn);
1962
paulfee0f4c2004-09-13 05:12:46 +00001963 /* Process change. */
1964 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001965
1966 bgp_attr_extra_free (&new_attr);
1967
paulfee0f4c2004-09-13 05:12:46 +00001968 return;
1969
1970 filtered:
1971
1972 /* This BGP update is filtered. Log the reason then update BGP entry. */
1973 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001974 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001975 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1976 peer->host,
1977 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1978 p->prefixlen, rsclient->host, reason);
1979
1980 if (ri)
paulb40d9392005-08-22 22:34:41 +00001981 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001982
1983 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001984
1985 if (new_attr.extra)
1986 bgp_attr_extra_free (&new_attr);
1987
paulfee0f4c2004-09-13 05:12:46 +00001988 return;
1989}
1990
paul94f2b392005-06-28 12:44:16 +00001991static void
paulfee0f4c2004-09-13 05:12:46 +00001992bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1993 struct peer *peer, struct prefix *p, int type, int sub_type,
1994 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00001995{
paulfee0f4c2004-09-13 05:12:46 +00001996 struct bgp_node *rn;
1997 struct bgp_info *ri;
1998 char buf[SU_ADDRSTRLEN];
1999
2000 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002001 return;
paulfee0f4c2004-09-13 05:12:46 +00002002
2003 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2004
2005 /* Lookup withdrawn route. */
2006 for (ri = rn->info; ri; ri = ri->next)
2007 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2008 break;
2009
2010 /* Withdraw specified route from routing table. */
2011 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002012 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002013 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002014 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002015 "%s Can't find the route %s/%d", peer->host,
2016 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2017 p->prefixlen);
2018
2019 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002020 bgp_unlock_node (rn);
2021}
paulfee0f4c2004-09-13 05:12:46 +00002022
paul94f2b392005-06-28 12:44:16 +00002023static int
paulfee0f4c2004-09-13 05:12:46 +00002024bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002025 afi_t afi, safi_t safi, int type, int sub_type,
2026 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2027{
2028 int ret;
2029 int aspath_loop_count = 0;
2030 struct bgp_node *rn;
2031 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002032 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002033 struct attr *attr_new;
2034 struct bgp_info *ri;
2035 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002036 const char *reason;
paul718e3742002-12-13 20:15:29 +00002037 char buf[SU_ADDRSTRLEN];
2038
2039 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002040 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002041
paul718e3742002-12-13 20:15:29 +00002042 /* When peer's soft reconfiguration enabled. Record input packet in
2043 Adj-RIBs-In. */
2044 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2045 && peer != bgp->peer_self && ! soft_reconfig)
2046 bgp_adj_in_set (rn, peer, attr);
2047
2048 /* Check previously received route. */
2049 for (ri = rn->info; ri; ri = ri->next)
2050 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2051 break;
2052
2053 /* AS path local-as loop check. */
2054 if (peer->change_local_as)
2055 {
2056 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2057 aspath_loop_count = 1;
2058
2059 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2060 {
2061 reason = "as-path contains our own AS;";
2062 goto filtered;
2063 }
2064 }
2065
2066 /* AS path loop check. */
2067 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2068 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2069 && aspath_loop_check(attr->aspath, bgp->confed_id)
2070 > peer->allowas_in[afi][safi]))
2071 {
2072 reason = "as-path contains our own AS;";
2073 goto filtered;
2074 }
2075
2076 /* Route reflector originator ID check. */
2077 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002078 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002079 {
2080 reason = "originator is us;";
2081 goto filtered;
2082 }
2083
2084 /* Route reflector cluster ID check. */
2085 if (bgp_cluster_filter (peer, attr))
2086 {
2087 reason = "reflected from the same cluster;";
2088 goto filtered;
2089 }
2090
2091 /* Apply incoming filter. */
2092 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2093 {
2094 reason = "filter;";
2095 goto filtered;
2096 }
2097
2098 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002099 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002100
2101 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2102 {
2103 reason = "route-map;";
2104 goto filtered;
2105 }
2106
2107 /* IPv4 unicast next hop check. */
2108 if (afi == AFI_IP && safi == SAFI_UNICAST)
2109 {
2110 /* If the peer is EBGP and nexthop is not on connected route,
2111 discard it. */
2112 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2113 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002114 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002115 {
2116 reason = "non-connected next-hop;";
2117 goto filtered;
2118 }
2119
2120 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2121 must not be my own address. */
2122 if (bgp_nexthop_self (afi, &new_attr)
2123 || new_attr.nexthop.s_addr == 0
2124 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2125 {
2126 reason = "martian next-hop;";
2127 goto filtered;
2128 }
2129 }
2130
2131 attr_new = bgp_attr_intern (&new_attr);
2132
2133 /* If the update is implicit withdraw. */
2134 if (ri)
2135 {
2136 ri->uptime = time (NULL);
2137
2138 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002139 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2140 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002141 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002142 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002143
2144 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2145 && peer_sort (peer) == BGP_PEER_EBGP
2146 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2147 {
2148 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002149 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002150 peer->host,
2151 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2152 p->prefixlen);
2153
paul902212c2006-02-05 17:51:19 +00002154 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2155 {
2156 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2157 bgp_process (bgp, rn, afi, safi);
2158 }
paul718e3742002-12-13 20:15:29 +00002159 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002160 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002161 {
2162 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002163 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002164 "%s rcvd %s/%d...duplicate ignored",
2165 peer->host,
2166 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2167 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002168
2169 /* graceful restart STALE flag unset. */
2170 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2171 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002172 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002173 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002174 }
paul718e3742002-12-13 20:15:29 +00002175 }
2176
2177 bgp_unlock_node (rn);
2178 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002179 bgp_attr_extra_free (&new_attr);
2180
paul718e3742002-12-13 20:15:29 +00002181 return 0;
2182 }
2183
Paul Jakma16d2e242007-04-10 19:32:10 +00002184 /* Withdraw/Announce before we fully processed the withdraw */
2185 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2186 {
2187 if (BGP_DEBUG (update, UPDATE_IN))
2188 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2189 peer->host,
2190 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2191 p->prefixlen);
2192 bgp_info_restore (rn, ri);
2193 }
2194
paul718e3742002-12-13 20:15:29 +00002195 /* Received Logging. */
2196 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002197 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002198 peer->host,
2199 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2200 p->prefixlen);
2201
hasso93406d82005-02-02 14:40:33 +00002202 /* graceful restart STALE flag unset. */
2203 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002204 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002205
paul718e3742002-12-13 20:15:29 +00002206 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002207 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002208
2209 /* implicit withdraw, decrement aggregate and pcount here.
2210 * only if update is accepted, they'll increment below.
2211 */
paul902212c2006-02-05 17:51:19 +00002212 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2213
paul718e3742002-12-13 20:15:29 +00002214 /* Update bgp route dampening information. */
2215 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2216 && peer_sort (peer) == BGP_PEER_EBGP)
2217 {
2218 /* This is implicit withdraw so we should update dampening
2219 information. */
2220 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2221 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002222 }
2223
paul718e3742002-12-13 20:15:29 +00002224 /* Update to new attribute. */
2225 bgp_attr_unintern (ri->attr);
2226 ri->attr = attr_new;
2227
2228 /* Update MPLS tag. */
2229 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002230 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002231
2232 /* Update bgp route dampening information. */
2233 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2234 && peer_sort (peer) == BGP_PEER_EBGP)
2235 {
2236 /* Now we do normal update dampening. */
2237 ret = bgp_damp_update (ri, rn, afi, safi);
2238 if (ret == BGP_DAMP_SUPPRESSED)
2239 {
2240 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002241 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002242 return 0;
2243 }
2244 }
2245
2246 /* Nexthop reachability check. */
2247 if ((afi == AFI_IP || afi == AFI_IP6)
2248 && safi == SAFI_UNICAST
2249 && (peer_sort (peer) == BGP_PEER_IBGP
2250 || (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;
2286 new->uptime = time (NULL);
2287
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
2296 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002297 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002298 {
2299 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002300 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002301 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002302 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002303 }
2304 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002305 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002306
paul902212c2006-02-05 17:51:19 +00002307 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002308 bgp_aggregate_increment (bgp, p, new, afi, safi);
2309
2310 /* Register new BGP information. */
2311 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002312
2313 /* route_node_get lock */
2314 bgp_unlock_node (rn);
2315
Paul Jakmafb982c22007-05-04 20:15:47 +00002316 bgp_attr_extra_free (&new_attr);
2317
paul718e3742002-12-13 20:15:29 +00002318 /* If maximum prefix count is configured and current prefix
2319 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002320 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2321 return -1;
paul718e3742002-12-13 20:15:29 +00002322
2323 /* Process change. */
2324 bgp_process (bgp, rn, afi, safi);
2325
2326 return 0;
2327
2328 /* This BGP update is filtered. Log the reason then update BGP
2329 entry. */
2330 filtered:
2331 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002332 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002333 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2334 peer->host,
2335 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2336 p->prefixlen, reason);
2337
2338 if (ri)
paulb40d9392005-08-22 22:34:41 +00002339 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002340
2341 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002342
2343 bgp_attr_extra_free (&new_attr);
2344
paul718e3742002-12-13 20:15:29 +00002345 return 0;
2346}
2347
2348int
paulfee0f4c2004-09-13 05:12:46 +00002349bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2350 afi_t afi, safi_t safi, int type, int sub_type,
2351 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2352{
2353 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002354 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002355 struct bgp *bgp;
2356 int ret;
2357
2358 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2359 soft_reconfig);
2360
2361 bgp = peer->bgp;
2362
2363 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002364 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002365 {
2366 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2367 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2368 sub_type, prd, tag);
2369 }
2370
2371 return ret;
2372}
2373
2374int
paul718e3742002-12-13 20:15:29 +00002375bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002376 afi_t afi, safi_t safi, int type, int sub_type,
2377 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002378{
2379 struct bgp *bgp;
2380 char buf[SU_ADDRSTRLEN];
2381 struct bgp_node *rn;
2382 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002383 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002384 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002385
2386 bgp = peer->bgp;
2387
paulfee0f4c2004-09-13 05:12:46 +00002388 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002389 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002390 {
2391 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2392 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2393 }
2394
paul718e3742002-12-13 20:15:29 +00002395 /* Logging. */
2396 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002397 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002398 peer->host,
2399 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2400 p->prefixlen);
2401
2402 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002403 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002404
2405 /* If peer is soft reconfiguration enabled. Record input packet for
2406 further calculation. */
2407 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2408 && peer != bgp->peer_self)
2409 bgp_adj_in_unset (rn, peer);
2410
2411 /* Lookup withdrawn route. */
2412 for (ri = rn->info; ri; ri = ri->next)
2413 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2414 break;
2415
2416 /* Withdraw specified route from routing table. */
2417 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002418 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002419 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002420 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002421 "%s Can't find the route %s/%d", peer->host,
2422 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2423 p->prefixlen);
2424
2425 /* Unlock bgp_node_get() lock. */
2426 bgp_unlock_node (rn);
2427
2428 return 0;
2429}
2430
2431void
2432bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2433{
2434 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002435 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002436 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002437 struct prefix p;
2438 struct bgp_info binfo;
2439 struct peer *from;
2440 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002441
Paul Jakmab2497022007-06-14 11:17:58 +00002442 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002443 return;
2444
paul718e3742002-12-13 20:15:29 +00002445 bgp = peer->bgp;
2446 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002447
paul718e3742002-12-13 20:15:29 +00002448 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2449 aspath = attr.aspath;
2450 attr.local_pref = bgp->default_local_pref;
2451 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2452
2453 if (afi == AFI_IP)
2454 str2prefix ("0.0.0.0/0", &p);
2455#ifdef HAVE_IPV6
2456 else if (afi == AFI_IP6)
2457 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002458 struct attr_extra *ae;
2459 attr.extra = NULL;
2460
2461 ae = bgp_attr_extra_get (&attr);
2462 attr.extra = ae;
2463
paul718e3742002-12-13 20:15:29 +00002464 str2prefix ("::/0", &p);
2465
2466 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002467 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002468 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002469 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002470
2471 /* If the peer is on shared nextwork and we have link-local
2472 nexthop set it. */
2473 if (peer->shared_network
2474 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2475 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002476 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002477 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002478 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002479 }
2480 }
2481#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002482
2483 if (peer->default_rmap[afi][safi].name)
2484 {
2485 binfo.peer = bgp->peer_self;
2486 binfo.attr = &attr;
2487
paulfee0f4c2004-09-13 05:12:46 +00002488 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2489
paul718e3742002-12-13 20:15:29 +00002490 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2491 RMAP_BGP, &binfo);
2492
paulfee0f4c2004-09-13 05:12:46 +00002493 bgp->peer_self->rmap_type = 0;
2494
paul718e3742002-12-13 20:15:29 +00002495 if (ret == RMAP_DENYMATCH)
2496 {
2497 bgp_attr_flush (&attr);
2498 withdraw = 1;
2499 }
2500 }
2501
2502 if (withdraw)
2503 {
2504 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2505 bgp_default_withdraw_send (peer, afi, safi);
2506 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2507 }
2508 else
2509 {
2510 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2511 bgp_default_update_send (peer, &attr, afi, safi, from);
2512 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002513
2514 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002515 aspath_unintern (aspath);
2516}
2517
2518static void
2519bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002520 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002521{
2522 struct bgp_node *rn;
2523 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002524 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002525
paul718e3742002-12-13 20:15:29 +00002526 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002527 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002528
2529 if (safi != SAFI_MPLS_VPN
2530 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2531 bgp_default_originate (peer, afi, safi, 0);
2532
2533 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2534 for (ri = rn->info; ri; ri = ri->next)
2535 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2536 {
paulfee0f4c2004-09-13 05:12:46 +00002537 if ( (rsclient) ?
2538 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2539 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002540 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2541 else
2542 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002543
2544 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002545 }
2546}
2547
2548void
2549bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2550{
2551 struct bgp_node *rn;
2552 struct bgp_table *table;
2553
2554 if (peer->status != Established)
2555 return;
2556
2557 if (! peer->afc_nego[afi][safi])
2558 return;
2559
2560 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2561 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2562 return;
2563
2564 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002565 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002566 else
2567 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2568 rn = bgp_route_next(rn))
2569 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002570 bgp_announce_table (peer, afi, safi, table, 0);
2571
2572 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2573 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002574}
2575
2576void
2577bgp_announce_route_all (struct peer *peer)
2578{
2579 afi_t afi;
2580 safi_t safi;
2581
2582 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2583 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2584 bgp_announce_route (peer, afi, safi);
2585}
2586
2587static void
paulfee0f4c2004-09-13 05:12:46 +00002588bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2589 safi_t safi, struct bgp_table *table)
2590{
2591 struct bgp_node *rn;
2592 struct bgp_adj_in *ain;
2593
2594 if (! table)
2595 table = rsclient->bgp->rib[afi][safi];
2596
2597 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2598 for (ain = rn->adj_in; ain; ain = ain->next)
2599 {
2600 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2601 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2602 }
2603}
2604
2605void
2606bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2607{
2608 struct bgp_table *table;
2609 struct bgp_node *rn;
2610
2611 if (safi != SAFI_MPLS_VPN)
2612 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2613
2614 else
2615 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2616 rn = bgp_route_next (rn))
2617 if ((table = rn->info) != NULL)
2618 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2619}
2620
2621static void
paul718e3742002-12-13 20:15:29 +00002622bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2623 struct bgp_table *table)
2624{
2625 int ret;
2626 struct bgp_node *rn;
2627 struct bgp_adj_in *ain;
2628
2629 if (! table)
2630 table = peer->bgp->rib[afi][safi];
2631
2632 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2633 for (ain = rn->adj_in; ain; ain = ain->next)
2634 {
2635 if (ain->peer == peer)
2636 {
2637 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2638 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2639 NULL, NULL, 1);
2640 if (ret < 0)
2641 {
2642 bgp_unlock_node (rn);
2643 return;
2644 }
2645 continue;
2646 }
2647 }
2648}
2649
2650void
2651bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2652{
2653 struct bgp_node *rn;
2654 struct bgp_table *table;
2655
2656 if (peer->status != Established)
2657 return;
2658
2659 if (safi != SAFI_MPLS_VPN)
2660 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2661 else
2662 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2663 rn = bgp_route_next (rn))
2664 if ((table = rn->info) != NULL)
2665 bgp_soft_reconfig_table (peer, afi, safi, table);
2666}
2667
Chris Caputo228da422009-07-18 05:44:03 +00002668
2669struct bgp_clear_node_queue
2670{
2671 struct bgp_node *rn;
2672 enum bgp_clear_route_type purpose;
2673};
2674
paul200df112005-06-01 11:17:05 +00002675static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002676bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002677{
Chris Caputo228da422009-07-18 05:44:03 +00002678 struct bgp_clear_node_queue *cnq = data;
2679 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002680 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002681 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002682 afi_t afi = rn->table->afi;
2683 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002684
Paul Jakma64e580a2006-02-21 01:09:01 +00002685 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002686
Paul Jakma64e580a2006-02-21 01:09:01 +00002687 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002688 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002689 {
2690 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002691 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2692 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002693 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002694 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2695 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002696 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002697 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002698 break;
2699 }
paul200df112005-06-01 11:17:05 +00002700 return WQ_SUCCESS;
2701}
2702
2703static void
paul0fb58d52005-11-14 14:31:49 +00002704bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002705{
Chris Caputo228da422009-07-18 05:44:03 +00002706 struct bgp_clear_node_queue *cnq = data;
2707 struct bgp_node *rn = cnq->rn;
2708 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002709
2710 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002711 bgp_table_unlock (table);
2712 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002713}
2714
2715static void
paul94f2b392005-06-28 12:44:16 +00002716bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002717{
Paul Jakma64e580a2006-02-21 01:09:01 +00002718 struct peer *peer = wq->spec.data;
2719
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002720 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002721 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002722
2723 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002724}
2725
2726static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002727bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002728{
Nick Hilliarde7cc3b32009-03-17 22:14:25 +00002729 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx"];
Paul Jakma64e580a2006-02-21 01:09:01 +00002730
2731 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2732#undef CLEAR_QUEUE_NAME_LEN
2733
2734 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002735 {
2736 zlog_err ("%s: Failed to allocate work queue", __func__);
2737 exit (1);
2738 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002739 peer->clear_node_queue->spec.hold = 10;
2740 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2741 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2742 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2743 peer->clear_node_queue->spec.max_retries = 0;
2744
2745 /* we only 'lock' this peer reference when the queue is actually active */
2746 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002747}
2748
paul718e3742002-12-13 20:15:29 +00002749static void
2750bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002751 struct bgp_table *table, struct peer *rsclient,
2752 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002753{
2754 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002755
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002756
paul718e3742002-12-13 20:15:29 +00002757 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002758 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002759
hasso6cf159b2005-03-21 10:28:14 +00002760 /* If still no table => afi/safi isn't configured at all or smth. */
2761 if (! table)
2762 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002763
2764 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2765 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002766 struct bgp_info *ri;
2767 struct bgp_adj_in *ain;
2768 struct bgp_adj_out *aout;
2769
Paul Jakma65ca75e2006-05-04 08:08:15 +00002770 if (rn->info == NULL)
2771 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002772
2773 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2774 * queued for every clearing peer, regardless of whether it is
2775 * relevant to the peer at hand.
2776 *
2777 * Overview: There are 3 different indices which need to be
2778 * scrubbed, potentially, when a peer is removed:
2779 *
2780 * 1 peer's routes visible via the RIB (ie accepted routes)
2781 * 2 peer's routes visible by the (optional) peer's adj-in index
2782 * 3 other routes visible by the peer's adj-out index
2783 *
2784 * 3 there is no hurry in scrubbing, once the struct peer is
2785 * removed from bgp->peer, we could just GC such deleted peer's
2786 * adj-outs at our leisure.
2787 *
2788 * 1 and 2 must be 'scrubbed' in some way, at least made
2789 * invisible via RIB index before peer session is allowed to be
2790 * brought back up. So one needs to know when such a 'search' is
2791 * complete.
2792 *
2793 * Ideally:
2794 *
2795 * - there'd be a single global queue or a single RIB walker
2796 * - rather than tracking which route_nodes still need to be
2797 * examined on a peer basis, we'd track which peers still
2798 * aren't cleared
2799 *
2800 * Given that our per-peer prefix-counts now should be reliable,
2801 * this may actually be achievable. It doesn't seem to be a huge
2802 * problem at this time,
2803 */
2804 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002805 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002806 {
Chris Caputo228da422009-07-18 05:44:03 +00002807 struct bgp_clear_node_queue *cnq;
2808
2809 /* both unlocked in bgp_clear_node_queue_del */
2810 bgp_table_lock (rn->table);
2811 bgp_lock_node (rn);
2812 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2813 sizeof (struct bgp_clear_node_queue));
2814 cnq->rn = rn;
2815 cnq->purpose = purpose;
2816 work_queue_add (peer->clear_node_queue, cnq);
2817 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002818 }
2819
2820 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002821 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002822 {
2823 bgp_adj_in_remove (rn, ain);
2824 bgp_unlock_node (rn);
2825 break;
2826 }
2827 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002828 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002829 {
2830 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2831 bgp_unlock_node (rn);
2832 break;
2833 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002834 }
2835 return;
2836}
2837
2838void
Chris Caputo228da422009-07-18 05:44:03 +00002839bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2840 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002841{
2842 struct bgp_node *rn;
2843 struct bgp_table *table;
2844 struct peer *rsclient;
2845 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002846
Paul Jakma64e580a2006-02-21 01:09:01 +00002847 if (peer->clear_node_queue == NULL)
2848 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002849
Paul Jakmaca058a32006-09-14 02:58:49 +00002850 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2851 * Idle until it receives a Clearing_Completed event. This protects
2852 * against peers which flap faster than we can we clear, which could
2853 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002854 *
2855 * a) race with routes from the new session being installed before
2856 * clear_route_node visits the node (to delete the route of that
2857 * peer)
2858 * b) resource exhaustion, clear_route_node likely leads to an entry
2859 * on the process_main queue. Fast-flapping could cause that queue
2860 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002861 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002862 if (!peer->clear_node_queue->thread)
2863 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002864
Chris Caputo228da422009-07-18 05:44:03 +00002865 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002866 {
Chris Caputo228da422009-07-18 05:44:03 +00002867 case BGP_CLEAR_ROUTE_NORMAL:
2868 if (safi != SAFI_MPLS_VPN)
2869 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2870 else
2871 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2872 rn = bgp_route_next (rn))
2873 if ((table = rn->info) != NULL)
2874 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2875
2876 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2877 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2878 PEER_FLAG_RSERVER_CLIENT))
2879 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2880 break;
2881
2882 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2883 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2884 break;
2885
2886 default:
2887 assert (0);
2888 break;
paulfee0f4c2004-09-13 05:12:46 +00002889 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002890
Paul Jakmaca058a32006-09-14 02:58:49 +00002891 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002892 * completion function won't be run by workqueue code - call it here.
2893 * XXX: Actually, this assumption doesn't hold, see
2894 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002895 *
2896 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002897 * really needed if peer state is Established - peers in
2898 * pre-Established states shouldn't have any route-update state
2899 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002900 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002901 * We still can get here in pre-Established though, through
2902 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2903 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002904 *
2905 * At some future point, this check could be move to the top of the
2906 * function, and do a quick early-return when state is
2907 * pre-Established, avoiding above list and table scans. Once we're
2908 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002909 */
2910 if (!peer->clear_node_queue->thread)
2911 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002912}
2913
2914void
2915bgp_clear_route_all (struct peer *peer)
2916{
2917 afi_t afi;
2918 safi_t safi;
2919
2920 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2921 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002922 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002923}
2924
2925void
2926bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2927{
2928 struct bgp_table *table;
2929 struct bgp_node *rn;
2930 struct bgp_adj_in *ain;
2931
2932 table = peer->bgp->rib[afi][safi];
2933
2934 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2935 for (ain = rn->adj_in; ain ; ain = ain->next)
2936 if (ain->peer == peer)
2937 {
2938 bgp_adj_in_remove (rn, ain);
2939 bgp_unlock_node (rn);
2940 break;
2941 }
2942}
hasso93406d82005-02-02 14:40:33 +00002943
2944void
2945bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2946{
2947 struct bgp_node *rn;
2948 struct bgp_info *ri;
2949 struct bgp_table *table;
2950
2951 table = peer->bgp->rib[afi][safi];
2952
2953 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2954 {
2955 for (ri = rn->info; ri; ri = ri->next)
2956 if (ri->peer == peer)
2957 {
2958 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2959 bgp_rib_remove (rn, ri, peer, afi, safi);
2960 break;
2961 }
2962 }
2963}
paul718e3742002-12-13 20:15:29 +00002964
2965/* Delete all kernel routes. */
2966void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002967bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002968{
2969 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002970 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002971 struct bgp_node *rn;
2972 struct bgp_table *table;
2973 struct bgp_info *ri;
2974
paul1eb8ef22005-04-07 07:30:20 +00002975 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002976 {
2977 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2978
2979 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2980 for (ri = rn->info; ri; ri = ri->next)
2981 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2982 && ri->type == ZEBRA_ROUTE_BGP
2983 && ri->sub_type == BGP_ROUTE_NORMAL)
2984 bgp_zebra_withdraw (&rn->p, ri);
2985
2986 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2987
2988 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2989 for (ri = rn->info; ri; ri = ri->next)
2990 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2991 && ri->type == ZEBRA_ROUTE_BGP
2992 && ri->sub_type == BGP_ROUTE_NORMAL)
2993 bgp_zebra_withdraw (&rn->p, ri);
2994 }
2995}
2996
2997void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002998bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00002999{
3000 vty_reset ();
3001 bgp_zclient_reset ();
3002 access_list_reset ();
3003 prefix_list_reset ();
3004}
3005
3006/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3007 value. */
3008int
3009bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3010{
3011 u_char *pnt;
3012 u_char *lim;
3013 struct prefix p;
3014 int psize;
3015 int ret;
3016
3017 /* Check peer status. */
3018 if (peer->status != Established)
3019 return 0;
3020
3021 pnt = packet->nlri;
3022 lim = pnt + packet->length;
3023
3024 for (; pnt < lim; pnt += psize)
3025 {
3026 /* Clear prefix structure. */
3027 memset (&p, 0, sizeof (struct prefix));
3028
3029 /* Fetch prefix length. */
3030 p.prefixlen = *pnt++;
3031 p.family = afi2family (packet->afi);
3032
3033 /* Already checked in nlri_sanity_check(). We do double check
3034 here. */
3035 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3036 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3037 return -1;
3038
3039 /* Packet size overflow check. */
3040 psize = PSIZE (p.prefixlen);
3041
3042 /* When packet overflow occur return immediately. */
3043 if (pnt + psize > lim)
3044 return -1;
3045
3046 /* Fetch prefix from NLRI packet. */
3047 memcpy (&p.u.prefix, pnt, psize);
3048
3049 /* Check address. */
3050 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3051 {
3052 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3053 {
paulf5ba3872004-07-09 12:11:31 +00003054 /*
3055 * From draft-ietf-idr-bgp4-22, Section 6.3:
3056 * If a BGP router receives an UPDATE message with a
3057 * semantically incorrect NLRI field, in which a prefix is
3058 * semantically incorrect (eg. an unexpected multicast IP
3059 * address), it should ignore the prefix.
3060 */
paul718e3742002-12-13 20:15:29 +00003061 zlog (peer->log, LOG_ERR,
3062 "IPv4 unicast NLRI is multicast address %s",
3063 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003064
paul718e3742002-12-13 20:15:29 +00003065 return -1;
3066 }
3067 }
3068
3069#ifdef HAVE_IPV6
3070 /* Check address. */
3071 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3072 {
3073 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3074 {
3075 char buf[BUFSIZ];
3076
3077 zlog (peer->log, LOG_WARNING,
3078 "IPv6 link-local NLRI received %s ignore this NLRI",
3079 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3080
3081 continue;
3082 }
3083 }
3084#endif /* HAVE_IPV6 */
3085
3086 /* Normal process. */
3087 if (attr)
3088 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3089 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3090 else
3091 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3092 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3093
3094 /* Address family configuration mismatch or maximum-prefix count
3095 overflow. */
3096 if (ret < 0)
3097 return -1;
3098 }
3099
3100 /* Packet length consistency check. */
3101 if (pnt != lim)
3102 return -1;
3103
3104 return 0;
3105}
3106
3107/* NLRI encode syntax check routine. */
3108int
3109bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3110 bgp_size_t length)
3111{
3112 u_char *end;
3113 u_char prefixlen;
3114 int psize;
3115
3116 end = pnt + length;
3117
3118 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3119 syntactic validity. If the field is syntactically incorrect,
3120 then the Error Subcode is set to Invalid Network Field. */
3121
3122 while (pnt < end)
3123 {
3124 prefixlen = *pnt++;
3125
3126 /* Prefix length check. */
3127 if ((afi == AFI_IP && prefixlen > 32)
3128 || (afi == AFI_IP6 && prefixlen > 128))
3129 {
3130 plog_err (peer->log,
3131 "%s [Error] Update packet error (wrong prefix length %d)",
3132 peer->host, prefixlen);
3133 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3134 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3135 return -1;
3136 }
3137
3138 /* Packet size overflow check. */
3139 psize = PSIZE (prefixlen);
3140
3141 if (pnt + psize > end)
3142 {
3143 plog_err (peer->log,
3144 "%s [Error] Update packet error"
3145 " (prefix data overflow prefix size is %d)",
3146 peer->host, psize);
3147 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3148 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3149 return -1;
3150 }
3151
3152 pnt += psize;
3153 }
3154
3155 /* Packet length consistency check. */
3156 if (pnt != end)
3157 {
3158 plog_err (peer->log,
3159 "%s [Error] Update packet error"
3160 " (prefix length mismatch with total length)",
3161 peer->host);
3162 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3163 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3164 return -1;
3165 }
3166 return 0;
3167}
3168
paul94f2b392005-06-28 12:44:16 +00003169static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003170bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003171{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003172 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003173}
3174
paul94f2b392005-06-28 12:44:16 +00003175static void
paul718e3742002-12-13 20:15:29 +00003176bgp_static_free (struct bgp_static *bgp_static)
3177{
3178 if (bgp_static->rmap.name)
3179 free (bgp_static->rmap.name);
3180 XFREE (MTYPE_BGP_STATIC, bgp_static);
3181}
3182
paul94f2b392005-06-28 12:44:16 +00003183static void
paulfee0f4c2004-09-13 05:12:46 +00003184bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3185 struct prefix *p, afi_t afi, safi_t safi)
3186{
3187 struct bgp_node *rn;
3188 struct bgp_info *ri;
3189
3190 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3191
3192 /* Check selected route and self inserted route. */
3193 for (ri = rn->info; ri; ri = ri->next)
3194 if (ri->peer == bgp->peer_self
3195 && ri->type == ZEBRA_ROUTE_BGP
3196 && ri->sub_type == BGP_ROUTE_STATIC)
3197 break;
3198
3199 /* Withdraw static BGP route from routing table. */
3200 if (ri)
3201 {
paulfee0f4c2004-09-13 05:12:46 +00003202 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003203 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003204 }
3205
3206 /* Unlock bgp_node_lookup. */
3207 bgp_unlock_node (rn);
3208}
3209
paul94f2b392005-06-28 12:44:16 +00003210static void
paulfee0f4c2004-09-13 05:12:46 +00003211bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003212 struct bgp_static *bgp_static,
3213 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003214{
3215 struct bgp_node *rn;
3216 struct bgp_info *ri;
3217 struct bgp_info *new;
3218 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003219 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003220 struct attr attr = {0 };
3221 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003222 struct bgp *bgp;
3223 int ret;
3224 char buf[SU_ADDRSTRLEN];
3225
3226 bgp = rsclient->bgp;
3227
Paul Jakma06e110f2006-05-12 23:29:22 +00003228 assert (bgp_static);
3229 if (!bgp_static)
3230 return;
3231
paulfee0f4c2004-09-13 05:12:46 +00003232 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3233
3234 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003235
3236 attr.nexthop = bgp_static->igpnexthop;
3237 attr.med = bgp_static->igpmetric;
3238 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003239
3240 if (bgp_static->ttl)
3241 {
3242 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3243 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3244 attr.pathlimit.as = 0;
3245 attr.pathlimit.ttl = bgp_static->ttl;
3246 }
3247
3248 if (bgp_static->atomic)
3249 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3250
paulfee0f4c2004-09-13 05:12:46 +00003251 /* Apply network route-map for export to this rsclient. */
3252 if (bgp_static->rmap.name)
3253 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003254 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003255 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003256 info.attr = &attr_tmp;
3257
paulfee0f4c2004-09-13 05:12:46 +00003258 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3259 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3260
3261 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3262
3263 rsclient->rmap_type = 0;
3264
3265 if (ret == RMAP_DENYMATCH)
3266 {
3267 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003268 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003269
3270 /* Unintern original. */
3271 aspath_unintern (attr.aspath);
3272 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003273 bgp_attr_extra_free (&attr);
3274
paulfee0f4c2004-09-13 05:12:46 +00003275 return;
3276 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003277 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003278 }
3279 else
3280 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003281
paulfee0f4c2004-09-13 05:12:46 +00003282 new_attr = *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003283
paulfee0f4c2004-09-13 05:12:46 +00003284 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3285
Paul Jakmafb982c22007-05-04 20:15:47 +00003286 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3287 == RMAP_DENY)
3288 {
paulfee0f4c2004-09-13 05:12:46 +00003289 /* This BGP update is filtered. Log the reason then update BGP entry. */
3290 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003291 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003292 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3293 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3294 p->prefixlen, rsclient->host);
3295
3296 bgp->peer_self->rmap_type = 0;
3297
3298 bgp_attr_unintern (attr_new);
3299 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003300 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003301
3302 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3303
3304 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003305 }
paulfee0f4c2004-09-13 05:12:46 +00003306
3307 bgp->peer_self->rmap_type = 0;
3308
3309 bgp_attr_unintern (attr_new);
3310 attr_new = bgp_attr_intern (&new_attr);
3311
3312 for (ri = rn->info; ri; ri = ri->next)
3313 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3314 && ri->sub_type == BGP_ROUTE_STATIC)
3315 break;
3316
3317 if (ri)
3318 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003319 if (attrhash_cmp (ri->attr, attr_new) &&
3320 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003321 {
3322 bgp_unlock_node (rn);
3323 bgp_attr_unintern (attr_new);
3324 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003325 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003326 return;
3327 }
3328 else
3329 {
3330 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003331 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003332
3333 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003334 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3335 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003336 bgp_attr_unintern (ri->attr);
3337 ri->attr = attr_new;
3338 ri->uptime = time (NULL);
3339
3340 /* Process change. */
3341 bgp_process (bgp, rn, afi, safi);
3342 bgp_unlock_node (rn);
3343 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003344 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003345 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003346 }
paulfee0f4c2004-09-13 05:12:46 +00003347 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003348
paulfee0f4c2004-09-13 05:12:46 +00003349 /* Make new BGP info. */
3350 new = bgp_info_new ();
3351 new->type = ZEBRA_ROUTE_BGP;
3352 new->sub_type = BGP_ROUTE_STATIC;
3353 new->peer = bgp->peer_self;
3354 SET_FLAG (new->flags, BGP_INFO_VALID);
3355 new->attr = attr_new;
3356 new->uptime = time (NULL);
3357
3358 /* Register new BGP information. */
3359 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003360
3361 /* route_node_get lock */
3362 bgp_unlock_node (rn);
3363
paulfee0f4c2004-09-13 05:12:46 +00003364 /* Process change. */
3365 bgp_process (bgp, rn, afi, safi);
3366
3367 /* Unintern original. */
3368 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003369 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003370}
3371
paul94f2b392005-06-28 12:44:16 +00003372static void
paulfee0f4c2004-09-13 05:12:46 +00003373bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003374 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3375{
3376 struct bgp_node *rn;
3377 struct bgp_info *ri;
3378 struct bgp_info *new;
3379 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003380 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003381 struct attr *attr_new;
3382 int ret;
3383
Paul Jakmadd8103a2006-05-12 23:27:30 +00003384 assert (bgp_static);
3385 if (!bgp_static)
3386 return;
3387
paulfee0f4c2004-09-13 05:12:46 +00003388 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003389
3390 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003391
3392 attr.nexthop = bgp_static->igpnexthop;
3393 attr.med = bgp_static->igpmetric;
3394 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003395
Paul Jakma41367172007-08-06 15:24:51 +00003396 if (bgp_static->ttl)
3397 {
3398 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3399 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3400 attr.pathlimit.as = 0;
3401 attr.pathlimit.ttl = bgp_static->ttl;
3402 }
3403
3404 if (bgp_static->atomic)
3405 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3406
paul718e3742002-12-13 20:15:29 +00003407 /* Apply route-map. */
3408 if (bgp_static->rmap.name)
3409 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003410 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003411 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003412 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003413
paulfee0f4c2004-09-13 05:12:46 +00003414 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3415
paul718e3742002-12-13 20:15:29 +00003416 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003417
paulfee0f4c2004-09-13 05:12:46 +00003418 bgp->peer_self->rmap_type = 0;
3419
paul718e3742002-12-13 20:15:29 +00003420 if (ret == RMAP_DENYMATCH)
3421 {
3422 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003423 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003424
3425 /* Unintern original. */
3426 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003427 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003428 bgp_static_withdraw (bgp, p, afi, safi);
3429 return;
3430 }
paul286e1e72003-08-08 00:24:31 +00003431 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003432 }
paul286e1e72003-08-08 00:24:31 +00003433 else
3434 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003435
3436 for (ri = rn->info; ri; ri = ri->next)
3437 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3438 && ri->sub_type == BGP_ROUTE_STATIC)
3439 break;
3440
3441 if (ri)
3442 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003443 if (attrhash_cmp (ri->attr, attr_new) &&
3444 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003445 {
3446 bgp_unlock_node (rn);
3447 bgp_attr_unintern (attr_new);
3448 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003449 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003450 return;
3451 }
3452 else
3453 {
3454 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003455 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003456
3457 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003458 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3459 bgp_info_restore(rn, ri);
3460 else
3461 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003462 bgp_attr_unintern (ri->attr);
3463 ri->attr = attr_new;
3464 ri->uptime = time (NULL);
3465
3466 /* Process change. */
3467 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3468 bgp_process (bgp, rn, afi, safi);
3469 bgp_unlock_node (rn);
3470 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003471 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003472 return;
3473 }
3474 }
3475
3476 /* Make new BGP info. */
3477 new = bgp_info_new ();
3478 new->type = ZEBRA_ROUTE_BGP;
3479 new->sub_type = BGP_ROUTE_STATIC;
3480 new->peer = bgp->peer_self;
3481 SET_FLAG (new->flags, BGP_INFO_VALID);
3482 new->attr = attr_new;
3483 new->uptime = time (NULL);
3484
3485 /* Aggregate address increment. */
3486 bgp_aggregate_increment (bgp, p, new, afi, safi);
3487
3488 /* Register new BGP information. */
3489 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003490
3491 /* route_node_get lock */
3492 bgp_unlock_node (rn);
3493
paul718e3742002-12-13 20:15:29 +00003494 /* Process change. */
3495 bgp_process (bgp, rn, afi, safi);
3496
3497 /* Unintern original. */
3498 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003499 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003500}
3501
3502void
paulfee0f4c2004-09-13 05:12:46 +00003503bgp_static_update (struct bgp *bgp, struct prefix *p,
3504 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3505{
3506 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003507 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003508
3509 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3510
paul1eb8ef22005-04-07 07:30:20 +00003511 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003512 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003513 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3514 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003515 }
3516}
3517
paul94f2b392005-06-28 12:44:16 +00003518static void
paul718e3742002-12-13 20:15:29 +00003519bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3520 u_char safi, struct prefix_rd *prd, u_char *tag)
3521{
3522 struct bgp_node *rn;
3523 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003524
paulfee0f4c2004-09-13 05:12:46 +00003525 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003526
3527 /* Make new BGP info. */
3528 new = bgp_info_new ();
3529 new->type = ZEBRA_ROUTE_BGP;
3530 new->sub_type = BGP_ROUTE_STATIC;
3531 new->peer = bgp->peer_self;
3532 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3533 SET_FLAG (new->flags, BGP_INFO_VALID);
3534 new->uptime = time (NULL);
Paul Jakmafb982c22007-05-04 20:15:47 +00003535 new->extra = bgp_info_extra_new();
3536 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003537
3538 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003539 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003540
3541 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003542 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003543
paul200df112005-06-01 11:17:05 +00003544 /* route_node_get lock */
3545 bgp_unlock_node (rn);
3546
paul718e3742002-12-13 20:15:29 +00003547 /* Process change. */
3548 bgp_process (bgp, rn, afi, safi);
3549}
3550
3551void
3552bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3553 safi_t safi)
3554{
3555 struct bgp_node *rn;
3556 struct bgp_info *ri;
3557
paulfee0f4c2004-09-13 05:12:46 +00003558 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003559
3560 /* Check selected route and self inserted route. */
3561 for (ri = rn->info; ri; ri = ri->next)
3562 if (ri->peer == bgp->peer_self
3563 && ri->type == ZEBRA_ROUTE_BGP
3564 && ri->sub_type == BGP_ROUTE_STATIC)
3565 break;
3566
3567 /* Withdraw static BGP route from routing table. */
3568 if (ri)
3569 {
3570 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003571 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003572 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003573 }
3574
3575 /* Unlock bgp_node_lookup. */
3576 bgp_unlock_node (rn);
3577}
3578
3579void
paulfee0f4c2004-09-13 05:12:46 +00003580bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3581{
3582 struct bgp_static *bgp_static;
3583 struct bgp *bgp;
3584 struct bgp_node *rn;
3585 struct prefix *p;
3586
3587 bgp = rsclient->bgp;
3588
3589 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3590 if ((bgp_static = rn->info) != NULL)
3591 {
3592 p = &rn->p;
3593
3594 bgp_static_update_rsclient (rsclient, p, bgp_static,
3595 afi, safi);
3596 }
3597}
3598
paul94f2b392005-06-28 12:44:16 +00003599static void
paul718e3742002-12-13 20:15:29 +00003600bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3601 u_char safi, struct prefix_rd *prd, u_char *tag)
3602{
3603 struct bgp_node *rn;
3604 struct bgp_info *ri;
3605
paulfee0f4c2004-09-13 05:12:46 +00003606 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003607
3608 /* Check selected route and self inserted route. */
3609 for (ri = rn->info; ri; ri = ri->next)
3610 if (ri->peer == bgp->peer_self
3611 && ri->type == ZEBRA_ROUTE_BGP
3612 && ri->sub_type == BGP_ROUTE_STATIC)
3613 break;
3614
3615 /* Withdraw static BGP route from routing table. */
3616 if (ri)
3617 {
3618 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003619 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003620 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003621 }
3622
3623 /* Unlock bgp_node_lookup. */
3624 bgp_unlock_node (rn);
3625}
3626
Paul Jakma41367172007-08-06 15:24:51 +00003627static void
3628bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3629 int ttl_edge)
3630{
3631 struct bgp_node *parent = rn;
3632 struct bgp_static *sp;
3633
3634 /* Existing static changed TTL, search parents and adjust their atomic */
3635 while ((parent = parent->parent))
3636 if ((sp = parent->info))
3637 {
3638 int sp_level = (sp->atomic ? 1 : 0);
3639 ttl_edge ? sp->atomic++ : sp->atomic--;
3640
3641 /* did we change state of parent whether atomic is set or not? */
3642 if (sp_level != (sp->atomic ? 1 : 0))
3643 {
3644 bgp_static_update (bgp, &parent->p, sp,
3645 rn->table->afi, rn->table->safi);
3646 }
3647 }
3648}
3649
paul718e3742002-12-13 20:15:29 +00003650/* Configure static BGP network. When user don't run zebra, static
3651 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003652static int
paulfd79ac92004-10-13 05:06:08 +00003653bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakma41367172007-08-06 15:24:51 +00003654 u_int16_t afi, u_char safi, const char *rmap, int backdoor,
3655 u_char ttl)
paul718e3742002-12-13 20:15:29 +00003656{
3657 int ret;
3658 struct prefix p;
3659 struct bgp_static *bgp_static;
3660 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003661 u_char need_update = 0;
3662 u_char ttl_change = 0;
3663 u_char ttl_edge = (ttl ? 1 : 0);
3664 u_char new = 0;
paul718e3742002-12-13 20:15:29 +00003665
3666 /* Convert IP prefix string to struct prefix. */
3667 ret = str2prefix (ip_str, &p);
3668 if (! ret)
3669 {
3670 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3671 return CMD_WARNING;
3672 }
3673#ifdef HAVE_IPV6
3674 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3675 {
3676 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3677 VTY_NEWLINE);
3678 return CMD_WARNING;
3679 }
3680#endif /* HAVE_IPV6 */
3681
3682 apply_mask (&p);
3683
3684 /* Set BGP static route configuration. */
3685 rn = bgp_node_get (bgp->route[afi][safi], &p);
3686
3687 if (rn->info)
3688 {
3689 /* Configuration change. */
3690 bgp_static = rn->info;
3691
3692 /* Check previous routes are installed into BGP. */
Paul Jakma41367172007-08-06 15:24:51 +00003693 if (bgp_static->valid)
3694 {
3695 if (bgp_static->backdoor != backdoor
3696 || bgp_static->ttl != ttl)
3697 need_update = 1;
3698 }
3699
3700 /* need to catch TTL set/unset transitions for handling of
3701 * ATOMIC_AGGREGATE
3702 */
3703 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3704 ttl_change = 1;
3705
paul718e3742002-12-13 20:15:29 +00003706 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003707 bgp_static->ttl = ttl;
3708
paul718e3742002-12-13 20:15:29 +00003709 if (rmap)
3710 {
3711 if (bgp_static->rmap.name)
3712 free (bgp_static->rmap.name);
3713 bgp_static->rmap.name = strdup (rmap);
3714 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3715 }
3716 else
3717 {
3718 if (bgp_static->rmap.name)
3719 free (bgp_static->rmap.name);
3720 bgp_static->rmap.name = NULL;
3721 bgp_static->rmap.map = NULL;
3722 bgp_static->valid = 0;
3723 }
3724 bgp_unlock_node (rn);
3725 }
3726 else
3727 {
3728 /* New configuration. */
3729 bgp_static = bgp_static_new ();
3730 bgp_static->backdoor = backdoor;
3731 bgp_static->valid = 0;
3732 bgp_static->igpmetric = 0;
3733 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003734 bgp_static->ttl = ttl;
3735 ttl_change = ttl_edge;
3736 new = 1;
3737
paul718e3742002-12-13 20:15:29 +00003738 if (rmap)
3739 {
3740 if (bgp_static->rmap.name)
3741 free (bgp_static->rmap.name);
3742 bgp_static->rmap.name = strdup (rmap);
3743 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3744 }
3745 rn->info = bgp_static;
3746 }
3747
Paul Jakma41367172007-08-06 15:24:51 +00003748 /* ".. sites that choose to advertise the
3749 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3750 * all less specific covering prefixes as well as the more specific
3751 * prefixes."
3752 *
3753 * So:
3754 * Prefix that has just had pathlimit set/unset:
3755 * - Must bump ATOMIC refcount on all parents.
3756 *
3757 * To catch less specific prefixes:
3758 * - Must search children for ones with TTL, bump atomic refcount
3759 * (we dont care if we're deleting a less specific prefix..)
3760 */
3761 if (ttl_change)
3762 {
3763 /* Existing static changed TTL, search parents and adjust their atomic */
3764 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3765 }
3766
3767 if (new)
3768 {
3769 struct bgp_node *child;
3770 struct bgp_static *sc;
3771
3772 /* New static, search children and bump this statics atomic.. */
3773 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3774 while ((child = bgp_route_next_until (child, rn)))
3775 {
3776 if ((sc = child->info) && sc->ttl)
3777 bgp_static->atomic++;
3778 }
3779 }
3780
paul718e3742002-12-13 20:15:29 +00003781 /* If BGP scan is not enabled, we should install this route here. */
3782 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3783 {
3784 bgp_static->valid = 1;
3785
3786 if (need_update)
3787 bgp_static_withdraw (bgp, &p, afi, safi);
3788
3789 if (! bgp_static->backdoor)
3790 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3791 }
3792
3793 return CMD_SUCCESS;
3794}
3795
3796/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003797static int
paulfd79ac92004-10-13 05:06:08 +00003798bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003799 u_int16_t afi, u_char safi)
3800{
3801 int ret;
3802 struct prefix p;
3803 struct bgp_static *bgp_static;
3804 struct bgp_node *rn;
3805
3806 /* Convert IP prefix string to struct prefix. */
3807 ret = str2prefix (ip_str, &p);
3808 if (! ret)
3809 {
3810 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3811 return CMD_WARNING;
3812 }
3813#ifdef HAVE_IPV6
3814 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3815 {
3816 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3817 VTY_NEWLINE);
3818 return CMD_WARNING;
3819 }
3820#endif /* HAVE_IPV6 */
3821
3822 apply_mask (&p);
3823
3824 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3825 if (! rn)
3826 {
3827 vty_out (vty, "%% Can't find specified static route configuration.%s",
3828 VTY_NEWLINE);
3829 return CMD_WARNING;
3830 }
3831
3832 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003833
3834 /* decrement atomic in parents, see bgp_static_set */
3835 bgp_pathlimit_update_parents (bgp, rn, 0);
3836
paul718e3742002-12-13 20:15:29 +00003837 /* Update BGP RIB. */
3838 if (! bgp_static->backdoor)
3839 bgp_static_withdraw (bgp, &p, afi, safi);
3840
3841 /* Clear configuration. */
3842 bgp_static_free (bgp_static);
3843 rn->info = NULL;
3844 bgp_unlock_node (rn);
3845 bgp_unlock_node (rn);
3846
3847 return CMD_SUCCESS;
3848}
3849
3850/* Called from bgp_delete(). Delete all static routes from the BGP
3851 instance. */
3852void
3853bgp_static_delete (struct bgp *bgp)
3854{
3855 afi_t afi;
3856 safi_t safi;
3857 struct bgp_node *rn;
3858 struct bgp_node *rm;
3859 struct bgp_table *table;
3860 struct bgp_static *bgp_static;
3861
3862 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3863 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3864 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3865 if (rn->info != NULL)
3866 {
3867 if (safi == SAFI_MPLS_VPN)
3868 {
3869 table = rn->info;
3870
3871 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3872 {
3873 bgp_static = rn->info;
3874 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3875 AFI_IP, SAFI_MPLS_VPN,
3876 (struct prefix_rd *)&rn->p,
3877 bgp_static->tag);
3878 bgp_static_free (bgp_static);
3879 rn->info = NULL;
3880 bgp_unlock_node (rn);
3881 }
3882 }
3883 else
3884 {
3885 bgp_static = rn->info;
3886 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3887 bgp_static_free (bgp_static);
3888 rn->info = NULL;
3889 bgp_unlock_node (rn);
3890 }
3891 }
3892}
3893
3894int
paulfd79ac92004-10-13 05:06:08 +00003895bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3896 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003897{
3898 int ret;
3899 struct prefix p;
3900 struct prefix_rd prd;
3901 struct bgp *bgp;
3902 struct bgp_node *prn;
3903 struct bgp_node *rn;
3904 struct bgp_table *table;
3905 struct bgp_static *bgp_static;
3906 u_char tag[3];
3907
3908 bgp = vty->index;
3909
3910 ret = str2prefix (ip_str, &p);
3911 if (! ret)
3912 {
3913 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3914 return CMD_WARNING;
3915 }
3916 apply_mask (&p);
3917
3918 ret = str2prefix_rd (rd_str, &prd);
3919 if (! ret)
3920 {
3921 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3922 return CMD_WARNING;
3923 }
3924
3925 ret = str2tag (tag_str, tag);
3926 if (! ret)
3927 {
3928 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3929 return CMD_WARNING;
3930 }
3931
3932 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3933 (struct prefix *)&prd);
3934 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003935 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003936 else
3937 bgp_unlock_node (prn);
3938 table = prn->info;
3939
3940 rn = bgp_node_get (table, &p);
3941
3942 if (rn->info)
3943 {
3944 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3945 bgp_unlock_node (rn);
3946 }
3947 else
3948 {
3949 /* New configuration. */
3950 bgp_static = bgp_static_new ();
3951 bgp_static->valid = 1;
3952 memcpy (bgp_static->tag, tag, 3);
3953 rn->info = bgp_static;
3954
3955 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3956 }
3957
3958 return CMD_SUCCESS;
3959}
3960
3961/* Configure static BGP network. */
3962int
paulfd79ac92004-10-13 05:06:08 +00003963bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3964 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003965{
3966 int ret;
3967 struct bgp *bgp;
3968 struct prefix p;
3969 struct prefix_rd prd;
3970 struct bgp_node *prn;
3971 struct bgp_node *rn;
3972 struct bgp_table *table;
3973 struct bgp_static *bgp_static;
3974 u_char tag[3];
3975
3976 bgp = vty->index;
3977
3978 /* Convert IP prefix string to struct prefix. */
3979 ret = str2prefix (ip_str, &p);
3980 if (! ret)
3981 {
3982 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3983 return CMD_WARNING;
3984 }
3985 apply_mask (&p);
3986
3987 ret = str2prefix_rd (rd_str, &prd);
3988 if (! ret)
3989 {
3990 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3991 return CMD_WARNING;
3992 }
3993
3994 ret = str2tag (tag_str, tag);
3995 if (! ret)
3996 {
3997 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3998 return CMD_WARNING;
3999 }
4000
4001 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4002 (struct prefix *)&prd);
4003 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004004 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004005 else
4006 bgp_unlock_node (prn);
4007 table = prn->info;
4008
4009 rn = bgp_node_lookup (table, &p);
4010
4011 if (rn)
4012 {
4013 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4014
4015 bgp_static = rn->info;
4016 bgp_static_free (bgp_static);
4017 rn->info = NULL;
4018 bgp_unlock_node (rn);
4019 bgp_unlock_node (rn);
4020 }
4021 else
4022 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4023
4024 return CMD_SUCCESS;
4025}
4026
4027DEFUN (bgp_network,
4028 bgp_network_cmd,
4029 "network A.B.C.D/M",
4030 "Specify a network to announce via BGP\n"
4031 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4032{
Paul Jakma41367172007-08-06 15:24:51 +00004033 u_char ttl = 0;
4034
4035 if (argc == 2)
4036 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4037
paul718e3742002-12-13 20:15:29 +00004038 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004039 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004040}
4041
Paul Jakma41367172007-08-06 15:24:51 +00004042ALIAS (bgp_network,
4043 bgp_network_ttl_cmd,
4044 "network A.B.C.D/M pathlimit <0-255>",
4045 "Specify a network to announce via BGP\n"
4046 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4047 "AS-Path hopcount limit attribute\n"
4048 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4049
paul718e3742002-12-13 20:15:29 +00004050DEFUN (bgp_network_route_map,
4051 bgp_network_route_map_cmd,
4052 "network A.B.C.D/M route-map WORD",
4053 "Specify a network to announce via BGP\n"
4054 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4055 "Route-map to modify the attributes\n"
4056 "Name of the route map\n")
4057{
4058 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004059 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004060}
4061
4062DEFUN (bgp_network_backdoor,
4063 bgp_network_backdoor_cmd,
4064 "network A.B.C.D/M backdoor",
4065 "Specify a network to announce via BGP\n"
4066 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4067 "Specify a BGP backdoor route\n")
4068{
Paul Jakma41367172007-08-06 15:24:51 +00004069 u_char ttl = 0;
4070
4071 if (argc == 2)
4072 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4073
4074 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4075 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004076}
4077
Paul Jakma41367172007-08-06 15:24:51 +00004078ALIAS (bgp_network_backdoor,
4079 bgp_network_backdoor_ttl_cmd,
4080 "network A.B.C.D/M backdoor pathlimit <0-255>",
4081 "Specify a network to announce via BGP\n"
4082 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4083 "Specify a BGP backdoor route\n"
4084 "AS-Path hopcount limit attribute\n"
4085 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4086
paul718e3742002-12-13 20:15:29 +00004087DEFUN (bgp_network_mask,
4088 bgp_network_mask_cmd,
4089 "network A.B.C.D mask A.B.C.D",
4090 "Specify a network to announce via BGP\n"
4091 "Network number\n"
4092 "Network mask\n"
4093 "Network mask\n")
4094{
4095 int ret;
4096 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004097 u_char ttl = 0;
4098
4099 if (argc == 3)
4100 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4101
paul718e3742002-12-13 20:15:29 +00004102 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4103 if (! ret)
4104 {
4105 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4106 return CMD_WARNING;
4107 }
4108
4109 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004110 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004111}
4112
Paul Jakma41367172007-08-06 15:24:51 +00004113ALIAS (bgp_network_mask,
4114 bgp_network_mask_ttl_cmd,
4115 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4116 "Specify a network to announce via BGP\n"
4117 "Network number\n"
4118 "Network mask\n"
4119 "Network mask\n"
4120 "AS-Path hopcount limit attribute\n"
4121 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4122
paul718e3742002-12-13 20:15:29 +00004123DEFUN (bgp_network_mask_route_map,
4124 bgp_network_mask_route_map_cmd,
4125 "network A.B.C.D mask A.B.C.D route-map WORD",
4126 "Specify a network to announce via BGP\n"
4127 "Network number\n"
4128 "Network mask\n"
4129 "Network mask\n"
4130 "Route-map to modify the attributes\n"
4131 "Name of the route map\n")
4132{
4133 int ret;
4134 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004135
paul718e3742002-12-13 20:15:29 +00004136 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4137 if (! ret)
4138 {
4139 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4140 return CMD_WARNING;
4141 }
4142
4143 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004144 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
paul718e3742002-12-13 20:15:29 +00004145}
4146
4147DEFUN (bgp_network_mask_backdoor,
4148 bgp_network_mask_backdoor_cmd,
4149 "network A.B.C.D mask A.B.C.D backdoor",
4150 "Specify a network to announce via BGP\n"
4151 "Network number\n"
4152 "Network mask\n"
4153 "Network mask\n"
4154 "Specify a BGP backdoor route\n")
4155{
4156 int ret;
4157 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004158 u_char ttl = 0;
4159
4160 if (argc == 3)
4161 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
paul718e3742002-12-13 20:15:29 +00004162
4163 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4164 if (! ret)
4165 {
4166 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4167 return CMD_WARNING;
4168 }
4169
Paul Jakma41367172007-08-06 15:24:51 +00004170 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4171 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004172}
4173
Paul Jakma41367172007-08-06 15:24:51 +00004174ALIAS (bgp_network_mask_backdoor,
4175 bgp_network_mask_backdoor_ttl_cmd,
4176 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4177 "Specify a network to announce via BGP\n"
4178 "Network number\n"
4179 "Network mask\n"
4180 "Network mask\n"
4181 "Specify a BGP backdoor route\n"
4182 "AS-Path hopcount limit attribute\n"
4183 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4184
paul718e3742002-12-13 20:15:29 +00004185DEFUN (bgp_network_mask_natural,
4186 bgp_network_mask_natural_cmd,
4187 "network A.B.C.D",
4188 "Specify a network to announce via BGP\n"
4189 "Network number\n")
4190{
4191 int ret;
4192 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004193 u_char ttl = 0;
4194
4195 if (argc == 2)
4196 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004197
4198 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4199 if (! ret)
4200 {
4201 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4202 return CMD_WARNING;
4203 }
4204
4205 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004206 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004207}
4208
Paul Jakma41367172007-08-06 15:24:51 +00004209ALIAS (bgp_network_mask_natural,
4210 bgp_network_mask_natural_ttl_cmd,
4211 "network A.B.C.D pathlimit <0-255>",
4212 "Specify a network to announce via BGP\n"
4213 "Network number\n"
4214 "AS-Path hopcount limit attribute\n"
4215 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4216
paul718e3742002-12-13 20:15:29 +00004217DEFUN (bgp_network_mask_natural_route_map,
4218 bgp_network_mask_natural_route_map_cmd,
4219 "network A.B.C.D route-map WORD",
4220 "Specify a network to announce via BGP\n"
4221 "Network number\n"
4222 "Route-map to modify the attributes\n"
4223 "Name of the route map\n")
4224{
4225 int ret;
4226 char prefix_str[BUFSIZ];
4227
4228 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4229 if (! ret)
4230 {
4231 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4232 return CMD_WARNING;
4233 }
4234
4235 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004236 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004237}
4238
4239DEFUN (bgp_network_mask_natural_backdoor,
4240 bgp_network_mask_natural_backdoor_cmd,
4241 "network A.B.C.D backdoor",
4242 "Specify a network to announce via BGP\n"
4243 "Network number\n"
4244 "Specify a BGP backdoor route\n")
4245{
4246 int ret;
4247 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004248 u_char ttl = 0;
4249
4250 if (argc == 2)
4251 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004252
4253 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4254 if (! ret)
4255 {
4256 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4257 return CMD_WARNING;
4258 }
4259
Paul Jakma41367172007-08-06 15:24:51 +00004260 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4261 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004262}
4263
Paul Jakma41367172007-08-06 15:24:51 +00004264ALIAS (bgp_network_mask_natural_backdoor,
4265 bgp_network_mask_natural_backdoor_ttl_cmd,
4266 "network A.B.C.D backdoor pathlimit (1-255>",
4267 "Specify a network to announce via BGP\n"
4268 "Network number\n"
4269 "Specify a BGP backdoor route\n"
4270 "AS-Path hopcount limit attribute\n"
4271 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4272
paul718e3742002-12-13 20:15:29 +00004273DEFUN (no_bgp_network,
4274 no_bgp_network_cmd,
4275 "no network A.B.C.D/M",
4276 NO_STR
4277 "Specify a network to announce via BGP\n"
4278 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4279{
4280 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4281 bgp_node_safi (vty));
4282}
4283
4284ALIAS (no_bgp_network,
Paul Jakma41367172007-08-06 15:24:51 +00004285 no_bgp_network_ttl_cmd,
4286 "no network A.B.C.D/M pathlimit <0-255>",
4287 NO_STR
4288 "Specify a network to announce via BGP\n"
4289 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4290 "AS-Path hopcount limit attribute\n"
4291 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4292
4293ALIAS (no_bgp_network,
paul718e3742002-12-13 20:15:29 +00004294 no_bgp_network_route_map_cmd,
4295 "no network A.B.C.D/M route-map WORD",
4296 NO_STR
4297 "Specify a network to announce via BGP\n"
4298 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4299 "Route-map to modify the attributes\n"
4300 "Name of the route map\n")
4301
4302ALIAS (no_bgp_network,
4303 no_bgp_network_backdoor_cmd,
4304 "no network A.B.C.D/M backdoor",
4305 NO_STR
4306 "Specify a network to announce via BGP\n"
4307 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4308 "Specify a BGP backdoor route\n")
4309
Paul Jakma41367172007-08-06 15:24:51 +00004310ALIAS (no_bgp_network,
4311 no_bgp_network_backdoor_ttl_cmd,
4312 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4313 NO_STR
4314 "Specify a network to announce via BGP\n"
4315 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4316 "Specify a BGP backdoor route\n"
4317 "AS-Path hopcount limit attribute\n"
4318 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4319
paul718e3742002-12-13 20:15:29 +00004320DEFUN (no_bgp_network_mask,
4321 no_bgp_network_mask_cmd,
4322 "no network A.B.C.D mask A.B.C.D",
4323 NO_STR
4324 "Specify a network to announce via BGP\n"
4325 "Network number\n"
4326 "Network mask\n"
4327 "Network mask\n")
4328{
4329 int ret;
4330 char prefix_str[BUFSIZ];
4331
4332 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4333 if (! ret)
4334 {
4335 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4336 return CMD_WARNING;
4337 }
4338
4339 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4340 bgp_node_safi (vty));
4341}
4342
Paul Jakma41367172007-08-06 15:24:51 +00004343ALIAS (no_bgp_network,
4344 no_bgp_network_mask_ttl_cmd,
4345 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4346 NO_STR
4347 "Specify a network to announce via BGP\n"
4348 "Network number\n"
4349 "Network mask\n"
4350 "Network mask\n"
4351 "AS-Path hopcount limit attribute\n"
4352 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4353
paul718e3742002-12-13 20:15:29 +00004354ALIAS (no_bgp_network_mask,
4355 no_bgp_network_mask_route_map_cmd,
4356 "no network A.B.C.D mask A.B.C.D route-map WORD",
4357 NO_STR
4358 "Specify a network to announce via BGP\n"
4359 "Network number\n"
4360 "Network mask\n"
4361 "Network mask\n"
4362 "Route-map to modify the attributes\n"
4363 "Name of the route map\n")
4364
4365ALIAS (no_bgp_network_mask,
4366 no_bgp_network_mask_backdoor_cmd,
4367 "no network A.B.C.D mask A.B.C.D backdoor",
4368 NO_STR
4369 "Specify a network to announce via BGP\n"
4370 "Network number\n"
4371 "Network mask\n"
4372 "Network mask\n"
4373 "Specify a BGP backdoor route\n")
4374
Paul Jakma41367172007-08-06 15:24:51 +00004375ALIAS (no_bgp_network_mask,
4376 no_bgp_network_mask_backdoor_ttl_cmd,
4377 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4378 NO_STR
4379 "Specify a network to announce via BGP\n"
4380 "Network number\n"
4381 "Network mask\n"
4382 "Network mask\n"
4383 "Specify a BGP backdoor route\n"
4384 "AS-Path hopcount limit attribute\n"
4385 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4386
paul718e3742002-12-13 20:15:29 +00004387DEFUN (no_bgp_network_mask_natural,
4388 no_bgp_network_mask_natural_cmd,
4389 "no network A.B.C.D",
4390 NO_STR
4391 "Specify a network to announce via BGP\n"
4392 "Network number\n")
4393{
4394 int ret;
4395 char prefix_str[BUFSIZ];
4396
4397 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4398 if (! ret)
4399 {
4400 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4401 return CMD_WARNING;
4402 }
4403
4404 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4405 bgp_node_safi (vty));
4406}
4407
4408ALIAS (no_bgp_network_mask_natural,
4409 no_bgp_network_mask_natural_route_map_cmd,
4410 "no network A.B.C.D route-map WORD",
4411 NO_STR
4412 "Specify a network to announce via BGP\n"
4413 "Network number\n"
4414 "Route-map to modify the attributes\n"
4415 "Name of the route map\n")
4416
4417ALIAS (no_bgp_network_mask_natural,
4418 no_bgp_network_mask_natural_backdoor_cmd,
4419 "no network A.B.C.D backdoor",
4420 NO_STR
4421 "Specify a network to announce via BGP\n"
4422 "Network number\n"
4423 "Specify a BGP backdoor route\n")
4424
Paul Jakma41367172007-08-06 15:24:51 +00004425ALIAS (no_bgp_network_mask_natural,
4426 no_bgp_network_mask_natural_ttl_cmd,
4427 "no network A.B.C.D pathlimit <0-255>",
4428 NO_STR
4429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "AS-Path hopcount limit attribute\n"
4432 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4433
4434ALIAS (no_bgp_network_mask_natural,
4435 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4436 "no network A.B.C.D backdoor pathlimit <0-255>",
4437 NO_STR
4438 "Specify a network to announce via BGP\n"
4439 "Network number\n"
4440 "Specify a BGP backdoor route\n"
4441 "AS-Path hopcount limit attribute\n"
4442 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4443
paul718e3742002-12-13 20:15:29 +00004444#ifdef HAVE_IPV6
4445DEFUN (ipv6_bgp_network,
4446 ipv6_bgp_network_cmd,
4447 "network X:X::X:X/M",
4448 "Specify a network to announce via BGP\n"
4449 "IPv6 prefix <network>/<length>\n")
4450{
Paul Jakma41367172007-08-06 15:24:51 +00004451 u_char ttl = 0;
4452
4453 if (argc == 2)
4454 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4455
4456 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4457 NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004458}
4459
Paul Jakma41367172007-08-06 15:24:51 +00004460ALIAS (ipv6_bgp_network,
4461 ipv6_bgp_network_ttl_cmd,
4462 "network X:X::X:X/M pathlimit <0-255>",
4463 "Specify a network to announce via BGP\n"
4464 "IPv6 prefix <network>/<length>\n"
4465 "AS-Path hopcount limit attribute\n"
4466 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4467
paul718e3742002-12-13 20:15:29 +00004468DEFUN (ipv6_bgp_network_route_map,
4469 ipv6_bgp_network_route_map_cmd,
4470 "network X:X::X:X/M route-map WORD",
4471 "Specify a network to announce via BGP\n"
4472 "IPv6 prefix <network>/<length>\n"
4473 "Route-map to modify the attributes\n"
4474 "Name of the route map\n")
4475{
4476 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakma41367172007-08-06 15:24:51 +00004477 bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004478}
4479
4480DEFUN (no_ipv6_bgp_network,
4481 no_ipv6_bgp_network_cmd,
4482 "no network X:X::X:X/M",
4483 NO_STR
4484 "Specify a network to announce via BGP\n"
4485 "IPv6 prefix <network>/<length>\n")
4486{
4487 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4488}
4489
4490ALIAS (no_ipv6_bgp_network,
4491 no_ipv6_bgp_network_route_map_cmd,
4492 "no network X:X::X:X/M route-map WORD",
4493 NO_STR
4494 "Specify a network to announce via BGP\n"
4495 "IPv6 prefix <network>/<length>\n"
4496 "Route-map to modify the attributes\n"
4497 "Name of the route map\n")
4498
Paul Jakma41367172007-08-06 15:24:51 +00004499ALIAS (no_ipv6_bgp_network,
4500 no_ipv6_bgp_network_ttl_cmd,
4501 "no network X:X::X:X/M pathlimit <0-255>",
4502 NO_STR
4503 "Specify a network to announce via BGP\n"
4504 "IPv6 prefix <network>/<length>\n"
4505 "AS-Path hopcount limit attribute\n"
4506 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4507
paul718e3742002-12-13 20:15:29 +00004508ALIAS (ipv6_bgp_network,
4509 old_ipv6_bgp_network_cmd,
4510 "ipv6 bgp network X:X::X:X/M",
4511 IPV6_STR
4512 BGP_STR
4513 "Specify a network to announce via BGP\n"
4514 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4515
4516ALIAS (no_ipv6_bgp_network,
4517 old_no_ipv6_bgp_network_cmd,
4518 "no ipv6 bgp network X:X::X:X/M",
4519 NO_STR
4520 IPV6_STR
4521 BGP_STR
4522 "Specify a network to announce via BGP\n"
4523 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4524#endif /* HAVE_IPV6 */
4525
4526/* Aggreagete address:
4527
4528 advertise-map Set condition to advertise attribute
4529 as-set Generate AS set path information
4530 attribute-map Set attributes of aggregate
4531 route-map Set parameters of aggregate
4532 summary-only Filter more specific routes from updates
4533 suppress-map Conditionally filter more specific routes from updates
4534 <cr>
4535 */
4536struct bgp_aggregate
4537{
4538 /* Summary-only flag. */
4539 u_char summary_only;
4540
4541 /* AS set generation. */
4542 u_char as_set;
4543
4544 /* Route-map for aggregated route. */
4545 struct route_map *map;
4546
4547 /* Suppress-count. */
4548 unsigned long count;
4549
4550 /* SAFI configuration. */
4551 safi_t safi;
4552};
4553
paul94f2b392005-06-28 12:44:16 +00004554static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004555bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004556{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004557 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004558}
4559
paul94f2b392005-06-28 12:44:16 +00004560static void
paul718e3742002-12-13 20:15:29 +00004561bgp_aggregate_free (struct bgp_aggregate *aggregate)
4562{
4563 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4564}
4565
paul94f2b392005-06-28 12:44:16 +00004566static void
paul718e3742002-12-13 20:15:29 +00004567bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4568 afi_t afi, safi_t safi, struct bgp_info *del,
4569 struct bgp_aggregate *aggregate)
4570{
4571 struct bgp_table *table;
4572 struct bgp_node *top;
4573 struct bgp_node *rn;
4574 u_char origin;
4575 struct aspath *aspath = NULL;
4576 struct aspath *asmerge = NULL;
4577 struct community *community = NULL;
4578 struct community *commerge = NULL;
4579 struct in_addr nexthop;
4580 u_int32_t med = 0;
4581 struct bgp_info *ri;
4582 struct bgp_info *new;
4583 int first = 1;
4584 unsigned long match = 0;
4585
4586 /* Record adding route's nexthop and med. */
4587 if (rinew)
4588 {
4589 nexthop = rinew->attr->nexthop;
4590 med = rinew->attr->med;
4591 }
4592
4593 /* ORIGIN attribute: If at least one route among routes that are
4594 aggregated has ORIGIN with the value INCOMPLETE, then the
4595 aggregated route must have the ORIGIN attribute with the value
4596 INCOMPLETE. Otherwise, if at least one route among routes that
4597 are aggregated has ORIGIN with the value EGP, then the aggregated
4598 route must have the origin attribute with the value EGP. In all
4599 other case the value of the ORIGIN attribute of the aggregated
4600 route is INTERNAL. */
4601 origin = BGP_ORIGIN_IGP;
4602
4603 table = bgp->rib[afi][safi];
4604
4605 top = bgp_node_get (table, p);
4606 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4607 if (rn->p.prefixlen > p->prefixlen)
4608 {
4609 match = 0;
4610
4611 for (ri = rn->info; ri; ri = ri->next)
4612 {
4613 if (BGP_INFO_HOLDDOWN (ri))
4614 continue;
4615
4616 if (del && ri == del)
4617 continue;
4618
4619 if (! rinew && first)
4620 {
4621 nexthop = ri->attr->nexthop;
4622 med = ri->attr->med;
4623 first = 0;
4624 }
4625
4626#ifdef AGGREGATE_NEXTHOP_CHECK
4627 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4628 || ri->attr->med != med)
4629 {
4630 if (aspath)
4631 aspath_free (aspath);
4632 if (community)
4633 community_free (community);
4634 bgp_unlock_node (rn);
4635 bgp_unlock_node (top);
4636 return;
4637 }
4638#endif /* AGGREGATE_NEXTHOP_CHECK */
4639
4640 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4641 {
4642 if (aggregate->summary_only)
4643 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004644 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004645 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004646 match++;
4647 }
4648
4649 aggregate->count++;
4650
4651 if (aggregate->as_set)
4652 {
4653 if (origin < ri->attr->origin)
4654 origin = ri->attr->origin;
4655
4656 if (aspath)
4657 {
4658 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4659 aspath_free (aspath);
4660 aspath = asmerge;
4661 }
4662 else
4663 aspath = aspath_dup (ri->attr->aspath);
4664
4665 if (ri->attr->community)
4666 {
4667 if (community)
4668 {
4669 commerge = community_merge (community,
4670 ri->attr->community);
4671 community = community_uniq_sort (commerge);
4672 community_free (commerge);
4673 }
4674 else
4675 community = community_dup (ri->attr->community);
4676 }
4677 }
4678 }
4679 }
4680 if (match)
4681 bgp_process (bgp, rn, afi, safi);
4682 }
4683 bgp_unlock_node (top);
4684
4685 if (rinew)
4686 {
4687 aggregate->count++;
4688
4689 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004690 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004691
4692 if (aggregate->as_set)
4693 {
4694 if (origin < rinew->attr->origin)
4695 origin = rinew->attr->origin;
4696
4697 if (aspath)
4698 {
4699 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4700 aspath_free (aspath);
4701 aspath = asmerge;
4702 }
4703 else
4704 aspath = aspath_dup (rinew->attr->aspath);
4705
4706 if (rinew->attr->community)
4707 {
4708 if (community)
4709 {
4710 commerge = community_merge (community,
4711 rinew->attr->community);
4712 community = community_uniq_sort (commerge);
4713 community_free (commerge);
4714 }
4715 else
4716 community = community_dup (rinew->attr->community);
4717 }
4718 }
4719 }
4720
4721 if (aggregate->count > 0)
4722 {
4723 rn = bgp_node_get (table, p);
4724 new = bgp_info_new ();
4725 new->type = ZEBRA_ROUTE_BGP;
4726 new->sub_type = BGP_ROUTE_AGGREGATE;
4727 new->peer = bgp->peer_self;
4728 SET_FLAG (new->flags, BGP_INFO_VALID);
4729 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4730 new->uptime = time (NULL);
4731
4732 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004733 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004734 bgp_process (bgp, rn, afi, safi);
4735 }
4736 else
4737 {
4738 if (aspath)
4739 aspath_free (aspath);
4740 if (community)
4741 community_free (community);
4742 }
4743}
4744
4745void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4746 struct bgp_aggregate *);
4747
4748void
4749bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4750 struct bgp_info *ri, afi_t afi, safi_t safi)
4751{
4752 struct bgp_node *child;
4753 struct bgp_node *rn;
4754 struct bgp_aggregate *aggregate;
4755
4756 /* MPLS-VPN aggregation is not yet supported. */
4757 if (safi == SAFI_MPLS_VPN)
4758 return;
4759
4760 if (p->prefixlen == 0)
4761 return;
4762
4763 if (BGP_INFO_HOLDDOWN (ri))
4764 return;
4765
4766 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4767
4768 /* Aggregate address configuration check. */
4769 for (rn = child; rn; rn = rn->parent)
4770 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4771 {
4772 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004773 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004774 }
4775 bgp_unlock_node (child);
4776}
4777
4778void
4779bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4780 struct bgp_info *del, afi_t afi, safi_t safi)
4781{
4782 struct bgp_node *child;
4783 struct bgp_node *rn;
4784 struct bgp_aggregate *aggregate;
4785
4786 /* MPLS-VPN aggregation is not yet supported. */
4787 if (safi == SAFI_MPLS_VPN)
4788 return;
4789
4790 if (p->prefixlen == 0)
4791 return;
4792
4793 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4794
4795 /* Aggregate address configuration check. */
4796 for (rn = child; rn; rn = rn->parent)
4797 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4798 {
4799 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004800 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004801 }
4802 bgp_unlock_node (child);
4803}
4804
paul94f2b392005-06-28 12:44:16 +00004805static void
paul718e3742002-12-13 20:15:29 +00004806bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4807 struct bgp_aggregate *aggregate)
4808{
4809 struct bgp_table *table;
4810 struct bgp_node *top;
4811 struct bgp_node *rn;
4812 struct bgp_info *new;
4813 struct bgp_info *ri;
4814 unsigned long match;
4815 u_char origin = BGP_ORIGIN_IGP;
4816 struct aspath *aspath = NULL;
4817 struct aspath *asmerge = NULL;
4818 struct community *community = NULL;
4819 struct community *commerge = NULL;
4820
4821 table = bgp->rib[afi][safi];
4822
4823 /* Sanity check. */
4824 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4825 return;
4826 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4827 return;
4828
4829 /* If routes exists below this node, generate aggregate routes. */
4830 top = bgp_node_get (table, p);
4831 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4832 if (rn->p.prefixlen > p->prefixlen)
4833 {
4834 match = 0;
4835
4836 for (ri = rn->info; ri; ri = ri->next)
4837 {
4838 if (BGP_INFO_HOLDDOWN (ri))
4839 continue;
4840
4841 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4842 {
4843 /* summary-only aggregate route suppress aggregated
4844 route announcement. */
4845 if (aggregate->summary_only)
4846 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004847 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004848 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004849 match++;
4850 }
4851 /* as-set aggregate route generate origin, as path,
4852 community aggregation. */
4853 if (aggregate->as_set)
4854 {
4855 if (origin < ri->attr->origin)
4856 origin = ri->attr->origin;
4857
4858 if (aspath)
4859 {
4860 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4861 aspath_free (aspath);
4862 aspath = asmerge;
4863 }
4864 else
4865 aspath = aspath_dup (ri->attr->aspath);
4866
4867 if (ri->attr->community)
4868 {
4869 if (community)
4870 {
4871 commerge = community_merge (community,
4872 ri->attr->community);
4873 community = community_uniq_sort (commerge);
4874 community_free (commerge);
4875 }
4876 else
4877 community = community_dup (ri->attr->community);
4878 }
4879 }
4880 aggregate->count++;
4881 }
4882 }
4883
4884 /* If this node is suppressed, process the change. */
4885 if (match)
4886 bgp_process (bgp, rn, afi, safi);
4887 }
4888 bgp_unlock_node (top);
4889
4890 /* Add aggregate route to BGP table. */
4891 if (aggregate->count)
4892 {
4893 rn = bgp_node_get (table, p);
4894
4895 new = bgp_info_new ();
4896 new->type = ZEBRA_ROUTE_BGP;
4897 new->sub_type = BGP_ROUTE_AGGREGATE;
4898 new->peer = bgp->peer_self;
4899 SET_FLAG (new->flags, BGP_INFO_VALID);
4900 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4901 new->uptime = time (NULL);
4902
4903 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004904 bgp_unlock_node (rn);
4905
paul718e3742002-12-13 20:15:29 +00004906 /* Process change. */
4907 bgp_process (bgp, rn, afi, safi);
4908 }
4909}
4910
4911void
4912bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4913 safi_t safi, struct bgp_aggregate *aggregate)
4914{
4915 struct bgp_table *table;
4916 struct bgp_node *top;
4917 struct bgp_node *rn;
4918 struct bgp_info *ri;
4919 unsigned long match;
4920
4921 table = bgp->rib[afi][safi];
4922
4923 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4924 return;
4925 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4926 return;
4927
4928 /* If routes exists below this node, generate aggregate routes. */
4929 top = bgp_node_get (table, p);
4930 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4931 if (rn->p.prefixlen > p->prefixlen)
4932 {
4933 match = 0;
4934
4935 for (ri = rn->info; ri; ri = ri->next)
4936 {
4937 if (BGP_INFO_HOLDDOWN (ri))
4938 continue;
4939
4940 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4941 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004942 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004943 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004944 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004945
Paul Jakmafb982c22007-05-04 20:15:47 +00004946 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004947 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004948 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004949 match++;
4950 }
4951 }
4952 aggregate->count--;
4953 }
4954 }
4955
Paul Jakmafb982c22007-05-04 20:15:47 +00004956 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004957 if (match)
4958 bgp_process (bgp, rn, afi, safi);
4959 }
4960 bgp_unlock_node (top);
4961
4962 /* Delete aggregate route from BGP table. */
4963 rn = bgp_node_get (table, p);
4964
4965 for (ri = rn->info; ri; ri = ri->next)
4966 if (ri->peer == bgp->peer_self
4967 && ri->type == ZEBRA_ROUTE_BGP
4968 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4969 break;
4970
4971 /* Withdraw static BGP route from routing table. */
4972 if (ri)
4973 {
paul718e3742002-12-13 20:15:29 +00004974 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004975 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004976 }
4977
4978 /* Unlock bgp_node_lookup. */
4979 bgp_unlock_node (rn);
4980}
4981
4982/* Aggregate route attribute. */
4983#define AGGREGATE_SUMMARY_ONLY 1
4984#define AGGREGATE_AS_SET 1
4985
paul94f2b392005-06-28 12:44:16 +00004986static int
paulfd79ac92004-10-13 05:06:08 +00004987bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4988 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004989 u_char summary_only, u_char as_set)
4990{
4991 int ret;
4992 struct prefix p;
4993 struct bgp_node *rn;
4994 struct bgp *bgp;
4995 struct bgp_aggregate *aggregate;
4996
4997 /* Convert string to prefix structure. */
4998 ret = str2prefix (prefix_str, &p);
4999 if (!ret)
5000 {
5001 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5002 return CMD_WARNING;
5003 }
5004 apply_mask (&p);
5005
5006 /* Get BGP structure. */
5007 bgp = vty->index;
5008
5009 /* Old configuration check. */
5010 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5011
5012 if (rn->info)
5013 {
5014 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
5015 bgp_unlock_node (rn);
5016 return CMD_WARNING;
5017 }
5018
5019 /* Make aggregate address structure. */
5020 aggregate = bgp_aggregate_new ();
5021 aggregate->summary_only = summary_only;
5022 aggregate->as_set = as_set;
5023 aggregate->safi = safi;
5024 rn->info = aggregate;
5025
5026 /* Aggregate address insert into BGP routing table. */
5027 if (safi & SAFI_UNICAST)
5028 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5029 if (safi & SAFI_MULTICAST)
5030 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5031
5032 return CMD_SUCCESS;
5033}
5034
paul94f2b392005-06-28 12:44:16 +00005035static int
paulfd79ac92004-10-13 05:06:08 +00005036bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5037 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00005038{
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_lookup (bgp->aggregate[afi][safi], &p);
5059 if (! rn)
5060 {
5061 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5062 VTY_NEWLINE);
5063 return CMD_WARNING;
5064 }
5065
5066 aggregate = rn->info;
5067 if (aggregate->safi & SAFI_UNICAST)
5068 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5069 if (aggregate->safi & SAFI_MULTICAST)
5070 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5071
5072 /* Unlock aggregate address configuration. */
5073 rn->info = NULL;
5074 bgp_aggregate_free (aggregate);
5075 bgp_unlock_node (rn);
5076 bgp_unlock_node (rn);
5077
5078 return CMD_SUCCESS;
5079}
5080
5081DEFUN (aggregate_address,
5082 aggregate_address_cmd,
5083 "aggregate-address A.B.C.D/M",
5084 "Configure BGP aggregate entries\n"
5085 "Aggregate prefix\n")
5086{
5087 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5088}
5089
5090DEFUN (aggregate_address_mask,
5091 aggregate_address_mask_cmd,
5092 "aggregate-address A.B.C.D A.B.C.D",
5093 "Configure BGP aggregate entries\n"
5094 "Aggregate address\n"
5095 "Aggregate mask\n")
5096{
5097 int ret;
5098 char prefix_str[BUFSIZ];
5099
5100 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5101
5102 if (! ret)
5103 {
5104 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5105 return CMD_WARNING;
5106 }
5107
5108 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5109 0, 0);
5110}
5111
5112DEFUN (aggregate_address_summary_only,
5113 aggregate_address_summary_only_cmd,
5114 "aggregate-address A.B.C.D/M summary-only",
5115 "Configure BGP aggregate entries\n"
5116 "Aggregate prefix\n"
5117 "Filter more specific routes from updates\n")
5118{
5119 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5120 AGGREGATE_SUMMARY_ONLY, 0);
5121}
5122
5123DEFUN (aggregate_address_mask_summary_only,
5124 aggregate_address_mask_summary_only_cmd,
5125 "aggregate-address A.B.C.D A.B.C.D summary-only",
5126 "Configure BGP aggregate entries\n"
5127 "Aggregate address\n"
5128 "Aggregate mask\n"
5129 "Filter more specific routes from updates\n")
5130{
5131 int ret;
5132 char prefix_str[BUFSIZ];
5133
5134 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5135
5136 if (! ret)
5137 {
5138 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5139 return CMD_WARNING;
5140 }
5141
5142 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5143 AGGREGATE_SUMMARY_ONLY, 0);
5144}
5145
5146DEFUN (aggregate_address_as_set,
5147 aggregate_address_as_set_cmd,
5148 "aggregate-address A.B.C.D/M as-set",
5149 "Configure BGP aggregate entries\n"
5150 "Aggregate prefix\n"
5151 "Generate AS set path information\n")
5152{
5153 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5154 0, AGGREGATE_AS_SET);
5155}
5156
5157DEFUN (aggregate_address_mask_as_set,
5158 aggregate_address_mask_as_set_cmd,
5159 "aggregate-address A.B.C.D A.B.C.D as-set",
5160 "Configure BGP aggregate entries\n"
5161 "Aggregate address\n"
5162 "Aggregate mask\n"
5163 "Generate AS set path information\n")
5164{
5165 int ret;
5166 char prefix_str[BUFSIZ];
5167
5168 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5169
5170 if (! ret)
5171 {
5172 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5173 return CMD_WARNING;
5174 }
5175
5176 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5177 0, AGGREGATE_AS_SET);
5178}
5179
5180
5181DEFUN (aggregate_address_as_set_summary,
5182 aggregate_address_as_set_summary_cmd,
5183 "aggregate-address A.B.C.D/M as-set summary-only",
5184 "Configure BGP aggregate entries\n"
5185 "Aggregate prefix\n"
5186 "Generate AS set path information\n"
5187 "Filter more specific routes from updates\n")
5188{
5189 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5190 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5191}
5192
5193ALIAS (aggregate_address_as_set_summary,
5194 aggregate_address_summary_as_set_cmd,
5195 "aggregate-address A.B.C.D/M summary-only as-set",
5196 "Configure BGP aggregate entries\n"
5197 "Aggregate prefix\n"
5198 "Filter more specific routes from updates\n"
5199 "Generate AS set path information\n")
5200
5201DEFUN (aggregate_address_mask_as_set_summary,
5202 aggregate_address_mask_as_set_summary_cmd,
5203 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5204 "Configure BGP aggregate entries\n"
5205 "Aggregate address\n"
5206 "Aggregate mask\n"
5207 "Generate AS set path information\n"
5208 "Filter more specific routes from updates\n")
5209{
5210 int ret;
5211 char prefix_str[BUFSIZ];
5212
5213 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5214
5215 if (! ret)
5216 {
5217 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5218 return CMD_WARNING;
5219 }
5220
5221 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5222 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5223}
5224
5225ALIAS (aggregate_address_mask_as_set_summary,
5226 aggregate_address_mask_summary_as_set_cmd,
5227 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5228 "Configure BGP aggregate entries\n"
5229 "Aggregate address\n"
5230 "Aggregate mask\n"
5231 "Filter more specific routes from updates\n"
5232 "Generate AS set path information\n")
5233
5234DEFUN (no_aggregate_address,
5235 no_aggregate_address_cmd,
5236 "no aggregate-address A.B.C.D/M",
5237 NO_STR
5238 "Configure BGP aggregate entries\n"
5239 "Aggregate prefix\n")
5240{
5241 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5242}
5243
5244ALIAS (no_aggregate_address,
5245 no_aggregate_address_summary_only_cmd,
5246 "no aggregate-address A.B.C.D/M summary-only",
5247 NO_STR
5248 "Configure BGP aggregate entries\n"
5249 "Aggregate prefix\n"
5250 "Filter more specific routes from updates\n")
5251
5252ALIAS (no_aggregate_address,
5253 no_aggregate_address_as_set_cmd,
5254 "no aggregate-address A.B.C.D/M as-set",
5255 NO_STR
5256 "Configure BGP aggregate entries\n"
5257 "Aggregate prefix\n"
5258 "Generate AS set path information\n")
5259
5260ALIAS (no_aggregate_address,
5261 no_aggregate_address_as_set_summary_cmd,
5262 "no aggregate-address A.B.C.D/M as-set summary-only",
5263 NO_STR
5264 "Configure BGP aggregate entries\n"
5265 "Aggregate prefix\n"
5266 "Generate AS set path information\n"
5267 "Filter more specific routes from updates\n")
5268
5269ALIAS (no_aggregate_address,
5270 no_aggregate_address_summary_as_set_cmd,
5271 "no aggregate-address A.B.C.D/M summary-only as-set",
5272 NO_STR
5273 "Configure BGP aggregate entries\n"
5274 "Aggregate prefix\n"
5275 "Filter more specific routes from updates\n"
5276 "Generate AS set path information\n")
5277
5278DEFUN (no_aggregate_address_mask,
5279 no_aggregate_address_mask_cmd,
5280 "no aggregate-address A.B.C.D A.B.C.D",
5281 NO_STR
5282 "Configure BGP aggregate entries\n"
5283 "Aggregate address\n"
5284 "Aggregate mask\n")
5285{
5286 int ret;
5287 char prefix_str[BUFSIZ];
5288
5289 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5290
5291 if (! ret)
5292 {
5293 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5294 return CMD_WARNING;
5295 }
5296
5297 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5298}
5299
5300ALIAS (no_aggregate_address_mask,
5301 no_aggregate_address_mask_summary_only_cmd,
5302 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5303 NO_STR
5304 "Configure BGP aggregate entries\n"
5305 "Aggregate address\n"
5306 "Aggregate mask\n"
5307 "Filter more specific routes from updates\n")
5308
5309ALIAS (no_aggregate_address_mask,
5310 no_aggregate_address_mask_as_set_cmd,
5311 "no aggregate-address A.B.C.D A.B.C.D as-set",
5312 NO_STR
5313 "Configure BGP aggregate entries\n"
5314 "Aggregate address\n"
5315 "Aggregate mask\n"
5316 "Generate AS set path information\n")
5317
5318ALIAS (no_aggregate_address_mask,
5319 no_aggregate_address_mask_as_set_summary_cmd,
5320 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5321 NO_STR
5322 "Configure BGP aggregate entries\n"
5323 "Aggregate address\n"
5324 "Aggregate mask\n"
5325 "Generate AS set path information\n"
5326 "Filter more specific routes from updates\n")
5327
5328ALIAS (no_aggregate_address_mask,
5329 no_aggregate_address_mask_summary_as_set_cmd,
5330 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5331 NO_STR
5332 "Configure BGP aggregate entries\n"
5333 "Aggregate address\n"
5334 "Aggregate mask\n"
5335 "Filter more specific routes from updates\n"
5336 "Generate AS set path information\n")
5337
5338#ifdef HAVE_IPV6
5339DEFUN (ipv6_aggregate_address,
5340 ipv6_aggregate_address_cmd,
5341 "aggregate-address X:X::X:X/M",
5342 "Configure BGP aggregate entries\n"
5343 "Aggregate prefix\n")
5344{
5345 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5346}
5347
5348DEFUN (ipv6_aggregate_address_summary_only,
5349 ipv6_aggregate_address_summary_only_cmd,
5350 "aggregate-address X:X::X:X/M summary-only",
5351 "Configure BGP aggregate entries\n"
5352 "Aggregate prefix\n"
5353 "Filter more specific routes from updates\n")
5354{
5355 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5356 AGGREGATE_SUMMARY_ONLY, 0);
5357}
5358
5359DEFUN (no_ipv6_aggregate_address,
5360 no_ipv6_aggregate_address_cmd,
5361 "no aggregate-address X:X::X:X/M",
5362 NO_STR
5363 "Configure BGP aggregate entries\n"
5364 "Aggregate prefix\n")
5365{
5366 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5367}
5368
5369DEFUN (no_ipv6_aggregate_address_summary_only,
5370 no_ipv6_aggregate_address_summary_only_cmd,
5371 "no aggregate-address X:X::X:X/M summary-only",
5372 NO_STR
5373 "Configure BGP aggregate entries\n"
5374 "Aggregate prefix\n"
5375 "Filter more specific routes from updates\n")
5376{
5377 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5378}
5379
5380ALIAS (ipv6_aggregate_address,
5381 old_ipv6_aggregate_address_cmd,
5382 "ipv6 bgp aggregate-address X:X::X:X/M",
5383 IPV6_STR
5384 BGP_STR
5385 "Configure BGP aggregate entries\n"
5386 "Aggregate prefix\n")
5387
5388ALIAS (ipv6_aggregate_address_summary_only,
5389 old_ipv6_aggregate_address_summary_only_cmd,
5390 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5391 IPV6_STR
5392 BGP_STR
5393 "Configure BGP aggregate entries\n"
5394 "Aggregate prefix\n"
5395 "Filter more specific routes from updates\n")
5396
5397ALIAS (no_ipv6_aggregate_address,
5398 old_no_ipv6_aggregate_address_cmd,
5399 "no ipv6 bgp aggregate-address X:X::X:X/M",
5400 NO_STR
5401 IPV6_STR
5402 BGP_STR
5403 "Configure BGP aggregate entries\n"
5404 "Aggregate prefix\n")
5405
5406ALIAS (no_ipv6_aggregate_address_summary_only,
5407 old_no_ipv6_aggregate_address_summary_only_cmd,
5408 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5409 NO_STR
5410 IPV6_STR
5411 BGP_STR
5412 "Configure BGP aggregate entries\n"
5413 "Aggregate prefix\n"
5414 "Filter more specific routes from updates\n")
5415#endif /* HAVE_IPV6 */
5416
5417/* Redistribute route treatment. */
5418void
5419bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5420 u_int32_t metric, u_char type)
5421{
5422 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005423 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005424 struct bgp_info *new;
5425 struct bgp_info *bi;
5426 struct bgp_info info;
5427 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005428 struct attr attr = { 0 };
5429 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005430 struct attr *new_attr;
5431 afi_t afi;
5432 int ret;
5433
5434 /* Make default attribute. */
5435 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5436 if (nexthop)
5437 attr.nexthop = *nexthop;
5438
5439 attr.med = metric;
5440 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5441
paul1eb8ef22005-04-07 07:30:20 +00005442 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005443 {
5444 afi = family2afi (p->family);
5445
5446 if (bgp->redist[afi][type])
5447 {
5448 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005449 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005450
5451 if (bgp->redist_metric_flag[afi][type])
5452 attr_new.med = bgp->redist_metric[afi][type];
5453
5454 /* Apply route-map. */
5455 if (bgp->rmap[afi][type].map)
5456 {
5457 info.peer = bgp->peer_self;
5458 info.attr = &attr_new;
5459
paulfee0f4c2004-09-13 05:12:46 +00005460 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5461
paul718e3742002-12-13 20:15:29 +00005462 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5463 &info);
paulfee0f4c2004-09-13 05:12:46 +00005464
5465 bgp->peer_self->rmap_type = 0;
5466
paul718e3742002-12-13 20:15:29 +00005467 if (ret == RMAP_DENYMATCH)
5468 {
5469 /* Free uninterned attribute. */
5470 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005471 bgp_attr_extra_free (&attr_new);
5472
paul718e3742002-12-13 20:15:29 +00005473 /* Unintern original. */
5474 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005475 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005476 bgp_redistribute_delete (p, type);
5477 return;
5478 }
5479 }
5480
Paul Jakmafb982c22007-05-04 20:15:47 +00005481 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5482 afi, SAFI_UNICAST, p, NULL);
5483
paul718e3742002-12-13 20:15:29 +00005484 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005485 bgp_attr_extra_free (&attr_new);
5486
paul718e3742002-12-13 20:15:29 +00005487 for (bi = bn->info; bi; bi = bi->next)
5488 if (bi->peer == bgp->peer_self
5489 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5490 break;
5491
5492 if (bi)
5493 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005494 if (attrhash_cmp (bi->attr, new_attr) &&
5495 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005496 {
5497 bgp_attr_unintern (new_attr);
5498 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005499 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005500 bgp_unlock_node (bn);
5501 return;
5502 }
5503 else
5504 {
5505 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005506 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005507
5508 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005509 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5510 bgp_info_restore(bn, bi);
5511 else
5512 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005513 bgp_attr_unintern (bi->attr);
5514 bi->attr = new_attr;
5515 bi->uptime = time (NULL);
5516
5517 /* Process change. */
5518 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5519 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5520 bgp_unlock_node (bn);
5521 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005522 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005523 return;
5524 }
5525 }
5526
5527 new = bgp_info_new ();
5528 new->type = type;
5529 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5530 new->peer = bgp->peer_self;
5531 SET_FLAG (new->flags, BGP_INFO_VALID);
5532 new->attr = new_attr;
5533 new->uptime = time (NULL);
5534
5535 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5536 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005537 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005538 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5539 }
5540 }
5541
5542 /* Unintern original. */
5543 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005544 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005545}
5546
5547void
5548bgp_redistribute_delete (struct prefix *p, u_char type)
5549{
5550 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005551 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005552 afi_t afi;
5553 struct bgp_node *rn;
5554 struct bgp_info *ri;
5555
paul1eb8ef22005-04-07 07:30:20 +00005556 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005557 {
5558 afi = family2afi (p->family);
5559
5560 if (bgp->redist[afi][type])
5561 {
paulfee0f4c2004-09-13 05:12:46 +00005562 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005563
5564 for (ri = rn->info; ri; ri = ri->next)
5565 if (ri->peer == bgp->peer_self
5566 && ri->type == type)
5567 break;
5568
5569 if (ri)
5570 {
5571 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005572 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005573 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005574 }
5575 bgp_unlock_node (rn);
5576 }
5577 }
5578}
5579
5580/* Withdraw specified route type's route. */
5581void
5582bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5583{
5584 struct bgp_node *rn;
5585 struct bgp_info *ri;
5586 struct bgp_table *table;
5587
5588 table = bgp->rib[afi][SAFI_UNICAST];
5589
5590 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5591 {
5592 for (ri = rn->info; ri; ri = ri->next)
5593 if (ri->peer == bgp->peer_self
5594 && ri->type == type)
5595 break;
5596
5597 if (ri)
5598 {
5599 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005600 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005601 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005602 }
5603 }
5604}
5605
5606/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005607static void
paul718e3742002-12-13 20:15:29 +00005608route_vty_out_route (struct prefix *p, struct vty *vty)
5609{
5610 int len;
5611 u_int32_t destination;
5612 char buf[BUFSIZ];
5613
5614 if (p->family == AF_INET)
5615 {
5616 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5617 destination = ntohl (p->u.prefix4.s_addr);
5618
5619 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5620 || (IN_CLASSB (destination) && p->prefixlen == 16)
5621 || (IN_CLASSA (destination) && p->prefixlen == 8)
5622 || p->u.prefix4.s_addr == 0)
5623 {
5624 /* When mask is natural, mask is not displayed. */
5625 }
5626 else
5627 len += vty_out (vty, "/%d", p->prefixlen);
5628 }
5629 else
5630 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5631 p->prefixlen);
5632
5633 len = 17 - len;
5634 if (len < 1)
5635 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5636 else
5637 vty_out (vty, "%*s", len, " ");
5638}
5639
paul718e3742002-12-13 20:15:29 +00005640enum bgp_display_type
5641{
5642 normal_list,
5643};
5644
paulb40d9392005-08-22 22:34:41 +00005645/* Print the short form route status for a bgp_info */
5646static void
5647route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005648{
paulb40d9392005-08-22 22:34:41 +00005649 /* Route status display. */
5650 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5651 vty_out (vty, "R");
5652 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005653 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005654 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005655 vty_out (vty, "s");
5656 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5657 vty_out (vty, "*");
5658 else
5659 vty_out (vty, " ");
5660
5661 /* Selected */
5662 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5663 vty_out (vty, "h");
5664 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5665 vty_out (vty, "d");
5666 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5667 vty_out (vty, ">");
5668 else
5669 vty_out (vty, " ");
5670
5671 /* Internal route. */
5672 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5673 vty_out (vty, "i");
5674 else
paulb40d9392005-08-22 22:34:41 +00005675 vty_out (vty, " ");
5676}
5677
5678/* called from terminal list command */
5679void
5680route_vty_out (struct vty *vty, struct prefix *p,
5681 struct bgp_info *binfo, int display, safi_t safi)
5682{
5683 struct attr *attr;
5684
5685 /* short status lead text */
5686 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005687
5688 /* print prefix and mask */
5689 if (! display)
5690 route_vty_out_route (p, vty);
5691 else
5692 vty_out (vty, "%*s", 17, " ");
5693
5694 /* Print attribute */
5695 attr = binfo->attr;
5696 if (attr)
5697 {
5698 if (p->family == AF_INET)
5699 {
5700 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005701 vty_out (vty, "%-16s",
5702 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005703 else
5704 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5705 }
5706#ifdef HAVE_IPV6
5707 else if (p->family == AF_INET6)
5708 {
5709 int len;
5710 char buf[BUFSIZ];
5711
5712 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005713 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5714 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005715 len = 16 - len;
5716 if (len < 1)
5717 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5718 else
5719 vty_out (vty, "%*s", len, " ");
5720 }
5721#endif /* HAVE_IPV6 */
5722
5723 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5724 vty_out (vty, "%10d", attr->med);
5725 else
5726 vty_out (vty, " ");
5727
5728 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5729 vty_out (vty, "%7d", attr->local_pref);
5730 else
5731 vty_out (vty, " ");
5732
Paul Jakmafb982c22007-05-04 20:15:47 +00005733 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005734
Paul Jakmab2518c12006-05-12 23:48:40 +00005735 /* Print aspath */
5736 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005737 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005738
Paul Jakmab2518c12006-05-12 23:48:40 +00005739 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005740 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005741 }
paul718e3742002-12-13 20:15:29 +00005742 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005743}
5744
5745/* called from terminal list command */
5746void
5747route_vty_out_tmp (struct vty *vty, struct prefix *p,
5748 struct attr *attr, safi_t safi)
5749{
5750 /* Route status display. */
5751 vty_out (vty, "*");
5752 vty_out (vty, ">");
5753 vty_out (vty, " ");
5754
5755 /* print prefix and mask */
5756 route_vty_out_route (p, vty);
5757
5758 /* Print attribute */
5759 if (attr)
5760 {
5761 if (p->family == AF_INET)
5762 {
5763 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005764 vty_out (vty, "%-16s",
5765 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005766 else
5767 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5768 }
5769#ifdef HAVE_IPV6
5770 else if (p->family == AF_INET6)
5771 {
5772 int len;
5773 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005774
5775 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005776
5777 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005778 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5779 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005780 len = 16 - len;
5781 if (len < 1)
5782 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5783 else
5784 vty_out (vty, "%*s", len, " ");
5785 }
5786#endif /* HAVE_IPV6 */
5787
5788 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5789 vty_out (vty, "%10d", attr->med);
5790 else
5791 vty_out (vty, " ");
5792
5793 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5794 vty_out (vty, "%7d", attr->local_pref);
5795 else
5796 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005797
5798 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5799
Paul Jakmab2518c12006-05-12 23:48:40 +00005800 /* Print aspath */
5801 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005802 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005803
Paul Jakmab2518c12006-05-12 23:48:40 +00005804 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005805 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005806 }
paul718e3742002-12-13 20:15:29 +00005807
5808 vty_out (vty, "%s", VTY_NEWLINE);
5809}
5810
ajs5a646652004-11-05 01:25:55 +00005811void
paul718e3742002-12-13 20:15:29 +00005812route_vty_out_tag (struct vty *vty, struct prefix *p,
5813 struct bgp_info *binfo, int display, safi_t safi)
5814{
5815 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005816 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005817
5818 if (!binfo->extra)
5819 return;
5820
paulb40d9392005-08-22 22:34:41 +00005821 /* short status lead text */
5822 route_vty_short_status_out (vty, binfo);
5823
paul718e3742002-12-13 20:15:29 +00005824 /* print prefix and mask */
5825 if (! display)
5826 route_vty_out_route (p, vty);
5827 else
5828 vty_out (vty, "%*s", 17, " ");
5829
5830 /* Print attribute */
5831 attr = binfo->attr;
5832 if (attr)
5833 {
5834 if (p->family == AF_INET)
5835 {
5836 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005837 vty_out (vty, "%-16s",
5838 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005839 else
5840 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5841 }
5842#ifdef HAVE_IPV6
5843 else if (p->family == AF_INET6)
5844 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005845 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005846 char buf[BUFSIZ];
5847 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005848 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005849 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005850 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5851 buf, BUFSIZ));
5852 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005853 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005854 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5855 buf, BUFSIZ),
5856 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5857 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005858
5859 }
5860#endif /* HAVE_IPV6 */
5861 }
5862
Paul Jakmafb982c22007-05-04 20:15:47 +00005863 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005864
5865 vty_out (vty, "notag/%d", label);
5866
5867 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005868}
5869
5870/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005871static void
paul718e3742002-12-13 20:15:29 +00005872damp_route_vty_out (struct vty *vty, struct prefix *p,
5873 struct bgp_info *binfo, int display, safi_t safi)
5874{
5875 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005876 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005877 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005878
paulb40d9392005-08-22 22:34:41 +00005879 /* short status lead text */
5880 route_vty_short_status_out (vty, binfo);
5881
paul718e3742002-12-13 20:15:29 +00005882 /* print prefix and mask */
5883 if (! display)
5884 route_vty_out_route (p, vty);
5885 else
5886 vty_out (vty, "%*s", 17, " ");
5887
5888 len = vty_out (vty, "%s", binfo->peer->host);
5889 len = 17 - len;
5890 if (len < 1)
5891 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5892 else
5893 vty_out (vty, "%*s", len, " ");
5894
Chris Caputo50aef6f2009-06-23 06:06:49 +00005895 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005896
5897 /* Print attribute */
5898 attr = binfo->attr;
5899 if (attr)
5900 {
5901 /* Print aspath */
5902 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005903 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005904
5905 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005906 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005907 }
5908 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005909}
5910
paul718e3742002-12-13 20:15:29 +00005911/* flap route */
ajs5a646652004-11-05 01:25:55 +00005912static void
paul718e3742002-12-13 20:15:29 +00005913flap_route_vty_out (struct vty *vty, struct prefix *p,
5914 struct bgp_info *binfo, int display, safi_t safi)
5915{
5916 struct attr *attr;
5917 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005918 char timebuf[BGP_UPTIME_LEN];
5919 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005920
5921 if (!binfo->extra)
5922 return;
5923
5924 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005925
paulb40d9392005-08-22 22:34:41 +00005926 /* short status lead text */
5927 route_vty_short_status_out (vty, binfo);
5928
paul718e3742002-12-13 20:15:29 +00005929 /* print prefix and mask */
5930 if (! display)
5931 route_vty_out_route (p, vty);
5932 else
5933 vty_out (vty, "%*s", 17, " ");
5934
5935 len = vty_out (vty, "%s", binfo->peer->host);
5936 len = 16 - len;
5937 if (len < 1)
5938 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5939 else
5940 vty_out (vty, "%*s", len, " ");
5941
5942 len = vty_out (vty, "%d", bdi->flap);
5943 len = 5 - len;
5944 if (len < 1)
5945 vty_out (vty, " ");
5946 else
5947 vty_out (vty, "%*s ", len, " ");
5948
5949 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5950 timebuf, BGP_UPTIME_LEN));
5951
5952 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5953 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005954 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005955 else
5956 vty_out (vty, "%*s ", 8, " ");
5957
5958 /* Print attribute */
5959 attr = binfo->attr;
5960 if (attr)
5961 {
5962 /* Print aspath */
5963 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005964 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005965
5966 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005967 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005968 }
5969 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005970}
5971
paul94f2b392005-06-28 12:44:16 +00005972static void
paul718e3742002-12-13 20:15:29 +00005973route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5974 struct bgp_info *binfo, afi_t afi, safi_t safi)
5975{
5976 char buf[INET6_ADDRSTRLEN];
5977 char buf1[BUFSIZ];
5978 struct attr *attr;
5979 int sockunion_vty_out (struct vty *, union sockunion *);
5980
5981 attr = binfo->attr;
5982
5983 if (attr)
5984 {
5985 /* Line1 display AS-path, Aggregator */
5986 if (attr->aspath)
5987 {
5988 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005989 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005990 vty_out (vty, "Local");
5991 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005992 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005993 }
5994
paulb40d9392005-08-22 22:34:41 +00005995 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5996 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005997 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5998 vty_out (vty, ", (stale)");
5999 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006000 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006001 attr->extra->aggregator_as,
6002 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006003 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6004 vty_out (vty, ", (Received from a RR-client)");
6005 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6006 vty_out (vty, ", (Received from a RS-client)");
6007 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6008 vty_out (vty, ", (history entry)");
6009 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6010 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006011 vty_out (vty, "%s", VTY_NEWLINE);
6012
6013 /* Line2 display Next-hop, Neighbor, Router-id */
6014 if (p->family == AF_INET)
6015 {
6016 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006017 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006018 inet_ntoa (attr->nexthop));
6019 }
6020#ifdef HAVE_IPV6
6021 else
6022 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006023 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006024 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006025 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006026 buf, INET6_ADDRSTRLEN));
6027 }
6028#endif /* HAVE_IPV6 */
6029
6030 if (binfo->peer == bgp->peer_self)
6031 {
6032 vty_out (vty, " from %s ",
6033 p->family == AF_INET ? "0.0.0.0" : "::");
6034 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6035 }
6036 else
6037 {
6038 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6039 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006040 else if (binfo->extra && binfo->extra->igpmetric)
6041 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006042 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006043 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006044 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006045 else
6046 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6047 }
6048 vty_out (vty, "%s", VTY_NEWLINE);
6049
6050#ifdef HAVE_IPV6
6051 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006052 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006053 {
6054 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006055 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006056 buf, INET6_ADDRSTRLEN),
6057 VTY_NEWLINE);
6058 }
6059#endif /* HAVE_IPV6 */
6060
6061 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6062 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6063
6064 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6065 vty_out (vty, ", metric %d", attr->med);
6066
6067 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6068 vty_out (vty, ", localpref %d", attr->local_pref);
6069 else
6070 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6071
Paul Jakmafb982c22007-05-04 20:15:47 +00006072 if (attr->extra && attr->extra->weight != 0)
6073 vty_out (vty, ", weight %d", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006074
6075 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6076 vty_out (vty, ", valid");
6077
6078 if (binfo->peer != bgp->peer_self)
6079 {
6080 if (binfo->peer->as == binfo->peer->local_as)
6081 vty_out (vty, ", internal");
6082 else
6083 vty_out (vty, ", %s",
6084 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6085 }
6086 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6087 vty_out (vty, ", aggregated, local");
6088 else if (binfo->type != ZEBRA_ROUTE_BGP)
6089 vty_out (vty, ", sourced");
6090 else
6091 vty_out (vty, ", sourced, local");
6092
6093 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6094 vty_out (vty, ", atomic-aggregate");
6095
6096 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6097 vty_out (vty, ", best");
6098
6099 vty_out (vty, "%s", VTY_NEWLINE);
6100
6101 /* Line 4 display Community */
6102 if (attr->community)
6103 vty_out (vty, " Community: %s%s", attr->community->str,
6104 VTY_NEWLINE);
6105
6106 /* Line 5 display Extended-community */
6107 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006108 vty_out (vty, " Extended Community: %s%s",
6109 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006110
6111 /* Line 6 display Originator, Cluster-id */
6112 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6113 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6114 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006115 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006116 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006117 vty_out (vty, " Originator: %s",
6118 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006119
6120 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6121 {
6122 int i;
6123 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006124 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6125 vty_out (vty, "%s ",
6126 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006127 }
6128 vty_out (vty, "%s", VTY_NEWLINE);
6129 }
Paul Jakma41367172007-08-06 15:24:51 +00006130
6131 /* 7: AS Pathlimit */
6132 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6133 {
6134
6135 vty_out (vty, " AS-Pathlimit: %u",
6136 attr->pathlimit.ttl);
6137 if (attr->pathlimit.as)
6138 vty_out (vty, " (%u)", attr->pathlimit.as);
6139 vty_out (vty, "%s", VTY_NEWLINE);
6140 }
6141
Paul Jakmafb982c22007-05-04 20:15:47 +00006142 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006143 bgp_damp_info_vty (vty, binfo);
6144
6145 /* Line 7 display Uptime */
6146 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
6147 }
6148 vty_out (vty, "%s", VTY_NEWLINE);
6149}
6150
paulb40d9392005-08-22 22:34:41 +00006151#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 +00006152#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006153#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6154#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6155#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6156
6157enum bgp_show_type
6158{
6159 bgp_show_type_normal,
6160 bgp_show_type_regexp,
6161 bgp_show_type_prefix_list,
6162 bgp_show_type_filter_list,
6163 bgp_show_type_route_map,
6164 bgp_show_type_neighbor,
6165 bgp_show_type_cidr_only,
6166 bgp_show_type_prefix_longer,
6167 bgp_show_type_community_all,
6168 bgp_show_type_community,
6169 bgp_show_type_community_exact,
6170 bgp_show_type_community_list,
6171 bgp_show_type_community_list_exact,
6172 bgp_show_type_flap_statistics,
6173 bgp_show_type_flap_address,
6174 bgp_show_type_flap_prefix,
6175 bgp_show_type_flap_cidr_only,
6176 bgp_show_type_flap_regexp,
6177 bgp_show_type_flap_filter_list,
6178 bgp_show_type_flap_prefix_list,
6179 bgp_show_type_flap_prefix_longer,
6180 bgp_show_type_flap_route_map,
6181 bgp_show_type_flap_neighbor,
6182 bgp_show_type_dampend_paths,
6183 bgp_show_type_damp_neighbor
6184};
6185
ajs5a646652004-11-05 01:25:55 +00006186static int
paulfee0f4c2004-09-13 05:12:46 +00006187bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006188 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006189{
paul718e3742002-12-13 20:15:29 +00006190 struct bgp_info *ri;
6191 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006192 int header = 1;
paul718e3742002-12-13 20:15:29 +00006193 int display;
ajs5a646652004-11-05 01:25:55 +00006194 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006195
6196 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006197 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006198
paul718e3742002-12-13 20:15:29 +00006199 /* Start processing of routes. */
6200 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6201 if (rn->info != NULL)
6202 {
6203 display = 0;
6204
6205 for (ri = rn->info; ri; ri = ri->next)
6206 {
ajs5a646652004-11-05 01:25:55 +00006207 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006208 || type == bgp_show_type_flap_address
6209 || type == bgp_show_type_flap_prefix
6210 || type == bgp_show_type_flap_cidr_only
6211 || type == bgp_show_type_flap_regexp
6212 || type == bgp_show_type_flap_filter_list
6213 || type == bgp_show_type_flap_prefix_list
6214 || type == bgp_show_type_flap_prefix_longer
6215 || type == bgp_show_type_flap_route_map
6216 || type == bgp_show_type_flap_neighbor
6217 || type == bgp_show_type_dampend_paths
6218 || type == bgp_show_type_damp_neighbor)
6219 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006220 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006221 continue;
6222 }
6223 if (type == bgp_show_type_regexp
6224 || type == bgp_show_type_flap_regexp)
6225 {
ajs5a646652004-11-05 01:25:55 +00006226 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006227
6228 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6229 continue;
6230 }
6231 if (type == bgp_show_type_prefix_list
6232 || type == bgp_show_type_flap_prefix_list)
6233 {
ajs5a646652004-11-05 01:25:55 +00006234 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006235
6236 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6237 continue;
6238 }
6239 if (type == bgp_show_type_filter_list
6240 || type == bgp_show_type_flap_filter_list)
6241 {
ajs5a646652004-11-05 01:25:55 +00006242 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006243
6244 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6245 continue;
6246 }
6247 if (type == bgp_show_type_route_map
6248 || type == bgp_show_type_flap_route_map)
6249 {
ajs5a646652004-11-05 01:25:55 +00006250 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006251 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006252 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006253 int ret;
6254
Paul Jakmafb982c22007-05-04 20:15:47 +00006255 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006256 binfo.peer = ri->peer;
6257 binfo.attr = &dummy_attr;
6258
6259 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006260
6261 bgp_attr_extra_free (&dummy_attr);
6262
paul718e3742002-12-13 20:15:29 +00006263 if (ret == RMAP_DENYMATCH)
6264 continue;
6265 }
6266 if (type == bgp_show_type_neighbor
6267 || type == bgp_show_type_flap_neighbor
6268 || type == bgp_show_type_damp_neighbor)
6269 {
ajs5a646652004-11-05 01:25:55 +00006270 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006271
6272 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6273 continue;
6274 }
6275 if (type == bgp_show_type_cidr_only
6276 || type == bgp_show_type_flap_cidr_only)
6277 {
6278 u_int32_t destination;
6279
6280 destination = ntohl (rn->p.u.prefix4.s_addr);
6281 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6282 continue;
6283 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6284 continue;
6285 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6286 continue;
6287 }
6288 if (type == bgp_show_type_prefix_longer
6289 || type == bgp_show_type_flap_prefix_longer)
6290 {
ajs5a646652004-11-05 01:25:55 +00006291 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006292
6293 if (! prefix_match (p, &rn->p))
6294 continue;
6295 }
6296 if (type == bgp_show_type_community_all)
6297 {
6298 if (! ri->attr->community)
6299 continue;
6300 }
6301 if (type == bgp_show_type_community)
6302 {
ajs5a646652004-11-05 01:25:55 +00006303 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006304
6305 if (! ri->attr->community ||
6306 ! community_match (ri->attr->community, com))
6307 continue;
6308 }
6309 if (type == bgp_show_type_community_exact)
6310 {
ajs5a646652004-11-05 01:25:55 +00006311 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006312
6313 if (! ri->attr->community ||
6314 ! community_cmp (ri->attr->community, com))
6315 continue;
6316 }
6317 if (type == bgp_show_type_community_list)
6318 {
ajs5a646652004-11-05 01:25:55 +00006319 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006320
6321 if (! community_list_match (ri->attr->community, list))
6322 continue;
6323 }
6324 if (type == bgp_show_type_community_list_exact)
6325 {
ajs5a646652004-11-05 01:25:55 +00006326 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006327
6328 if (! community_list_exact_match (ri->attr->community, list))
6329 continue;
6330 }
6331 if (type == bgp_show_type_flap_address
6332 || type == bgp_show_type_flap_prefix)
6333 {
ajs5a646652004-11-05 01:25:55 +00006334 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006335
6336 if (! prefix_match (&rn->p, p))
6337 continue;
6338
6339 if (type == bgp_show_type_flap_prefix)
6340 if (p->prefixlen != rn->p.prefixlen)
6341 continue;
6342 }
6343 if (type == bgp_show_type_dampend_paths
6344 || type == bgp_show_type_damp_neighbor)
6345 {
6346 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6347 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6348 continue;
6349 }
6350
6351 if (header)
6352 {
hasso93406d82005-02-02 14:40:33 +00006353 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6354 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6355 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006356 if (type == bgp_show_type_dampend_paths
6357 || type == bgp_show_type_damp_neighbor)
6358 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6359 else if (type == bgp_show_type_flap_statistics
6360 || type == bgp_show_type_flap_address
6361 || type == bgp_show_type_flap_prefix
6362 || type == bgp_show_type_flap_cidr_only
6363 || type == bgp_show_type_flap_regexp
6364 || type == bgp_show_type_flap_filter_list
6365 || type == bgp_show_type_flap_prefix_list
6366 || type == bgp_show_type_flap_prefix_longer
6367 || type == bgp_show_type_flap_route_map
6368 || type == bgp_show_type_flap_neighbor)
6369 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6370 else
6371 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006372 header = 0;
6373 }
6374
6375 if (type == bgp_show_type_dampend_paths
6376 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006377 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006378 else if (type == bgp_show_type_flap_statistics
6379 || type == bgp_show_type_flap_address
6380 || type == bgp_show_type_flap_prefix
6381 || type == bgp_show_type_flap_cidr_only
6382 || type == bgp_show_type_flap_regexp
6383 || type == bgp_show_type_flap_filter_list
6384 || type == bgp_show_type_flap_prefix_list
6385 || type == bgp_show_type_flap_prefix_longer
6386 || type == bgp_show_type_flap_route_map
6387 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006388 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006389 else
ajs5a646652004-11-05 01:25:55 +00006390 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006391 display++;
6392 }
6393 if (display)
ajs5a646652004-11-05 01:25:55 +00006394 output_count++;
paul718e3742002-12-13 20:15:29 +00006395 }
6396
6397 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006398 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006399 {
6400 if (type == bgp_show_type_normal)
6401 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6402 }
6403 else
6404 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006405 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006406
6407 return CMD_SUCCESS;
6408}
6409
ajs5a646652004-11-05 01:25:55 +00006410static int
paulfee0f4c2004-09-13 05:12:46 +00006411bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006412 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006413{
6414 struct bgp_table *table;
6415
6416 if (bgp == NULL) {
6417 bgp = bgp_get_default ();
6418 }
6419
6420 if (bgp == NULL)
6421 {
6422 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6423 return CMD_WARNING;
6424 }
6425
6426
6427 table = bgp->rib[afi][safi];
6428
ajs5a646652004-11-05 01:25:55 +00006429 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006430}
6431
paul718e3742002-12-13 20:15:29 +00006432/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006433static void
paul718e3742002-12-13 20:15:29 +00006434route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6435 struct bgp_node *rn,
6436 struct prefix_rd *prd, afi_t afi, safi_t safi)
6437{
6438 struct bgp_info *ri;
6439 struct prefix *p;
6440 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006441 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006442 char buf1[INET6_ADDRSTRLEN];
6443 char buf2[INET6_ADDRSTRLEN];
6444 int count = 0;
6445 int best = 0;
6446 int suppress = 0;
6447 int no_export = 0;
6448 int no_advertise = 0;
6449 int local_as = 0;
6450 int first = 0;
6451
6452 p = &rn->p;
6453 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6454 (safi == SAFI_MPLS_VPN ?
6455 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6456 safi == SAFI_MPLS_VPN ? ":" : "",
6457 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6458 p->prefixlen, VTY_NEWLINE);
6459
6460 for (ri = rn->info; ri; ri = ri->next)
6461 {
6462 count++;
6463 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6464 {
6465 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006466 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006467 suppress = 1;
6468 if (ri->attr->community != NULL)
6469 {
6470 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6471 no_advertise = 1;
6472 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6473 no_export = 1;
6474 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6475 local_as = 1;
6476 }
6477 }
6478 }
6479
6480 vty_out (vty, "Paths: (%d available", count);
6481 if (best)
6482 {
6483 vty_out (vty, ", best #%d", best);
6484 if (safi == SAFI_UNICAST)
6485 vty_out (vty, ", table Default-IP-Routing-Table");
6486 }
6487 else
6488 vty_out (vty, ", no best path");
6489 if (no_advertise)
6490 vty_out (vty, ", not advertised to any peer");
6491 else if (no_export)
6492 vty_out (vty, ", not advertised to EBGP peer");
6493 else if (local_as)
6494 vty_out (vty, ", not advertised outside local AS");
6495 if (suppress)
6496 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6497 vty_out (vty, ")%s", VTY_NEWLINE);
6498
6499 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006500 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006501 {
6502 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6503 {
6504 if (! first)
6505 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6506 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6507 first = 1;
6508 }
6509 }
6510 if (! first)
6511 vty_out (vty, " Not advertised to any peer");
6512 vty_out (vty, "%s", VTY_NEWLINE);
6513}
6514
6515/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006516static int
paulfee0f4c2004-09-13 05:12:46 +00006517bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006518 struct bgp_table *rib, const char *ip_str,
6519 afi_t afi, safi_t safi, struct prefix_rd *prd,
6520 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006521{
6522 int ret;
6523 int header;
6524 int display = 0;
6525 struct prefix match;
6526 struct bgp_node *rn;
6527 struct bgp_node *rm;
6528 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006529 struct bgp_table *table;
6530
paul718e3742002-12-13 20:15:29 +00006531 /* Check IP address argument. */
6532 ret = str2prefix (ip_str, &match);
6533 if (! ret)
6534 {
6535 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6536 return CMD_WARNING;
6537 }
6538
6539 match.family = afi2family (afi);
6540
6541 if (safi == SAFI_MPLS_VPN)
6542 {
paulfee0f4c2004-09-13 05:12:46 +00006543 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006544 {
6545 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6546 continue;
6547
6548 if ((table = rn->info) != NULL)
6549 {
6550 header = 1;
6551
6552 if ((rm = bgp_node_match (table, &match)) != NULL)
6553 {
6554 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6555 continue;
6556
6557 for (ri = rm->info; ri; ri = ri->next)
6558 {
6559 if (header)
6560 {
6561 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6562 AFI_IP, SAFI_MPLS_VPN);
6563
6564 header = 0;
6565 }
6566 display++;
6567 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6568 }
6569 }
6570 }
6571 }
6572 }
6573 else
6574 {
6575 header = 1;
6576
paulfee0f4c2004-09-13 05:12:46 +00006577 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006578 {
6579 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6580 {
6581 for (ri = rn->info; ri; ri = ri->next)
6582 {
6583 if (header)
6584 {
6585 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6586 header = 0;
6587 }
6588 display++;
6589 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6590 }
6591 }
6592 }
6593 }
6594
6595 if (! display)
6596 {
6597 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6598 return CMD_WARNING;
6599 }
6600
6601 return CMD_SUCCESS;
6602}
6603
paulfee0f4c2004-09-13 05:12:46 +00006604/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006605static int
paulfd79ac92004-10-13 05:06:08 +00006606bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006607 afi_t afi, safi_t safi, struct prefix_rd *prd,
6608 int prefix_check)
6609{
6610 struct bgp *bgp;
6611
6612 /* BGP structure lookup. */
6613 if (view_name)
6614 {
6615 bgp = bgp_lookup_by_name (view_name);
6616 if (bgp == NULL)
6617 {
6618 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6619 return CMD_WARNING;
6620 }
6621 }
6622 else
6623 {
6624 bgp = bgp_get_default ();
6625 if (bgp == NULL)
6626 {
6627 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6628 return CMD_WARNING;
6629 }
6630 }
6631
6632 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6633 afi, safi, prd, prefix_check);
6634}
6635
paul718e3742002-12-13 20:15:29 +00006636/* BGP route print out function. */
6637DEFUN (show_ip_bgp,
6638 show_ip_bgp_cmd,
6639 "show ip bgp",
6640 SHOW_STR
6641 IP_STR
6642 BGP_STR)
6643{
ajs5a646652004-11-05 01:25:55 +00006644 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006645}
6646
6647DEFUN (show_ip_bgp_ipv4,
6648 show_ip_bgp_ipv4_cmd,
6649 "show ip bgp ipv4 (unicast|multicast)",
6650 SHOW_STR
6651 IP_STR
6652 BGP_STR
6653 "Address family\n"
6654 "Address Family modifier\n"
6655 "Address Family modifier\n")
6656{
6657 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006658 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6659 NULL);
paul718e3742002-12-13 20:15:29 +00006660
ajs5a646652004-11-05 01:25:55 +00006661 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006662}
6663
6664DEFUN (show_ip_bgp_route,
6665 show_ip_bgp_route_cmd,
6666 "show ip bgp A.B.C.D",
6667 SHOW_STR
6668 IP_STR
6669 BGP_STR
6670 "Network in the BGP routing table to display\n")
6671{
6672 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6673}
6674
6675DEFUN (show_ip_bgp_ipv4_route,
6676 show_ip_bgp_ipv4_route_cmd,
6677 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6678 SHOW_STR
6679 IP_STR
6680 BGP_STR
6681 "Address family\n"
6682 "Address Family modifier\n"
6683 "Address Family modifier\n"
6684 "Network in the BGP routing table to display\n")
6685{
6686 if (strncmp (argv[0], "m", 1) == 0)
6687 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6688
6689 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6690}
6691
6692DEFUN (show_ip_bgp_vpnv4_all_route,
6693 show_ip_bgp_vpnv4_all_route_cmd,
6694 "show ip bgp vpnv4 all A.B.C.D",
6695 SHOW_STR
6696 IP_STR
6697 BGP_STR
6698 "Display VPNv4 NLRI specific information\n"
6699 "Display information about all VPNv4 NLRIs\n"
6700 "Network in the BGP routing table to display\n")
6701{
6702 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6703}
6704
6705DEFUN (show_ip_bgp_vpnv4_rd_route,
6706 show_ip_bgp_vpnv4_rd_route_cmd,
6707 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6708 SHOW_STR
6709 IP_STR
6710 BGP_STR
6711 "Display VPNv4 NLRI specific information\n"
6712 "Display information for a route distinguisher\n"
6713 "VPN Route Distinguisher\n"
6714 "Network in the BGP routing table to display\n")
6715{
6716 int ret;
6717 struct prefix_rd prd;
6718
6719 ret = str2prefix_rd (argv[0], &prd);
6720 if (! ret)
6721 {
6722 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6723 return CMD_WARNING;
6724 }
6725 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6726}
6727
6728DEFUN (show_ip_bgp_prefix,
6729 show_ip_bgp_prefix_cmd,
6730 "show ip bgp A.B.C.D/M",
6731 SHOW_STR
6732 IP_STR
6733 BGP_STR
6734 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6735{
6736 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6737}
6738
6739DEFUN (show_ip_bgp_ipv4_prefix,
6740 show_ip_bgp_ipv4_prefix_cmd,
6741 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6742 SHOW_STR
6743 IP_STR
6744 BGP_STR
6745 "Address family\n"
6746 "Address Family modifier\n"
6747 "Address Family modifier\n"
6748 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6749{
6750 if (strncmp (argv[0], "m", 1) == 0)
6751 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6752
6753 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6754}
6755
6756DEFUN (show_ip_bgp_vpnv4_all_prefix,
6757 show_ip_bgp_vpnv4_all_prefix_cmd,
6758 "show ip bgp vpnv4 all A.B.C.D/M",
6759 SHOW_STR
6760 IP_STR
6761 BGP_STR
6762 "Display VPNv4 NLRI specific information\n"
6763 "Display information about all VPNv4 NLRIs\n"
6764 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6765{
6766 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6767}
6768
6769DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6770 show_ip_bgp_vpnv4_rd_prefix_cmd,
6771 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6772 SHOW_STR
6773 IP_STR
6774 BGP_STR
6775 "Display VPNv4 NLRI specific information\n"
6776 "Display information for a route distinguisher\n"
6777 "VPN Route Distinguisher\n"
6778 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6779{
6780 int ret;
6781 struct prefix_rd prd;
6782
6783 ret = str2prefix_rd (argv[0], &prd);
6784 if (! ret)
6785 {
6786 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6787 return CMD_WARNING;
6788 }
6789 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6790}
6791
6792DEFUN (show_ip_bgp_view,
6793 show_ip_bgp_view_cmd,
6794 "show ip bgp view WORD",
6795 SHOW_STR
6796 IP_STR
6797 BGP_STR
6798 "BGP view\n"
6799 "BGP view name\n")
6800{
paulbb46e942003-10-24 19:02:03 +00006801 struct bgp *bgp;
6802
6803 /* BGP structure lookup. */
6804 bgp = bgp_lookup_by_name (argv[0]);
6805 if (bgp == NULL)
6806 {
6807 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6808 return CMD_WARNING;
6809 }
6810
ajs5a646652004-11-05 01:25:55 +00006811 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006812}
6813
6814DEFUN (show_ip_bgp_view_route,
6815 show_ip_bgp_view_route_cmd,
6816 "show ip bgp view WORD A.B.C.D",
6817 SHOW_STR
6818 IP_STR
6819 BGP_STR
6820 "BGP view\n"
6821 "BGP view name\n"
6822 "Network in the BGP routing table to display\n")
6823{
6824 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6825}
6826
6827DEFUN (show_ip_bgp_view_prefix,
6828 show_ip_bgp_view_prefix_cmd,
6829 "show ip bgp view WORD A.B.C.D/M",
6830 SHOW_STR
6831 IP_STR
6832 BGP_STR
6833 "BGP view\n"
6834 "BGP view name\n"
6835 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6836{
6837 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6838}
6839
6840#ifdef HAVE_IPV6
6841DEFUN (show_bgp,
6842 show_bgp_cmd,
6843 "show bgp",
6844 SHOW_STR
6845 BGP_STR)
6846{
ajs5a646652004-11-05 01:25:55 +00006847 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6848 NULL);
paul718e3742002-12-13 20:15:29 +00006849}
6850
6851ALIAS (show_bgp,
6852 show_bgp_ipv6_cmd,
6853 "show bgp ipv6",
6854 SHOW_STR
6855 BGP_STR
6856 "Address family\n")
6857
6858/* old command */
6859DEFUN (show_ipv6_bgp,
6860 show_ipv6_bgp_cmd,
6861 "show ipv6 bgp",
6862 SHOW_STR
6863 IP_STR
6864 BGP_STR)
6865{
ajs5a646652004-11-05 01:25:55 +00006866 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6867 NULL);
paul718e3742002-12-13 20:15:29 +00006868}
6869
6870DEFUN (show_bgp_route,
6871 show_bgp_route_cmd,
6872 "show bgp X:X::X:X",
6873 SHOW_STR
6874 BGP_STR
6875 "Network in the BGP routing table to display\n")
6876{
6877 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6878}
6879
6880ALIAS (show_bgp_route,
6881 show_bgp_ipv6_route_cmd,
6882 "show bgp ipv6 X:X::X:X",
6883 SHOW_STR
6884 BGP_STR
6885 "Address family\n"
6886 "Network in the BGP routing table to display\n")
6887
6888/* old command */
6889DEFUN (show_ipv6_bgp_route,
6890 show_ipv6_bgp_route_cmd,
6891 "show ipv6 bgp X:X::X:X",
6892 SHOW_STR
6893 IP_STR
6894 BGP_STR
6895 "Network in the BGP routing table to display\n")
6896{
6897 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6898}
6899
6900DEFUN (show_bgp_prefix,
6901 show_bgp_prefix_cmd,
6902 "show bgp X:X::X:X/M",
6903 SHOW_STR
6904 BGP_STR
6905 "IPv6 prefix <network>/<length>\n")
6906{
6907 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6908}
6909
6910ALIAS (show_bgp_prefix,
6911 show_bgp_ipv6_prefix_cmd,
6912 "show bgp ipv6 X:X::X:X/M",
6913 SHOW_STR
6914 BGP_STR
6915 "Address family\n"
6916 "IPv6 prefix <network>/<length>\n")
6917
6918/* old command */
6919DEFUN (show_ipv6_bgp_prefix,
6920 show_ipv6_bgp_prefix_cmd,
6921 "show ipv6 bgp X:X::X:X/M",
6922 SHOW_STR
6923 IP_STR
6924 BGP_STR
6925 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6926{
6927 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6928}
6929
paulbb46e942003-10-24 19:02:03 +00006930DEFUN (show_bgp_view,
6931 show_bgp_view_cmd,
6932 "show bgp view WORD",
6933 SHOW_STR
6934 BGP_STR
6935 "BGP view\n"
6936 "View name\n")
6937{
6938 struct bgp *bgp;
6939
6940 /* BGP structure lookup. */
6941 bgp = bgp_lookup_by_name (argv[0]);
6942 if (bgp == NULL)
6943 {
6944 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6945 return CMD_WARNING;
6946 }
6947
ajs5a646652004-11-05 01:25:55 +00006948 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006949}
6950
6951ALIAS (show_bgp_view,
6952 show_bgp_view_ipv6_cmd,
6953 "show bgp view WORD ipv6",
6954 SHOW_STR
6955 BGP_STR
6956 "BGP view\n"
6957 "View name\n"
6958 "Address family\n")
6959
6960DEFUN (show_bgp_view_route,
6961 show_bgp_view_route_cmd,
6962 "show bgp view WORD X:X::X:X",
6963 SHOW_STR
6964 BGP_STR
6965 "BGP view\n"
6966 "View name\n"
6967 "Network in the BGP routing table to display\n")
6968{
6969 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6970}
6971
6972ALIAS (show_bgp_view_route,
6973 show_bgp_view_ipv6_route_cmd,
6974 "show bgp view WORD ipv6 X:X::X:X",
6975 SHOW_STR
6976 BGP_STR
6977 "BGP view\n"
6978 "View name\n"
6979 "Address family\n"
6980 "Network in the BGP routing table to display\n")
6981
6982DEFUN (show_bgp_view_prefix,
6983 show_bgp_view_prefix_cmd,
6984 "show bgp view WORD X:X::X:X/M",
6985 SHOW_STR
6986 BGP_STR
6987 "BGP view\n"
6988 "View name\n"
6989 "IPv6 prefix <network>/<length>\n")
6990{
6991 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6992}
6993
6994ALIAS (show_bgp_view_prefix,
6995 show_bgp_view_ipv6_prefix_cmd,
6996 "show bgp view WORD ipv6 X:X::X:X/M",
6997 SHOW_STR
6998 BGP_STR
6999 "BGP view\n"
7000 "View name\n"
7001 "Address family\n"
7002 "IPv6 prefix <network>/<length>\n")
7003
paul718e3742002-12-13 20:15:29 +00007004/* old command */
7005DEFUN (show_ipv6_mbgp,
7006 show_ipv6_mbgp_cmd,
7007 "show ipv6 mbgp",
7008 SHOW_STR
7009 IP_STR
7010 MBGP_STR)
7011{
ajs5a646652004-11-05 01:25:55 +00007012 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7013 NULL);
paul718e3742002-12-13 20:15:29 +00007014}
7015
7016/* old command */
7017DEFUN (show_ipv6_mbgp_route,
7018 show_ipv6_mbgp_route_cmd,
7019 "show ipv6 mbgp X:X::X:X",
7020 SHOW_STR
7021 IP_STR
7022 MBGP_STR
7023 "Network in the MBGP routing table to display\n")
7024{
7025 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7026}
7027
7028/* old command */
7029DEFUN (show_ipv6_mbgp_prefix,
7030 show_ipv6_mbgp_prefix_cmd,
7031 "show ipv6 mbgp X:X::X:X/M",
7032 SHOW_STR
7033 IP_STR
7034 MBGP_STR
7035 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7036{
7037 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7038}
7039#endif
7040
paul718e3742002-12-13 20:15:29 +00007041
paul94f2b392005-06-28 12:44:16 +00007042static int
paulfd79ac92004-10-13 05:06:08 +00007043bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007044 safi_t safi, enum bgp_show_type type)
7045{
7046 int i;
7047 struct buffer *b;
7048 char *regstr;
7049 int first;
7050 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007051 int rc;
paul718e3742002-12-13 20:15:29 +00007052
7053 first = 0;
7054 b = buffer_new (1024);
7055 for (i = 0; i < argc; i++)
7056 {
7057 if (first)
7058 buffer_putc (b, ' ');
7059 else
7060 {
7061 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7062 continue;
7063 first = 1;
7064 }
7065
7066 buffer_putstr (b, argv[i]);
7067 }
7068 buffer_putc (b, '\0');
7069
7070 regstr = buffer_getstr (b);
7071 buffer_free (b);
7072
7073 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007074 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007075 if (! regex)
7076 {
7077 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7078 VTY_NEWLINE);
7079 return CMD_WARNING;
7080 }
7081
ajs5a646652004-11-05 01:25:55 +00007082 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7083 bgp_regex_free (regex);
7084 return rc;
paul718e3742002-12-13 20:15:29 +00007085}
7086
7087DEFUN (show_ip_bgp_regexp,
7088 show_ip_bgp_regexp_cmd,
7089 "show ip bgp regexp .LINE",
7090 SHOW_STR
7091 IP_STR
7092 BGP_STR
7093 "Display routes matching the AS path regular expression\n"
7094 "A regular-expression to match the BGP AS paths\n")
7095{
7096 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7097 bgp_show_type_regexp);
7098}
7099
7100DEFUN (show_ip_bgp_flap_regexp,
7101 show_ip_bgp_flap_regexp_cmd,
7102 "show ip bgp flap-statistics regexp .LINE",
7103 SHOW_STR
7104 IP_STR
7105 BGP_STR
7106 "Display flap statistics of routes\n"
7107 "Display routes matching the AS path regular expression\n"
7108 "A regular-expression to match the BGP AS paths\n")
7109{
7110 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7111 bgp_show_type_flap_regexp);
7112}
7113
7114DEFUN (show_ip_bgp_ipv4_regexp,
7115 show_ip_bgp_ipv4_regexp_cmd,
7116 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7117 SHOW_STR
7118 IP_STR
7119 BGP_STR
7120 "Address family\n"
7121 "Address Family modifier\n"
7122 "Address Family modifier\n"
7123 "Display routes matching the AS path regular expression\n"
7124 "A regular-expression to match the BGP AS paths\n")
7125{
7126 if (strncmp (argv[0], "m", 1) == 0)
7127 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7128 bgp_show_type_regexp);
7129
7130 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7131 bgp_show_type_regexp);
7132}
7133
7134#ifdef HAVE_IPV6
7135DEFUN (show_bgp_regexp,
7136 show_bgp_regexp_cmd,
7137 "show bgp regexp .LINE",
7138 SHOW_STR
7139 BGP_STR
7140 "Display routes matching the AS path regular expression\n"
7141 "A regular-expression to match the BGP AS paths\n")
7142{
7143 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7144 bgp_show_type_regexp);
7145}
7146
7147ALIAS (show_bgp_regexp,
7148 show_bgp_ipv6_regexp_cmd,
7149 "show bgp ipv6 regexp .LINE",
7150 SHOW_STR
7151 BGP_STR
7152 "Address family\n"
7153 "Display routes matching the AS path regular expression\n"
7154 "A regular-expression to match the BGP AS paths\n")
7155
7156/* old command */
7157DEFUN (show_ipv6_bgp_regexp,
7158 show_ipv6_bgp_regexp_cmd,
7159 "show ipv6 bgp regexp .LINE",
7160 SHOW_STR
7161 IP_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
7170/* old command */
7171DEFUN (show_ipv6_mbgp_regexp,
7172 show_ipv6_mbgp_regexp_cmd,
7173 "show ipv6 mbgp regexp .LINE",
7174 SHOW_STR
7175 IP_STR
7176 BGP_STR
7177 "Display routes matching the AS path regular expression\n"
7178 "A regular-expression to match the MBGP AS paths\n")
7179{
7180 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7181 bgp_show_type_regexp);
7182}
7183#endif /* HAVE_IPV6 */
7184
paul94f2b392005-06-28 12:44:16 +00007185static int
paulfd79ac92004-10-13 05:06:08 +00007186bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007187 safi_t safi, enum bgp_show_type type)
7188{
7189 struct prefix_list *plist;
7190
7191 plist = prefix_list_lookup (afi, prefix_list_str);
7192 if (plist == NULL)
7193 {
7194 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7195 prefix_list_str, VTY_NEWLINE);
7196 return CMD_WARNING;
7197 }
7198
ajs5a646652004-11-05 01:25:55 +00007199 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007200}
7201
7202DEFUN (show_ip_bgp_prefix_list,
7203 show_ip_bgp_prefix_list_cmd,
7204 "show ip bgp prefix-list WORD",
7205 SHOW_STR
7206 IP_STR
7207 BGP_STR
7208 "Display routes conforming to the prefix-list\n"
7209 "IP prefix-list name\n")
7210{
7211 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7212 bgp_show_type_prefix_list);
7213}
7214
7215DEFUN (show_ip_bgp_flap_prefix_list,
7216 show_ip_bgp_flap_prefix_list_cmd,
7217 "show ip bgp flap-statistics prefix-list WORD",
7218 SHOW_STR
7219 IP_STR
7220 BGP_STR
7221 "Display flap statistics of routes\n"
7222 "Display routes conforming to the prefix-list\n"
7223 "IP prefix-list name\n")
7224{
7225 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7226 bgp_show_type_flap_prefix_list);
7227}
7228
7229DEFUN (show_ip_bgp_ipv4_prefix_list,
7230 show_ip_bgp_ipv4_prefix_list_cmd,
7231 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7232 SHOW_STR
7233 IP_STR
7234 BGP_STR
7235 "Address family\n"
7236 "Address Family modifier\n"
7237 "Address Family modifier\n"
7238 "Display routes conforming to the prefix-list\n"
7239 "IP prefix-list name\n")
7240{
7241 if (strncmp (argv[0], "m", 1) == 0)
7242 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7243 bgp_show_type_prefix_list);
7244
7245 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7246 bgp_show_type_prefix_list);
7247}
7248
7249#ifdef HAVE_IPV6
7250DEFUN (show_bgp_prefix_list,
7251 show_bgp_prefix_list_cmd,
7252 "show bgp prefix-list WORD",
7253 SHOW_STR
7254 BGP_STR
7255 "Display routes conforming to the prefix-list\n"
7256 "IPv6 prefix-list name\n")
7257{
7258 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7259 bgp_show_type_prefix_list);
7260}
7261
7262ALIAS (show_bgp_prefix_list,
7263 show_bgp_ipv6_prefix_list_cmd,
7264 "show bgp ipv6 prefix-list WORD",
7265 SHOW_STR
7266 BGP_STR
7267 "Address family\n"
7268 "Display routes conforming to the prefix-list\n"
7269 "IPv6 prefix-list name\n")
7270
7271/* old command */
7272DEFUN (show_ipv6_bgp_prefix_list,
7273 show_ipv6_bgp_prefix_list_cmd,
7274 "show ipv6 bgp prefix-list WORD",
7275 SHOW_STR
7276 IPV6_STR
7277 BGP_STR
7278 "Display routes matching 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
7285/* old command */
7286DEFUN (show_ipv6_mbgp_prefix_list,
7287 show_ipv6_mbgp_prefix_list_cmd,
7288 "show ipv6 mbgp prefix-list WORD",
7289 SHOW_STR
7290 IPV6_STR
7291 MBGP_STR
7292 "Display routes matching the prefix-list\n"
7293 "IPv6 prefix-list name\n")
7294{
7295 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7296 bgp_show_type_prefix_list);
7297}
7298#endif /* HAVE_IPV6 */
7299
paul94f2b392005-06-28 12:44:16 +00007300static int
paulfd79ac92004-10-13 05:06:08 +00007301bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007302 safi_t safi, enum bgp_show_type type)
7303{
7304 struct as_list *as_list;
7305
7306 as_list = as_list_lookup (filter);
7307 if (as_list == NULL)
7308 {
7309 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7310 return CMD_WARNING;
7311 }
7312
ajs5a646652004-11-05 01:25:55 +00007313 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007314}
7315
7316DEFUN (show_ip_bgp_filter_list,
7317 show_ip_bgp_filter_list_cmd,
7318 "show ip bgp filter-list WORD",
7319 SHOW_STR
7320 IP_STR
7321 BGP_STR
7322 "Display routes conforming to the filter-list\n"
7323 "Regular expression access list name\n")
7324{
7325 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7326 bgp_show_type_filter_list);
7327}
7328
7329DEFUN (show_ip_bgp_flap_filter_list,
7330 show_ip_bgp_flap_filter_list_cmd,
7331 "show ip bgp flap-statistics filter-list WORD",
7332 SHOW_STR
7333 IP_STR
7334 BGP_STR
7335 "Display flap statistics of routes\n"
7336 "Display routes conforming to the filter-list\n"
7337 "Regular expression access list name\n")
7338{
7339 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7340 bgp_show_type_flap_filter_list);
7341}
7342
7343DEFUN (show_ip_bgp_ipv4_filter_list,
7344 show_ip_bgp_ipv4_filter_list_cmd,
7345 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7346 SHOW_STR
7347 IP_STR
7348 BGP_STR
7349 "Address family\n"
7350 "Address Family modifier\n"
7351 "Address Family modifier\n"
7352 "Display routes conforming to the filter-list\n"
7353 "Regular expression access list name\n")
7354{
7355 if (strncmp (argv[0], "m", 1) == 0)
7356 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7357 bgp_show_type_filter_list);
7358
7359 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7360 bgp_show_type_filter_list);
7361}
7362
7363#ifdef HAVE_IPV6
7364DEFUN (show_bgp_filter_list,
7365 show_bgp_filter_list_cmd,
7366 "show bgp filter-list WORD",
7367 SHOW_STR
7368 BGP_STR
7369 "Display routes conforming to the filter-list\n"
7370 "Regular expression access list name\n")
7371{
7372 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7373 bgp_show_type_filter_list);
7374}
7375
7376ALIAS (show_bgp_filter_list,
7377 show_bgp_ipv6_filter_list_cmd,
7378 "show bgp ipv6 filter-list WORD",
7379 SHOW_STR
7380 BGP_STR
7381 "Address family\n"
7382 "Display routes conforming to the filter-list\n"
7383 "Regular expression access list name\n")
7384
7385/* old command */
7386DEFUN (show_ipv6_bgp_filter_list,
7387 show_ipv6_bgp_filter_list_cmd,
7388 "show ipv6 bgp filter-list WORD",
7389 SHOW_STR
7390 IPV6_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
7399/* old command */
7400DEFUN (show_ipv6_mbgp_filter_list,
7401 show_ipv6_mbgp_filter_list_cmd,
7402 "show ipv6 mbgp filter-list WORD",
7403 SHOW_STR
7404 IPV6_STR
7405 MBGP_STR
7406 "Display routes conforming to the filter-list\n"
7407 "Regular expression access list name\n")
7408{
7409 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7410 bgp_show_type_filter_list);
7411}
7412#endif /* HAVE_IPV6 */
7413
paul94f2b392005-06-28 12:44:16 +00007414static int
paulfd79ac92004-10-13 05:06:08 +00007415bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007416 safi_t safi, enum bgp_show_type type)
7417{
7418 struct route_map *rmap;
7419
7420 rmap = route_map_lookup_by_name (rmap_str);
7421 if (! rmap)
7422 {
7423 vty_out (vty, "%% %s is not a valid route-map name%s",
7424 rmap_str, VTY_NEWLINE);
7425 return CMD_WARNING;
7426 }
7427
ajs5a646652004-11-05 01:25:55 +00007428 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007429}
7430
7431DEFUN (show_ip_bgp_route_map,
7432 show_ip_bgp_route_map_cmd,
7433 "show ip bgp route-map WORD",
7434 SHOW_STR
7435 IP_STR
7436 BGP_STR
7437 "Display routes matching the route-map\n"
7438 "A route-map to match on\n")
7439{
7440 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7441 bgp_show_type_route_map);
7442}
7443
7444DEFUN (show_ip_bgp_flap_route_map,
7445 show_ip_bgp_flap_route_map_cmd,
7446 "show ip bgp flap-statistics route-map WORD",
7447 SHOW_STR
7448 IP_STR
7449 BGP_STR
7450 "Display flap statistics of routes\n"
7451 "Display routes matching the route-map\n"
7452 "A route-map to match on\n")
7453{
7454 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7455 bgp_show_type_flap_route_map);
7456}
7457
7458DEFUN (show_ip_bgp_ipv4_route_map,
7459 show_ip_bgp_ipv4_route_map_cmd,
7460 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7461 SHOW_STR
7462 IP_STR
7463 BGP_STR
7464 "Address family\n"
7465 "Address Family modifier\n"
7466 "Address Family modifier\n"
7467 "Display routes matching the route-map\n"
7468 "A route-map to match on\n")
7469{
7470 if (strncmp (argv[0], "m", 1) == 0)
7471 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7472 bgp_show_type_route_map);
7473
7474 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7475 bgp_show_type_route_map);
7476}
7477
7478DEFUN (show_bgp_route_map,
7479 show_bgp_route_map_cmd,
7480 "show bgp route-map WORD",
7481 SHOW_STR
7482 BGP_STR
7483 "Display routes matching the route-map\n"
7484 "A route-map to match on\n")
7485{
7486 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7487 bgp_show_type_route_map);
7488}
7489
7490ALIAS (show_bgp_route_map,
7491 show_bgp_ipv6_route_map_cmd,
7492 "show bgp ipv6 route-map WORD",
7493 SHOW_STR
7494 BGP_STR
7495 "Address family\n"
7496 "Display routes matching the route-map\n"
7497 "A route-map to match on\n")
7498
7499DEFUN (show_ip_bgp_cidr_only,
7500 show_ip_bgp_cidr_only_cmd,
7501 "show ip bgp cidr-only",
7502 SHOW_STR
7503 IP_STR
7504 BGP_STR
7505 "Display only routes with non-natural netmasks\n")
7506{
7507 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007508 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007509}
7510
7511DEFUN (show_ip_bgp_flap_cidr_only,
7512 show_ip_bgp_flap_cidr_only_cmd,
7513 "show ip bgp flap-statistics cidr-only",
7514 SHOW_STR
7515 IP_STR
7516 BGP_STR
7517 "Display flap statistics of routes\n"
7518 "Display only routes with non-natural netmasks\n")
7519{
7520 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007521 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007522}
7523
7524DEFUN (show_ip_bgp_ipv4_cidr_only,
7525 show_ip_bgp_ipv4_cidr_only_cmd,
7526 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7527 SHOW_STR
7528 IP_STR
7529 BGP_STR
7530 "Address family\n"
7531 "Address Family modifier\n"
7532 "Address Family modifier\n"
7533 "Display only routes with non-natural netmasks\n")
7534{
7535 if (strncmp (argv[0], "m", 1) == 0)
7536 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007537 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007538
7539 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007540 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007541}
7542
7543DEFUN (show_ip_bgp_community_all,
7544 show_ip_bgp_community_all_cmd,
7545 "show ip bgp community",
7546 SHOW_STR
7547 IP_STR
7548 BGP_STR
7549 "Display routes matching the communities\n")
7550{
7551 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007552 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007553}
7554
7555DEFUN (show_ip_bgp_ipv4_community_all,
7556 show_ip_bgp_ipv4_community_all_cmd,
7557 "show ip bgp ipv4 (unicast|multicast) community",
7558 SHOW_STR
7559 IP_STR
7560 BGP_STR
7561 "Address family\n"
7562 "Address Family modifier\n"
7563 "Address Family modifier\n"
7564 "Display routes matching the communities\n")
7565{
7566 if (strncmp (argv[0], "m", 1) == 0)
7567 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007568 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007569
7570 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007571 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007572}
7573
7574#ifdef HAVE_IPV6
7575DEFUN (show_bgp_community_all,
7576 show_bgp_community_all_cmd,
7577 "show bgp community",
7578 SHOW_STR
7579 BGP_STR
7580 "Display routes matching the communities\n")
7581{
7582 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007583 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007584}
7585
7586ALIAS (show_bgp_community_all,
7587 show_bgp_ipv6_community_all_cmd,
7588 "show bgp ipv6 community",
7589 SHOW_STR
7590 BGP_STR
7591 "Address family\n"
7592 "Display routes matching the communities\n")
7593
7594/* old command */
7595DEFUN (show_ipv6_bgp_community_all,
7596 show_ipv6_bgp_community_all_cmd,
7597 "show ipv6 bgp community",
7598 SHOW_STR
7599 IPV6_STR
7600 BGP_STR
7601 "Display routes matching the communities\n")
7602{
7603 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007604 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007605}
7606
7607/* old command */
7608DEFUN (show_ipv6_mbgp_community_all,
7609 show_ipv6_mbgp_community_all_cmd,
7610 "show ipv6 mbgp community",
7611 SHOW_STR
7612 IPV6_STR
7613 MBGP_STR
7614 "Display routes matching the communities\n")
7615{
7616 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007617 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007618}
7619#endif /* HAVE_IPV6 */
7620
paul94f2b392005-06-28 12:44:16 +00007621static int
paulfd79ac92004-10-13 05:06:08 +00007622bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7623 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007624{
7625 struct community *com;
7626 struct buffer *b;
7627 int i;
7628 char *str;
7629 int first = 0;
7630
7631 b = buffer_new (1024);
7632 for (i = 0; i < argc; i++)
7633 {
7634 if (first)
7635 buffer_putc (b, ' ');
7636 else
7637 {
7638 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7639 continue;
7640 first = 1;
7641 }
7642
7643 buffer_putstr (b, argv[i]);
7644 }
7645 buffer_putc (b, '\0');
7646
7647 str = buffer_getstr (b);
7648 buffer_free (b);
7649
7650 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007651 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007652 if (! com)
7653 {
7654 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7655 return CMD_WARNING;
7656 }
7657
ajs5a646652004-11-05 01:25:55 +00007658 return bgp_show (vty, NULL, afi, safi,
7659 (exact ? bgp_show_type_community_exact :
7660 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007661}
7662
7663DEFUN (show_ip_bgp_community,
7664 show_ip_bgp_community_cmd,
7665 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7666 SHOW_STR
7667 IP_STR
7668 BGP_STR
7669 "Display routes matching the communities\n"
7670 "community number\n"
7671 "Do not send outside local AS (well-known community)\n"
7672 "Do not advertise to any peer (well-known community)\n"
7673 "Do not export to next AS (well-known community)\n")
7674{
7675 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7676}
7677
7678ALIAS (show_ip_bgp_community,
7679 show_ip_bgp_community2_cmd,
7680 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7681 SHOW_STR
7682 IP_STR
7683 BGP_STR
7684 "Display routes matching the communities\n"
7685 "community number\n"
7686 "Do not send outside local AS (well-known community)\n"
7687 "Do not advertise to any peer (well-known community)\n"
7688 "Do not export to next AS (well-known community)\n"
7689 "community number\n"
7690 "Do not send outside local AS (well-known community)\n"
7691 "Do not advertise to any peer (well-known community)\n"
7692 "Do not export to next AS (well-known community)\n")
7693
7694ALIAS (show_ip_bgp_community,
7695 show_ip_bgp_community3_cmd,
7696 "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)",
7697 SHOW_STR
7698 IP_STR
7699 BGP_STR
7700 "Display routes matching the communities\n"
7701 "community number\n"
7702 "Do not send outside local AS (well-known community)\n"
7703 "Do not advertise to any peer (well-known community)\n"
7704 "Do not export to next AS (well-known community)\n"
7705 "community number\n"
7706 "Do not send outside local AS (well-known community)\n"
7707 "Do not advertise to any peer (well-known community)\n"
7708 "Do not export to next AS (well-known community)\n"
7709 "community number\n"
7710 "Do not send outside local AS (well-known community)\n"
7711 "Do not advertise to any peer (well-known community)\n"
7712 "Do not export to next AS (well-known community)\n")
7713
7714ALIAS (show_ip_bgp_community,
7715 show_ip_bgp_community4_cmd,
7716 "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)",
7717 SHOW_STR
7718 IP_STR
7719 BGP_STR
7720 "Display routes matching the communities\n"
7721 "community number\n"
7722 "Do not send outside local AS (well-known community)\n"
7723 "Do not advertise to any peer (well-known community)\n"
7724 "Do not export to next AS (well-known community)\n"
7725 "community number\n"
7726 "Do not send outside local AS (well-known community)\n"
7727 "Do not advertise to any peer (well-known community)\n"
7728 "Do not export to next AS (well-known community)\n"
7729 "community number\n"
7730 "Do not send outside local AS (well-known community)\n"
7731 "Do not advertise to any peer (well-known community)\n"
7732 "Do not export to next AS (well-known community)\n"
7733 "community number\n"
7734 "Do not send outside local AS (well-known community)\n"
7735 "Do not advertise to any peer (well-known community)\n"
7736 "Do not export to next AS (well-known community)\n")
7737
7738DEFUN (show_ip_bgp_ipv4_community,
7739 show_ip_bgp_ipv4_community_cmd,
7740 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7741 SHOW_STR
7742 IP_STR
7743 BGP_STR
7744 "Address family\n"
7745 "Address Family modifier\n"
7746 "Address Family modifier\n"
7747 "Display routes matching the communities\n"
7748 "community number\n"
7749 "Do not send outside local AS (well-known community)\n"
7750 "Do not advertise to any peer (well-known community)\n"
7751 "Do not export to next AS (well-known community)\n")
7752{
7753 if (strncmp (argv[0], "m", 1) == 0)
7754 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7755
7756 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7757}
7758
7759ALIAS (show_ip_bgp_ipv4_community,
7760 show_ip_bgp_ipv4_community2_cmd,
7761 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7762 SHOW_STR
7763 IP_STR
7764 BGP_STR
7765 "Address family\n"
7766 "Address Family modifier\n"
7767 "Address Family modifier\n"
7768 "Display routes matching the communities\n"
7769 "community number\n"
7770 "Do not send outside local AS (well-known community)\n"
7771 "Do not advertise to any peer (well-known community)\n"
7772 "Do not export to next AS (well-known community)\n"
7773 "community number\n"
7774 "Do not send outside local AS (well-known community)\n"
7775 "Do not advertise to any peer (well-known community)\n"
7776 "Do not export to next AS (well-known community)\n")
7777
7778ALIAS (show_ip_bgp_ipv4_community,
7779 show_ip_bgp_ipv4_community3_cmd,
7780 "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)",
7781 SHOW_STR
7782 IP_STR
7783 BGP_STR
7784 "Address family\n"
7785 "Address Family modifier\n"
7786 "Address Family modifier\n"
7787 "Display routes matching the communities\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\n"
7796 "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_community4_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) (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 "community number\n"
7824 "Do not send outside local AS (well-known community)\n"
7825 "Do not advertise to any peer (well-known community)\n"
7826 "Do not export to next AS (well-known community)\n")
7827
7828DEFUN (show_ip_bgp_community_exact,
7829 show_ip_bgp_community_exact_cmd,
7830 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7831 SHOW_STR
7832 IP_STR
7833 BGP_STR
7834 "Display routes matching the communities\n"
7835 "community number\n"
7836 "Do not send outside local AS (well-known community)\n"
7837 "Do not advertise to any peer (well-known community)\n"
7838 "Do not export to next AS (well-known community)\n"
7839 "Exact match of the communities")
7840{
7841 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7842}
7843
7844ALIAS (show_ip_bgp_community_exact,
7845 show_ip_bgp_community2_exact_cmd,
7846 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7847 SHOW_STR
7848 IP_STR
7849 BGP_STR
7850 "Display routes matching the communities\n"
7851 "community number\n"
7852 "Do not send outside local AS (well-known community)\n"
7853 "Do not advertise to any peer (well-known community)\n"
7854 "Do not export to next AS (well-known community)\n"
7855 "community number\n"
7856 "Do not send outside local AS (well-known community)\n"
7857 "Do not advertise to any peer (well-known community)\n"
7858 "Do not export to next AS (well-known community)\n"
7859 "Exact match of the communities")
7860
7861ALIAS (show_ip_bgp_community_exact,
7862 show_ip_bgp_community3_exact_cmd,
7863 "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",
7864 SHOW_STR
7865 IP_STR
7866 BGP_STR
7867 "Display routes matching the communities\n"
7868 "community number\n"
7869 "Do not send outside local AS (well-known community)\n"
7870 "Do not advertise to any peer (well-known community)\n"
7871 "Do not export to next AS (well-known community)\n"
7872 "community number\n"
7873 "Do not send outside local AS (well-known community)\n"
7874 "Do not advertise to any peer (well-known community)\n"
7875 "Do not export to next AS (well-known community)\n"
7876 "community number\n"
7877 "Do not send outside local AS (well-known community)\n"
7878 "Do not advertise to any peer (well-known community)\n"
7879 "Do not export to next AS (well-known community)\n"
7880 "Exact match of the communities")
7881
7882ALIAS (show_ip_bgp_community_exact,
7883 show_ip_bgp_community4_exact_cmd,
7884 "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",
7885 SHOW_STR
7886 IP_STR
7887 BGP_STR
7888 "Display routes matching the communities\n"
7889 "community number\n"
7890 "Do not send outside local AS (well-known community)\n"
7891 "Do not advertise to any peer (well-known community)\n"
7892 "Do not export to next AS (well-known community)\n"
7893 "community number\n"
7894 "Do not send outside local AS (well-known community)\n"
7895 "Do not advertise to any peer (well-known community)\n"
7896 "Do not export to next AS (well-known community)\n"
7897 "community number\n"
7898 "Do not send outside local AS (well-known community)\n"
7899 "Do not advertise to any peer (well-known community)\n"
7900 "Do not export to next AS (well-known community)\n"
7901 "community number\n"
7902 "Do not send outside local AS (well-known community)\n"
7903 "Do not advertise to any peer (well-known community)\n"
7904 "Do not export to next AS (well-known community)\n"
7905 "Exact match of the communities")
7906
7907DEFUN (show_ip_bgp_ipv4_community_exact,
7908 show_ip_bgp_ipv4_community_exact_cmd,
7909 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7910 SHOW_STR
7911 IP_STR
7912 BGP_STR
7913 "Address family\n"
7914 "Address Family modifier\n"
7915 "Address Family modifier\n"
7916 "Display routes matching the communities\n"
7917 "community number\n"
7918 "Do not send outside local AS (well-known community)\n"
7919 "Do not advertise to any peer (well-known community)\n"
7920 "Do not export to next AS (well-known community)\n"
7921 "Exact match of the communities")
7922{
7923 if (strncmp (argv[0], "m", 1) == 0)
7924 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7925
7926 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7927}
7928
7929ALIAS (show_ip_bgp_ipv4_community_exact,
7930 show_ip_bgp_ipv4_community2_exact_cmd,
7931 "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",
7932 SHOW_STR
7933 IP_STR
7934 BGP_STR
7935 "Address family\n"
7936 "Address Family modifier\n"
7937 "Address Family modifier\n"
7938 "Display routes matching the communities\n"
7939 "community number\n"
7940 "Do not send outside local AS (well-known community)\n"
7941 "Do not advertise to any peer (well-known community)\n"
7942 "Do not export to next AS (well-known community)\n"
7943 "community number\n"
7944 "Do not send outside local AS (well-known community)\n"
7945 "Do not advertise to any peer (well-known community)\n"
7946 "Do not export to next AS (well-known community)\n"
7947 "Exact match of the communities")
7948
7949ALIAS (show_ip_bgp_ipv4_community_exact,
7950 show_ip_bgp_ipv4_community3_exact_cmd,
7951 "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",
7952 SHOW_STR
7953 IP_STR
7954 BGP_STR
7955 "Address family\n"
7956 "Address Family modifier\n"
7957 "Address Family modifier\n"
7958 "Display routes matching the communities\n"
7959 "community number\n"
7960 "Do not send outside local AS (well-known community)\n"
7961 "Do not advertise to any peer (well-known community)\n"
7962 "Do not export to next AS (well-known community)\n"
7963 "community number\n"
7964 "Do not send outside local AS (well-known community)\n"
7965 "Do not advertise to any peer (well-known community)\n"
7966 "Do not export to next AS (well-known community)\n"
7967 "community number\n"
7968 "Do not send outside local AS (well-known community)\n"
7969 "Do not advertise to any peer (well-known community)\n"
7970 "Do not export to next AS (well-known community)\n"
7971 "Exact match of the communities")
7972
7973ALIAS (show_ip_bgp_ipv4_community_exact,
7974 show_ip_bgp_ipv4_community4_exact_cmd,
7975 "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",
7976 SHOW_STR
7977 IP_STR
7978 BGP_STR
7979 "Address family\n"
7980 "Address Family modifier\n"
7981 "Address Family modifier\n"
7982 "Display routes matching the communities\n"
7983 "community number\n"
7984 "Do not send outside local AS (well-known community)\n"
7985 "Do not advertise to any peer (well-known community)\n"
7986 "Do not export to next AS (well-known community)\n"
7987 "community number\n"
7988 "Do not send outside local AS (well-known community)\n"
7989 "Do not advertise to any peer (well-known community)\n"
7990 "Do not export to next AS (well-known community)\n"
7991 "community number\n"
7992 "Do not send outside local AS (well-known community)\n"
7993 "Do not advertise to any peer (well-known community)\n"
7994 "Do not export to next AS (well-known community)\n"
7995 "community number\n"
7996 "Do not send outside local AS (well-known community)\n"
7997 "Do not advertise to any peer (well-known community)\n"
7998 "Do not export to next AS (well-known community)\n"
7999 "Exact match of the communities")
8000
8001#ifdef HAVE_IPV6
8002DEFUN (show_bgp_community,
8003 show_bgp_community_cmd,
8004 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8005 SHOW_STR
8006 BGP_STR
8007 "Display routes matching the communities\n"
8008 "community number\n"
8009 "Do not send outside local AS (well-known community)\n"
8010 "Do not advertise to any peer (well-known community)\n"
8011 "Do not export to next AS (well-known community)\n")
8012{
8013 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8014}
8015
8016ALIAS (show_bgp_community,
8017 show_bgp_ipv6_community_cmd,
8018 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8019 SHOW_STR
8020 BGP_STR
8021 "Address family\n"
8022 "Display routes matching the communities\n"
8023 "community number\n"
8024 "Do not send outside local AS (well-known community)\n"
8025 "Do not advertise to any peer (well-known community)\n"
8026 "Do not export to next AS (well-known community)\n")
8027
8028ALIAS (show_bgp_community,
8029 show_bgp_community2_cmd,
8030 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8031 SHOW_STR
8032 BGP_STR
8033 "Display routes matching the communities\n"
8034 "community number\n"
8035 "Do not send outside local AS (well-known community)\n"
8036 "Do not advertise to any peer (well-known community)\n"
8037 "Do not export to next AS (well-known community)\n"
8038 "community number\n"
8039 "Do not send outside local AS (well-known community)\n"
8040 "Do not advertise to any peer (well-known community)\n"
8041 "Do not export to next AS (well-known community)\n")
8042
8043ALIAS (show_bgp_community,
8044 show_bgp_ipv6_community2_cmd,
8045 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8046 SHOW_STR
8047 BGP_STR
8048 "Address family\n"
8049 "Display routes matching the communities\n"
8050 "community number\n"
8051 "Do not send outside local AS (well-known community)\n"
8052 "Do not advertise to any peer (well-known community)\n"
8053 "Do not export to next AS (well-known community)\n"
8054 "community number\n"
8055 "Do not send outside local AS (well-known community)\n"
8056 "Do not advertise to any peer (well-known community)\n"
8057 "Do not export to next AS (well-known community)\n")
8058
8059ALIAS (show_bgp_community,
8060 show_bgp_community3_cmd,
8061 "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)",
8062 SHOW_STR
8063 BGP_STR
8064 "Display routes matching the communities\n"
8065 "community number\n"
8066 "Do not send outside local AS (well-known community)\n"
8067 "Do not advertise to any peer (well-known community)\n"
8068 "Do not export to next AS (well-known community)\n"
8069 "community number\n"
8070 "Do not send outside local AS (well-known community)\n"
8071 "Do not advertise to any peer (well-known community)\n"
8072 "Do not export to next AS (well-known community)\n"
8073 "community number\n"
8074 "Do not send outside local AS (well-known community)\n"
8075 "Do not advertise to any peer (well-known community)\n"
8076 "Do not export to next AS (well-known community)\n")
8077
8078ALIAS (show_bgp_community,
8079 show_bgp_ipv6_community3_cmd,
8080 "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)",
8081 SHOW_STR
8082 BGP_STR
8083 "Address family\n"
8084 "Display routes matching the communities\n"
8085 "community number\n"
8086 "Do not send outside local AS (well-known community)\n"
8087 "Do not advertise to any peer (well-known community)\n"
8088 "Do not export to next AS (well-known community)\n"
8089 "community number\n"
8090 "Do not send outside local AS (well-known community)\n"
8091 "Do not advertise to any peer (well-known community)\n"
8092 "Do not export to next AS (well-known community)\n"
8093 "community number\n"
8094 "Do not send outside local AS (well-known community)\n"
8095 "Do not advertise to any peer (well-known community)\n"
8096 "Do not export to next AS (well-known community)\n")
8097
8098ALIAS (show_bgp_community,
8099 show_bgp_community4_cmd,
8100 "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)",
8101 SHOW_STR
8102 BGP_STR
8103 "Display routes matching the communities\n"
8104 "community number\n"
8105 "Do not send outside local AS (well-known community)\n"
8106 "Do not advertise to any peer (well-known community)\n"
8107 "Do not export to next AS (well-known community)\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_ipv6_community4_cmd,
8123 "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)",
8124 SHOW_STR
8125 BGP_STR
8126 "Address family\n"
8127 "Display routes matching the communities\n"
8128 "community number\n"
8129 "Do not send outside local AS (well-known community)\n"
8130 "Do not advertise to any peer (well-known community)\n"
8131 "Do not export to next AS (well-known community)\n"
8132 "community number\n"
8133 "Do not send outside local AS (well-known community)\n"
8134 "Do not advertise to any peer (well-known community)\n"
8135 "Do not export to next AS (well-known community)\n"
8136 "community number\n"
8137 "Do not send outside local AS (well-known community)\n"
8138 "Do not advertise to any peer (well-known community)\n"
8139 "Do not export to next AS (well-known community)\n"
8140 "community number\n"
8141 "Do not send outside local AS (well-known community)\n"
8142 "Do not advertise to any peer (well-known community)\n"
8143 "Do not export to next AS (well-known community)\n")
8144
8145/* old command */
8146DEFUN (show_ipv6_bgp_community,
8147 show_ipv6_bgp_community_cmd,
8148 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8149 SHOW_STR
8150 IPV6_STR
8151 BGP_STR
8152 "Display routes matching the communities\n"
8153 "community number\n"
8154 "Do not send outside local AS (well-known community)\n"
8155 "Do not advertise to any peer (well-known community)\n"
8156 "Do not export to next AS (well-known community)\n")
8157{
8158 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8159}
8160
8161/* old command */
8162ALIAS (show_ipv6_bgp_community,
8163 show_ipv6_bgp_community2_cmd,
8164 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8165 SHOW_STR
8166 IPV6_STR
8167 BGP_STR
8168 "Display routes matching the communities\n"
8169 "community number\n"
8170 "Do not send outside local AS (well-known community)\n"
8171 "Do not advertise to any peer (well-known community)\n"
8172 "Do not export to next AS (well-known community)\n"
8173 "community number\n"
8174 "Do not send outside local AS (well-known community)\n"
8175 "Do not advertise to any peer (well-known community)\n"
8176 "Do not export to next AS (well-known community)\n")
8177
8178/* old command */
8179ALIAS (show_ipv6_bgp_community,
8180 show_ipv6_bgp_community3_cmd,
8181 "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)",
8182 SHOW_STR
8183 IPV6_STR
8184 BGP_STR
8185 "Display routes matching the communities\n"
8186 "community number\n"
8187 "Do not send outside local AS (well-known community)\n"
8188 "Do not advertise to any peer (well-known community)\n"
8189 "Do not export to next AS (well-known community)\n"
8190 "community number\n"
8191 "Do not send outside local AS (well-known community)\n"
8192 "Do not advertise to any peer (well-known community)\n"
8193 "Do not export to next AS (well-known community)\n"
8194 "community number\n"
8195 "Do not send outside local AS (well-known community)\n"
8196 "Do not advertise to any peer (well-known community)\n"
8197 "Do not export to next AS (well-known community)\n")
8198
8199/* old command */
8200ALIAS (show_ipv6_bgp_community,
8201 show_ipv6_bgp_community4_cmd,
8202 "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)",
8203 SHOW_STR
8204 IPV6_STR
8205 BGP_STR
8206 "Display routes matching the communities\n"
8207 "community number\n"
8208 "Do not send outside local AS (well-known community)\n"
8209 "Do not advertise to any peer (well-known community)\n"
8210 "Do not export to next AS (well-known community)\n"
8211 "community number\n"
8212 "Do not send outside local AS (well-known community)\n"
8213 "Do not advertise to any peer (well-known community)\n"
8214 "Do not export to next AS (well-known community)\n"
8215 "community number\n"
8216 "Do not send outside local AS (well-known community)\n"
8217 "Do not advertise to any peer (well-known community)\n"
8218 "Do not export to next AS (well-known community)\n"
8219 "community number\n"
8220 "Do not send outside local AS (well-known community)\n"
8221 "Do not advertise to any peer (well-known community)\n"
8222 "Do not export to next AS (well-known community)\n")
8223
8224DEFUN (show_bgp_community_exact,
8225 show_bgp_community_exact_cmd,
8226 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8227 SHOW_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 "Exact match of the communities")
8235{
8236 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8237}
8238
8239ALIAS (show_bgp_community_exact,
8240 show_bgp_ipv6_community_exact_cmd,
8241 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8242 SHOW_STR
8243 BGP_STR
8244 "Address family\n"
8245 "Display routes matching the communities\n"
8246 "community number\n"
8247 "Do not send outside local AS (well-known community)\n"
8248 "Do not advertise to any peer (well-known community)\n"
8249 "Do not export to next AS (well-known community)\n"
8250 "Exact match of the communities")
8251
8252ALIAS (show_bgp_community_exact,
8253 show_bgp_community2_exact_cmd,
8254 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8255 SHOW_STR
8256 BGP_STR
8257 "Display routes matching the communities\n"
8258 "community number\n"
8259 "Do not send outside local AS (well-known community)\n"
8260 "Do not advertise to any peer (well-known community)\n"
8261 "Do not export to next AS (well-known community)\n"
8262 "community number\n"
8263 "Do not send outside local AS (well-known community)\n"
8264 "Do not advertise to any peer (well-known community)\n"
8265 "Do not export to next AS (well-known community)\n"
8266 "Exact match of the communities")
8267
8268ALIAS (show_bgp_community_exact,
8269 show_bgp_ipv6_community2_exact_cmd,
8270 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8271 SHOW_STR
8272 BGP_STR
8273 "Address family\n"
8274 "Display routes matching the communities\n"
8275 "community number\n"
8276 "Do not send outside local AS (well-known community)\n"
8277 "Do not advertise to any peer (well-known community)\n"
8278 "Do not export to next AS (well-known community)\n"
8279 "community number\n"
8280 "Do not send outside local AS (well-known community)\n"
8281 "Do not advertise to any peer (well-known community)\n"
8282 "Do not export to next AS (well-known community)\n"
8283 "Exact match of the communities")
8284
8285ALIAS (show_bgp_community_exact,
8286 show_bgp_community3_exact_cmd,
8287 "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",
8288 SHOW_STR
8289 BGP_STR
8290 "Display routes matching the communities\n"
8291 "community number\n"
8292 "Do not send outside local AS (well-known community)\n"
8293 "Do not advertise to any peer (well-known community)\n"
8294 "Do not export to next AS (well-known community)\n"
8295 "community number\n"
8296 "Do not send outside local AS (well-known community)\n"
8297 "Do not advertise to any peer (well-known community)\n"
8298 "Do not export to next AS (well-known community)\n"
8299 "community number\n"
8300 "Do not send outside local AS (well-known community)\n"
8301 "Do not advertise to any peer (well-known community)\n"
8302 "Do not export to next AS (well-known community)\n"
8303 "Exact match of the communities")
8304
8305ALIAS (show_bgp_community_exact,
8306 show_bgp_ipv6_community3_exact_cmd,
8307 "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",
8308 SHOW_STR
8309 BGP_STR
8310 "Address family\n"
8311 "Display routes matching the communities\n"
8312 "community number\n"
8313 "Do not send outside local AS (well-known community)\n"
8314 "Do not advertise to any peer (well-known community)\n"
8315 "Do not export to next AS (well-known community)\n"
8316 "community number\n"
8317 "Do not send outside local AS (well-known community)\n"
8318 "Do not advertise to any peer (well-known community)\n"
8319 "Do not export to next AS (well-known community)\n"
8320 "community number\n"
8321 "Do not send outside local AS (well-known community)\n"
8322 "Do not advertise to any peer (well-known community)\n"
8323 "Do not export to next AS (well-known community)\n"
8324 "Exact match of the communities")
8325
8326ALIAS (show_bgp_community_exact,
8327 show_bgp_community4_exact_cmd,
8328 "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",
8329 SHOW_STR
8330 BGP_STR
8331 "Display routes matching the communities\n"
8332 "community number\n"
8333 "Do not send outside local AS (well-known community)\n"
8334 "Do not advertise to any peer (well-known community)\n"
8335 "Do not export to next AS (well-known community)\n"
8336 "community number\n"
8337 "Do not send outside local AS (well-known community)\n"
8338 "Do not advertise to any peer (well-known community)\n"
8339 "Do not export to next AS (well-known community)\n"
8340 "community number\n"
8341 "Do not send outside local AS (well-known community)\n"
8342 "Do not advertise to any peer (well-known community)\n"
8343 "Do not export to next AS (well-known community)\n"
8344 "community number\n"
8345 "Do not send outside local AS (well-known community)\n"
8346 "Do not advertise to any peer (well-known community)\n"
8347 "Do not export to next AS (well-known community)\n"
8348 "Exact match of the communities")
8349
8350ALIAS (show_bgp_community_exact,
8351 show_bgp_ipv6_community4_exact_cmd,
8352 "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",
8353 SHOW_STR
8354 BGP_STR
8355 "Address family\n"
8356 "Display routes matching the communities\n"
8357 "community number\n"
8358 "Do not send outside local AS (well-known community)\n"
8359 "Do not advertise to any peer (well-known community)\n"
8360 "Do not export to next AS (well-known community)\n"
8361 "community number\n"
8362 "Do not send outside local AS (well-known community)\n"
8363 "Do not advertise to any peer (well-known community)\n"
8364 "Do not export to next AS (well-known community)\n"
8365 "community number\n"
8366 "Do not send outside local AS (well-known community)\n"
8367 "Do not advertise to any peer (well-known community)\n"
8368 "Do not export to next AS (well-known community)\n"
8369 "community number\n"
8370 "Do not send outside local AS (well-known community)\n"
8371 "Do not advertise to any peer (well-known community)\n"
8372 "Do not export to next AS (well-known community)\n"
8373 "Exact match of the communities")
8374
8375/* old command */
8376DEFUN (show_ipv6_bgp_community_exact,
8377 show_ipv6_bgp_community_exact_cmd,
8378 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8379 SHOW_STR
8380 IPV6_STR
8381 BGP_STR
8382 "Display routes matching the communities\n"
8383 "community number\n"
8384 "Do not send outside local AS (well-known community)\n"
8385 "Do not advertise to any peer (well-known community)\n"
8386 "Do not export to next AS (well-known community)\n"
8387 "Exact match of the communities")
8388{
8389 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8390}
8391
8392/* old command */
8393ALIAS (show_ipv6_bgp_community_exact,
8394 show_ipv6_bgp_community2_exact_cmd,
8395 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8396 SHOW_STR
8397 IPV6_STR
8398 BGP_STR
8399 "Display routes matching the communities\n"
8400 "community number\n"
8401 "Do not send outside local AS (well-known community)\n"
8402 "Do not advertise to any peer (well-known community)\n"
8403 "Do not export to next AS (well-known community)\n"
8404 "community number\n"
8405 "Do not send outside local AS (well-known community)\n"
8406 "Do not advertise to any peer (well-known community)\n"
8407 "Do not export to next AS (well-known community)\n"
8408 "Exact match of the communities")
8409
8410/* old command */
8411ALIAS (show_ipv6_bgp_community_exact,
8412 show_ipv6_bgp_community3_exact_cmd,
8413 "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",
8414 SHOW_STR
8415 IPV6_STR
8416 BGP_STR
8417 "Display routes matching the communities\n"
8418 "community number\n"
8419 "Do not send outside local AS (well-known community)\n"
8420 "Do not advertise to any peer (well-known community)\n"
8421 "Do not export to next AS (well-known community)\n"
8422 "community number\n"
8423 "Do not send outside local AS (well-known community)\n"
8424 "Do not advertise to any peer (well-known community)\n"
8425 "Do not export to next AS (well-known community)\n"
8426 "community number\n"
8427 "Do not send outside local AS (well-known community)\n"
8428 "Do not advertise to any peer (well-known community)\n"
8429 "Do not export to next AS (well-known community)\n"
8430 "Exact match of the communities")
8431
8432/* old command */
8433ALIAS (show_ipv6_bgp_community_exact,
8434 show_ipv6_bgp_community4_exact_cmd,
8435 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8436 SHOW_STR
8437 IPV6_STR
8438 BGP_STR
8439 "Display routes matching the communities\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n"
8448 "community number\n"
8449 "Do not send outside local AS (well-known community)\n"
8450 "Do not advertise to any peer (well-known community)\n"
8451 "Do not export to next AS (well-known community)\n"
8452 "community number\n"
8453 "Do not send outside local AS (well-known community)\n"
8454 "Do not advertise to any peer (well-known community)\n"
8455 "Do not export to next AS (well-known community)\n"
8456 "Exact match of the communities")
8457
8458/* old command */
8459DEFUN (show_ipv6_mbgp_community,
8460 show_ipv6_mbgp_community_cmd,
8461 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8462 SHOW_STR
8463 IPV6_STR
8464 MBGP_STR
8465 "Display routes matching the communities\n"
8466 "community number\n"
8467 "Do not send outside local AS (well-known community)\n"
8468 "Do not advertise to any peer (well-known community)\n"
8469 "Do not export to next AS (well-known community)\n")
8470{
8471 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8472}
8473
8474/* old command */
8475ALIAS (show_ipv6_mbgp_community,
8476 show_ipv6_mbgp_community2_cmd,
8477 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8478 SHOW_STR
8479 IPV6_STR
8480 MBGP_STR
8481 "Display routes matching the communities\n"
8482 "community number\n"
8483 "Do not send outside local AS (well-known community)\n"
8484 "Do not advertise to any peer (well-known community)\n"
8485 "Do not export to next AS (well-known community)\n"
8486 "community number\n"
8487 "Do not send outside local AS (well-known community)\n"
8488 "Do not advertise to any peer (well-known community)\n"
8489 "Do not export to next AS (well-known community)\n")
8490
8491/* old command */
8492ALIAS (show_ipv6_mbgp_community,
8493 show_ipv6_mbgp_community3_cmd,
8494 "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)",
8495 SHOW_STR
8496 IPV6_STR
8497 MBGP_STR
8498 "Display routes matching the communities\n"
8499 "community number\n"
8500 "Do not send outside local AS (well-known community)\n"
8501 "Do not advertise to any peer (well-known community)\n"
8502 "Do not export to next AS (well-known community)\n"
8503 "community number\n"
8504 "Do not send outside local AS (well-known community)\n"
8505 "Do not advertise to any peer (well-known community)\n"
8506 "Do not export to next AS (well-known community)\n"
8507 "community number\n"
8508 "Do not send outside local AS (well-known community)\n"
8509 "Do not advertise to any peer (well-known community)\n"
8510 "Do not export to next AS (well-known community)\n")
8511
8512/* old command */
8513ALIAS (show_ipv6_mbgp_community,
8514 show_ipv6_mbgp_community4_cmd,
8515 "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)",
8516 SHOW_STR
8517 IPV6_STR
8518 MBGP_STR
8519 "Display routes matching the communities\n"
8520 "community number\n"
8521 "Do not send outside local AS (well-known community)\n"
8522 "Do not advertise to any peer (well-known community)\n"
8523 "Do not export to next AS (well-known community)\n"
8524 "community number\n"
8525 "Do not send outside local AS (well-known community)\n"
8526 "Do not advertise to any peer (well-known community)\n"
8527 "Do not export to next AS (well-known community)\n"
8528 "community number\n"
8529 "Do not send outside local AS (well-known community)\n"
8530 "Do not advertise to any peer (well-known community)\n"
8531 "Do not export to next AS (well-known community)\n"
8532 "community number\n"
8533 "Do not send outside local AS (well-known community)\n"
8534 "Do not advertise to any peer (well-known community)\n"
8535 "Do not export to next AS (well-known community)\n")
8536
8537/* old command */
8538DEFUN (show_ipv6_mbgp_community_exact,
8539 show_ipv6_mbgp_community_exact_cmd,
8540 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8541 SHOW_STR
8542 IPV6_STR
8543 MBGP_STR
8544 "Display routes matching the communities\n"
8545 "community number\n"
8546 "Do not send outside local AS (well-known community)\n"
8547 "Do not advertise to any peer (well-known community)\n"
8548 "Do not export to next AS (well-known community)\n"
8549 "Exact match of the communities")
8550{
8551 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8552}
8553
8554/* old command */
8555ALIAS (show_ipv6_mbgp_community_exact,
8556 show_ipv6_mbgp_community2_exact_cmd,
8557 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8558 SHOW_STR
8559 IPV6_STR
8560 MBGP_STR
8561 "Display routes matching the communities\n"
8562 "community number\n"
8563 "Do not send outside local AS (well-known community)\n"
8564 "Do not advertise to any peer (well-known community)\n"
8565 "Do not export to next AS (well-known community)\n"
8566 "community number\n"
8567 "Do not send outside local AS (well-known community)\n"
8568 "Do not advertise to any peer (well-known community)\n"
8569 "Do not export to next AS (well-known community)\n"
8570 "Exact match of the communities")
8571
8572/* old command */
8573ALIAS (show_ipv6_mbgp_community_exact,
8574 show_ipv6_mbgp_community3_exact_cmd,
8575 "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",
8576 SHOW_STR
8577 IPV6_STR
8578 MBGP_STR
8579 "Display routes matching the communities\n"
8580 "community number\n"
8581 "Do not send outside local AS (well-known community)\n"
8582 "Do not advertise to any peer (well-known community)\n"
8583 "Do not export to next AS (well-known community)\n"
8584 "community number\n"
8585 "Do not send outside local AS (well-known community)\n"
8586 "Do not advertise to any peer (well-known community)\n"
8587 "Do not export to next AS (well-known community)\n"
8588 "community number\n"
8589 "Do not send outside local AS (well-known community)\n"
8590 "Do not advertise to any peer (well-known community)\n"
8591 "Do not export to next AS (well-known community)\n"
8592 "Exact match of the communities")
8593
8594/* old command */
8595ALIAS (show_ipv6_mbgp_community_exact,
8596 show_ipv6_mbgp_community4_exact_cmd,
8597 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8598 SHOW_STR
8599 IPV6_STR
8600 MBGP_STR
8601 "Display routes matching the communities\n"
8602 "community number\n"
8603 "Do not send outside local AS (well-known community)\n"
8604 "Do not advertise to any peer (well-known community)\n"
8605 "Do not export to next AS (well-known community)\n"
8606 "community number\n"
8607 "Do not send outside local AS (well-known community)\n"
8608 "Do not advertise to any peer (well-known community)\n"
8609 "Do not export to next AS (well-known community)\n"
8610 "community number\n"
8611 "Do not send outside local AS (well-known community)\n"
8612 "Do not advertise to any peer (well-known community)\n"
8613 "Do not export to next AS (well-known community)\n"
8614 "community number\n"
8615 "Do not send outside local AS (well-known community)\n"
8616 "Do not advertise to any peer (well-known community)\n"
8617 "Do not export to next AS (well-known community)\n"
8618 "Exact match of the communities")
8619#endif /* HAVE_IPV6 */
8620
paul94f2b392005-06-28 12:44:16 +00008621static int
paulfd79ac92004-10-13 05:06:08 +00008622bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008623 u_int16_t afi, u_char safi)
8624{
8625 struct community_list *list;
8626
hassofee6e4e2005-02-02 16:29:31 +00008627 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008628 if (list == NULL)
8629 {
8630 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8631 VTY_NEWLINE);
8632 return CMD_WARNING;
8633 }
8634
ajs5a646652004-11-05 01:25:55 +00008635 return bgp_show (vty, NULL, afi, safi,
8636 (exact ? bgp_show_type_community_list_exact :
8637 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008638}
8639
8640DEFUN (show_ip_bgp_community_list,
8641 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008642 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008643 SHOW_STR
8644 IP_STR
8645 BGP_STR
8646 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008647 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008648 "community-list name\n")
8649{
8650 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8651}
8652
8653DEFUN (show_ip_bgp_ipv4_community_list,
8654 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008655 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008656 SHOW_STR
8657 IP_STR
8658 BGP_STR
8659 "Address family\n"
8660 "Address Family modifier\n"
8661 "Address Family modifier\n"
8662 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008663 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008664 "community-list name\n")
8665{
8666 if (strncmp (argv[0], "m", 1) == 0)
8667 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8668
8669 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8670}
8671
8672DEFUN (show_ip_bgp_community_list_exact,
8673 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008674 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008675 SHOW_STR
8676 IP_STR
8677 BGP_STR
8678 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008679 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008680 "community-list name\n"
8681 "Exact match of the communities\n")
8682{
8683 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8684}
8685
8686DEFUN (show_ip_bgp_ipv4_community_list_exact,
8687 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008688 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008689 SHOW_STR
8690 IP_STR
8691 BGP_STR
8692 "Address family\n"
8693 "Address Family modifier\n"
8694 "Address Family modifier\n"
8695 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008696 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008697 "community-list name\n"
8698 "Exact match of the communities\n")
8699{
8700 if (strncmp (argv[0], "m", 1) == 0)
8701 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8702
8703 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8704}
8705
8706#ifdef HAVE_IPV6
8707DEFUN (show_bgp_community_list,
8708 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008709 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008710 SHOW_STR
8711 BGP_STR
8712 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008713 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008714 "community-list name\n")
8715{
8716 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8717}
8718
8719ALIAS (show_bgp_community_list,
8720 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008721 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008722 SHOW_STR
8723 BGP_STR
8724 "Address family\n"
8725 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008726 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008727 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008728
8729/* old command */
8730DEFUN (show_ipv6_bgp_community_list,
8731 show_ipv6_bgp_community_list_cmd,
8732 "show ipv6 bgp community-list WORD",
8733 SHOW_STR
8734 IPV6_STR
8735 BGP_STR
8736 "Display routes matching the community-list\n"
8737 "community-list name\n")
8738{
8739 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8740}
8741
8742/* old command */
8743DEFUN (show_ipv6_mbgp_community_list,
8744 show_ipv6_mbgp_community_list_cmd,
8745 "show ipv6 mbgp community-list WORD",
8746 SHOW_STR
8747 IPV6_STR
8748 MBGP_STR
8749 "Display routes matching the community-list\n"
8750 "community-list name\n")
8751{
8752 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8753}
8754
8755DEFUN (show_bgp_community_list_exact,
8756 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008757 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008758 SHOW_STR
8759 BGP_STR
8760 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008761 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008762 "community-list name\n"
8763 "Exact match of the communities\n")
8764{
8765 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8766}
8767
8768ALIAS (show_bgp_community_list_exact,
8769 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008770 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008771 SHOW_STR
8772 BGP_STR
8773 "Address family\n"
8774 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008775 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008776 "community-list name\n"
8777 "Exact match of the communities\n")
8778
8779/* old command */
8780DEFUN (show_ipv6_bgp_community_list_exact,
8781 show_ipv6_bgp_community_list_exact_cmd,
8782 "show ipv6 bgp community-list WORD exact-match",
8783 SHOW_STR
8784 IPV6_STR
8785 BGP_STR
8786 "Display routes matching the community-list\n"
8787 "community-list name\n"
8788 "Exact match of the communities\n")
8789{
8790 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8791}
8792
8793/* old command */
8794DEFUN (show_ipv6_mbgp_community_list_exact,
8795 show_ipv6_mbgp_community_list_exact_cmd,
8796 "show ipv6 mbgp community-list WORD exact-match",
8797 SHOW_STR
8798 IPV6_STR
8799 MBGP_STR
8800 "Display routes matching the community-list\n"
8801 "community-list name\n"
8802 "Exact match of the communities\n")
8803{
8804 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8805}
8806#endif /* HAVE_IPV6 */
8807
paul94f2b392005-06-28 12:44:16 +00008808static int
paulfd79ac92004-10-13 05:06:08 +00008809bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008810 safi_t safi, enum bgp_show_type type)
8811{
8812 int ret;
8813 struct prefix *p;
8814
8815 p = prefix_new();
8816
8817 ret = str2prefix (prefix, p);
8818 if (! ret)
8819 {
8820 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8821 return CMD_WARNING;
8822 }
8823
ajs5a646652004-11-05 01:25:55 +00008824 ret = bgp_show (vty, NULL, afi, safi, type, p);
8825 prefix_free(p);
8826 return ret;
paul718e3742002-12-13 20:15:29 +00008827}
8828
8829DEFUN (show_ip_bgp_prefix_longer,
8830 show_ip_bgp_prefix_longer_cmd,
8831 "show ip bgp A.B.C.D/M longer-prefixes",
8832 SHOW_STR
8833 IP_STR
8834 BGP_STR
8835 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8836 "Display route and more specific routes\n")
8837{
8838 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8839 bgp_show_type_prefix_longer);
8840}
8841
8842DEFUN (show_ip_bgp_flap_prefix_longer,
8843 show_ip_bgp_flap_prefix_longer_cmd,
8844 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8845 SHOW_STR
8846 IP_STR
8847 BGP_STR
8848 "Display flap statistics of routes\n"
8849 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8850 "Display route and more specific routes\n")
8851{
8852 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8853 bgp_show_type_flap_prefix_longer);
8854}
8855
8856DEFUN (show_ip_bgp_ipv4_prefix_longer,
8857 show_ip_bgp_ipv4_prefix_longer_cmd,
8858 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8859 SHOW_STR
8860 IP_STR
8861 BGP_STR
8862 "Address family\n"
8863 "Address Family modifier\n"
8864 "Address Family modifier\n"
8865 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8866 "Display route and more specific routes\n")
8867{
8868 if (strncmp (argv[0], "m", 1) == 0)
8869 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8870 bgp_show_type_prefix_longer);
8871
8872 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8873 bgp_show_type_prefix_longer);
8874}
8875
8876DEFUN (show_ip_bgp_flap_address,
8877 show_ip_bgp_flap_address_cmd,
8878 "show ip bgp flap-statistics A.B.C.D",
8879 SHOW_STR
8880 IP_STR
8881 BGP_STR
8882 "Display flap statistics of routes\n"
8883 "Network in the BGP routing table to display\n")
8884{
8885 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8886 bgp_show_type_flap_address);
8887}
8888
8889DEFUN (show_ip_bgp_flap_prefix,
8890 show_ip_bgp_flap_prefix_cmd,
8891 "show ip bgp flap-statistics A.B.C.D/M",
8892 SHOW_STR
8893 IP_STR
8894 BGP_STR
8895 "Display flap statistics of routes\n"
8896 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8897{
8898 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8899 bgp_show_type_flap_prefix);
8900}
8901#ifdef HAVE_IPV6
8902DEFUN (show_bgp_prefix_longer,
8903 show_bgp_prefix_longer_cmd,
8904 "show bgp X:X::X:X/M longer-prefixes",
8905 SHOW_STR
8906 BGP_STR
8907 "IPv6 prefix <network>/<length>\n"
8908 "Display route and more specific routes\n")
8909{
8910 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8911 bgp_show_type_prefix_longer);
8912}
8913
8914ALIAS (show_bgp_prefix_longer,
8915 show_bgp_ipv6_prefix_longer_cmd,
8916 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8917 SHOW_STR
8918 BGP_STR
8919 "Address family\n"
8920 "IPv6 prefix <network>/<length>\n"
8921 "Display route and more specific routes\n")
8922
8923/* old command */
8924DEFUN (show_ipv6_bgp_prefix_longer,
8925 show_ipv6_bgp_prefix_longer_cmd,
8926 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8927 SHOW_STR
8928 IPV6_STR
8929 BGP_STR
8930 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\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
8937/* old command */
8938DEFUN (show_ipv6_mbgp_prefix_longer,
8939 show_ipv6_mbgp_prefix_longer_cmd,
8940 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8941 SHOW_STR
8942 IPV6_STR
8943 MBGP_STR
8944 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8945 "Display route and more specific routes\n")
8946{
8947 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8948 bgp_show_type_prefix_longer);
8949}
8950#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008951
paul94f2b392005-06-28 12:44:16 +00008952static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008953peer_lookup_in_view (struct vty *vty, const char *view_name,
8954 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008955{
8956 int ret;
8957 struct bgp *bgp;
8958 struct peer *peer;
8959 union sockunion su;
8960
8961 /* BGP structure lookup. */
8962 if (view_name)
8963 {
8964 bgp = bgp_lookup_by_name (view_name);
8965 if (! bgp)
8966 {
8967 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8968 return NULL;
8969 }
8970 }
paul5228ad22004-06-04 17:58:18 +00008971 else
paulbb46e942003-10-24 19:02:03 +00008972 {
8973 bgp = bgp_get_default ();
8974 if (! bgp)
8975 {
8976 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8977 return NULL;
8978 }
8979 }
8980
8981 /* Get peer sockunion. */
8982 ret = str2sockunion (ip_str, &su);
8983 if (ret < 0)
8984 {
8985 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8986 return NULL;
8987 }
8988
8989 /* Peer structure lookup. */
8990 peer = peer_lookup (bgp, &su);
8991 if (! peer)
8992 {
8993 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8994 return NULL;
8995 }
8996
8997 return peer;
8998}
Paul Jakma2815e612006-09-14 02:56:07 +00008999
9000enum bgp_stats
9001{
9002 BGP_STATS_MAXBITLEN = 0,
9003 BGP_STATS_RIB,
9004 BGP_STATS_PREFIXES,
9005 BGP_STATS_TOTPLEN,
9006 BGP_STATS_UNAGGREGATEABLE,
9007 BGP_STATS_MAX_AGGREGATEABLE,
9008 BGP_STATS_AGGREGATES,
9009 BGP_STATS_SPACE,
9010 BGP_STATS_ASPATH_COUNT,
9011 BGP_STATS_ASPATH_MAXHOPS,
9012 BGP_STATS_ASPATH_TOTHOPS,
9013 BGP_STATS_ASPATH_MAXSIZE,
9014 BGP_STATS_ASPATH_TOTSIZE,
9015 BGP_STATS_ASN_HIGHEST,
9016 BGP_STATS_MAX,
9017};
paulbb46e942003-10-24 19:02:03 +00009018
Paul Jakma2815e612006-09-14 02:56:07 +00009019static const char *table_stats_strs[] =
9020{
9021 [BGP_STATS_PREFIXES] = "Total Prefixes",
9022 [BGP_STATS_TOTPLEN] = "Average prefix length",
9023 [BGP_STATS_RIB] = "Total Advertisements",
9024 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9025 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9026 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9027 [BGP_STATS_SPACE] = "Address space advertised",
9028 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9029 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9030 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9031 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9032 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9033 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9034 [BGP_STATS_MAX] = NULL,
9035};
9036
9037struct bgp_table_stats
9038{
9039 struct bgp_table *table;
9040 unsigned long long counts[BGP_STATS_MAX];
9041};
9042
9043#if 0
9044#define TALLY_SIGFIG 100000
9045static unsigned long
9046ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9047{
9048 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9049 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9050 unsigned long ret = newtot / count;
9051
9052 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9053 return ret + 1;
9054 else
9055 return ret;
9056}
9057#endif
9058
9059static int
9060bgp_table_stats_walker (struct thread *t)
9061{
9062 struct bgp_node *rn;
9063 struct bgp_node *top;
9064 struct bgp_table_stats *ts = THREAD_ARG (t);
9065 unsigned int space = 0;
9066
Paul Jakma53d9f672006-10-15 23:41:16 +00009067 if (!(top = bgp_table_top (ts->table)))
9068 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009069
9070 switch (top->p.family)
9071 {
9072 case AF_INET:
9073 space = IPV4_MAX_BITLEN;
9074 break;
9075 case AF_INET6:
9076 space = IPV6_MAX_BITLEN;
9077 break;
9078 }
9079
9080 ts->counts[BGP_STATS_MAXBITLEN] = space;
9081
9082 for (rn = top; rn; rn = bgp_route_next (rn))
9083 {
9084 struct bgp_info *ri;
9085 struct bgp_node *prn = rn->parent;
9086 unsigned int rinum = 0;
9087
9088 if (rn == top)
9089 continue;
9090
9091 if (!rn->info)
9092 continue;
9093
9094 ts->counts[BGP_STATS_PREFIXES]++;
9095 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9096
9097#if 0
9098 ts->counts[BGP_STATS_AVGPLEN]
9099 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9100 ts->counts[BGP_STATS_AVGPLEN],
9101 rn->p.prefixlen);
9102#endif
9103
9104 /* check if the prefix is included by any other announcements */
9105 while (prn && !prn->info)
9106 prn = prn->parent;
9107
9108 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009109 {
9110 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9111 /* announced address space */
9112 if (space)
9113 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9114 }
Paul Jakma2815e612006-09-14 02:56:07 +00009115 else if (prn->info)
9116 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9117
Paul Jakma2815e612006-09-14 02:56:07 +00009118 for (ri = rn->info; ri; ri = ri->next)
9119 {
9120 rinum++;
9121 ts->counts[BGP_STATS_RIB]++;
9122
9123 if (ri->attr &&
9124 (CHECK_FLAG (ri->attr->flag,
9125 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9126 ts->counts[BGP_STATS_AGGREGATES]++;
9127
9128 /* as-path stats */
9129 if (ri->attr && ri->attr->aspath)
9130 {
9131 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9132 unsigned int size = aspath_size (ri->attr->aspath);
9133 as_t highest = aspath_highest (ri->attr->aspath);
9134
9135 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9136
9137 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9138 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9139
9140 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9141 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9142
9143 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9144 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9145#if 0
9146 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9147 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9148 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9149 hops);
9150 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9151 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9152 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9153 size);
9154#endif
9155 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9156 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9157 }
9158 }
9159 }
9160 return 0;
9161}
9162
9163static int
9164bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9165{
9166 struct bgp_table_stats ts;
9167 unsigned int i;
9168
9169 if (!bgp->rib[afi][safi])
9170 {
9171 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9172 return CMD_WARNING;
9173 }
9174
9175 memset (&ts, 0, sizeof (ts));
9176 ts.table = bgp->rib[afi][safi];
9177 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9178
9179 vty_out (vty, "BGP %s RIB statistics%s%s",
9180 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9181
9182 for (i = 0; i < BGP_STATS_MAX; i++)
9183 {
9184 if (!table_stats_strs[i])
9185 continue;
9186
9187 switch (i)
9188 {
9189#if 0
9190 case BGP_STATS_ASPATH_AVGHOPS:
9191 case BGP_STATS_ASPATH_AVGSIZE:
9192 case BGP_STATS_AVGPLEN:
9193 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9194 vty_out (vty, "%12.2f",
9195 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9196 break;
9197#endif
9198 case BGP_STATS_ASPATH_TOTHOPS:
9199 case BGP_STATS_ASPATH_TOTSIZE:
9200 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9201 vty_out (vty, "%12.2f",
9202 ts.counts[i] ?
9203 (float)ts.counts[i] /
9204 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9205 : 0);
9206 break;
9207 case BGP_STATS_TOTPLEN:
9208 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9209 vty_out (vty, "%12.2f",
9210 ts.counts[i] ?
9211 (float)ts.counts[i] /
9212 (float)ts.counts[BGP_STATS_PREFIXES]
9213 : 0);
9214 break;
9215 case BGP_STATS_SPACE:
9216 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9217 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9218 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9219 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009220 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009221 vty_out (vty, "%12.2f%s",
9222 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009223 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009224 VTY_NEWLINE);
9225 vty_out (vty, "%30s: ", "/8 equivalent ");
9226 vty_out (vty, "%12.2f%s",
9227 (float)ts.counts[BGP_STATS_SPACE] /
9228 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9229 VTY_NEWLINE);
9230 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9231 break;
9232 vty_out (vty, "%30s: ", "/24 equivalent ");
9233 vty_out (vty, "%12.2f",
9234 (float)ts.counts[BGP_STATS_SPACE] /
9235 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9236 break;
9237 default:
9238 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9239 vty_out (vty, "%12llu", ts.counts[i]);
9240 }
9241
9242 vty_out (vty, "%s", VTY_NEWLINE);
9243 }
9244 return CMD_SUCCESS;
9245}
9246
9247static int
9248bgp_table_stats_vty (struct vty *vty, const char *name,
9249 const char *afi_str, const char *safi_str)
9250{
9251 struct bgp *bgp;
9252 afi_t afi;
9253 safi_t safi;
9254
9255 if (name)
9256 bgp = bgp_lookup_by_name (name);
9257 else
9258 bgp = bgp_get_default ();
9259
9260 if (!bgp)
9261 {
9262 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9263 return CMD_WARNING;
9264 }
9265 if (strncmp (afi_str, "ipv", 3) == 0)
9266 {
9267 if (strncmp (afi_str, "ipv4", 4) == 0)
9268 afi = AFI_IP;
9269 else if (strncmp (afi_str, "ipv6", 4) == 0)
9270 afi = AFI_IP6;
9271 else
9272 {
9273 vty_out (vty, "%% Invalid address family %s%s",
9274 afi_str, VTY_NEWLINE);
9275 return CMD_WARNING;
9276 }
9277 if (strncmp (safi_str, "m", 1) == 0)
9278 safi = SAFI_MULTICAST;
9279 else if (strncmp (safi_str, "u", 1) == 0)
9280 safi = SAFI_UNICAST;
9281 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9282 safi = BGP_SAFI_VPNV4;
9283 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9284 safi = BGP_SAFI_VPNV6;
9285 else
9286 {
9287 vty_out (vty, "%% Invalid subsequent address family %s%s",
9288 safi_str, VTY_NEWLINE);
9289 return CMD_WARNING;
9290 }
9291 }
9292 else
9293 {
9294 vty_out (vty, "%% Invalid address family %s%s",
9295 afi_str, VTY_NEWLINE);
9296 return CMD_WARNING;
9297 }
9298
9299 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9300 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9301 {
9302 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9303 afi_str, safi_str, VTY_NEWLINE);
9304 return CMD_WARNING;
9305 }
9306 return bgp_table_stats (vty, bgp, afi, safi);
9307}
9308
9309DEFUN (show_bgp_statistics,
9310 show_bgp_statistics_cmd,
9311 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9312 SHOW_STR
9313 BGP_STR
9314 "Address family\n"
9315 "Address family\n"
9316 "Address Family modifier\n"
9317 "Address Family modifier\n"
9318 "BGP RIB advertisement statistics\n")
9319{
9320 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9321}
9322
9323ALIAS (show_bgp_statistics,
9324 show_bgp_statistics_vpnv4_cmd,
9325 "show bgp (ipv4) (vpnv4) statistics",
9326 SHOW_STR
9327 BGP_STR
9328 "Address family\n"
9329 "Address Family modifier\n"
9330 "BGP RIB advertisement statistics\n")
9331
9332DEFUN (show_bgp_statistics_view,
9333 show_bgp_statistics_view_cmd,
9334 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9335 SHOW_STR
9336 BGP_STR
9337 "BGP view\n"
9338 "Address family\n"
9339 "Address family\n"
9340 "Address Family modifier\n"
9341 "Address Family modifier\n"
9342 "BGP RIB advertisement statistics\n")
9343{
9344 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9345}
9346
9347ALIAS (show_bgp_statistics_view,
9348 show_bgp_statistics_view_vpnv4_cmd,
9349 "show bgp view WORD (ipv4) (vpnv4) statistics",
9350 SHOW_STR
9351 BGP_STR
9352 "BGP view\n"
9353 "Address family\n"
9354 "Address Family modifier\n"
9355 "BGP RIB advertisement statistics\n")
9356
Paul Jakmaff7924f2006-09-04 01:10:36 +00009357enum bgp_pcounts
9358{
9359 PCOUNT_ADJ_IN = 0,
9360 PCOUNT_DAMPED,
9361 PCOUNT_REMOVED,
9362 PCOUNT_HISTORY,
9363 PCOUNT_STALE,
9364 PCOUNT_VALID,
9365 PCOUNT_ALL,
9366 PCOUNT_COUNTED,
9367 PCOUNT_PFCNT, /* the figure we display to users */
9368 PCOUNT_MAX,
9369};
9370
9371static const char *pcount_strs[] =
9372{
9373 [PCOUNT_ADJ_IN] = "Adj-in",
9374 [PCOUNT_DAMPED] = "Damped",
9375 [PCOUNT_REMOVED] = "Removed",
9376 [PCOUNT_HISTORY] = "History",
9377 [PCOUNT_STALE] = "Stale",
9378 [PCOUNT_VALID] = "Valid",
9379 [PCOUNT_ALL] = "All RIB",
9380 [PCOUNT_COUNTED] = "PfxCt counted",
9381 [PCOUNT_PFCNT] = "Useable",
9382 [PCOUNT_MAX] = NULL,
9383};
9384
Paul Jakma2815e612006-09-14 02:56:07 +00009385struct peer_pcounts
9386{
9387 unsigned int count[PCOUNT_MAX];
9388 const struct peer *peer;
9389 const struct bgp_table *table;
9390};
9391
Paul Jakmaff7924f2006-09-04 01:10:36 +00009392static int
Paul Jakma2815e612006-09-14 02:56:07 +00009393bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009394{
9395 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009396 struct peer_pcounts *pc = THREAD_ARG (t);
9397 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009398
Paul Jakma2815e612006-09-14 02:56:07 +00009399 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009400 {
9401 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009402 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009403
9404 for (ain = rn->adj_in; ain; ain = ain->next)
9405 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009406 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009407
Paul Jakmaff7924f2006-09-04 01:10:36 +00009408 for (ri = rn->info; ri; ri = ri->next)
9409 {
9410 char buf[SU_ADDRSTRLEN];
9411
9412 if (ri->peer != peer)
9413 continue;
9414
Paul Jakma2815e612006-09-14 02:56:07 +00009415 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009416
9417 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009418 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009419 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009420 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009421 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009422 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009423 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009424 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009425 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009426 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009427 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009428 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009429
9430 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9431 {
Paul Jakma2815e612006-09-14 02:56:07 +00009432 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009433 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009434 plog_warn (peer->log,
9435 "%s [pcount] %s/%d is counted but flags 0x%x",
9436 peer->host,
9437 inet_ntop(rn->p.family, &rn->p.u.prefix,
9438 buf, SU_ADDRSTRLEN),
9439 rn->p.prefixlen,
9440 ri->flags);
9441 }
9442 else
9443 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009444 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009445 plog_warn (peer->log,
9446 "%s [pcount] %s/%d not counted but flags 0x%x",
9447 peer->host,
9448 inet_ntop(rn->p.family, &rn->p.u.prefix,
9449 buf, SU_ADDRSTRLEN),
9450 rn->p.prefixlen,
9451 ri->flags);
9452 }
9453 }
9454 }
Paul Jakma2815e612006-09-14 02:56:07 +00009455 return 0;
9456}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009457
Paul Jakma2815e612006-09-14 02:56:07 +00009458static int
9459bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9460{
9461 struct peer_pcounts pcounts = { .peer = peer };
9462 unsigned int i;
9463
9464 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9465 || !peer->bgp->rib[afi][safi])
9466 {
9467 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9468 return CMD_WARNING;
9469 }
9470
9471 memset (&pcounts, 0, sizeof(pcounts));
9472 pcounts.peer = peer;
9473 pcounts.table = peer->bgp->rib[afi][safi];
9474
9475 /* in-place call via thread subsystem so as to record execution time
9476 * stats for the thread-walk (i.e. ensure this can't be blamed on
9477 * on just vty_read()).
9478 */
9479 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9480
Paul Jakmaff7924f2006-09-04 01:10:36 +00009481 vty_out (vty, "Prefix counts for %s, %s%s",
9482 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9483 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9484 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9485 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9486
9487 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009488 vty_out (vty, "%20s: %-10d%s",
9489 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009490
Paul Jakma2815e612006-09-14 02:56:07 +00009491 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009492 {
9493 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9494 peer->host, VTY_NEWLINE);
9495 vty_out (vty, "Please report this bug, with the above command output%s",
9496 VTY_NEWLINE);
9497 }
9498
9499 return CMD_SUCCESS;
9500}
9501
9502DEFUN (show_ip_bgp_neighbor_prefix_counts,
9503 show_ip_bgp_neighbor_prefix_counts_cmd,
9504 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9505 SHOW_STR
9506 IP_STR
9507 BGP_STR
9508 "Detailed information on TCP and BGP neighbor connections\n"
9509 "Neighbor to display information about\n"
9510 "Neighbor to display information about\n"
9511 "Display detailed prefix count information\n")
9512{
9513 struct peer *peer;
9514
9515 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9516 if (! peer)
9517 return CMD_WARNING;
9518
9519 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9520}
9521
9522DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9523 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9524 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9525 SHOW_STR
9526 BGP_STR
9527 "Address family\n"
9528 "Detailed information on TCP and BGP neighbor connections\n"
9529 "Neighbor to display information about\n"
9530 "Neighbor to display information about\n"
9531 "Display detailed prefix count information\n")
9532{
9533 struct peer *peer;
9534
9535 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9536 if (! peer)
9537 return CMD_WARNING;
9538
9539 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9540}
9541
9542DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9543 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9544 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9545 SHOW_STR
9546 IP_STR
9547 BGP_STR
9548 "Address family\n"
9549 "Address Family modifier\n"
9550 "Address Family modifier\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[1]);
9559 if (! peer)
9560 return CMD_WARNING;
9561
9562 if (strncmp (argv[0], "m", 1) == 0)
9563 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9564
9565 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9566}
9567
9568DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9569 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9570 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9571 SHOW_STR
9572 IP_STR
9573 BGP_STR
9574 "Address family\n"
9575 "Address Family modifier\n"
9576 "Address Family modifier\n"
9577 "Detailed information on TCP and BGP neighbor connections\n"
9578 "Neighbor to display information about\n"
9579 "Neighbor to display information about\n"
9580 "Display detailed prefix count information\n")
9581{
9582 struct peer *peer;
9583
9584 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9585 if (! peer)
9586 return CMD_WARNING;
9587
9588 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9589}
9590
9591
paul94f2b392005-06-28 12:44:16 +00009592static void
paul718e3742002-12-13 20:15:29 +00009593show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9594 int in)
9595{
9596 struct bgp_table *table;
9597 struct bgp_adj_in *ain;
9598 struct bgp_adj_out *adj;
9599 unsigned long output_count;
9600 struct bgp_node *rn;
9601 int header1 = 1;
9602 struct bgp *bgp;
9603 int header2 = 1;
9604
paulbb46e942003-10-24 19:02:03 +00009605 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009606
9607 if (! bgp)
9608 return;
9609
9610 table = bgp->rib[afi][safi];
9611
9612 output_count = 0;
9613
9614 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9615 PEER_STATUS_DEFAULT_ORIGINATE))
9616 {
9617 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 +00009618 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9619 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009620
9621 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9622 VTY_NEWLINE, VTY_NEWLINE);
9623 header1 = 0;
9624 }
9625
9626 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9627 if (in)
9628 {
9629 for (ain = rn->adj_in; ain; ain = ain->next)
9630 if (ain->peer == peer)
9631 {
9632 if (header1)
9633 {
9634 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 +00009635 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9636 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009637 header1 = 0;
9638 }
9639 if (header2)
9640 {
9641 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9642 header2 = 0;
9643 }
9644 if (ain->attr)
9645 {
9646 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9647 output_count++;
9648 }
9649 }
9650 }
9651 else
9652 {
9653 for (adj = rn->adj_out; adj; adj = adj->next)
9654 if (adj->peer == peer)
9655 {
9656 if (header1)
9657 {
9658 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 +00009659 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9660 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009661 header1 = 0;
9662 }
9663 if (header2)
9664 {
9665 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9666 header2 = 0;
9667 }
9668 if (adj->attr)
9669 {
9670 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9671 output_count++;
9672 }
9673 }
9674 }
9675
9676 if (output_count != 0)
9677 vty_out (vty, "%sTotal number of prefixes %ld%s",
9678 VTY_NEWLINE, output_count, VTY_NEWLINE);
9679}
9680
paul94f2b392005-06-28 12:44:16 +00009681static int
paulbb46e942003-10-24 19:02:03 +00009682peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9683{
paul718e3742002-12-13 20:15:29 +00009684 if (! peer || ! peer->afc[afi][safi])
9685 {
9686 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9687 return CMD_WARNING;
9688 }
9689
9690 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9691 {
9692 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9693 VTY_NEWLINE);
9694 return CMD_WARNING;
9695 }
9696
9697 show_adj_route (vty, peer, afi, safi, in);
9698
9699 return CMD_SUCCESS;
9700}
9701
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009702DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9703 show_ip_bgp_view_neighbor_advertised_route_cmd,
9704 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9705 SHOW_STR
9706 IP_STR
9707 BGP_STR
9708 "BGP view\n"
9709 "View name\n"
9710 "Detailed information on TCP and BGP neighbor connections\n"
9711 "Neighbor to display information about\n"
9712 "Neighbor to display information about\n"
9713 "Display the routes advertised to a BGP neighbor\n")
9714{
9715 struct peer *peer;
9716
9717 if (argc == 2)
9718 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9719 else
9720 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9721
9722 if (! peer)
9723 return CMD_WARNING;
9724
9725 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9726}
9727
9728ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009729 show_ip_bgp_neighbor_advertised_route_cmd,
9730 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9731 SHOW_STR
9732 IP_STR
9733 BGP_STR
9734 "Detailed information on TCP and BGP neighbor connections\n"
9735 "Neighbor to display information about\n"
9736 "Neighbor to display information about\n"
9737 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009738
9739DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9740 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9741 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9742 SHOW_STR
9743 IP_STR
9744 BGP_STR
9745 "Address family\n"
9746 "Address Family modifier\n"
9747 "Address Family modifier\n"
9748 "Detailed information on TCP and BGP neighbor connections\n"
9749 "Neighbor to display information about\n"
9750 "Neighbor to display information about\n"
9751 "Display the routes advertised to a BGP neighbor\n")
9752{
paulbb46e942003-10-24 19:02:03 +00009753 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009754
paulbb46e942003-10-24 19:02:03 +00009755 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9756 if (! peer)
9757 return CMD_WARNING;
9758
9759 if (strncmp (argv[0], "m", 1) == 0)
9760 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9761
9762 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009763}
9764
9765#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009766DEFUN (show_bgp_view_neighbor_advertised_route,
9767 show_bgp_view_neighbor_advertised_route_cmd,
9768 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9769 SHOW_STR
9770 BGP_STR
9771 "BGP view\n"
9772 "View name\n"
9773 "Detailed information on TCP and BGP neighbor connections\n"
9774 "Neighbor to display information about\n"
9775 "Neighbor to display information about\n"
9776 "Display the routes advertised to a BGP neighbor\n")
9777{
9778 struct peer *peer;
9779
9780 if (argc == 2)
9781 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9782 else
9783 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9784
9785 if (! peer)
9786 return CMD_WARNING;
9787
9788 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9789}
9790
9791ALIAS (show_bgp_view_neighbor_advertised_route,
9792 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9793 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9794 SHOW_STR
9795 BGP_STR
9796 "BGP view\n"
9797 "View name\n"
9798 "Address family\n"
9799 "Detailed information on TCP and BGP neighbor connections\n"
9800 "Neighbor to display information about\n"
9801 "Neighbor to display information about\n"
9802 "Display the routes advertised to a BGP neighbor\n")
9803
9804DEFUN (show_bgp_view_neighbor_received_routes,
9805 show_bgp_view_neighbor_received_routes_cmd,
9806 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9807 SHOW_STR
9808 BGP_STR
9809 "BGP view\n"
9810 "View name\n"
9811 "Detailed information on TCP and BGP neighbor connections\n"
9812 "Neighbor to display information about\n"
9813 "Neighbor to display information about\n"
9814 "Display the received routes from neighbor\n")
9815{
9816 struct peer *peer;
9817
9818 if (argc == 2)
9819 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9820 else
9821 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9822
9823 if (! peer)
9824 return CMD_WARNING;
9825
9826 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9827}
9828
9829ALIAS (show_bgp_view_neighbor_received_routes,
9830 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9831 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9832 SHOW_STR
9833 BGP_STR
9834 "BGP view\n"
9835 "View name\n"
9836 "Address family\n"
9837 "Detailed information on TCP and BGP neighbor connections\n"
9838 "Neighbor to display information about\n"
9839 "Neighbor to display information about\n"
9840 "Display the received routes from neighbor\n")
9841
9842ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009843 show_bgp_neighbor_advertised_route_cmd,
9844 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9845 SHOW_STR
9846 BGP_STR
9847 "Detailed information on TCP and BGP neighbor connections\n"
9848 "Neighbor to display information about\n"
9849 "Neighbor to display information about\n"
9850 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009851
9852ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009853 show_bgp_ipv6_neighbor_advertised_route_cmd,
9854 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9855 SHOW_STR
9856 BGP_STR
9857 "Address family\n"
9858 "Detailed information on TCP and BGP neighbor connections\n"
9859 "Neighbor to display information about\n"
9860 "Neighbor to display information about\n"
9861 "Display the routes advertised to a BGP neighbor\n")
9862
9863/* old command */
paulbb46e942003-10-24 19:02:03 +00009864ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009865 ipv6_bgp_neighbor_advertised_route_cmd,
9866 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9867 SHOW_STR
9868 IPV6_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
paul718e3742002-12-13 20:15:29 +00009875/* old command */
9876DEFUN (ipv6_mbgp_neighbor_advertised_route,
9877 ipv6_mbgp_neighbor_advertised_route_cmd,
9878 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9879 SHOW_STR
9880 IPV6_STR
9881 MBGP_STR
9882 "Detailed information on TCP and BGP neighbor connections\n"
9883 "Neighbor to display information about\n"
9884 "Neighbor to display information about\n"
9885 "Display the routes advertised to a BGP neighbor\n")
9886{
paulbb46e942003-10-24 19:02:03 +00009887 struct peer *peer;
9888
9889 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9890 if (! peer)
9891 return CMD_WARNING;
9892
9893 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009894}
9895#endif /* HAVE_IPV6 */
9896
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009897DEFUN (show_ip_bgp_view_neighbor_received_routes,
9898 show_ip_bgp_view_neighbor_received_routes_cmd,
9899 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9900 SHOW_STR
9901 IP_STR
9902 BGP_STR
9903 "BGP view\n"
9904 "View name\n"
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 received routes from neighbor\n")
9909{
9910 struct peer *peer;
9911
9912 if (argc == 2)
9913 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9914 else
9915 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9916
9917 if (! peer)
9918 return CMD_WARNING;
9919
9920 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9921}
9922
9923ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009924 show_ip_bgp_neighbor_received_routes_cmd,
9925 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9926 SHOW_STR
9927 IP_STR
9928 BGP_STR
9929 "Detailed information on TCP and BGP neighbor connections\n"
9930 "Neighbor to display information about\n"
9931 "Neighbor to display information about\n"
9932 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009933
9934DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9935 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9936 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9937 SHOW_STR
9938 IP_STR
9939 BGP_STR
9940 "Address family\n"
9941 "Address Family modifier\n"
9942 "Address Family modifier\n"
9943 "Detailed information on TCP and BGP neighbor connections\n"
9944 "Neighbor to display information about\n"
9945 "Neighbor to display information about\n"
9946 "Display the received routes from neighbor\n")
9947{
paulbb46e942003-10-24 19:02:03 +00009948 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009949
paulbb46e942003-10-24 19:02:03 +00009950 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9951 if (! peer)
9952 return CMD_WARNING;
9953
9954 if (strncmp (argv[0], "m", 1) == 0)
9955 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9956
9957 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009958}
9959
9960DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9961 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9962 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9963 SHOW_STR
9964 IP_STR
9965 BGP_STR
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 information received from a BGP neighbor\n"
9970 "Display the prefixlist filter\n")
9971{
9972 char name[BUFSIZ];
9973 union sockunion *su;
9974 struct peer *peer;
9975 int count;
9976
9977 su = sockunion_str2su (argv[0]);
9978 if (su == NULL)
9979 return CMD_WARNING;
9980
9981 peer = peer_lookup (NULL, su);
9982 if (! peer)
9983 return CMD_WARNING;
9984
9985 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9986 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9987 if (count)
9988 {
9989 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9990 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9991 }
9992
9993 return CMD_SUCCESS;
9994}
9995
9996DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9997 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9998 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9999 SHOW_STR
10000 IP_STR
10001 BGP_STR
10002 "Address family\n"
10003 "Address Family modifier\n"
10004 "Address Family modifier\n"
10005 "Detailed information on TCP and BGP neighbor connections\n"
10006 "Neighbor to display information about\n"
10007 "Neighbor to display information about\n"
10008 "Display information received from a BGP neighbor\n"
10009 "Display the prefixlist filter\n")
10010{
10011 char name[BUFSIZ];
10012 union sockunion *su;
10013 struct peer *peer;
10014 int count;
10015
10016 su = sockunion_str2su (argv[1]);
10017 if (su == NULL)
10018 return CMD_WARNING;
10019
10020 peer = peer_lookup (NULL, su);
10021 if (! peer)
10022 return CMD_WARNING;
10023
10024 if (strncmp (argv[0], "m", 1) == 0)
10025 {
10026 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10027 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10028 if (count)
10029 {
10030 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10031 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10032 }
10033 }
10034 else
10035 {
10036 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10037 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10038 if (count)
10039 {
10040 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10041 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10042 }
10043 }
10044
10045 return CMD_SUCCESS;
10046}
10047
10048
10049#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010050ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010051 show_bgp_neighbor_received_routes_cmd,
10052 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10053 SHOW_STR
10054 BGP_STR
10055 "Detailed information on TCP and BGP neighbor connections\n"
10056 "Neighbor to display information about\n"
10057 "Neighbor to display information about\n"
10058 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010059
paulbb46e942003-10-24 19:02:03 +000010060ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010061 show_bgp_ipv6_neighbor_received_routes_cmd,
10062 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10063 SHOW_STR
10064 BGP_STR
10065 "Address family\n"
10066 "Detailed information on TCP and BGP neighbor connections\n"
10067 "Neighbor to display information about\n"
10068 "Neighbor to display information about\n"
10069 "Display the received routes from neighbor\n")
10070
10071DEFUN (show_bgp_neighbor_received_prefix_filter,
10072 show_bgp_neighbor_received_prefix_filter_cmd,
10073 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10074 SHOW_STR
10075 BGP_STR
10076 "Detailed information on TCP and BGP neighbor connections\n"
10077 "Neighbor to display information about\n"
10078 "Neighbor to display information about\n"
10079 "Display information received from a BGP neighbor\n"
10080 "Display the prefixlist filter\n")
10081{
10082 char name[BUFSIZ];
10083 union sockunion *su;
10084 struct peer *peer;
10085 int count;
10086
10087 su = sockunion_str2su (argv[0]);
10088 if (su == NULL)
10089 return CMD_WARNING;
10090
10091 peer = peer_lookup (NULL, su);
10092 if (! peer)
10093 return CMD_WARNING;
10094
10095 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10096 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10097 if (count)
10098 {
10099 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10100 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10101 }
10102
10103 return CMD_SUCCESS;
10104}
10105
10106ALIAS (show_bgp_neighbor_received_prefix_filter,
10107 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10108 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10109 SHOW_STR
10110 BGP_STR
10111 "Address family\n"
10112 "Detailed information on TCP and BGP neighbor connections\n"
10113 "Neighbor to display information about\n"
10114 "Neighbor to display information about\n"
10115 "Display information received from a BGP neighbor\n"
10116 "Display the prefixlist filter\n")
10117
10118/* old command */
paulbb46e942003-10-24 19:02:03 +000010119ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010120 ipv6_bgp_neighbor_received_routes_cmd,
10121 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10122 SHOW_STR
10123 IPV6_STR
10124 BGP_STR
10125 "Detailed information on TCP and BGP neighbor connections\n"
10126 "Neighbor to display information about\n"
10127 "Neighbor to display information about\n"
10128 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010129
10130/* old command */
10131DEFUN (ipv6_mbgp_neighbor_received_routes,
10132 ipv6_mbgp_neighbor_received_routes_cmd,
10133 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10134 SHOW_STR
10135 IPV6_STR
10136 MBGP_STR
10137 "Detailed information on TCP and BGP neighbor connections\n"
10138 "Neighbor to display information about\n"
10139 "Neighbor to display information about\n"
10140 "Display the received routes from neighbor\n")
10141{
paulbb46e942003-10-24 19:02:03 +000010142 struct peer *peer;
10143
10144 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10145 if (! peer)
10146 return CMD_WARNING;
10147
10148 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010149}
paulbb46e942003-10-24 19:02:03 +000010150
10151DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10152 show_bgp_view_neighbor_received_prefix_filter_cmd,
10153 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10154 SHOW_STR
10155 BGP_STR
10156 "BGP view\n"
10157 "View name\n"
10158 "Detailed information on TCP and BGP neighbor connections\n"
10159 "Neighbor to display information about\n"
10160 "Neighbor to display information about\n"
10161 "Display information received from a BGP neighbor\n"
10162 "Display the prefixlist filter\n")
10163{
10164 char name[BUFSIZ];
10165 union sockunion *su;
10166 struct peer *peer;
10167 struct bgp *bgp;
10168 int count;
10169
10170 /* BGP structure lookup. */
10171 bgp = bgp_lookup_by_name (argv[0]);
10172 if (bgp == NULL)
10173 {
10174 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10175 return CMD_WARNING;
10176 }
10177
10178 su = sockunion_str2su (argv[1]);
10179 if (su == NULL)
10180 return CMD_WARNING;
10181
10182 peer = peer_lookup (bgp, su);
10183 if (! peer)
10184 return CMD_WARNING;
10185
10186 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10187 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10188 if (count)
10189 {
10190 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10191 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10192 }
10193
10194 return CMD_SUCCESS;
10195}
10196
10197ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10198 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10199 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10200 SHOW_STR
10201 BGP_STR
10202 "BGP view\n"
10203 "View name\n"
10204 "Address family\n"
10205 "Detailed information on TCP and BGP neighbor connections\n"
10206 "Neighbor to display information about\n"
10207 "Neighbor to display information about\n"
10208 "Display information received from a BGP neighbor\n"
10209 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010210#endif /* HAVE_IPV6 */
10211
paul94f2b392005-06-28 12:44:16 +000010212static int
paulbb46e942003-10-24 19:02:03 +000010213bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010214 safi_t safi, enum bgp_show_type type)
10215{
paul718e3742002-12-13 20:15:29 +000010216 if (! peer || ! peer->afc[afi][safi])
10217 {
10218 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010219 return CMD_WARNING;
10220 }
10221
ajs5a646652004-11-05 01:25:55 +000010222 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010223}
10224
10225DEFUN (show_ip_bgp_neighbor_routes,
10226 show_ip_bgp_neighbor_routes_cmd,
10227 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10228 SHOW_STR
10229 IP_STR
10230 BGP_STR
10231 "Detailed information on TCP and BGP neighbor connections\n"
10232 "Neighbor to display information about\n"
10233 "Neighbor to display information about\n"
10234 "Display routes learned from neighbor\n")
10235{
paulbb46e942003-10-24 19:02:03 +000010236 struct peer *peer;
10237
10238 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10239 if (! peer)
10240 return CMD_WARNING;
10241
10242 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010243 bgp_show_type_neighbor);
10244}
10245
10246DEFUN (show_ip_bgp_neighbor_flap,
10247 show_ip_bgp_neighbor_flap_cmd,
10248 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10249 SHOW_STR
10250 IP_STR
10251 BGP_STR
10252 "Detailed information on TCP and BGP neighbor connections\n"
10253 "Neighbor to display information about\n"
10254 "Neighbor to display information about\n"
10255 "Display flap statistics of the routes learned from neighbor\n")
10256{
paulbb46e942003-10-24 19:02:03 +000010257 struct peer *peer;
10258
10259 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10260 if (! peer)
10261 return CMD_WARNING;
10262
10263 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010264 bgp_show_type_flap_neighbor);
10265}
10266
10267DEFUN (show_ip_bgp_neighbor_damp,
10268 show_ip_bgp_neighbor_damp_cmd,
10269 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10270 SHOW_STR
10271 IP_STR
10272 BGP_STR
10273 "Detailed information on TCP and BGP neighbor connections\n"
10274 "Neighbor to display information about\n"
10275 "Neighbor to display information about\n"
10276 "Display the dampened routes received from neighbor\n")
10277{
paulbb46e942003-10-24 19:02:03 +000010278 struct peer *peer;
10279
10280 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10281 if (! peer)
10282 return CMD_WARNING;
10283
10284 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010285 bgp_show_type_damp_neighbor);
10286}
10287
10288DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10289 show_ip_bgp_ipv4_neighbor_routes_cmd,
10290 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10291 SHOW_STR
10292 IP_STR
10293 BGP_STR
10294 "Address family\n"
10295 "Address Family modifier\n"
10296 "Address Family modifier\n"
10297 "Detailed information on TCP and BGP neighbor connections\n"
10298 "Neighbor to display information about\n"
10299 "Neighbor to display information about\n"
10300 "Display routes learned from neighbor\n")
10301{
paulbb46e942003-10-24 19:02:03 +000010302 struct peer *peer;
10303
10304 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10305 if (! peer)
10306 return CMD_WARNING;
10307
paul718e3742002-12-13 20:15:29 +000010308 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010309 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010310 bgp_show_type_neighbor);
10311
paulbb46e942003-10-24 19:02:03 +000010312 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010313 bgp_show_type_neighbor);
10314}
paulbb46e942003-10-24 19:02:03 +000010315
paulfee0f4c2004-09-13 05:12:46 +000010316DEFUN (show_ip_bgp_view_rsclient,
10317 show_ip_bgp_view_rsclient_cmd,
10318 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10319 SHOW_STR
10320 IP_STR
10321 BGP_STR
10322 "BGP view\n"
10323 "BGP view name\n"
10324 "Information about Route Server Client\n"
10325 NEIGHBOR_ADDR_STR)
10326{
10327 struct bgp_table *table;
10328 struct peer *peer;
10329
10330 if (argc == 2)
10331 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10332 else
10333 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10334
10335 if (! peer)
10336 return CMD_WARNING;
10337
10338 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10339 {
10340 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10341 VTY_NEWLINE);
10342 return CMD_WARNING;
10343 }
10344
10345 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10346 PEER_FLAG_RSERVER_CLIENT))
10347 {
10348 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10349 VTY_NEWLINE);
10350 return CMD_WARNING;
10351 }
10352
10353 table = peer->rib[AFI_IP][SAFI_UNICAST];
10354
ajs5a646652004-11-05 01:25:55 +000010355 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010356}
10357
10358ALIAS (show_ip_bgp_view_rsclient,
10359 show_ip_bgp_rsclient_cmd,
10360 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10361 SHOW_STR
10362 IP_STR
10363 BGP_STR
10364 "Information about Route Server Client\n"
10365 NEIGHBOR_ADDR_STR)
10366
10367DEFUN (show_ip_bgp_view_rsclient_route,
10368 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010369 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010370 SHOW_STR
10371 IP_STR
10372 BGP_STR
10373 "BGP view\n"
10374 "BGP view name\n"
10375 "Information about Route Server Client\n"
10376 NEIGHBOR_ADDR_STR
10377 "Network in the BGP routing table to display\n")
10378{
10379 struct bgp *bgp;
10380 struct peer *peer;
10381
10382 /* BGP structure lookup. */
10383 if (argc == 3)
10384 {
10385 bgp = bgp_lookup_by_name (argv[0]);
10386 if (bgp == NULL)
10387 {
10388 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10389 return CMD_WARNING;
10390 }
10391 }
10392 else
10393 {
10394 bgp = bgp_get_default ();
10395 if (bgp == NULL)
10396 {
10397 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10398 return CMD_WARNING;
10399 }
10400 }
10401
10402 if (argc == 3)
10403 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10404 else
10405 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10406
10407 if (! peer)
10408 return CMD_WARNING;
10409
10410 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10411 {
10412 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10413 VTY_NEWLINE);
10414 return CMD_WARNING;
10415}
10416
10417 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10418 PEER_FLAG_RSERVER_CLIENT))
10419 {
10420 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10421 VTY_NEWLINE);
10422 return CMD_WARNING;
10423 }
10424
10425 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10426 (argc == 3) ? argv[2] : argv[1],
10427 AFI_IP, SAFI_UNICAST, NULL, 0);
10428}
10429
10430ALIAS (show_ip_bgp_view_rsclient_route,
10431 show_ip_bgp_rsclient_route_cmd,
10432 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10433 SHOW_STR
10434 IP_STR
10435 BGP_STR
10436 "Information about Route Server Client\n"
10437 NEIGHBOR_ADDR_STR
10438 "Network in the BGP routing table to display\n")
10439
10440DEFUN (show_ip_bgp_view_rsclient_prefix,
10441 show_ip_bgp_view_rsclient_prefix_cmd,
10442 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10443 SHOW_STR
10444 IP_STR
10445 BGP_STR
10446 "BGP view\n"
10447 "BGP view name\n"
10448 "Information about Route Server Client\n"
10449 NEIGHBOR_ADDR_STR
10450 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10451{
10452 struct bgp *bgp;
10453 struct peer *peer;
10454
10455 /* BGP structure lookup. */
10456 if (argc == 3)
10457 {
10458 bgp = bgp_lookup_by_name (argv[0]);
10459 if (bgp == NULL)
10460 {
10461 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10462 return CMD_WARNING;
10463 }
10464 }
10465 else
10466 {
10467 bgp = bgp_get_default ();
10468 if (bgp == NULL)
10469 {
10470 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10471 return CMD_WARNING;
10472 }
10473 }
10474
10475 if (argc == 3)
10476 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10477 else
10478 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10479
10480 if (! peer)
10481 return CMD_WARNING;
10482
10483 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10484 {
10485 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10486 VTY_NEWLINE);
10487 return CMD_WARNING;
10488}
10489
10490 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10491 PEER_FLAG_RSERVER_CLIENT))
10492{
10493 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10494 VTY_NEWLINE);
10495 return CMD_WARNING;
10496 }
10497
10498 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10499 (argc == 3) ? argv[2] : argv[1],
10500 AFI_IP, SAFI_UNICAST, NULL, 1);
10501}
10502
10503ALIAS (show_ip_bgp_view_rsclient_prefix,
10504 show_ip_bgp_rsclient_prefix_cmd,
10505 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10506 SHOW_STR
10507 IP_STR
10508 BGP_STR
10509 "Information about Route Server Client\n"
10510 NEIGHBOR_ADDR_STR
10511 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10512
10513
paul718e3742002-12-13 20:15:29 +000010514#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010515DEFUN (show_bgp_view_neighbor_routes,
10516 show_bgp_view_neighbor_routes_cmd,
10517 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10518 SHOW_STR
10519 BGP_STR
10520 "BGP view\n"
10521 "BGP view name\n"
10522 "Detailed information on TCP and BGP neighbor connections\n"
10523 "Neighbor to display information about\n"
10524 "Neighbor to display information about\n"
10525 "Display routes learned from neighbor\n")
10526{
10527 struct peer *peer;
10528
10529 if (argc == 2)
10530 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10531 else
10532 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10533
10534 if (! peer)
10535 return CMD_WARNING;
10536
10537 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10538 bgp_show_type_neighbor);
10539}
10540
10541ALIAS (show_bgp_view_neighbor_routes,
10542 show_bgp_view_ipv6_neighbor_routes_cmd,
10543 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10544 SHOW_STR
10545 BGP_STR
10546 "BGP view\n"
10547 "BGP view name\n"
10548 "Address family\n"
10549 "Detailed information on TCP and BGP neighbor connections\n"
10550 "Neighbor to display information about\n"
10551 "Neighbor to display information about\n"
10552 "Display routes learned from neighbor\n")
10553
10554DEFUN (show_bgp_view_neighbor_damp,
10555 show_bgp_view_neighbor_damp_cmd,
10556 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10557 SHOW_STR
10558 BGP_STR
10559 "BGP view\n"
10560 "BGP view name\n"
10561 "Detailed information on TCP and BGP neighbor connections\n"
10562 "Neighbor to display information about\n"
10563 "Neighbor to display information about\n"
10564 "Display the dampened routes received from neighbor\n")
10565{
10566 struct peer *peer;
10567
10568 if (argc == 2)
10569 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10570 else
10571 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10572
10573 if (! peer)
10574 return CMD_WARNING;
10575
10576 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10577 bgp_show_type_damp_neighbor);
10578}
10579
10580ALIAS (show_bgp_view_neighbor_damp,
10581 show_bgp_view_ipv6_neighbor_damp_cmd,
10582 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10583 SHOW_STR
10584 BGP_STR
10585 "BGP view\n"
10586 "BGP view name\n"
10587 "Address family\n"
10588 "Detailed information on TCP and BGP neighbor connections\n"
10589 "Neighbor to display information about\n"
10590 "Neighbor to display information about\n"
10591 "Display the dampened routes received from neighbor\n")
10592
10593DEFUN (show_bgp_view_neighbor_flap,
10594 show_bgp_view_neighbor_flap_cmd,
10595 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10596 SHOW_STR
10597 BGP_STR
10598 "BGP view\n"
10599 "BGP view name\n"
10600 "Detailed information on TCP and BGP neighbor connections\n"
10601 "Neighbor to display information about\n"
10602 "Neighbor to display information about\n"
10603 "Display flap statistics of the routes learned from neighbor\n")
10604{
10605 struct peer *peer;
10606
10607 if (argc == 2)
10608 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10609 else
10610 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10611
10612 if (! peer)
10613 return CMD_WARNING;
10614
10615 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10616 bgp_show_type_flap_neighbor);
10617}
10618
10619ALIAS (show_bgp_view_neighbor_flap,
10620 show_bgp_view_ipv6_neighbor_flap_cmd,
10621 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10622 SHOW_STR
10623 BGP_STR
10624 "BGP view\n"
10625 "BGP view name\n"
10626 "Address family\n"
10627 "Detailed information on TCP and BGP neighbor connections\n"
10628 "Neighbor to display information about\n"
10629 "Neighbor to display information about\n"
10630 "Display flap statistics of the routes learned from neighbor\n")
10631
10632ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010633 show_bgp_neighbor_routes_cmd,
10634 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10635 SHOW_STR
10636 BGP_STR
10637 "Detailed information on TCP and BGP neighbor connections\n"
10638 "Neighbor to display information about\n"
10639 "Neighbor to display information about\n"
10640 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010641
paulbb46e942003-10-24 19:02:03 +000010642
10643ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010644 show_bgp_ipv6_neighbor_routes_cmd,
10645 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10646 SHOW_STR
10647 BGP_STR
10648 "Address family\n"
10649 "Detailed information on TCP and BGP neighbor connections\n"
10650 "Neighbor to display information about\n"
10651 "Neighbor to display information about\n"
10652 "Display routes learned from neighbor\n")
10653
10654/* old command */
paulbb46e942003-10-24 19:02:03 +000010655ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010656 ipv6_bgp_neighbor_routes_cmd,
10657 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10658 SHOW_STR
10659 IPV6_STR
10660 BGP_STR
10661 "Detailed information on TCP and BGP neighbor connections\n"
10662 "Neighbor to display information about\n"
10663 "Neighbor to display information about\n"
10664 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010665
10666/* old command */
10667DEFUN (ipv6_mbgp_neighbor_routes,
10668 ipv6_mbgp_neighbor_routes_cmd,
10669 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10670 SHOW_STR
10671 IPV6_STR
10672 MBGP_STR
10673 "Detailed information on TCP and BGP neighbor connections\n"
10674 "Neighbor to display information about\n"
10675 "Neighbor to display information about\n"
10676 "Display routes learned from neighbor\n")
10677{
paulbb46e942003-10-24 19:02:03 +000010678 struct peer *peer;
10679
10680 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10681 if (! peer)
10682 return CMD_WARNING;
10683
10684 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010685 bgp_show_type_neighbor);
10686}
paulbb46e942003-10-24 19:02:03 +000010687
10688ALIAS (show_bgp_view_neighbor_flap,
10689 show_bgp_neighbor_flap_cmd,
10690 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10691 SHOW_STR
10692 BGP_STR
10693 "Detailed information on TCP and BGP neighbor connections\n"
10694 "Neighbor to display information about\n"
10695 "Neighbor to display information about\n"
10696 "Display flap statistics of the routes learned from neighbor\n")
10697
10698ALIAS (show_bgp_view_neighbor_flap,
10699 show_bgp_ipv6_neighbor_flap_cmd,
10700 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10701 SHOW_STR
10702 BGP_STR
10703 "Address family\n"
10704 "Detailed information on TCP and BGP neighbor connections\n"
10705 "Neighbor to display information about\n"
10706 "Neighbor to display information about\n"
10707 "Display flap statistics of the routes learned from neighbor\n")
10708
10709ALIAS (show_bgp_view_neighbor_damp,
10710 show_bgp_neighbor_damp_cmd,
10711 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10712 SHOW_STR
10713 BGP_STR
10714 "Detailed information on TCP and BGP neighbor connections\n"
10715 "Neighbor to display information about\n"
10716 "Neighbor to display information about\n"
10717 "Display the dampened routes received from neighbor\n")
10718
10719ALIAS (show_bgp_view_neighbor_damp,
10720 show_bgp_ipv6_neighbor_damp_cmd,
10721 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10722 SHOW_STR
10723 BGP_STR
10724 "Address family\n"
10725 "Detailed information on TCP and BGP neighbor connections\n"
10726 "Neighbor to display information about\n"
10727 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010728 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010729
10730DEFUN (show_bgp_view_rsclient,
10731 show_bgp_view_rsclient_cmd,
10732 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10733 SHOW_STR
10734 BGP_STR
10735 "BGP view\n"
10736 "BGP view name\n"
10737 "Information about Route Server Client\n"
10738 NEIGHBOR_ADDR_STR)
10739{
10740 struct bgp_table *table;
10741 struct peer *peer;
10742
10743 if (argc == 2)
10744 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10745 else
10746 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10747
10748 if (! peer)
10749 return CMD_WARNING;
10750
10751 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10752 {
10753 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10754 VTY_NEWLINE);
10755 return CMD_WARNING;
10756 }
10757
10758 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10759 PEER_FLAG_RSERVER_CLIENT))
10760 {
10761 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10762 VTY_NEWLINE);
10763 return CMD_WARNING;
10764 }
10765
10766 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10767
ajs5a646652004-11-05 01:25:55 +000010768 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010769}
10770
10771ALIAS (show_bgp_view_rsclient,
10772 show_bgp_rsclient_cmd,
10773 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10774 SHOW_STR
10775 BGP_STR
10776 "Information about Route Server Client\n"
10777 NEIGHBOR_ADDR_STR)
10778
10779DEFUN (show_bgp_view_rsclient_route,
10780 show_bgp_view_rsclient_route_cmd,
10781 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10782 SHOW_STR
10783 BGP_STR
10784 "BGP view\n"
10785 "BGP view name\n"
10786 "Information about Route Server Client\n"
10787 NEIGHBOR_ADDR_STR
10788 "Network in the BGP routing table to display\n")
10789{
10790 struct bgp *bgp;
10791 struct peer *peer;
10792
10793 /* BGP structure lookup. */
10794 if (argc == 3)
10795 {
10796 bgp = bgp_lookup_by_name (argv[0]);
10797 if (bgp == NULL)
10798 {
10799 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10800 return CMD_WARNING;
10801 }
10802 }
10803 else
10804 {
10805 bgp = bgp_get_default ();
10806 if (bgp == NULL)
10807 {
10808 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10809 return CMD_WARNING;
10810 }
10811 }
10812
10813 if (argc == 3)
10814 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10815 else
10816 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10817
10818 if (! peer)
10819 return CMD_WARNING;
10820
10821 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10822 {
10823 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10824 VTY_NEWLINE);
10825 return CMD_WARNING;
10826 }
10827
10828 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10829 PEER_FLAG_RSERVER_CLIENT))
10830 {
10831 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10832 VTY_NEWLINE);
10833 return CMD_WARNING;
10834 }
10835
10836 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10837 (argc == 3) ? argv[2] : argv[1],
10838 AFI_IP6, SAFI_UNICAST, NULL, 0);
10839}
10840
10841ALIAS (show_bgp_view_rsclient_route,
10842 show_bgp_rsclient_route_cmd,
10843 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10844 SHOW_STR
10845 BGP_STR
10846 "Information about Route Server Client\n"
10847 NEIGHBOR_ADDR_STR
10848 "Network in the BGP routing table to display\n")
10849
10850DEFUN (show_bgp_view_rsclient_prefix,
10851 show_bgp_view_rsclient_prefix_cmd,
10852 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10853 SHOW_STR
10854 BGP_STR
10855 "BGP view\n"
10856 "BGP view name\n"
10857 "Information about Route Server Client\n"
10858 NEIGHBOR_ADDR_STR
10859 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10860{
10861 struct bgp *bgp;
10862 struct peer *peer;
10863
10864 /* BGP structure lookup. */
10865 if (argc == 3)
10866 {
10867 bgp = bgp_lookup_by_name (argv[0]);
10868 if (bgp == NULL)
10869 {
10870 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10871 return CMD_WARNING;
10872 }
10873 }
10874 else
10875 {
10876 bgp = bgp_get_default ();
10877 if (bgp == NULL)
10878 {
10879 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10880 return CMD_WARNING;
10881 }
10882 }
10883
10884 if (argc == 3)
10885 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10886 else
10887 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10888
10889 if (! peer)
10890 return CMD_WARNING;
10891
10892 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10893 {
10894 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10895 VTY_NEWLINE);
10896 return CMD_WARNING;
10897 }
10898
10899 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10900 PEER_FLAG_RSERVER_CLIENT))
10901 {
10902 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10903 VTY_NEWLINE);
10904 return CMD_WARNING;
10905 }
10906
10907 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10908 (argc == 3) ? argv[2] : argv[1],
10909 AFI_IP6, SAFI_UNICAST, NULL, 1);
10910}
10911
10912ALIAS (show_bgp_view_rsclient_prefix,
10913 show_bgp_rsclient_prefix_cmd,
10914 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10915 SHOW_STR
10916 BGP_STR
10917 "Information about Route Server Client\n"
10918 NEIGHBOR_ADDR_STR
10919 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10920
paul718e3742002-12-13 20:15:29 +000010921#endif /* HAVE_IPV6 */
10922
10923struct bgp_table *bgp_distance_table;
10924
10925struct bgp_distance
10926{
10927 /* Distance value for the IP source prefix. */
10928 u_char distance;
10929
10930 /* Name of the access-list to be matched. */
10931 char *access_list;
10932};
10933
paul94f2b392005-06-28 12:44:16 +000010934static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010935bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010936{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010937 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010938}
10939
paul94f2b392005-06-28 12:44:16 +000010940static void
paul718e3742002-12-13 20:15:29 +000010941bgp_distance_free (struct bgp_distance *bdistance)
10942{
10943 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10944}
10945
paul94f2b392005-06-28 12:44:16 +000010946static int
paulfd79ac92004-10-13 05:06:08 +000010947bgp_distance_set (struct vty *vty, const char *distance_str,
10948 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010949{
10950 int ret;
10951 struct prefix_ipv4 p;
10952 u_char distance;
10953 struct bgp_node *rn;
10954 struct bgp_distance *bdistance;
10955
10956 ret = str2prefix_ipv4 (ip_str, &p);
10957 if (ret == 0)
10958 {
10959 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10960 return CMD_WARNING;
10961 }
10962
10963 distance = atoi (distance_str);
10964
10965 /* Get BGP distance node. */
10966 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10967 if (rn->info)
10968 {
10969 bdistance = rn->info;
10970 bgp_unlock_node (rn);
10971 }
10972 else
10973 {
10974 bdistance = bgp_distance_new ();
10975 rn->info = bdistance;
10976 }
10977
10978 /* Set distance value. */
10979 bdistance->distance = distance;
10980
10981 /* Reset access-list configuration. */
10982 if (bdistance->access_list)
10983 {
10984 free (bdistance->access_list);
10985 bdistance->access_list = NULL;
10986 }
10987 if (access_list_str)
10988 bdistance->access_list = strdup (access_list_str);
10989
10990 return CMD_SUCCESS;
10991}
10992
paul94f2b392005-06-28 12:44:16 +000010993static int
paulfd79ac92004-10-13 05:06:08 +000010994bgp_distance_unset (struct vty *vty, const char *distance_str,
10995 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010996{
10997 int ret;
10998 struct prefix_ipv4 p;
10999 u_char distance;
11000 struct bgp_node *rn;
11001 struct bgp_distance *bdistance;
11002
11003 ret = str2prefix_ipv4 (ip_str, &p);
11004 if (ret == 0)
11005 {
11006 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11007 return CMD_WARNING;
11008 }
11009
11010 distance = atoi (distance_str);
11011
11012 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11013 if (! rn)
11014 {
11015 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11016 return CMD_WARNING;
11017 }
11018
11019 bdistance = rn->info;
11020
11021 if (bdistance->access_list)
11022 free (bdistance->access_list);
11023 bgp_distance_free (bdistance);
11024
11025 rn->info = NULL;
11026 bgp_unlock_node (rn);
11027 bgp_unlock_node (rn);
11028
11029 return CMD_SUCCESS;
11030}
11031
paul94f2b392005-06-28 12:44:16 +000011032static void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011033bgp_distance_reset (void)
paul718e3742002-12-13 20:15:29 +000011034{
11035 struct bgp_node *rn;
11036 struct bgp_distance *bdistance;
11037
11038 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11039 if ((bdistance = rn->info) != NULL)
11040 {
11041 if (bdistance->access_list)
11042 free (bdistance->access_list);
11043 bgp_distance_free (bdistance);
11044 rn->info = NULL;
11045 bgp_unlock_node (rn);
11046 }
11047}
11048
11049/* Apply BGP information to distance method. */
11050u_char
11051bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11052{
11053 struct bgp_node *rn;
11054 struct prefix_ipv4 q;
11055 struct peer *peer;
11056 struct bgp_distance *bdistance;
11057 struct access_list *alist;
11058 struct bgp_static *bgp_static;
11059
11060 if (! bgp)
11061 return 0;
11062
11063 if (p->family != AF_INET)
11064 return 0;
11065
11066 peer = rinfo->peer;
11067
11068 if (peer->su.sa.sa_family != AF_INET)
11069 return 0;
11070
11071 memset (&q, 0, sizeof (struct prefix_ipv4));
11072 q.family = AF_INET;
11073 q.prefix = peer->su.sin.sin_addr;
11074 q.prefixlen = IPV4_MAX_BITLEN;
11075
11076 /* Check source address. */
11077 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11078 if (rn)
11079 {
11080 bdistance = rn->info;
11081 bgp_unlock_node (rn);
11082
11083 if (bdistance->access_list)
11084 {
11085 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11086 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11087 return bdistance->distance;
11088 }
11089 else
11090 return bdistance->distance;
11091 }
11092
11093 /* Backdoor check. */
11094 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11095 if (rn)
11096 {
11097 bgp_static = rn->info;
11098 bgp_unlock_node (rn);
11099
11100 if (bgp_static->backdoor)
11101 {
11102 if (bgp->distance_local)
11103 return bgp->distance_local;
11104 else
11105 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11106 }
11107 }
11108
11109 if (peer_sort (peer) == BGP_PEER_EBGP)
11110 {
11111 if (bgp->distance_ebgp)
11112 return bgp->distance_ebgp;
11113 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11114 }
11115 else
11116 {
11117 if (bgp->distance_ibgp)
11118 return bgp->distance_ibgp;
11119 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11120 }
11121}
11122
11123DEFUN (bgp_distance,
11124 bgp_distance_cmd,
11125 "distance bgp <1-255> <1-255> <1-255>",
11126 "Define an administrative distance\n"
11127 "BGP distance\n"
11128 "Distance for routes external to the AS\n"
11129 "Distance for routes internal to the AS\n"
11130 "Distance for local routes\n")
11131{
11132 struct bgp *bgp;
11133
11134 bgp = vty->index;
11135
11136 bgp->distance_ebgp = atoi (argv[0]);
11137 bgp->distance_ibgp = atoi (argv[1]);
11138 bgp->distance_local = atoi (argv[2]);
11139 return CMD_SUCCESS;
11140}
11141
11142DEFUN (no_bgp_distance,
11143 no_bgp_distance_cmd,
11144 "no distance bgp <1-255> <1-255> <1-255>",
11145 NO_STR
11146 "Define an administrative distance\n"
11147 "BGP distance\n"
11148 "Distance for routes external to the AS\n"
11149 "Distance for routes internal to the AS\n"
11150 "Distance for local routes\n")
11151{
11152 struct bgp *bgp;
11153
11154 bgp = vty->index;
11155
11156 bgp->distance_ebgp= 0;
11157 bgp->distance_ibgp = 0;
11158 bgp->distance_local = 0;
11159 return CMD_SUCCESS;
11160}
11161
11162ALIAS (no_bgp_distance,
11163 no_bgp_distance2_cmd,
11164 "no distance bgp",
11165 NO_STR
11166 "Define an administrative distance\n"
11167 "BGP distance\n")
11168
11169DEFUN (bgp_distance_source,
11170 bgp_distance_source_cmd,
11171 "distance <1-255> A.B.C.D/M",
11172 "Define an administrative distance\n"
11173 "Administrative distance\n"
11174 "IP source prefix\n")
11175{
11176 bgp_distance_set (vty, argv[0], argv[1], NULL);
11177 return CMD_SUCCESS;
11178}
11179
11180DEFUN (no_bgp_distance_source,
11181 no_bgp_distance_source_cmd,
11182 "no distance <1-255> A.B.C.D/M",
11183 NO_STR
11184 "Define an administrative distance\n"
11185 "Administrative distance\n"
11186 "IP source prefix\n")
11187{
11188 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11189 return CMD_SUCCESS;
11190}
11191
11192DEFUN (bgp_distance_source_access_list,
11193 bgp_distance_source_access_list_cmd,
11194 "distance <1-255> A.B.C.D/M WORD",
11195 "Define an administrative distance\n"
11196 "Administrative distance\n"
11197 "IP source prefix\n"
11198 "Access list name\n")
11199{
11200 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11201 return CMD_SUCCESS;
11202}
11203
11204DEFUN (no_bgp_distance_source_access_list,
11205 no_bgp_distance_source_access_list_cmd,
11206 "no distance <1-255> A.B.C.D/M WORD",
11207 NO_STR
11208 "Define an administrative distance\n"
11209 "Administrative distance\n"
11210 "IP source prefix\n"
11211 "Access list name\n")
11212{
11213 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11214 return CMD_SUCCESS;
11215}
11216
11217DEFUN (bgp_damp_set,
11218 bgp_damp_set_cmd,
11219 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11220 "BGP Specific commands\n"
11221 "Enable route-flap dampening\n"
11222 "Half-life time for the penalty\n"
11223 "Value to start reusing a route\n"
11224 "Value to start suppressing a route\n"
11225 "Maximum duration to suppress a stable route\n")
11226{
11227 struct bgp *bgp;
11228 int half = DEFAULT_HALF_LIFE * 60;
11229 int reuse = DEFAULT_REUSE;
11230 int suppress = DEFAULT_SUPPRESS;
11231 int max = 4 * half;
11232
11233 if (argc == 4)
11234 {
11235 half = atoi (argv[0]) * 60;
11236 reuse = atoi (argv[1]);
11237 suppress = atoi (argv[2]);
11238 max = atoi (argv[3]) * 60;
11239 }
11240 else if (argc == 1)
11241 {
11242 half = atoi (argv[0]) * 60;
11243 max = 4 * half;
11244 }
11245
11246 bgp = vty->index;
11247 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11248 half, reuse, suppress, max);
11249}
11250
11251ALIAS (bgp_damp_set,
11252 bgp_damp_set2_cmd,
11253 "bgp dampening <1-45>",
11254 "BGP Specific commands\n"
11255 "Enable route-flap dampening\n"
11256 "Half-life time for the penalty\n")
11257
11258ALIAS (bgp_damp_set,
11259 bgp_damp_set3_cmd,
11260 "bgp dampening",
11261 "BGP Specific commands\n"
11262 "Enable route-flap dampening\n")
11263
11264DEFUN (bgp_damp_unset,
11265 bgp_damp_unset_cmd,
11266 "no bgp dampening",
11267 NO_STR
11268 "BGP Specific commands\n"
11269 "Enable route-flap dampening\n")
11270{
11271 struct bgp *bgp;
11272
11273 bgp = vty->index;
11274 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11275}
11276
11277ALIAS (bgp_damp_unset,
11278 bgp_damp_unset2_cmd,
11279 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11280 NO_STR
11281 "BGP Specific commands\n"
11282 "Enable route-flap dampening\n"
11283 "Half-life time for the penalty\n"
11284 "Value to start reusing a route\n"
11285 "Value to start suppressing a route\n"
11286 "Maximum duration to suppress a stable route\n")
11287
11288DEFUN (show_ip_bgp_dampened_paths,
11289 show_ip_bgp_dampened_paths_cmd,
11290 "show ip bgp dampened-paths",
11291 SHOW_STR
11292 IP_STR
11293 BGP_STR
11294 "Display paths suppressed due to dampening\n")
11295{
ajs5a646652004-11-05 01:25:55 +000011296 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11297 NULL);
paul718e3742002-12-13 20:15:29 +000011298}
11299
11300DEFUN (show_ip_bgp_flap_statistics,
11301 show_ip_bgp_flap_statistics_cmd,
11302 "show ip bgp flap-statistics",
11303 SHOW_STR
11304 IP_STR
11305 BGP_STR
11306 "Display flap statistics of routes\n")
11307{
ajs5a646652004-11-05 01:25:55 +000011308 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11309 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011310}
11311
11312/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011313static int
paulfd79ac92004-10-13 05:06:08 +000011314bgp_clear_damp_route (struct vty *vty, const char *view_name,
11315 const char *ip_str, afi_t afi, safi_t safi,
11316 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011317{
11318 int ret;
11319 struct prefix match;
11320 struct bgp_node *rn;
11321 struct bgp_node *rm;
11322 struct bgp_info *ri;
11323 struct bgp_info *ri_temp;
11324 struct bgp *bgp;
11325 struct bgp_table *table;
11326
11327 /* BGP structure lookup. */
11328 if (view_name)
11329 {
11330 bgp = bgp_lookup_by_name (view_name);
11331 if (bgp == NULL)
11332 {
11333 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11334 return CMD_WARNING;
11335 }
11336 }
11337 else
11338 {
11339 bgp = bgp_get_default ();
11340 if (bgp == NULL)
11341 {
11342 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11343 return CMD_WARNING;
11344 }
11345 }
11346
11347 /* Check IP address argument. */
11348 ret = str2prefix (ip_str, &match);
11349 if (! ret)
11350 {
11351 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11352 return CMD_WARNING;
11353 }
11354
11355 match.family = afi2family (afi);
11356
11357 if (safi == SAFI_MPLS_VPN)
11358 {
11359 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11360 {
11361 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11362 continue;
11363
11364 if ((table = rn->info) != NULL)
11365 if ((rm = bgp_node_match (table, &match)) != NULL)
11366 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11367 {
11368 ri = rm->info;
11369 while (ri)
11370 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011371 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011372 {
11373 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011374 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011375 ri = ri_temp;
11376 }
11377 else
11378 ri = ri->next;
11379 }
11380 }
11381 }
11382 }
11383 else
11384 {
11385 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11386 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11387 {
11388 ri = rn->info;
11389 while (ri)
11390 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011391 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011392 {
11393 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011394 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011395 ri = ri_temp;
11396 }
11397 else
11398 ri = ri->next;
11399 }
11400 }
11401 }
11402
11403 return CMD_SUCCESS;
11404}
11405
11406DEFUN (clear_ip_bgp_dampening,
11407 clear_ip_bgp_dampening_cmd,
11408 "clear ip bgp dampening",
11409 CLEAR_STR
11410 IP_STR
11411 BGP_STR
11412 "Clear route flap dampening information\n")
11413{
11414 bgp_damp_info_clean ();
11415 return CMD_SUCCESS;
11416}
11417
11418DEFUN (clear_ip_bgp_dampening_prefix,
11419 clear_ip_bgp_dampening_prefix_cmd,
11420 "clear ip bgp dampening A.B.C.D/M",
11421 CLEAR_STR
11422 IP_STR
11423 BGP_STR
11424 "Clear route flap dampening information\n"
11425 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11426{
11427 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11428 SAFI_UNICAST, NULL, 1);
11429}
11430
11431DEFUN (clear_ip_bgp_dampening_address,
11432 clear_ip_bgp_dampening_address_cmd,
11433 "clear ip bgp dampening A.B.C.D",
11434 CLEAR_STR
11435 IP_STR
11436 BGP_STR
11437 "Clear route flap dampening information\n"
11438 "Network to clear damping information\n")
11439{
11440 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11441 SAFI_UNICAST, NULL, 0);
11442}
11443
11444DEFUN (clear_ip_bgp_dampening_address_mask,
11445 clear_ip_bgp_dampening_address_mask_cmd,
11446 "clear ip bgp dampening A.B.C.D A.B.C.D",
11447 CLEAR_STR
11448 IP_STR
11449 BGP_STR
11450 "Clear route flap dampening information\n"
11451 "Network to clear damping information\n"
11452 "Network mask\n")
11453{
11454 int ret;
11455 char prefix_str[BUFSIZ];
11456
11457 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11458 if (! ret)
11459 {
11460 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11461 return CMD_WARNING;
11462 }
11463
11464 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11465 SAFI_UNICAST, NULL, 0);
11466}
11467
paul94f2b392005-06-28 12:44:16 +000011468static int
paul718e3742002-12-13 20:15:29 +000011469bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11470 afi_t afi, safi_t safi, int *write)
11471{
11472 struct bgp_node *prn;
11473 struct bgp_node *rn;
11474 struct bgp_table *table;
11475 struct prefix *p;
11476 struct prefix_rd *prd;
11477 struct bgp_static *bgp_static;
11478 u_int32_t label;
11479 char buf[SU_ADDRSTRLEN];
11480 char rdbuf[RD_ADDRSTRLEN];
11481
11482 /* Network configuration. */
11483 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11484 if ((table = prn->info) != NULL)
11485 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11486 if ((bgp_static = rn->info) != NULL)
11487 {
11488 p = &rn->p;
11489 prd = (struct prefix_rd *) &prn->p;
11490
11491 /* "address-family" display. */
11492 bgp_config_write_family_header (vty, afi, safi, write);
11493
11494 /* "network" configuration display. */
11495 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11496 label = decode_label (bgp_static->tag);
11497
11498 vty_out (vty, " network %s/%d rd %s tag %d",
11499 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11500 p->prefixlen,
11501 rdbuf, label);
11502 vty_out (vty, "%s", VTY_NEWLINE);
11503 }
11504 return 0;
11505}
11506
11507/* Configuration of static route announcement and aggregate
11508 information. */
11509int
11510bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11511 afi_t afi, safi_t safi, int *write)
11512{
11513 struct bgp_node *rn;
11514 struct prefix *p;
11515 struct bgp_static *bgp_static;
11516 struct bgp_aggregate *bgp_aggregate;
11517 char buf[SU_ADDRSTRLEN];
11518
11519 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11520 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11521
11522 /* Network configuration. */
11523 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11524 if ((bgp_static = rn->info) != NULL)
11525 {
11526 p = &rn->p;
11527
11528 /* "address-family" display. */
11529 bgp_config_write_family_header (vty, afi, safi, write);
11530
11531 /* "network" configuration display. */
11532 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11533 {
11534 u_int32_t destination;
11535 struct in_addr netmask;
11536
11537 destination = ntohl (p->u.prefix4.s_addr);
11538 masklen2ip (p->prefixlen, &netmask);
11539 vty_out (vty, " network %s",
11540 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11541
11542 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11543 || (IN_CLASSB (destination) && p->prefixlen == 16)
11544 || (IN_CLASSA (destination) && p->prefixlen == 8)
11545 || p->u.prefix4.s_addr == 0)
11546 {
11547 /* Natural mask is not display. */
11548 }
11549 else
11550 vty_out (vty, " mask %s", inet_ntoa (netmask));
11551 }
11552 else
11553 {
11554 vty_out (vty, " network %s/%d",
11555 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11556 p->prefixlen);
11557 }
11558
11559 if (bgp_static->rmap.name)
11560 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011561 else
11562 {
11563 if (bgp_static->backdoor)
11564 vty_out (vty, " backdoor");
11565 if (bgp_static->ttl)
11566 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11567 }
paul718e3742002-12-13 20:15:29 +000011568
11569 vty_out (vty, "%s", VTY_NEWLINE);
11570 }
11571
11572 /* Aggregate-address configuration. */
11573 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11574 if ((bgp_aggregate = rn->info) != NULL)
11575 {
11576 p = &rn->p;
11577
11578 /* "address-family" display. */
11579 bgp_config_write_family_header (vty, afi, safi, write);
11580
11581 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11582 {
11583 struct in_addr netmask;
11584
11585 masklen2ip (p->prefixlen, &netmask);
11586 vty_out (vty, " aggregate-address %s %s",
11587 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11588 inet_ntoa (netmask));
11589 }
11590 else
11591 {
11592 vty_out (vty, " aggregate-address %s/%d",
11593 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11594 p->prefixlen);
11595 }
11596
11597 if (bgp_aggregate->as_set)
11598 vty_out (vty, " as-set");
11599
11600 if (bgp_aggregate->summary_only)
11601 vty_out (vty, " summary-only");
11602
11603 vty_out (vty, "%s", VTY_NEWLINE);
11604 }
11605
11606 return 0;
11607}
11608
11609int
11610bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11611{
11612 struct bgp_node *rn;
11613 struct bgp_distance *bdistance;
11614
11615 /* Distance configuration. */
11616 if (bgp->distance_ebgp
11617 && bgp->distance_ibgp
11618 && bgp->distance_local
11619 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11620 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11621 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11622 vty_out (vty, " distance bgp %d %d %d%s",
11623 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11624 VTY_NEWLINE);
11625
11626 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11627 if ((bdistance = rn->info) != NULL)
11628 {
11629 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11630 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11631 bdistance->access_list ? bdistance->access_list : "",
11632 VTY_NEWLINE);
11633 }
11634
11635 return 0;
11636}
11637
11638/* Allocate routing table structure and install commands. */
11639void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011640bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011641{
11642 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011643 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011644
11645 /* IPv4 BGP commands. */
11646 install_element (BGP_NODE, &bgp_network_cmd);
11647 install_element (BGP_NODE, &bgp_network_mask_cmd);
11648 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11649 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11650 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11651 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11652 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11653 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11654 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011655 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11656 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11657 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11658 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11659 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11660 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011661 install_element (BGP_NODE, &no_bgp_network_cmd);
11662 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11663 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11664 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11665 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11666 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11667 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11668 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11669 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011670 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11671 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11672 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11673 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11674 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11675 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011676
11677 install_element (BGP_NODE, &aggregate_address_cmd);
11678 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11679 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11680 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11681 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11682 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11683 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11684 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11685 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11686 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11687 install_element (BGP_NODE, &no_aggregate_address_cmd);
11688 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11689 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11690 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11691 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11692 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11693 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11694 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11695 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11696 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11697
11698 /* IPv4 unicast configuration. */
11699 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11700 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11701 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11702 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11703 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11704 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011705 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11706 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11707 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11708 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11709 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11710 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 +000011711 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11712 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11713 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11714 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11715 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011716 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11717 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11718 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11719 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11720 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11721 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 +000011722 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11723 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11724 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11725 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11726 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11727 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11728 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11729 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11730 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11731 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11732 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11733 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11734 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11735 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11736 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11737 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11738 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11739 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11740 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11741 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11742
11743 /* IPv4 multicast configuration. */
11744 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11745 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11746 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11747 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11748 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11749 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011750 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11751 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11752 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11753 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11754 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11755 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 +000011756 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11757 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11758 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11759 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11760 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11761 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011762 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11763 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11764 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11765 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11766 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11767 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 +000011768 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11769 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11770 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11771 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11772 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11773 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11774 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11775 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11776 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11777 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11778 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11779 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11780 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11781 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11782 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11783 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11784 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11785 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11786 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11787 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11788
11789 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11790 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11791 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11792 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11793 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11794 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11795 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11796 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11797 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11798 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11799 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11800 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11801 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11802 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11803 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11804 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11805 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11806 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11807 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11808 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11809 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11810 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11811 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11812 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11813 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11814 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11815 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11816 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11817 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11818 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11819 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11820 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11821 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11822 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11823 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11824 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11825 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11826 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11827 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11828 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11829 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11830 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11831 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11832 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11833 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11834 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11835 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11836 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11837 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11838 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11839 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11840 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11841 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11842 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11843 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11844 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11845 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11846 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11847 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11848 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11849 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11850 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11851 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11852 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11853 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11854 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11855 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011856 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11857 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11858 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011859 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11860 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011861 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11862 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11863 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011864
11865 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11866 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11867 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11868 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11869 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11870 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11871 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11872 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11873 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11874 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11875 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11876 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11877 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11878 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11879 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11880 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11881 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11882 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11883 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11884 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11885 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11886 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11887 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11888 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11889 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11890 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11891 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11892 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11893 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11894 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011895
11896 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11897 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11898 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11899 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11900 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11901 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11902 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11903 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11904 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11905 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11906 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11907 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11908 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11909 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11910 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11911 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11912 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11913 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11914 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11915 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11916 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11917 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11918 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11919 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11920 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11921 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11922 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11923 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11924 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11925 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11926 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11927 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11928 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11929 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11930 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11931 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11932 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11933 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11934 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11935 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11936 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11937 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11938 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11939 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11940 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11941 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11942 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11943 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11944 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11945 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11946 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11947 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11948 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11949 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11950 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11951 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11952 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11953 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11954 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11955 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11956 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11957 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11958 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11959 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11960 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11961 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11962 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011963 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11964 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11965 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011966 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11967 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011968 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11969 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11970 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011971
11972 /* BGP dampening clear commands */
11973 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11974 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11975 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11976 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11977
Paul Jakmaff7924f2006-09-04 01:10:36 +000011978 /* prefix count */
11979 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11980 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11981 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011982#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011983 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11984
paul718e3742002-12-13 20:15:29 +000011985 /* New config IPv6 BGP commands. */
11986 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11987 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011988 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011989 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11990 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011991 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011992
11993 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11994 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11995 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11996 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11997
11998 /* Old config IPv6 BGP commands. */
11999 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12000 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12001
12002 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12003 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12004 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12005 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12006
12007 install_element (VIEW_NODE, &show_bgp_cmd);
12008 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
12009 install_element (VIEW_NODE, &show_bgp_route_cmd);
12010 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
12011 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12012 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
12013 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12014 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12015 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12016 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12017 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12018 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12019 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12020 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12021 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12022 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12023 install_element (VIEW_NODE, &show_bgp_community_cmd);
12024 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12025 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12026 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12027 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12028 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12029 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12030 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12031 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12032 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12033 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12034 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12035 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12036 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12037 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12038 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12039 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12040 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12041 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12042 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12043 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12044 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12045 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12046 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12047 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12048 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12049 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12050 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12051 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12052 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012053 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12054 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12055 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12056 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012057 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
12058 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
12059 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012060 install_element (VIEW_NODE, &show_bgp_view_cmd);
12061 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12062 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12063 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12064 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12065 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12066 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12067 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12068 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12069 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12070 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12071 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12072 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12073 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12074 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12075 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12076 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12077 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012078 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
12079 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
12080 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012081
12082 /* Restricted:
12083 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12084 */
12085 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12086 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
12087 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12088 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
12089 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12090 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12091 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12092 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12093 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12094 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12095 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12096 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12097 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12098 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12099 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12100 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12101 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12102 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12103 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12104 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12105 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
12106 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
12107 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12108 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12109 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12110 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12111 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12112 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12113 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
12114 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012115
12116 install_element (ENABLE_NODE, &show_bgp_cmd);
12117 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
12118 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12119 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
12120 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12121 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
12122 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12123 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12124 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12125 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12126 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12127 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12128 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12129 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12130 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12131 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12132 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12133 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12134 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12135 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12136 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12137 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12138 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12139 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12140 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12141 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12142 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12143 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12144 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12145 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12146 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12147 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12148 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12149 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12150 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12151 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12152 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12153 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12154 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12155 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12156 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12157 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12158 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12159 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12160 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12161 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012162 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12163 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12164 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12165 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012166 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12167 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12168 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012169 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12170 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12171 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12172 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12173 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12174 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12175 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12176 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12177 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12178 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12179 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12180 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12181 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12182 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12183 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12184 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12185 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12186 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012187 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12188 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12189 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012190
12191 /* Statistics */
12192 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12193 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12194 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12195 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12196
paul718e3742002-12-13 20:15:29 +000012197 /* old command */
12198 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12199 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12200 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12201 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12202 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12203 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12204 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12205 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12206 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12207 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12208 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12209 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12210 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12211 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12212 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12213 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12214 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12215 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12216 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12217 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12218 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12219 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12220 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12221 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12222 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12223 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12224 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12225 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12226 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12227 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12228 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12229 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12230 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12231 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12232 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12233 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012234
paul718e3742002-12-13 20:15:29 +000012235 /* old command */
12236 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12237 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12238 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12239 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12240 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12241 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12242 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12243 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12244 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12245 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12246 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12247 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12248 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12249 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12250 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12251 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12252 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12253 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12254 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12255 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12256 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12257 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12258 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12259 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12260 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12261 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12262 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12263 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12264 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12265 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12266 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12267 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12268 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12269 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12270 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12271 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12272
12273 /* old command */
12274 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12275 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12276 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12277 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12278
12279 /* old command */
12280 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12281 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12282 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12283 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12284
12285 /* old command */
12286 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12287 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12288 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12289 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12290#endif /* HAVE_IPV6 */
12291
12292 install_element (BGP_NODE, &bgp_distance_cmd);
12293 install_element (BGP_NODE, &no_bgp_distance_cmd);
12294 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12295 install_element (BGP_NODE, &bgp_distance_source_cmd);
12296 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12297 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12298 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12299
12300 install_element (BGP_NODE, &bgp_damp_set_cmd);
12301 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12302 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12303 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12304 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12305 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12306 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12307 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12308 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12309 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12310}
Chris Caputo228da422009-07-18 05:44:03 +000012311
12312void
12313bgp_route_finish (void)
12314{
12315 bgp_table_unlock (bgp_distance_table);
12316 bgp_distance_table = NULL;
12317}